short introduction to "perl -d"

32
Basics of perl -d Steven Lembark Workhorse Computing [email protected]

Upload: workhorse-computing

Post on 20-Aug-2015

1.443 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Short Introduction To "perl -d"

Basics of perl -d

Steven LembarkWorkhorse Computinglembarkwrkhorscom

Introducing Perls Debugger

Overview of the obvious uses common commands Few less obvious uses

Debugging regexen Evaluating structure bloat

Some pitfalls and how to avoid them

What is the Perl Debugger

The Perl debugger comes with perl in fact it is perl shyd is built into perls command line It functions like a perly shell evaluating source code

from files or the command line or executing debugger commands

You also use perl shyd with profiling utilities like NYTprof

Smarter Than Your Average Code

The most obvious thing you can do is walking code to track down bugs

You can also test Perl syntax just type it in Use it as a ldquoperly shellrdquo when your oneshyliners run

into multiple lines or you have to eyeball data structures between commands

QampD interactive data mining Good for examining data structures when writing

talks on data manglement or module guts

The Basics Getting In

At the command line perl shyd enters the debugger

You can start it vanilla with modules to watch startup with code or using modules to pull in utilities (eg regex debugging)

$ perl shyd shye 42

$ perl shyd foopm

$ perl shyd bar

$ perl shyMDevelSize shyd shye foo

Basics The Prompt

Once in you get the command prompt$ perl shyd shye 42Loading DB routines from perl5dbpl version 122 Editor support availableEnter h or `h h for help or `man perldebug for more helpmain(shye1) 42DBlt1gt

This is a ldquovanillardquo session there is no running code you can enter debugger commands perl syntax

The single ldquolt1gtrdquo indicate that this is the outermost call level

The ldquo1rdquo says that this is the first command

Q Who remembers what localtime returns A How to find out

Notice that now Im at command 2

Executing Perl Statements

DBlt1gt x localtime0 311 312 153 154 55 1116 37 1658 1 DBlt2gt

Gotchas

Each command you type is run its own block Lexical variables like ldquomy $foordquo will vanish Local values like ldquolocal $rdquo or ldquolocal $foo bar = rdquo

will also be unavailable after the line completes

You can put multiple statements onto a line with semishycolon separators

You can only input one line at a time Cutshyandshypaste of multiple lines wont work

Debugger Commands

These intentionally look pretty much like gdb On the other hand if you didnt grow up debugging C

code this may not help you much

The most common commands are for running code managing breakpoints (ie stopping code) interrogating values

Please note ldquoqrdquo gets you out Not ldquoquitrdquo ^C ^D or ldquogetmeoutofhererdquo

You may want to edit your commands Installing TermReadKey ampTermReadLine perl will use your inputrc if you have one For example my inputrc looks like

