Perl Debugger Pocket Reference by Richard Foley This errata page lists errors outstanding in the most recent printing. If you have technical questions or error reports, you can send them to booktech@oreilly.com. Please specify the printing date of your copy. This page was updated September 20, 2004. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification Confirmed errors: [76] - 2 missing sections (= and R)! These 2 commands are missing their (correct) index entries too! Insert the following chunk between the commands and the option sections: R Re-run the current debug session. R usage R R (current session) The R command quits the current session and restarts a new one, using as much information as it can remember from the previous session. Certain information is lost, though all command line arguments, debugger options, and environment variables are retained across the restart, as are command history, breakpoints, and actions. You might want to do this when you wish to continue debugging the current program, but wish to start from from the beginning again, for example to set a break point on a subroutine or module which has already been loaded. To demonstrate the command history and command line arguments, we can use the -- switch to tell Perl that the following arguments are to be passed as the command line to the program: perldb@monkey> B <...truncated output...> main::(-e:1): 0 DB<1> Now dump the command line arguments for reference: C<> DB<1> x \@ARGV 0 ARRAY(0x8148dbc) 0 'cmd-line' 1 'arguments' DB<2> Use shift to remove the left-most element and dump the arguments again to ensure we have just the one element remaining: DB<2> shift @ARGV DB<3> x \@ARGV 0 ARRAY(0x8148dbc) 0 'arguments' DB<3> Now restart the debugger session: C<> DB<4> R Warning: some settings and command-line options may be lost! <...truncated output...> main::(-e:1): 0 DB<4> Check the command line arguments again to ensure that we have the original once more and reuse the first command, noting the command numbers remain from the restarted session/s: DB<4> !1 x \@ARGV 0 ARRAY(0x81483c8) 0 'cmd-line' 1 'arguments' DB<5> ----- = Alias a word to a debugger command. = usage = [alias value] = alias value Whenever the string alias is seen, it will be replaced with the specified value. To print your favorite variable, or to map S (for subroutine) to F (for function) (my preference): perldb@monkey> perl -d -e 0 <...truncated output...> DB<1> = xo print "os: $^O" xo = print "os: $^O" DB<2> = F S F = S DB<3> xo os: linux DB<4> = alias Display the value of the given alias C<> DB<4> = xo xo = "print $^O" DB<5> = When no arguments are given, list all aliases C<> DB<5> = F = S xo = "print $^O" DB<5> An interesting use of an alias is one picked up from perlmonks (see http://perlmonks.org/) to set a breakpoint on any warning. Place the following code into a file warn.pl. warn ("warning here"); print("warned but not dead yet\n"); die ("dieing here"); Call it with the debugger and use c to run directly to the end of the program. perldb@monkey> perl -d warn.pl <...truncated output...> main::(warn.pl:2): warn ("warning here"); DB<1> c warning here at warn.pl line 2. warned but not dead yet dieing here at warn.pl line 4. Debugged program terminated. Use q to quit or R to restart, use O inhibit_exit to avoid stopping after program termination, h q, h R or h O to get additional info. DB<1> There was a warning() and a print statement followed by the program dieing at line 4. Place the following code into the rc .perldb file. sub afterinit { push(@DB::typeahead, '= bow \$SIG{__WARN__} = sub {\$DB::single=2;}'); } Then use R to restart the same session. C<> DB<1> R Warning: some settings and command-line options may be lost! Loading DB routines from perl5db.pl version 1.19 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(warn.pl:2): warn ("warning here"); auto(-1) DB<0> = bow \$SIG{__WARN__} = sub {\$DB::single=2;} bow = \$SIG{__WARN__} = sub {\$DB::single=2;} DB<1> Now the alias is set define a warn handler any time you need one. Simply type B to install it, followed by c to see how far the program gets this time. C<> DB<1> bow DB<2> c main::(warn.pl:3): print("warned but not dead yet\n"); DB<2> Very handy. You should be careful not to reuse any existing command mappings when creating aliases, or you're liable to end up with some strange behaviour or even unusable commands. For example, if you alias the C to something else, you won't be able to list your source code until you exit the current session and restart the debugger.