logos

With Andrii Grytsenko


Technical Diary - With Andrii Grytsenko

Perl debug

One of the perl debug way.

Perl module PadWalker is require. Install it over cpan util:

cpan -i PadWalker 

Let’s create simple script:

$cat ./hello.pl
#!/usr/bin/perl
sub say_hello {
my $what=shift;
print "Hello $what\n";
}

my $var1="var1";
my $var2="var2";
say_hello("you");
my $var3="var3";

And try to debug it:

$ perl -dF hello.pl
Loading DB routines from perl5db.pl version 1.31
Editor support available.Enter h or `h h' for help, or `man perldebug' for more help.main::(hello.pl:8):     say_hello("you");
DB<1>

type “h” to get help. To list a function use “l function_name”:

 DB<1> l say_hello
3       sub say_hello {
4:              my $what=shift;
5:              print "Hello $what\n";
6       }

To make step without entry to function use “n”. To go through function “s”

 DB<2> s
main::say_hello(hello.pl:4):            my $what=shift;

To return from subroutine use “r”.

use “y” to print all variables and their values or use “y variable” to print specific.

 DB<1> y
$var1 = 'var1'
$var2 = 'var2'

and

DB<1> y var1
$var1 = 'var1'

Options “M” print all used modules and path to them:

 DB<2> M
'AutoLoader.pm' => '5.67 from /usr/local/lib/perl5/5.8.9/AutoLoader.pm'
'Carp.pm' => '1.10 from /usr/local/lib/perl5/5.8.9/Carp.pm'
...

“R” – restart the scripts.

“V” – list variables

“S” – list subroutine

“q” – for exit

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Categories

Translate

Map IP Address

Map IP Address