SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
Basics of perl -d

   Steven Lembark
Workhorse Computing
lembark@wrkhors.com
Introducing Perl's 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.
●   '­d' is built into perl's 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 ­d 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 “perly shell” when your one­liners run 
    into multiple lines or you have to eyeball data 
    structures  between commands.
●   Q&D interactive data mining.
●   Good for examining data structures when writing 
    talks on data manglement or module guts.
The Basics: Getting In
●   At the command          $ perl ­d ­e 42;
    line: perl ­d enters    $ perl ­d foo.pm;
    the debugger.
                            $ perl ­d bar;
●   You can start it 
    'vanilla', with          $ perl ­MDevel::Size ­d ­e foo;
    modules to watch 
    startup, with code, 
    or using modules to 
    pull in utilities (e.g. 
    regex debugging).
Basics: The Prompt
●   Once in you get the command prompt:
    $ perl ­d ­e 42
    Loading DB routines from perl5db.pl version 1.22 
    Editor support available.
    Enter h or `h h' for help, or `man perldebug' for more help.
    main::(­e:1):   42
    DB<1>

●   This is a “vanilla” session: there is no running code, 
    you can enter debugger commands, perl syntax.
●   The single “<1>” indicate that this is the outermost 
    call level.
●   The “1” says that this is the first command.
Executing Perl Statements
●   Q: Who remembers what localtime returns?
●   A: How to find out?
     DB<1> x
    localtime
    0 31
    1 31
    2 15
    3 15
    4 5
    5 111
    6 3
    7 165
    8 1
     DB<2>
●   Notice that now I'm at command #2.
Gotchas
●   Each command you type is run its own block.
    ●   Lexical variables like “my $foo” will vanish.
    ●   Local values like “local $” or “local $foo{ bar } = ...” 
        will also be unavailable after the line completes.
●   You can put multiple statements onto a line with 
    semi­colon separators.
●   You can only input one line at a time.
    ●   Cut­and­paste of multiple lines won't work.
Debugger Commands
●   These intentionally look pretty much like gdb.
    ●   On the other hand, if you didn't grow up debugging C 
        code this may not help you much.
●   The most common commands are for running code, 
    managing breakpoints (i.e. stopping code), 
    interrogating values.
●   Please note: “q” gets you out.
    ●   Not “quit”, ^C, ^D, or “getmeoutofhere!”.
Setting Up the Debugger
●   You may want to edit your commands.
●   Installing Term::ReadKey &Term::ReadLine.
●   perl will use your .inputrc if you have one.
●   For example, my .inputrc looks like:
    set editing-mode vi
    set show-all-if-ambiguous on
    with allows ^[k to pull up the last line for editing.
●   Check the doc's if you use Emacs.
Running Code
●   Say some code blows up.
●   You could just run it with “r” 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.
    ●   “n” (“next”) steps over the subroutine calls.
    ●   “s” (“step”) steps into the subroutine calls. 
    ●   “r” (“return”) goes back to the caller if you accidentally 
        step one level too deep.
●   One really common combination: 
    ●   “c” to a subroutine that blows up.
    ●   “n” to the point before it dies.
    ●   “s” into the call that failed and see what happens.
Getting Out of a Hole: “r”
●   Sometimes you 's' into the wrong sub (say a DBI 
    call).
    ●   You don't want to abort the session.
    ●   You don't want to “n” your way through DBI.
    ●   Use “r” 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 non­
    reference value in $thingy after roughly 8_000 
    iterations.
●   Set a breakpoint and continue:
      <1> b 842 ! ref $thingy
      <2> c
Examining Values
●   “p” prints a value.
●   “x” examines it (similar to Data::Dumper).
  DB<6> p @a = map { $_ => [ 1 ] } ( 'a' .. 'c' )
aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0)

    DB<7> x @a = map { $_ => [ 1 ] } ( 'a' .. 'c' )
0    'a'
1    ARRAY(0xc12060)
     0 1
