Debugger Support

Perl provides special debugging hooks at both compile time and run time for creating debugging environments such as the standard debugger. These hooks are not to be confused with the perl -D options, which are usable only if your Perl was built with -DDEBUGGING support.

For example, whenever you call Perl's built-in caller function from the package DB, the arguments that the corresponding stack frame was called with are copied to the the @DB::args array. When you invoke Perl with the -d switch, the following additional features are enabled:

  • Perl inserts the contents of $ENV{PERL5DB} (or BEGIN {require 'perl5db.pl'} if not present) before the first line of your program.

  • The array @{"_<$filename"} holds the lines of $filename for all files compiled by Perl. The same for evaled strings that contain subroutines or are currently being executed. The $filename for evaled strings looks like (eval 34). Code assertions in regular expressions look like (re_eval 19).

  • The hash %{"_<$filename"} contains breakpoints and actions keyed by line number. You can set individual entries as opposed to the whole hash. Perl only cares about Boolean truth here, although the values used by perl5db.pl have the form "$break_condition\0$action". Values in this hash are magical in numeric context: they are zeros if the line is not breakable.

    The same holds for evaluated strings that contain subroutines or are currently being executed. The $filename for evaled strings looks like (eval 34) or (re_eval ...

Get Programming Perl, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.