Perl debugger tip

Richard Keen discovered (so what if it was in an online verion of the Programming Perl) a neat little Perl debugger hook that can be placed in code for automatic breakpoints.

Instead of stepping through code until all the modules are loaded, and then continuing to a line number or a specific method in a module , you can continue to a pre-defined breakpoint. To add such a breakpoint use :

$DB::single = 2;

Here’s some explanatory text on it from Programming Perl:

You can exert a little control over the Perl debugger from within your Perl program itself. You might do this, for example, to set an automatic breakpoint at a certain subroutine whenever a particular program is run under the debugger. From your own Perl code, however, you can transfer control back to the debugger using the following statement, which is harmless if the debugger is not running:

$DB::single = 1;

If you set $DB::single to 2, it’s equivalent to the n command, whereas a value of 1 emulates the s command. The $DB::trace variable should be set to 1 to simulate the t command.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s