The Perl debugger also allows you to define actions - code that is executed when a specific line is reached. This comes in handy when you need to try a piece of code with different variable values, or print notification before specific lines are executed.
Actions are set with the "a" command, which needs a line number and a line of code to be executed before the debugger executes the specified line. Consider the following example, which demonstrates:
In this case, when the debugger reaches line 30, it will automatically halt (because I set a breakpoint) and also print the value of the second element of the array $record (because I told it to via the "a" command).
Actions can be deleted with the "A" command, which can be supplied with either a line number
or the * wildcard.
* Following The Trail
As you might have guessed from my frequent use of this command in some of the previous examples, the "L" command provides a list of all currently-set breakpoints, actions and watch-expressions.
You can also obtain a list of previously-entered debugger commands with the "H" command, which displays a command history,
and even repeat previous commands with the "!" command.
You can obtain a stack trace with the "T" command, as in the following
This is fairly easy to decipher, so long as you start with the last line first. In the example above, it's clear to see that the script called the
You can also customize the debugger with the "o" command, which lets you alter debugger options. Try typing it at the debugger prompt and you should see something like this:
As you may have guessed, these are all internal debugger options which can be customized as per your requirements. To alter a particular options, simply use the "o" command followed by the option name and its value, as
Here's a brief list of the more interesting options available for
"RecallCommand" - the command used to repeat previous commands ("!) by default);
"pager" - the program to use when paging through long screens of output;
"hashDepth" - the depth to which hashes are displayed;
"arrayDepth" - the depth to which arrays are displayed;
"dumpDepth" - the depth to which structures are displayed;
"inhibit_exit" - continue debugger session even after the script has ended;
"windowSize" - number of lines of code to display with "v" and "l" commands;
blog comments powered by Disqus