home *** CD-ROM | disk | FTP | other *** search
- <!-- $RCSfile$$Revision$$Date$ -->
- <!-- $Log$ -->
- <HTML>
- <TITLE> PERLDEBUG </TITLE>
- <h2>NAME</h2>
- perldebug - Perl debugging
- <p><h2>DESCRIPTION</h2>
- First of all, have you tried using the
- <A HREF="perlrun.html#perlrun_362">-w</A>
- switch?
- <p><h3>Debugging</h3>
- If you invoke Perl with a
- <A HREF="perlrun.html#perlrun_346">-d</A>
- switch, your script will be run under the
- debugger. However, the Perl debugger is not a separate program as it is
- in a C environment. Instead, the
- <A HREF="perlrun.html#perlrun_346">-d</A>
- flag tells the compiler to insert
- source information into the pseudocode it's about to hand to the
- interpreter. (That means your code must compile correctly for the
- debugger to work on it.) Then when the interpreter starts up, it
- pre-loads a Perl library file containing the debugger itself. The program
- will halt before the first executable statement (but see below) and ask
- you for one of the following commands:
- <p>
- <dl>
- <dt><B>h</B>
- <dd>
- Prints out a help message.
- <p></dd>
- <dt><B>T</B>
- <dd>
- Stack trace.
- If you do bizarre things to your @_ arguments in a subroutine, the stack
- backtrace will not always show the original values.
- <p></dd>
- <dt><B>s</B>
- <dd>
- Single step. Executes until it reaches the beginning of another
- statement.
- <p></dd>
- <dt><B>n</B>
- <dd>
- Next. Executes over subroutine calls, until it reaches the beginning
- of the next statement.
- <p></dd>
- <dt><B>f</B>
- <dd>
- Finish. Executes statements until it has finished the current
- subroutine.
- <p></dd>
- <dt><B>c</B>
- <dd>
- Continue. Executes until the next breakpoint is reached.
- <p></dd>
- <dt><B>c line</B>
- <dd>
- Continue to the specified line. Inserts a one-time-only breakpoint at
- the specified line.
- <p></dd>
- <dt><B><CR></B>
- <dd>
- Repeat last n or s.
- <p></dd>
- <dt><B>l min+incr</B>
- <dd>
- List incr+1 lines starting at min. If min is omitted, starts where
- last listing left off. If incr is omitted, previous value of incr is
- used.
- <p></dd>
- <dt><B>l min-max</B>
- <dd>
- List lines in the indicated range.
- <p></dd>
- <dt><B>l line</B>
- <dd>
- List just the indicated line.
- <p></dd>
- <dt><B>l</B>
- <dd>
- List next window.
- <p></dd>
- <dt><B>-</B>
- <dd>
- List previous window.
- <p></dd>
- <dt><B>w line</B>
- <dd>
- List window (a few lines worth of code) around line.
- <p></dd>
- <dt><B>l subname</B>
- <dd>
- List subroutine. If it's a long subroutine it just lists the
- beginning. Use "l" to list more.
- <p></dd>
- <dt><B>/pattern/</B>
- <dd>
- Regular expression search forward in the source code for pattern; the
- final / is optional.
- <p></dd>
- <dt><B>?pattern?</B>
- <dd>
- Regular expression search backward in the source code for pattern; the
- final ? is optional.
- <p></dd>
- <dt><B>L</B>
- <dd>
- List lines that have breakpoints or actions.
- <p></dd>
- <dt><B>S</B>
- <dd>
- Lists the names of all subroutines.
- <p></dd>
- <dt><B>t</B>
- <dd>
- Toggle trace mode on or off.
- <p></dd>
- <dt><B>b line [ condition ]</B>
- <dd>
- Set a breakpoint. If line is omitted, sets a breakpoint on the line
- that is about to be executed. If a condition is specified, it is
- evaluated each time the statement is reached and a breakpoint is taken
- only if the condition is true. Breakpoints may only be set on lines
- that begin an executable statement. Conditions don't use <B>if</B>:
- <p></dd>
- <pre>
- b 237 $x > 30
- b 33 /pattern/i
- </pre>
- <dt><B>b subname [ condition ]</B>
- <dd>
- Set breakpoint at first executable line of subroutine.
- <p></dd>
- <dt><B>d line</B>
- <dd>
- Delete breakpoint. If line is omitted, deletes the breakpoint on the
- line that is about to be executed.
- <p></dd>
- <dt><B>D</B>
- <dd>
- Delete all breakpoints.
- <p></dd>
- <dt><B>a line command</B>
- <dd>
- Set an action for line. A multiline command may be entered by
- backslashing the newlines. This command is Perl code, not another
- debugger command.
- <p></dd>
- <dt><B>A</B>
- <dd>
- Delete all line actions.
- <p></dd>
- <dt><B>< command</B>
- <dd>
- Set an action to happen before every debugger prompt. A multiline
- command may be entered by backslashing the newlines.
- <p></dd>
- <dt><B>> command</B>
- <dd>
- Set an action to happen after the prompt when you've just given a
- command to return to executing the script. A multiline command may be
- entered by backslashing the newlines.
- <p></dd>
- <dt><B>V package [symbols]</B>
- <dd>
- Display all (or some) variables in package (defaulting to the <B>main</B>
- package) using a data pretty-printer (hashes show their keys and values so
- you see what's what, control characters are made printable, etc.). Make
- sure you don't put the type specifier (like $) there, just the symbol
- names, like this:
- <p></dd>
- <pre>
- V DB filename line
- </pre>
- <dt><B>X [symbols] </B>
- <dd>
- Same as as "V" command, but within the current package.
- <p></dd>
- <dt><B>! number</B>
- <dd>
- Redo a debugging command. If number is omitted, redoes the previous
- command.
- <p></dd>
- <dt><B>! -number</B>
- <dd>
- Redo the command that was that many commands ago.
- <p></dd>
- <dt><B>H -number</B>
- <dd>
- Display last n commands. Only commands longer than one character are
- listed. If number is omitted, lists them all.
- <p></dd>
- <dt><B>q or ^D</B>
- <dd>
- Quit. ("quit" doesn't work for this.)
- <p></dd>
- <dt><B>command</B>
- <dd>
- Execute command as a Perl statement. A missing semicolon will be
- supplied.
- <p></dd>
- <dt><B>p expr</B>
- <dd>
- Same as <B>print DB::OUT expr</B>. The DB::OUT filehandle is opened to
- /dev/tty, regardless of where STDOUT may be redirected to.
- <p></dd>
-
- </dl>
-
- Any command you type in that isn't recognized by the debugger will be
- directly executed (
- <A HREF="perlfunc.html#perlfunc_101">eval</A>
- 'd) as Perl code. Leading white space will
- cause the debugger to think it's <B>NOT</B> a debugger command.
- <p>If you have any compile-time executable statements (code within a BEGIN
- block or a
- <A HREF="perlfunc.html#perlfunc_263">use</A>
- statement), these will <I>NOT</I> be stopped by debugger,
- although
- <A HREF="perlfunc.html#perlfunc_205">require</A>
- s will. From your own code, however, you can transfer
- control back to the debugger using the following statement, which is harmless
- if the debugger is not running:
- <p><pre>
- $DB::single = 1;
- </pre>
- <h3>Customization</h3>
- If you want to modify the debugger, copy <I>perl5db.pl</I> from the Perl
- library to another name and modify it as necessary. You'll also want
- to set environment variable PERL5DB to say something like this:
- <p><pre>
- BEGIN { require "myperl5db.pl" }
- </pre>
- You can do some customization by setting up a <I>.perldb</I> file which
- contains initialization code. For instance, you could make aliases
- like these (the last one in particular most people seem to expect to
- be there):
- <p><pre>
- $DB::alias{'len'} = 's/^len(.*)/p length($1)/';
- $DB::alias{'stop'} = 's/^stop (at|in)/b/';
- $DB::alias{'.'} = 's/^\./p '
- . '"\$DB::sub(\$DB::filename:\$DB::line):\t"'
- . ',\$DB::dbline[\$DB::line]/' ;
- </pre>
- <h3>Other resources</h3>
- You did try the
- <A HREF="perlrun.html#perlrun_362">-w</A>
- switch, didn't you?
- <p><h2>BUGS</h2>
- If your program exit()s or die()s, so does the debugger.
- <p>There's no builtin way to restart the debugger without exiting and coming back
- into it. You could use an alias like this:
- <p><pre>
- $DB::alias{'rerun'} = 'exec "perl -d $DB::filename"';
- </pre>
- But you'd lose any pending breakpoint information, and that might not
- be the right path, etc.<p>