Perl Deparse plugin for Devel::Trepan via B::DeparseTree
This adds deparse and deval commands to the Devel::Trepan debugger; deparse deparses Perl code; deval evaluates de-parsed Perl at the current point in the Perl program that you are stopped at.
Perl reports location only at the granularity of a line number. Sometimes you would like better or more precise information. For example suppose I am stopped on this line taken from File::Basename::fileparse:
if (grep { $type eq $_ } qw(MSDOS DOS MSWin32 Epoc)) { # ...
In a debugger, there happen to be to distinct locations in the code that you might be stopped in. The first place is before the grep starts at all. Here, deparse will show:
grep { $type eq $_; } 'MSDOS', 'DOS', 'MSWin32', 'Epoc'
But also you might be stopped inside grep. Here deparse will show:
$ deparse grepwhile, pushmark B::OP=SCALAR(0x563a8ab1c268) at address 0x563a871c07d0: if (grep { $type eq $_ } 'MSDOS', 'DOS', 'MSWin32', 'Epoc') { | # code to be run next...
The | indicates that a "pushmark" really doesn't have an exact correspondence in the source text, but roughly here it is about where you would just before stepping into the block. In partular variable $_ has not been set.
|
$_
But notice that when we step athough we are on the same line, we are at a different position in the statement:
step
$ step $ deparse (trepanpl): deparse not my, padsv B::OP=SCALAR(0x563a8abd51a8) at address 0x563a871c0a78: $type eq $_ -----
So now we are actually inside the block, and so $_ is now set. If the above wasn't enough context to indicate where you are the -p option on deparse will show you parent levels in the tree:
-p
(trepanpl): deparse -p 3
00 not my: $type - - - - - - - - - - - - - - - - - - - - 01 binary operator eq: $type eq $_ - - - - - - - - - - - - - - - - - - - - 02 statements: $type eq $_ - - - - - - - - - - - - - - - - - - - - 03 map grep block: grep { $type eq $_ } 'MSDOS', 'DOS', 'MSWin32', 'Epoc' (trepanpl): 00 not my: $type - - - - - - - - - - - - - - - - - - - - 01 binary operator eq: $type eq $_ - - - - - - - - - - - - - - - - - - - - 02 statements: $type eq $_ - - - - - - - - - - - - - - - - - - - - 03 map grep block: grep { $type eq $_ } 'MSDOS', 'DOS', 'MSWin32', 'Epoc' (trepanpl):
See Exact Perl location with B::Deparse (and Devel::Callsite).
Deparses Perl from interpreter OPs. See deparse for more information and command syntax.
deparse
This is somewhat like eval or eval? which evaluates the Perl code that is about to be run, but (when it works), it can be more reliable. Eval works on simple-minded string manipulation via regular expressions to pull out what to evaluate, whereas deval gets its information directly from the interpreter code.
eval
eval?
deval
See deval for more information and command syntax.
Rocky Bernstein
Copyright (C) 2015, 2018 Rocky Bernstein <rocky@cpan.org>
This program is distributed WITHOUT ANY WARRANTY, including but not limited to the implied warranties of merchantability or fitness for a particular purpose.
The program is free software. You may distribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation (either version 2 or any later version) and the Perl Artistic License as published by O'Reilly Media, Inc. Please open the files named gpl-2.0.txt and Artistic for a copy of these licenses.
To install Devel::Trepan::Deparse, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Devel::Trepan::Deparse
CPAN shell
perl -MCPAN -e shell install Devel::Trepan::Deparse
For more information on module installation, please visit the detailed CPAN module installation guide.