2    'b'
3    ARRAY(0xc11dc0)
     0 1
4    'c'
5    ARRAY(0xc0e1d8)
     0 1
Hashes Are Lists to “x”
●   Hashes look a little odd at first:
        DB<8> x %a = map { $_ => [ 1 ] } ( 'a' .. 'c' )
    0    'a'
    1    ARRAY(0xc122a0)
         0 1
    2    'b'
    3    ARRAY(0xb07fe0)
         0 1
    4    'c'
    5    ARRAY(0xc122e8)
         0 1

●   They look exactly like the array: a list.
Hashref's Are Structures
●   Examining a hashref shows it as key => value pairs:
      DB<9> x %a
    0 HASH(0xc47008)
       'a' => ARRAY(0xc122a0)
          0 1
       'b' => ARRAY(0xb07fe0)
          0 1
       'c' => ARRAY(0xc122e8)
          0 1
You Don't Always Want It All
●   Occasionally you'll get something like:
    0     ARRAY(0xc99050)
          0 ARRAY(0xc99080)
             0 ARRAY(0xc990b0)
                0 ARRAY(0xc990e0)
                   0 ARRAY(0xc99110)
                      0 ARRAY(0xc99140)
                          empty array
        DB<17>

●   This was a structure that didn't fit onto the screen.
●   Use “x” with a limit to display less of it.
Getting What You Need
●   A digit following “x” limits the depth:
    DB<26> $i = 'z'
    DB<27> $a = $b = []
    DB<28> for( 1 .. 100 ) { $b = $b->[0] = [], $b->[1] = ++$i }
    DB<29> x 6 $a
    0 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 $struct­>{ key } will show the single hash value.
●   To walk through a structure in viewable chunks:
    ●   x 2 $struct­>{ key1 }{ key2 }
    ●   See what matters, paste on the next key/offset and keep 
        looking: 
    ●   x 2 $struct­>{ key1 }{ key2 }[ offset ]
You Are Here
●   The “T” 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 [mis­]managed down the call stack.
●   Viewing the code uses “l” and “v”.
    ●   “l” (list) shows the next line to be executed.
    ●   “v” (view) shows a small window around the line.
Finding Out What You Can Do
                      35:         my $frag
                      36:         = WCurve::Fragment->new
                      37:         (
●   “m”  shows the    38:
                      39:         );
                                      FloatCyl => ( $base x $length ), $name


    methods of an      DB<1> n
                      Testify::(01-FloatCart-basic-geometry.t:41):
                      41:         ok $frag eq $name, "Name: $frag ($name)";
    object.            DB<1> m $frag
                      add_skip_chain
                      carp
