Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Debugging a programby hexcoder (Curate) |
on Aug 06, 2008 at 16:42 UTC ( [id://702678]=note: print w/replies, xml ) | Need Help?? |
Here is my debugger tip. When I do rapid prototyping, I often want the debugger to stop whenever a warning is issued from the Perl interpreter (for example about an undefined scalar). The warning contains a line number which is fine, but when executed in a loop, this is not enough. I need the current context. Only then I can examine the state of the program in the context that produced the problem. So what to do? In the program I replace the signal handler for SIGWARN with my own handler that checks for the typical format of a Perl warning. I do that because I am interested only in warnings from the Perl interpreter. If this format has been detected, the code branches into a special path where I can set a breakpoint. After that the warning message is printed as before the modification. Update: thanks to perrin the breakpoint setting is not necessary anymore. Also the BEGIN block can be shifted in the .perldb initialization file (see Re^3: Debugging a program), so the original file remains unchanged. Example:
When I run the program under the debugger, it stops in the signal handler when the commented line is reached. I give the (r) command to return to the calling subroutine and investigate the context.
In Section
Seekers of Perl Wisdom
|
|