APM: FWIW-- Perl debugger trick

Bill Raty bill_raty at yahoo.com
Thu May 13 14:20:48 CDT 2004


For quite some time I've been dropping persistent debugging
break points in my code via:

  $DB::single = 1;

This does nothing appreciable to the code when it runs outside
of the debugger, but will cause the debbugger to stop at the
following line.

Today while reading perl_debug doc page (comes with most dists
or can be seen on www.perldoc.com), that you can leave commands
for the debugger to execute before showing its prompt by
stacking them in @DB::typeahead.  So if you make a little sub
like this:

sub _BREAK_HERE_ {
  if(@_) { @DB::typeahead = @_ }
  $DB::single = 1;
}

Then later in your code, like this try block:

  use Error (:try);

  sub _BREAK_HERE_ {
    if(@_) { @DB::typeahead = @_ }
    $DB::single = 1;
  }

  try {
    die "for example.\n";
  }  otherwise {
    my ($exception) = @_;
    _BREAK_HERE_ 'w', 'x $exception';
    1;  # debugger will stop here
  }
 
The debugger will show a 'window' of code around the line of
execution, and dump the $exception structure.

Hint: put the _BREAK_HERE_ sub in a .pl or .pm file so you can
'require' or 'use' it later.

Enjoy!,

-Bill


=====
Let's not elect Bush in '04 either.



More information about the Austin mailing list