●   Items with        confess
                      converge_limit
                      looks_like_number
    package           via   WCurve::Fragment:   (""
    prefixes are      via
                      via
                            WCurve::Fragment:
                            WCurve::Fragment:
                                                ()
                                                (0+
                      via   WCurve::Fragment:   (bool
    inherited.        via
                      via
                            WCurve::Fragment:
                            WCurve::Fragment:
                                                (int
                                                stop_offset

●   Leading '(' is    via
                      via
                            WCurve::Fragment: sum
                            WCurve::Fragment -> ArrayObj: (<=>

    an overload.      via
                      via
                            WCurve::Fragment -> ArrayObj: (cmp
                            WCurve::Fragment -> ArrayObj: DESTROY

                      via   UNIVERSAL:   DOES
                      via   UNIVERSAL:   VERSION
                      via   UNIVERSAL:   can
                      via   UNIVERSAL:   isa
Hardwired Breakpoints
●   Because the perl debugger is written in perl, you can 
    also set “hardwired” breakpoints:
      $DB::single = 1;
      $DB::single = 1 unless ref $thingy;
      $DB::single = 1 if $counter > @itemz;
●   These can be useful in permanent code:
      eval { … }
      or do
      { print $@; $DB::single = 1; 0 };
Tracing Code
●   Tracing code usually produces too much output.
●   To turn on tracing use $DB::trace = 1.
    ●   You can localize it to trace a code block.
    ●   Add if­logic to trace code leading up to errors:
        $DB::trace = 1 if ! ref $foo;
●   One trick for re­startable subs is to eval them and 
    trace the failures:
        eval { foo } or do{ trace = 1; foo }
Ever Wonder How a Regex Works?
●   The “re” module allows debugging regexen:
      use re 'debug';
      use re 'debugcolor';
●   There is more info in “perldoc perldebug”.
●   A monochrome example:
DB<7> 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 1..2147483647 (checking floating) stclass ALNUM plus minlen 1
Guessing start of match in sv for REx " (w+) $" against "this is a test"
Found floating substr ""$ at offset 14...
start_shift: 1 check_at: 14 s: 0 endpos: 14
Does not contradict STCLASS...
Guessed: match at offset 0
Matching REx " (w+) $" against "this is a test"
Matching stclass ALNUM against "this is a test" (14 chars)
    0 <this is a >| 1:OPEN1(3)
    0 <this is a >| 3:PLUS(5)
                                  ALNUM can match 4 times out of 2147483647...
    4 <this is a test>| 5: CLOSE1(7)
    4 <this is a test>| 7: EOL(8)
                                    failed...
...
    1 <this is a t>| 5: CLOSE1(7)
    1 <this is a t>| 7: EOL(8)
...
    7 <this is a test>| 5: CLOSE1(7)
    7 <this is a test>| 7: EOL(8)
                                    failed...
...
  10 <this is a test>| 3:PLUS(5)
                                  ALNUM can match 4 times out of 2147483647...
  14 <this is a test>| 5: CLOSE1(7)
  14 <this is a test>| 7: EOL(8)
  14 <this is a test>| 8: END(0)
Match successful!
test
  DB<8>
Benchmarking Size
●   Devel::Peek && Devel::Size 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 -Mdevel::Size -d -e 0;
●   The advantage to dealing with this in the debugger is 
    being able to interactively query the sizes of sub­
    structures to see where bloat comes from.
Knowing When You're There
●   The variable $^P will be true when code is running 
    in the debugger.
●   This allows you to automatically set hardwired 
    breakpoints or verbosity:
    my $max_verbose = $cmdline{ verbose } > 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 per­initialized ttys 
        (usually pre­opened xterm's). 
    ●   At that point you can switch to the alternate terminals to 
        handle each session.
Semi­automated Forks
●   You can usually dodge the issue by simply not 
    forking in the debugger:
    if( my $pid = $^P ? '' : fork )
    {
        # parent
    }
    elsif( defined $pid )
    {
        # child, debugger
    }
    else
    {
        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 Devel::Peek
    ●   perldoc Devel::Size
    ●   http://www.slideshare.net/lembark/perl5­memorymanglement

Más contenido relacionado

La actualidad más candente

Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Workhorse Computing
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationWorkhorse Computing
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CDavid Wheeler
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Workhorse Computing
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Nikita Popov
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Nikita Popov
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.VimLin Yo-An
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlordsheumann
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?Nikita Popov
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021Ayesh Karunaratne
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLsAugusto Pascutti
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Nikita Popov
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationAttila Balazs
 
November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2Kacper Gunia
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 

La actualidad más candente (20)

Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
Getting Testy With Perl6
Getting Testy With Perl6Getting Testy With Perl6
Getting Testy With Perl6
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning C
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
What's new in PHP 8.0?
What's new in PHP 8.0?What's new in PHP 8.0?
What's new in PHP 8.0?
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
groovy & grails - lecture 2
groovy & grails - lecture 2groovy & grails - lecture 2
groovy & grails - lecture 2
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
 
November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2November Camp - Spec BDD with PHPSpec 2
November Camp - Spec BDD with PHPSpec 2
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 

Similar a Short Introduction To "perl -d"

Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceJesse Vincent
 
Perl training-in-navi mumbai
Perl training-in-navi mumbaiPerl training-in-navi mumbai
Perl training-in-navi mumbaivibrantuser
 
Perl at SkyCon'12
Perl at SkyCon'12Perl at SkyCon'12
Perl at SkyCon'12Tim Bunce
 
20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdasshinolajla
 
Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricksdutor
 
Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceJesse Vincent
 
BITS: Introduction to relational databases and MySQL - Schema design
BITS: Introduction to relational databases and MySQL - Schema designBITS: Introduction to relational databases and MySQL - Schema design
BITS: Introduction to relational databases and MySQL - Schema designBITS
 
Basic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersBasic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersAppier
 
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...Data Con LA
 
Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
Our Friends the Utils: A highway traveled by wheels we didn't re-invent. Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
Our Friends the Utils: A highway traveled by wheels we didn't re-invent. Workhorse Computing
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topicsRajesh Verma
 

Similar a Short Introduction To "perl -d" (20)

PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Marat-Slides
Marat-SlidesMarat-Slides
Marat-Slides
 
3
33
3
 
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
 
Perl training-in-navi mumbai
Perl training-in-navi mumbaiPerl training-in-navi mumbai
Perl training-in-navi mumbai
 
Sdl Basic
Sdl BasicSdl Basic
Sdl Basic
 
Linux shell
Linux shellLinux shell
Linux shell
 
Perl5 Memory Manglement
Perl5 Memory ManglementPerl5 Memory Manglement
Perl5 Memory Manglement
 
Perl at SkyCon'12
Perl at SkyCon'12Perl at SkyCon'12
Perl at SkyCon'12
 
Gun make
Gun makeGun make
Gun make
 
20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas
 
Debugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB TricksDebugger Principle Overview & GDB Tricks
Debugger Principle Overview & GDB Tricks
 
Hiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret SauceHiveminder - Everything but the Secret Sauce
Hiveminder - Everything but the Secret Sauce
 
Writing Macros
Writing MacrosWriting Macros
Writing Macros
 
BITS: Introduction to relational databases and MySQL - Schema design
BITS: Introduction to relational databases and MySQL - Schema designBITS: Introduction to relational databases and MySQL - Schema design
BITS: Introduction to relational databases and MySQL - Schema design
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Basic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersBasic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python Programmers
 
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Iterative Spark Developmen...
 
Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
Our Friends the Utils: A highway traveled by wheels we didn't re-invent. Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topics
 

Más de Workhorse Computing

Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWorkhorse Computing
 
Paranormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add UpParanormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add UpWorkhorse Computing
 
Generating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in PosgresqlGenerating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in PosgresqlWorkhorse Computing
 
The W-curve and its application.
The W-curve and its application.The W-curve and its application.
The W-curve and its application.Workhorse Computing
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Workhorse Computing
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Workhorse Computing
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Workhorse Computing
 
Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Workhorse Computing
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Workhorse Computing
 

Más de Workhorse Computing (19)

Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility Modules
 
mro-every.pdf
mro-every.pdfmro-every.pdf
mro-every.pdf
 
Paranormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add UpParanormal statistics: Counting What Doesn't Add Up
Paranormal statistics: Counting What Doesn't Add Up
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
Generating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in PosgresqlGenerating & Querying Calendar Tables in Posgresql
Generating & Querying Calendar Tables in Posgresql
 
Effective Benchmarks
Effective BenchmarksEffective Benchmarks
Effective Benchmarks
 
The W-curve and its application.
The W-curve and its application.The W-curve and its application.
The W-curve and its application.
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
 
Neatly folding-a-tree
Neatly folding-a-treeNeatly folding-a-tree
Neatly folding-a-tree
 
Light my-fuse
Light my-fuseLight my-fuse
Light my-fuse
 
Paranormal stats
Paranormal statsParanormal stats
Paranormal stats
 
Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.Shared Object images in Docker: What you need is what you want.
Shared Object images in Docker: What you need is what you want.
 
Putting some "logic" in LVM.
Putting some "logic" in LVM.Putting some "logic" in LVM.
Putting some "logic" in LVM.
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.
 
Selenium sandwich-2
Selenium sandwich-2Selenium sandwich-2
Selenium sandwich-2
 
Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium Selenium Sandwich Part 1: Data driven Selenium
Selenium Sandwich Part 1: Data driven Selenium
 
Docker perl build
Docker perl buildDocker perl build
Docker perl build
 
Designing net-aws-glacier
Designing net-aws-glacierDesigning net-aws-glacier
Designing net-aws-glacier
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6
 

Último

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Último (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Short Introduction To "perl -d"

  • 1. Basics of perl -d Steven Lembark Workhorse Computing lembark@wrkhors.com
  • 2. Introducing Perl's Debugger ● Overview of the obvious uses, common commands. ● Few less obvious uses: ● Debugging regexen. ● Evaluating structure bloat. ● Some pitfalls and how to avoid them.
  • 3. What is the Perl Debugger? ● The Perl debugger comes with perl, in fact it is perl. ● '­d' is built into perl's 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 ­d with profiling utilities like  NYTprof.
  • 4. 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 “perly shell” when your one­liners run  into multiple lines or you have to eyeball data  structures  between commands. ● Q&D interactive data mining. ● Good for examining data structures when writing  talks on data manglement or module guts.
  • 5. The Basics: Getting In ● At the command  $ perl ­d ­e 42; line: perl ­d enters  $ perl ­d foo.pm; the debugger. $ perl ­d bar; ● You can start it  'vanilla', with  $ perl ­MDevel::Size ­d ­e foo; modules to watch  startup, with code,  or using modules to  pull in utilities (e.g.  regex debugging).
  • 6. Basics: The Prompt ● Once in you get the command prompt: $ perl ­d ­e 42 Loading DB routines from perl5db.pl version 1.22  Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(­e:1):   42 DB<1> ● This is a “vanilla” session: there is no running code,  you can enter debugger commands, perl syntax. ● The single “<1>” indicate that this is the outermost  call level. ● The “1” says that this is the first command.
  • 7. Executing Perl Statements ● Q: Who remembers what localtime returns? ● A: How to find out? DB<1> x localtime 0 31 1 31 2 15 3 15 4 5 5 111 6 3 7 165 8 1 DB<2> ● Notice that now I'm at command #2.
  • 8. Gotchas ● Each command you type is run its own block. ● Lexical variables like “my $foo” will vanish. ● Local values like “local $” or “local $foo{ bar } = ...”  will also be unavailable after the line completes. ● You can put multiple statements onto a line with  semi­colon separators. ● You can only input one line at a time. ● Cut­and­paste of multiple lines won't work.
  • 9. Debugger Commands ● These intentionally look pretty much like gdb. ● On the other hand, if you didn't grow up debugging C  code this may not help you much. ● The most common commands are for running code,  managing breakpoints (i.e. stopping code),  interrogating values. ● Please note: “q” gets you out. ● Not “quit”, ^C, ^D, or “getmeoutofhere!”.
  • 10. Setting Up the Debugger ● You may want to edit your commands. ● Installing Term::ReadKey &Term::ReadLine. ● perl will use your .inputrc if you have one. ● For example, my .inputrc looks like: set editing-mode vi set show-all-if-ambiguous on with allows ^[k to pull up the last line for editing. ● Check the doc's if you use Emacs.
  • 11. Running Code ● Say some code blows up. ● You could just run it with “r” 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
  • 12. Stepping Code ● You can also watch the code one line at a time. ● “n” (“next”) steps over the subroutine calls. ● “s” (“step”) steps into the subroutine calls.  ● “r” (“return”) goes back to the caller if you accidentally  step one level too deep. ● One really common combination:  ● “c” to a subroutine that blows up. ● “n” to the point before it dies. ● “s” into the call that failed and see what happens.
  • 13. Getting Out of a Hole: “r” ● Sometimes you 's' into the wrong sub (say a DBI  call). ● You don't want to abort the session. ● You don't want to “n” your way through DBI. ● Use “r” 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.
  • 14. Stopping Code: Breakpoints ● Breakpoints stop the code. ● They can include a condition. ● Say the code blows up at line 842 with a non­ reference value in $thingy after roughly 8_000  iterations. ● Set a breakpoint and continue: <1> b 842 ! ref $thingy <2> c
  • 15. Examining Values ● “p” prints a value. ● “x” examines it (similar to Data::Dumper). DB<6> p @a = map { $_ => [ 1 ] } ( 'a' .. 'c' ) aARRAY(0xc0f100)bARRAY(0xc12078)cARRAY(0xc0f0d0) DB<7> x @a = map { $_ => [ 1 ] } ( 'a' .. 'c' ) 0 'a' 1 ARRAY(0xc12060) 0 1 2 'b' 3 ARRAY(0xc11dc0) 0 1 4 'c' 5 ARRAY(0xc0e1d8) 0 1
  • 16. Hashes Are Lists to “x” ● Hashes look a little odd at first: DB<8> x %a = map { $_ => [ 1 ] } ( 'a' .. 'c' ) 0 'a' 1 ARRAY(0xc122a0) 0 1 2 'b' 3 ARRAY(0xb07fe0) 0 1 4 'c' 5 ARRAY(0xc122e8) 0 1 ● They look exactly like the array: a list.
  • 17. Hashref's Are Structures ● Examining a hashref shows it as key => value pairs: DB<9> x %a 0 HASH(0xc47008) 'a' => ARRAY(0xc122a0) 0 1 'b' => ARRAY(0xb07fe0) 0 1 'c' => ARRAY(0xc122e8) 0 1
  • 18. You Don't Always Want It All ● Occasionally you'll get something like: 0 ARRAY(0xc99050) 0 ARRAY(0xc99080) 0 ARRAY(0xc990b0) 0 ARRAY(0xc990e0) 0 ARRAY(0xc99110) 0 ARRAY(0xc99140) empty array DB<17> ● This was a structure that didn't fit onto the screen. ● Use “x” with a limit to display less of it.
  • 19. Getting What You Need ● A digit following “x” limits the depth: DB<26> $i = 'z' DB<27> $a = $b = [] DB<28> for( 1 .. 100 ) { $b = $b->[0] = [], $b->[1] = ++$i } DB<29> x 6 $a 0 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'
  • 20. Mining Large Data Structures ● x 2 $struct will show the top level, including hash  keys or offset lists. ● x 2 $struct­>{ key } will show the single hash value. ● To walk through a structure in viewable chunks: ● x 2 $struct­>{ key1 }{ key2 } ● See what matters, paste on the next key/offset and keep  looking:  ● x 2 $struct­>{ key1 }{ key2 }[ offset ]
  • 21. You Are Here ● The “T” 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 [mis­]managed down the call stack. ● Viewing the code uses “l” and “v”. ● “l” (list) shows the next line to be executed. ● “v” (view) shows a small window around the line.
  • 22. Finding Out What You Can Do 35: my $frag 36: = WCurve::Fragment->new 37: ( ● “m”  shows the  38: 39: ); FloatCyl => ( $base x $length ), $name methods of an  DB<1> n Testify::(01-FloatCart-basic-geometry.t:41): 41: ok $frag eq $name, "Name: $frag ($name)"; object. DB<1> m $frag add_skip_chain carp ● Items with  confess converge_limit looks_like_number package  via WCurve::Fragment: ("" prefixes are  via via WCurve::Fragment: WCurve::Fragment: () (0+ via WCurve::Fragment: (bool inherited. via via WCurve::Fragment: WCurve::Fragment: (int stop_offset ● Leading '(' is  via via WCurve::Fragment: sum WCurve::Fragment -> ArrayObj: (<=> an overload. via via WCurve::Fragment -> ArrayObj: (cmp WCurve::Fragment -> ArrayObj: DESTROY via UNIVERSAL: DOES via UNIVERSAL: VERSION via UNIVERSAL: can via UNIVERSAL: isa
  • 23. Hardwired Breakpoints ● Because the perl debugger is written in perl, you can  also set “hardwired” breakpoints: $DB::single = 1; $DB::single = 1 unless ref $thingy; $DB::single = 1 if $counter > @itemz; ● These can be useful in permanent code: eval { … } or do { print $@; $DB::single = 1; 0 };
  • 24. Tracing Code ● Tracing code usually produces too much output. ● To turn on tracing use $DB::trace = 1. ● You can localize it to trace a code block. ● Add if­logic to trace code leading up to errors: $DB::trace = 1 if ! ref $foo; ● One trick for re­startable subs is to eval them and  trace the failures: eval { foo } or do{ trace = 1; foo }
  • 25. Ever Wonder How a Regex Works? ● The “re” module allows debugging regexen: use re 'debug'; use re 'debugcolor'; ● There is more info in “perldoc perldebug”. ● A monochrome example:
  • 26. DB<7> 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 1..2147483647 (checking floating) stclass ALNUM plus minlen 1 Guessing start of match in sv for REx " (w+) $" against "this is a test" Found floating substr ""$ at offset 14... start_shift: 1 check_at: 14 s: 0 endpos: 14 Does not contradict STCLASS... Guessed: match at offset 0 Matching REx " (w+) $" against "this is a test" Matching stclass ALNUM against "this is a test" (14 chars) 0 <this is a >| 1:OPEN1(3) 0 <this is a >| 3:PLUS(5) ALNUM can match 4 times out of 2147483647... 4 <this is a test>| 5: CLOSE1(7) 4 <this is a test>| 7: EOL(8) failed... ... 1 <this is a t>| 5: CLOSE1(7) 1 <this is a t>| 7: EOL(8) ... 7 <this is a test>| 5: CLOSE1(7) 7 <this is a test>| 7: EOL(8) failed... ... 10 <this is a test>| 3:PLUS(5) ALNUM can match 4 times out of 2147483647... 14 <this is a test>| 5: CLOSE1(7) 14 <this is a test>| 7: EOL(8) 14 <this is a test>| 8: END(0) Match successful! test DB<8>
  • 27. Benchmarking Size ● Devel::Peek && Devel::Size 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 -Mdevel::Size -d -e 0; ● The advantage to dealing with this in the debugger is  being able to interactively query the sizes of sub­ structures to see where bloat comes from.
  • 28. Knowing When You're There ● The variable $^P will be true when code is running  in the debugger. ● This allows you to automatically set hardwired  breakpoints or verbosity: my $max_verbose = $cmdline{ verbose } > 1 || $^P;
  • 29. 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 per­initialized ttys  (usually pre­opened xterm's).  ● At that point you can switch to the alternate terminals to  handle each session.
  • 30. Semi­automated Forks ● You can usually dodge the issue by simply not  forking in the debugger: if( my $pid = $^P ? '' : fork ) { # parent } elsif( defined $pid ) { # child, debugger } else { die "Phorkafobia: $!"; }
  • 31. A Modern Version given( $^P ? '' : fork ) { when( '' ) { ... } when( undef ) { die "Phorkafobia: $!" } my $child = wait; # parent processes results. }
  • 32. Further Reference ● A always, perldoc is your friend. ● perldoc perldebug ● perldoc perlre ● Perldoc DB ● For examples of querying memory use: ● perldoc Devel::Peek ● perldoc Devel::Size ● http://www.slideshare.net/lembark/perl5­memorymanglement