Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Using the Perl Debugger

by root (Scribe)
on Dec 23, 1999 at 04:07 UTC ( #1322=perltutorial: print w/replies, xml ) Need Help??

Perl's debugger is a command line debugger, so while it's not pretty, with buttons and little red lines for your breakpoints, it can be pretty durn effective once you get used to it. This isn't so much of a tutorial as a brief overview of the most common commands.


bash$ perl -d
This will put you in the command line mode. It looks like:

main::(perl/ print "Just another perl monk\n";

Dissecting it, we have this information:

Module::(sub module)::function(physical file location:line number): current line of code;

now you can type in whatever you want to make your program proceed.

Know your command set!

Here's a few of the more often-used commands:

  • n -- next. Proceed to the next command
  • s -- step (in). If you are in a function call, proceed to that function.
  • x -- eXecute. Although it's more like eval. This lets you monitor variables, or execute arbitrary code. "x $FOO" will print out the value of $FOO, etc. It will automatically expand references, which is nice if you are using complex data structures.
  • b LINE -- Set a breakpoint on the target line. This way when you use "c", it will stop at the breakpoint
  • c -- continue running until breakpoint.
  • T -- print the call stack of functions
  • <enter> -- repeats the last command. Useful when preceeded by "n" or "s".
  • h -- help. Prints out a much more comprehensive command list than this...
  • q -- quit.

    What? More functionality?

    Of course there's a hell of a lot more functionality! Check out the perldebug man page...

  • Log In?

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: perltutorial [id://1322]
    [moritz]: seems there's a size limit for hostenum, and the error message just sucks
    [vrk]: None, other than the location of the error: auto/NetAddr/IP/
    [vrk]: Aha, there's a reference to "bug report 82719" in NetAddr/'s sub _splitref.
    [moritz]: wow, that's their idea of an "improved error message"
    [moritz]: how about "This network is too large to enumerate all host addresses." or so?
    [vrk]: Well, there's a call to notcontiguous() before the error, whose description is "counts the bit positions remaining in the mask when the rightmost '0's are removed"
    [vrk]: Clear as mud!

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (9)
    As of 2017-04-25 07:39 GMT
    Find Nodes?
      Voting Booth?
      I'm a fool:

      Results (449 votes). Check out past polls.