with allows ^[k to pull up the last line for editing Check the docs if you use Emacs

Setting Up the Debugger

set editing-mode viset show-all-if-ambiguous on

Running Code

Say some code blows up You could just run it with ldquorrdquo from the start That is handy once to see where it blows up Usually you want to stop at a particular place to see

why it blows up You can continue to a line no or sub name with

c 15

c call_foomatic

Stepping Code

You can also watch the code one line at a time ldquonrdquo (ldquonextrdquo) steps over the subroutine calls

ldquosrdquo (ldquosteprdquo) steps into the subroutine calls

ldquorrdquo (ldquoreturnrdquo) goes back to the caller if you accidentally step one level too deep

One really common combination ldquocrdquo to a subroutine that blows up

ldquonrdquo to the point before it dies

ldquosrdquo into the call that failed and see what happens

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 2: Short Introduction To "perl -d"

Introducing Perls Debugger

Overview of the obvious uses common commands Few less obvious uses

Debugging regexen Evaluating structure bloat

Some pitfalls and how to avoid them

What is the Perl Debugger

The Perl debugger comes with perl in fact it is perl shyd is built into perls command line It functions like a perly shell evaluating source code

from files or the command line or executing debugger commands

You also use perl shyd with profiling utilities like NYTprof

Smarter Than Your Average Code

The most obvious thing you can do is walking code to track down bugs

You can also test Perl syntax just type it in Use it as a ldquoperly shellrdquo when your oneshyliners run

into multiple lines or you have to eyeball data structures between commands

QampD interactive data mining Good for examining data structures when writing

talks on data manglement or module guts

The Basics Getting In

At the command line perl shyd enters the debugger

You can start it vanilla with modules to watch startup with code or using modules to pull in utilities (eg regex debugging)

$ perl shyd shye 42

$ perl shyd foopm

$ perl shyd bar

$ perl shyMDevelSize shyd shye foo

Basics The Prompt

Once in you get the command prompt$ perl shyd shye 42Loading DB routines from perl5dbpl version 122 Editor support availableEnter h or `h h for help or `man perldebug for more helpmain(shye1) 42DBlt1gt

This is a ldquovanillardquo session there is no running code you can enter debugger commands perl syntax

The single ldquolt1gtrdquo indicate that this is the outermost call level

The ldquo1rdquo says that this is the first command

Q Who remembers what localtime returns A How to find out

Notice that now Im at command 2

Executing Perl Statements

DBlt1gt x localtime0 311 312 153 154 55 1116 37 1658 1 DBlt2gt

Gotchas

Each command you type is run its own block Lexical variables like ldquomy $foordquo will vanish Local values like ldquolocal $rdquo or ldquolocal $foo bar = rdquo

will also be unavailable after the line completes

You can put multiple statements onto a line with semishycolon separators

You can only input one line at a time Cutshyandshypaste of multiple lines wont work

Debugger Commands

These intentionally look pretty much like gdb On the other hand if you didnt grow up debugging C

code this may not help you much

The most common commands are for running code managing breakpoints (ie stopping code) interrogating values

Please note ldquoqrdquo gets you out Not ldquoquitrdquo ^C ^D or ldquogetmeoutofhererdquo

You may want to edit your commands Installing TermReadKey ampTermReadLine perl will use your inputrc if you have one For example my inputrc looks like

with allows ^[k to pull up the last line for editing Check the docs if you use Emacs

Setting Up the Debugger

set editing-mode viset show-all-if-ambiguous on

Running Code

Say some code blows up You could just run it with ldquorrdquo from the start That is handy once to see where it blows up Usually you want to stop at a particular place to see

why it blows up You can continue to a line no or sub name with

c 15

c call_foomatic

Stepping Code

You can also watch the code one line at a time ldquonrdquo (ldquonextrdquo) steps over the subroutine calls

ldquosrdquo (ldquosteprdquo) steps into the subroutine calls

ldquorrdquo (ldquoreturnrdquo) goes back to the caller if you accidentally step one level too deep

One really common combination ldquocrdquo to a subroutine that blows up

ldquonrdquo to the point before it dies

ldquosrdquo into the call that failed and see what happens

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 3: Short Introduction To "perl -d"

What is the Perl Debugger

The Perl debugger comes with perl in fact it is perl shyd is built into perls command line It functions like a perly shell evaluating source code

from files or the command line or executing debugger commands

You also use perl shyd with profiling utilities like NYTprof

Smarter Than Your Average Code

The most obvious thing you can do is walking code to track down bugs

You can also test Perl syntax just type it in Use it as a ldquoperly shellrdquo when your oneshyliners run

into multiple lines or you have to eyeball data structures between commands

QampD interactive data mining Good for examining data structures when writing

talks on data manglement or module guts

The Basics Getting In

At the command line perl shyd enters the debugger

You can start it vanilla with modules to watch startup with code or using modules to pull in utilities (eg regex debugging)

$ perl shyd shye 42

$ perl shyd foopm

$ perl shyd bar

$ perl shyMDevelSize shyd shye foo

Basics The Prompt

Once in you get the command prompt$ perl shyd shye 42Loading DB routines from perl5dbpl version 122 Editor support availableEnter h or `h h for help or `man perldebug for more helpmain(shye1) 42DBlt1gt

This is a ldquovanillardquo session there is no running code you can enter debugger commands perl syntax

The single ldquolt1gtrdquo indicate that this is the outermost call level

The ldquo1rdquo says that this is the first command

Q Who remembers what localtime returns A How to find out

Notice that now Im at command 2

Executing Perl Statements

DBlt1gt x localtime0 311 312 153 154 55 1116 37 1658 1 DBlt2gt

Gotchas

Each command you type is run its own block Lexical variables like ldquomy $foordquo will vanish Local values like ldquolocal $rdquo or ldquolocal $foo bar = rdquo

will also be unavailable after the line completes

You can put multiple statements onto a line with semishycolon separators

You can only input one line at a time Cutshyandshypaste of multiple lines wont work

Debugger Commands

These intentionally look pretty much like gdb On the other hand if you didnt grow up debugging C

code this may not help you much

The most common commands are for running code managing breakpoints (ie stopping code) interrogating values

Please note ldquoqrdquo gets you out Not ldquoquitrdquo ^C ^D or ldquogetmeoutofhererdquo

You may want to edit your commands Installing TermReadKey ampTermReadLine perl will use your inputrc if you have one For example my inputrc looks like

with allows ^[k to pull up the last line for editing Check the docs if you use Emacs

Setting Up the Debugger

set editing-mode viset show-all-if-ambiguous on

Running Code

Say some code blows up You could just run it with ldquorrdquo from the start That is handy once to see where it blows up Usually you want to stop at a particular place to see

why it blows up You can continue to a line no or sub name with

c 15

c call_foomatic

Stepping Code

You can also watch the code one line at a time ldquonrdquo (ldquonextrdquo) steps over the subroutine calls

ldquosrdquo (ldquosteprdquo) steps into the subroutine calls

ldquorrdquo (ldquoreturnrdquo) goes back to the caller if you accidentally step one level too deep

One really common combination ldquocrdquo to a subroutine that blows up

ldquonrdquo to the point before it dies

ldquosrdquo into the call that failed and see what happens

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 4: Short Introduction To "perl -d"

Smarter Than Your Average Code

The most obvious thing you can do is walking code to track down bugs

You can also test Perl syntax just type it in Use it as a ldquoperly shellrdquo when your oneshyliners run

into multiple lines or you have to eyeball data structures between commands

QampD interactive data mining Good for examining data structures when writing

talks on data manglement or module guts

The Basics Getting In

At the command line perl shyd enters the debugger

You can start it vanilla with modules to watch startup with code or using modules to pull in utilities (eg regex debugging)

$ perl shyd shye 42

$ perl shyd foopm

$ perl shyd bar

$ perl shyMDevelSize shyd shye foo

Basics The Prompt

Once in you get the command prompt$ perl shyd shye 42Loading DB routines from perl5dbpl version 122 Editor support availableEnter h or `h h for help or `man perldebug for more helpmain(shye1) 42DBlt1gt

This is a ldquovanillardquo session there is no running code you can enter debugger commands perl syntax

The single ldquolt1gtrdquo indicate that this is the outermost call level

The ldquo1rdquo says that this is the first command

Q Who remembers what localtime returns A How to find out

Notice that now Im at command 2

Executing Perl Statements

DBlt1gt x localtime0 311 312 153 154 55 1116 37 1658 1 DBlt2gt

Gotchas

Each command you type is run its own block Lexical variables like ldquomy $foordquo will vanish Local values like ldquolocal $rdquo or ldquolocal $foo bar = rdquo

will also be unavailable after the line completes

You can put multiple statements onto a line with semishycolon separators

You can only input one line at a time Cutshyandshypaste of multiple lines wont work

Debugger Commands

These intentionally look pretty much like gdb On the other hand if you didnt grow up debugging C

code this may not help you much

The most common commands are for running code managing breakpoints (ie stopping code) interrogating values

Please note ldquoqrdquo gets you out Not ldquoquitrdquo ^C ^D or ldquogetmeoutofhererdquo

You may want to edit your commands Installing TermReadKey ampTermReadLine perl will use your inputrc if you have one For example my inputrc looks like

with allows ^[k to pull up the last line for editing Check the docs if you use Emacs

Setting Up the Debugger

set editing-mode viset show-all-if-ambiguous on

Running Code

Say some code blows up You could just run it with ldquorrdquo from the start That is handy once to see where it blows up Usually you want to stop at a particular place to see

why it blows up You can continue to a line no or sub name with

c 15

c call_foomatic

Stepping Code

You can also watch the code one line at a time ldquonrdquo (ldquonextrdquo) steps over the subroutine calls

ldquosrdquo (ldquosteprdquo) steps into the subroutine calls

ldquorrdquo (ldquoreturnrdquo) goes back to the caller if you accidentally step one level too deep

One really common combination ldquocrdquo to a subroutine that blows up

ldquonrdquo to the point before it dies

ldquosrdquo into the call that failed and see what happens

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 5: Short Introduction To "perl -d"

The Basics Getting In

At the command line perl shyd enters the debugger

You can start it vanilla with modules to watch startup with code or using modules to pull in utilities (eg regex debugging)

$ perl shyd shye 42

$ perl shyd foopm

$ perl shyd bar

$ perl shyMDevelSize shyd shye foo

Basics The Prompt

Once in you get the command prompt$ perl shyd shye 42Loading DB routines from perl5dbpl version 122 Editor support availableEnter h or `h h for help or `man perldebug for more helpmain(shye1) 42DBlt1gt

This is a ldquovanillardquo session there is no running code you can enter debugger commands perl syntax

The single ldquolt1gtrdquo indicate that this is the outermost call level

The ldquo1rdquo says that this is the first command

Q Who remembers what localtime returns A How to find out

Notice that now Im at command 2

Executing Perl Statements

DBlt1gt x localtime0 311 312 153 154 55 1116 37 1658 1 DBlt2gt

Gotchas

Each command you type is run its own block Lexical variables like ldquomy $foordquo will vanish Local values like ldquolocal $rdquo or ldquolocal $foo bar = rdquo

will also be unavailable after the line completes

You can put multiple statements onto a line with semishycolon separators

You can only input one line at a time Cutshyandshypaste of multiple lines wont work

Debugger Commands

These intentionally look pretty much like gdb On the other hand if you didnt grow up debugging C

code this may not help you much

The most common commands are for running code managing breakpoints (ie stopping code) interrogating values

Please note ldquoqrdquo gets you out Not ldquoquitrdquo ^C ^D or ldquogetmeoutofhererdquo

You may want to edit your commands Installing TermReadKey ampTermReadLine perl will use your inputrc if you have one For example my inputrc looks like

with allows ^[k to pull up the last line for editing Check the docs if you use Emacs

Setting Up the Debugger

set editing-mode viset show-all-if-ambiguous on

Running Code

Say some code blows up You could just run it with ldquorrdquo from the start That is handy once to see where it blows up Usually you want to stop at a particular place to see

why it blows up You can continue to a line no or sub name with

c 15

c call_foomatic

Stepping Code

You can also watch the code one line at a time ldquonrdquo (ldquonextrdquo) steps over the subroutine calls

ldquosrdquo (ldquosteprdquo) steps into the subroutine calls

ldquorrdquo (ldquoreturnrdquo) goes back to the caller if you accidentally step one level too deep

One really common combination ldquocrdquo to a subroutine that blows up

ldquonrdquo to the point before it dies

ldquosrdquo into the call that failed and see what happens

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 6: Short Introduction To "perl -d"

Basics The Prompt

Once in you get the command prompt$ perl shyd shye 42Loading DB routines from perl5dbpl version 122 Editor support availableEnter h or `h h for help or `man perldebug for more helpmain(shye1) 42DBlt1gt

This is a ldquovanillardquo session there is no running code you can enter debugger commands perl syntax

The single ldquolt1gtrdquo indicate that this is the outermost call level

The ldquo1rdquo says that this is the first command

Q Who remembers what localtime returns A How to find out

Notice that now Im at command 2

Executing Perl Statements

DBlt1gt x localtime0 311 312 153 154 55 1116 37 1658 1 DBlt2gt

Gotchas

Each command you type is run its own block Lexical variables like ldquomy $foordquo will vanish Local values like ldquolocal $rdquo or ldquolocal $foo bar = rdquo

will also be unavailable after the line completes

You can put multiple statements onto a line with semishycolon separators

You can only input one line at a time Cutshyandshypaste of multiple lines wont work

Debugger Commands

These intentionally look pretty much like gdb On the other hand if you didnt grow up debugging C

code this may not help you much

The most common commands are for running code managing breakpoints (ie stopping code) interrogating values

Please note ldquoqrdquo gets you out Not ldquoquitrdquo ^C ^D or ldquogetmeoutofhererdquo

You may want to edit your commands Installing TermReadKey ampTermReadLine perl will use your inputrc if you have one For example my inputrc looks like

with allows ^[k to pull up the last line for editing Check the docs if you use Emacs

Setting Up the Debugger

set editing-mode viset show-all-if-ambiguous on

Running Code

Say some code blows up You could just run it with ldquorrdquo from the start That is handy once to see where it blows up Usually you want to stop at a particular place to see

why it blows up You can continue to a line no or sub name with

c 15

c call_foomatic

Stepping Code

You can also watch the code one line at a time ldquonrdquo (ldquonextrdquo) steps over the subroutine calls

ldquosrdquo (ldquosteprdquo) steps into the subroutine calls

ldquorrdquo (ldquoreturnrdquo) goes back to the caller if you accidentally step one level too deep

One really common combination ldquocrdquo to a subroutine that blows up

ldquonrdquo to the point before it dies

ldquosrdquo into the call that failed and see what happens

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 7: Short Introduction To "perl -d"

Q Who remembers what localtime returns A How to find out

Notice that now Im at command 2

Executing Perl Statements

DBlt1gt x localtime0 311 312 153 154 55 1116 37 1658 1 DBlt2gt

Gotchas

Each command you type is run its own block Lexical variables like ldquomy $foordquo will vanish Local values like ldquolocal $rdquo or ldquolocal $foo bar = rdquo

will also be unavailable after the line completes

You can put multiple statements onto a line with semishycolon separators

You can only input one line at a time Cutshyandshypaste of multiple lines wont work

Debugger Commands

These intentionally look pretty much like gdb On the other hand if you didnt grow up debugging C

code this may not help you much

The most common commands are for running code managing breakpoints (ie stopping code) interrogating values

Please note ldquoqrdquo gets you out Not ldquoquitrdquo ^C ^D or ldquogetmeoutofhererdquo

You may want to edit your commands Installing TermReadKey ampTermReadLine perl will use your inputrc if you have one For example my inputrc looks like

with allows ^[k to pull up the last line for editing Check the docs if you use Emacs

Setting Up the Debugger

set editing-mode viset show-all-if-ambiguous on

Running Code

Say some code blows up You could just run it with ldquorrdquo from the start That is handy once to see where it blows up Usually you want to stop at a particular place to see

why it blows up You can continue to a line no or sub name with

c 15

c call_foomatic

Stepping Code

You can also watch the code one line at a time ldquonrdquo (ldquonextrdquo) steps over the subroutine calls

ldquosrdquo (ldquosteprdquo) steps into the subroutine calls

ldquorrdquo (ldquoreturnrdquo) goes back to the caller if you accidentally step one level too deep

One really common combination ldquocrdquo to a subroutine that blows up

ldquonrdquo to the point before it dies

ldquosrdquo into the call that failed and see what happens

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 8: Short Introduction To "perl -d"

Gotchas

Each command you type is run its own block Lexical variables like ldquomy $foordquo will vanish Local values like ldquolocal $rdquo or ldquolocal $foo bar = rdquo

will also be unavailable after the line completes

You can put multiple statements onto a line with semishycolon separators

You can only input one line at a time Cutshyandshypaste of multiple lines wont work

Debugger Commands

These intentionally look pretty much like gdb On the other hand if you didnt grow up debugging C

code this may not help you much

The most common commands are for running code managing breakpoints (ie stopping code) interrogating values

Please note ldquoqrdquo gets you out Not ldquoquitrdquo ^C ^D or ldquogetmeoutofhererdquo

You may want to edit your commands Installing TermReadKey ampTermReadLine perl will use your inputrc if you have one For example my inputrc looks like

with allows ^[k to pull up the last line for editing Check the docs if you use Emacs

Setting Up the Debugger

set editing-mode viset show-all-if-ambiguous on

Running Code

Say some code blows up You could just run it with ldquorrdquo from the start That is handy once to see where it blows up Usually you want to stop at a particular place to see

why it blows up You can continue to a line no or sub name with

c 15

c call_foomatic

Stepping Code

You can also watch the code one line at a time ldquonrdquo (ldquonextrdquo) steps over the subroutine calls

ldquosrdquo (ldquosteprdquo) steps into the subroutine calls

ldquorrdquo (ldquoreturnrdquo) goes back to the caller if you accidentally step one level too deep

One really common combination ldquocrdquo to a subroutine that blows up

ldquonrdquo to the point before it dies

ldquosrdquo into the call that failed and see what happens

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 9: Short Introduction To "perl -d"

Debugger Commands

These intentionally look pretty much like gdb On the other hand if you didnt grow up debugging C

code this may not help you much

The most common commands are for running code managing breakpoints (ie stopping code) interrogating values

Please note ldquoqrdquo gets you out Not ldquoquitrdquo ^C ^D or ldquogetmeoutofhererdquo

You may want to edit your commands Installing TermReadKey ampTermReadLine perl will use your inputrc if you have one For example my inputrc looks like

with allows ^[k to pull up the last line for editing Check the docs if you use Emacs

Setting Up the Debugger

set editing-mode viset show-all-if-ambiguous on

Running Code

Say some code blows up You could just run it with ldquorrdquo from the start That is handy once to see where it blows up Usually you want to stop at a particular place to see

why it blows up You can continue to a line no or sub name with

c 15

c call_foomatic

Stepping Code

You can also watch the code one line at a time ldquonrdquo (ldquonextrdquo) steps over the subroutine calls

ldquosrdquo (ldquosteprdquo) steps into the subroutine calls

ldquorrdquo (ldquoreturnrdquo) goes back to the caller if you accidentally step one level too deep

One really common combination ldquocrdquo to a subroutine that blows up

ldquonrdquo to the point before it dies

ldquosrdquo into the call that failed and see what happens

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 10: Short Introduction To "perl -d"

You may want to edit your commands Installing TermReadKey ampTermReadLine perl will use your inputrc if you have one For example my inputrc looks like

with allows ^[k to pull up the last line for editing Check the docs if you use Emacs

Setting Up the Debugger

set editing-mode viset show-all-if-ambiguous on

Running Code

Say some code blows up You could just run it with ldquorrdquo from the start That is handy once to see where it blows up Usually you want to stop at a particular place to see

why it blows up You can continue to a line no or sub name with

c 15

c call_foomatic

Stepping Code

You can also watch the code one line at a time ldquonrdquo (ldquonextrdquo) steps over the subroutine calls

ldquosrdquo (ldquosteprdquo) steps into the subroutine calls

ldquorrdquo (ldquoreturnrdquo) goes back to the caller if you accidentally step one level too deep

One really common combination ldquocrdquo to a subroutine that blows up

ldquonrdquo to the point before it dies

ldquosrdquo into the call that failed and see what happens

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 11: Short Introduction To "perl -d"

Running Code

Say some code blows up You could just run it with ldquorrdquo from the start That is handy once to see where it blows up Usually you want to stop at a particular place to see

why it blows up You can continue to a line no or sub name with

c 15

c call_foomatic

Stepping Code

You can also watch the code one line at a time ldquonrdquo (ldquonextrdquo) steps over the subroutine calls

ldquosrdquo (ldquosteprdquo) steps into the subroutine calls

ldquorrdquo (ldquoreturnrdquo) goes back to the caller if you accidentally step one level too deep

One really common combination ldquocrdquo to a subroutine that blows up

ldquonrdquo to the point before it dies

ldquosrdquo into the call that failed and see what happens

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 12: Short Introduction To "perl -d"

Stepping Code

You can also watch the code one line at a time ldquonrdquo (ldquonextrdquo) steps over the subroutine calls

ldquosrdquo (ldquosteprdquo) steps into the subroutine calls

ldquorrdquo (ldquoreturnrdquo) goes back to the caller if you accidentally step one level too deep

One really common combination ldquocrdquo to a subroutine that blows up

ldquonrdquo to the point before it dies

ldquosrdquo into the call that failed and see what happens

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 13: Short Introduction To "perl -d"

Getting Out of a Hole ldquorrdquo

Sometimes you s into the wrong sub (say a DBI call) You dont want to abort the session You dont want to ldquonrdquo your way through DBI Use ldquorrdquo to return from the current call

This also shows you the return value passed back to the caller Nice for checking that what you expect gets returned Beware if the structure is really large

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 14: Short Introduction To "perl -d"

Stopping Code Breakpoints

Breakpoints stop the code They can include a condition Say the code blows up at line 842 with a nonshy

reference value in $thingy after roughly 8_000 iterations

Set a breakpoint and continue

lt1gt b 842 ref $thingy

lt2gt c

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 15: Short Introduction To "perl -d"

Examining Values ldquoprdquo prints a value

ldquoxrdquo examines it (similar to DataDumper)

DBlt6gt p a = map $_ =gt [ 1 ] ( a c )aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

DBlt7gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc12060) 0 12 b3 ARRAY(0xc11dc0) 0 14 c5 ARRAY(0xc0e1d8) 0 1

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 16: Short Introduction To "perl -d"

Hashes look a little odd at first

They look exactly like the array a list

Hashes Are Lists to ldquoxrdquo

DBlt8gt x a = map $_ =gt [ 1 ] ( a c )0 a1 ARRAY(0xc122a0) 0 12 b3 ARRAY(0xb07fe0) 0 14 c5 ARRAY(0xc122e8) 0 1

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 17: Short Introduction To "perl -d"

Hashrefs Are Structures

Examining a hashref shows it as key =gt value pairs

DBlt9gt x a0 HASH(0xc47008) a =gt ARRAY(0xc122a0) 0 1 b =gt ARRAY(0xb07fe0) 0 1 c =gt ARRAY(0xc122e8) 0 1

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 18: Short Introduction To "perl -d"

Occasionally youll get something like

This was a structure that didnt fit onto the screen Use ldquoxrdquo with a limit to display less of it

You Dont Always Want It All

0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DBlt17gt

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 19: Short Introduction To "perl -d"

Getting What You Need

A digit following ldquoxrdquo limits the depthDBlt26gt $i = zDBlt27gt $a = $b = []DBlt28gt for( 1 100 ) $b = $b-gt[0] = [] $b-gt[1] = ++$i DBlt29gt x 6 $a0 ARRAY(0xc90e38) 0 ARRAY(0xc917f8) 0 ARRAY(0xc988e8) 0 ARRAY(0xc98af8) 0 ARRAY(0xc98a20) 0 ARRAY(0xc98b10) 1 ad 1 ac 1 ab 1 aa

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 20: Short Introduction To "perl -d"

Mining Large Data Structures

x 2 $struct will show the top level including hash keys or offset lists

x 2 $structshygt key will show the single hash value To walk through a structure in viewable chunks

x 2 $structshygt key1 key2 See what matters paste on the next keyoffset and keep

looking x 2 $structshygt key1 key2 [ offset ]

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 21: Short Introduction To "perl -d"

You Are Here

The ldquoTrdquo command provides a stack trace Useful with hardwired breakpoints They show the calling line numbers and values Makes it easier to set breakpoints up the stack to see how

values are [misshy]managed down the call stack

Viewing the code uses ldquolrdquo and ldquovrdquo ldquolrdquo (list) shows the next line to be executed ldquovrdquo (view) shows a small window around the line

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 22: Short Introduction To "perl -d"

Finding Out What You Can Do

ldquomrdquo shows the methods of an object

Items with package prefixes are inherited

Leading ( is an overload

35 my $frag36 = WCurveFragment-gtnew37 (38 FloatCyl =gt ( $base x $length ) $name39 ) DBlt1gt nTestify(01-FloatCart-basic-geometryt41)41 ok $frag eq $name Name $frag ($name) DBlt1gt m $fragadd_skip_chaincarpconfessconverge_limitlooks_like_number

via WCurveFragment (via WCurveFragment ()via WCurveFragment (0+via WCurveFragment (boolvia WCurveFragment (intvia WCurveFragment stop_offset

via WCurveFragment sumvia WCurveFragment -gt ArrayObj (lt=gtvia WCurveFragment -gt ArrayObj (cmpvia WCurveFragment -gt ArrayObj DESTROY

via UNIVERSAL DOESvia UNIVERSAL VERSIONvia UNIVERSAL canvia UNIVERSAL isa

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 23: Short Introduction To "perl -d"

Hardwired Breakpoints

Because the perl debugger is written in perl you can also set ldquohardwiredrdquo breakpoints

$DBsingle = 1

$DBsingle = 1 unless ref $thingy

$DBsingle = 1 if $counter gt itemz

These can be useful in permanent code

eval hellip

or do

print $ $DBsingle = 1 0

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 24: Short Introduction To "perl -d"

Tracing Code

Tracing code usually produces too much output To turn on tracing use $DBtrace = 1

You can localize it to trace a code block Add ifshylogic to trace code leading up to errors$DBtrace = 1 if ref $foo

One trick for reshystartable subs is to eval them and trace the failures

eval foo or do trace = 1 foo

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 25: Short Introduction To "perl -d"

Ever Wonder How a Regex Works

The ldquorerdquo module allows debugging regexen

use re debug

use re debugcolor

There is more info in ldquoperldoc perldebugrdquo A monochrome example

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 26: Short Introduction To "perl -d"

DBlt7gt do use re debug $a = qr (w+) $x print this is a test =~ $a Compiling REx (w+) $Final program 1 OPEN1 (3) 3 PLUS (5) 4 ALNUM (0) 5 CLOSE1 (7) 7 EOL (8) 8 END (0)floating $ at 12147483647 (checking floating) stclass ALNUM plus minlen 1Guessing start of match in sv for REx (w+) $ against this is a testFound floating substr $ at offset 14start_shift 1 check_at 14 s 0 endpos 14Does not contradict STCLASSGuessed match at offset 0Matching REx (w+) $ against this is a testMatching stclass ALNUM against this is a test (14 chars) 0 ltthis is a gt| 1OPEN1(3) 0 ltthis is a gt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 4 ltthis is a testgt| 5 CLOSE1(7) 4 ltthis is a testgt| 7 EOL(8) failed 1 ltthis is a tgt| 5 CLOSE1(7) 1 ltthis is a tgt| 7 EOL(8) 7 ltthis is a testgt| 5 CLOSE1(7) 7 ltthis is a testgt| 7 EOL(8) failed 10 ltthis is a testgt| 3PLUS(5) ALNUM can match 4 times out of 2147483647 14 ltthis is a testgt| 5 CLOSE1(7) 14 ltthis is a testgt| 7 EOL(8) 14 ltthis is a testgt| 8 END(0)Match successfultest DBlt8gt

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 27: Short Introduction To "perl -d"

Benchmarking Size

DevelPeek ampamp DevelSize show the contents and size of structures inside of perl

There are lots of examples in Perl Memory Manglement which is mostly a session of

perl -MdevelSize -d -e 0

The advantage to dealing with this in the debugger is being able to interactively query the sizes of subshystructures to see where bloat comes from

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 28: Short Introduction To "perl -d"

Knowing When Youre There

The variable $^P will be true when code is running in the debugger

This allows you to automatically set hardwired breakpoints or verbositymy $max_verbose = $cmdline verbose gt 1 || $^P

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 29: Short Introduction To "perl -d"

Spoon Feeding

The debugger does not handle forks automatically The problem is that multiple processes latch on to the tty

device files for input and output You can set the display to a set of pershyinitialized ttys

(usually preshyopened xterms) At that point you can switch to the alternate terminals to

handle each session

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 30: Short Introduction To "perl -d"

Semishyautomated Forks

You can usually dodge the issue by simply not forking in the debugger

if( my $pid = $^P fork ) parentelsif( defined $pid ) child debuggerelse die Phorkafobia $

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 31: Short Introduction To "perl -d"

A Modern Version

given( $^P fork ) when( ) when( undef ) die Phorkafobia $

my $child = wait

parent processes results

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32
Page 32: Short Introduction To "perl -d"

Further Reference

A always perldoc is your friend perldoc perldebug perldoc perlre Perldoc DB

For examples of querying memory use perldoc DevelPeek perldoc DevelSize httpwwwslidesharenetlembarkperl5shymemorymanglement

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
  • Slide 28
  • Slide 29
  • Slide 30
  • Slide 31
  • Slide 32