Using the Debugger
The debugger prompt is something like:
DB<8>
or even:
DB<<17>>
where the number shows how many commands you’ve executed. A csh-like history mechanism allows you to access
previous commands by number. For example, !17 would repeat command number 17. The number
of angle brackets indicates the depth of the debugger. For example, you
get more than one set of brackets if you’re already at a breakpoint and
then print out the result of a function call that itself also has a
breakpoint.
If you want to enter a multiline command, such as a subroutine definition with several statements, you may escape the newline that would normally end the debugger command with a backslash. Here’s an example:
DB<1>for (1..3) { \cont:print "ok\n"; \cont:}ok ok ok
Let’s say you want to fire up the debugger on a little program of
yours (let’s call it camel_flea) and
stop it as soon as it gets down to a function named infested. Here’s how you’d do that:
% perl –d camel_flea
Loading DB routines from perl5db.pl version 1.07
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(camel_flea:2): pests('bactrian', 4);
DB<1>The debugger halts your program right before the first runtime executable statement (but see below about compile-time statements) and asks you to enter a command. Again, whenever the debugger stops to show you a line of code, it displays the line it’s about to execute, not the one it just executed. The line displayed may not look exactly like ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access