Invoke the debugger by running perl with the -d option:
perl -d myprogram.pl
Here are some commands you can use from the debugger prompt. The commands are case sensitive. Arguments in brackets are optional. This is not an exhaustive list.
|code||Typing Perl code at the prompt causes the debugger to execute that code as if it were the next line in the program.|
|b [line] [condition]||Sets a breakpoint at line, which must begin an executable statement. If line is omitted, sets a breakpoint on the line that is currently about to be executed. condition, if given, is a Perl expression that is evaluated each time the statement is reached; execution breaks only if conditon is true.|
|b subname [condition]||Sets a breakpoint at the first executable line of the named subroutine subname. If condition is given it is evaluated as above.|
|c [line/sub]||Continues, optionally inserting a one-time-only breakpoint at the specified line or subroutine|
|d [line]||Deletes the breakpoint at the specified line. If line is omitted, deletes the breakpoint on the line that is currently about to be executed.|
|D||Deletes all installed breakpoints.|
If linespec is omitted, lists the the next few lines.
Otherwise lists the lines specified by linespec, which can be
one of the following:
|L||Lists all breakpoints and actions for the current file.|
|m expr/class||Evaluates expr and prints methods callable on the given object/class.|
|n||Next. Passes over subroutine calls and executes the next statement at this level.|
Prints expr to the DB::OUT file handle. (Same as:
|q||Quits the debugger|
|s||Single steps. Executes until it reaches the beginning of another statement, descending into subroutine calls.|
|w [line]||Lists a window of a few lines around the given line, or lists the current line if line is omitted.|
|x expr||Evaluates the expression and dumps out the result in a pretty-printed fashion. Prints nested data structures recursively.|
|<ENTER>||Pressing the <ENTER> key repeats the last n or s command.|
Emacs provides a nice interface to use with the perl debugger. In particular, it allows you to view your code as you are walking through it. Be warned: Emacs is a very powerful editor, but is not very intuitive in its use. You may want to see my Emacs reference for a list of Emacs commands.
Run perldb (like this): perl /home/gfoust/myprogram.plUsually this default guess is correct. However, you can edit this line to pass command line argument to perl or to your program. You could even change the file name; Emacs will automatically open whichever file you are debugging. When you've got it how you'd like it, press <ENTER>.
While using the debugger in emacs you may also use the following commands:
|Alt-p||Previous command. Cycle backwards through the command history (i.e. the debugger commands you have previously entered).|
|Alt-n||Next command. Cycle forwards through the command history.|
|Ctl-c, Ctl-n||Executes a "next" command—same as entering "n", only without cluttering up the debugger window.|
|Ctl-c, Ctl-s||Executes a "step" command—same as entering "s", only without cluttering up the debugger window.|