Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run `x` command within a < action in the perl debugger?

Tags:

debugging

perl

I'd like to get a semicomplex structure to be output before displaying the prompt in the debugger. The best way to display it is to use the x command, but the command isn't available under that name or perhaps it's not in scope.

How would I accomplish this?

like image 456
Adrian Avatar asked Jan 06 '23 11:01

Adrian


1 Answers

See the documentation for < [command] in perldebug:

< [ command ]

Set an action (Perl command) to happen before every debugger prompt.

x is not a Perl command. You want { [command]:

{ [ command ]

Set an action (debugger command) to happen before every debugger prompt.

For example:

$ perl -de'$foo = { foo => "bar" };
           print $foo'

Loading DB routines from perl5db.pl version 1.37
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(-e:1):   $foo = { foo => "bar" };
  DB<1> { x $foo
  DB<2> n
main::(-e:2):   print $foo
auto(-1)  DB<2> x $foo
0  HASH(0x22af2c8)
   'foo' => 'bar'

Alternatively, use your favorite dumper module (e.g. Data::Dumper, Data::Dump, Data::Printer):

$ perl -de'$foo = { foo => "bar" };
           print $foo'

Loading DB routines from perl5db.pl version 1.37
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(-e:1):   $foo = { foo => "bar" };
  DB<1> use Data::Dumper

  DB<2> < print Dumper $foo
  DB<3> n
main::(-e:2):   print $foo
$VAR1 = {
          'foo' => 'bar'
        };
like image 52
ThisSuitIsBlackNot Avatar answered Jan 13 '23 15:01

ThisSuitIsBlackNot