in reply to Re^2: RFC: Location via B::Deparse
in thread RFC: Location via B::Deparse

Devel::Trepan 0.70 has just been released. In it, the deparse command will use the current location to deparse. This does handle multiple statements on a single line, inside a subroutine. (I haven't been able to figure out how to get this to work in the main program.)

Just to get this done, I needed to monkeypatch B::Deparse and add some other routines that probably should in another package somewhere.

In order to be able to figure out the exact location in a callsite, e.g.

fib($x-1) + fib($x-2)
addresses in showing the call stack and are recorded in the stack in the 0.70 release. I beefed up Devel::Trepan::Disassemble and made a release of that too. The basic idea here is you disassemble the surrounding context to reconstruct the fragment of code. (The call location is marked with an arrow automatically if that is found.)

Better though would be more changes to B::Deparse so that you can pass it an opcode location and it deparse around that. Also, I'd like to see more COP instructions added say found for loops of the 3-part kind: initialize, test and increment.

As with other science and engineering, the more you do, the more you realize there is to do. I may beef up B::CodeLines so that it notes which lines have multiple statements in them.

Finally, I observe that providing really good debugging support, not just in Perl but other languages as well, is often really hard and strays way outside of the "debugger" proper. I think that's one reason you don't find things like this often in debuggers.

Replies are listed 'Best First'.
Re^4: RFC: Location via B::Deparse
by rockyb (Scribe) on Nov 11, 2015 at 17:16 UTC

    An update on where things stand now...

    Github now has modified code to save deparsed text fragments and more of an abstract runtime tree structure. I've moved the "deparse" command in Devel::Trepan out, since this now uses this cooler code, B::Deparsetree, which is not part of the core Perl distribution, and only works right now for versions 5.20 and 5.22.

    At some point I'll package these for CPAN and make a new release of Devel::Trepan. There still are lots of bugs and improvements that could be made in in B::DeparseTree: B::Deparse which it is based on has thousands of tests, and I tried merely a single thousand or so of these. And B::Deparse with these still has bugs based on trying run it against the core Perl tests.

    This was an incredible time sink. But I think it really cool. Things like Carp::Confess and callstack routines could be beefed up to give more information about the source at a failure.