Writing Your Own Debugger
The minimal working debugger consists of one line:
sub DB::DB {}which, since it does nothing whatsoever, can easily be defined via
the PERL5DB environment
variable:
$ PERL5DB="sub DB::DB {}" perl –d your–programAnother tiny, slightly more useful debugger could be created like this:
sub DB::DB {print ++$i; scalar <STDIN>}This little debugger would print the sequential number of each encountered statement and would wait for you to hit a newline before continuing.
The following debugger, small though it may appear, is really quite functional:
{
package DB;
sub DB {}
sub sub {print ++$i, " $sub\n"; &$sub}
}It prints the sequential number of the subroutine call and the
name of the called subroutine. Note that &DB::sub must be compiled from the package
DB, as we’ve done here.
If you base your new debugger on the current debugger, there are
some hooks that can help you customize it. At startup, the debugger
reads your init file from the current directory or your home directory.
After the file is read, the debugger reads the PERLDB_OPTS environment variable and parses
this as the remainder of an O ...
line such as you might enter at the debugger prompt.
The debugger also maintains magical internal variables, such
as @DB::dbline and
%DB::dbline, which are aliases for
@{"::_<current_file"}
%{"::_<current_file"}. Here,
current_file is the currently selected file,
either explicitly chosen with the debugger’s f command or implicitly by flow of
execution.
Some functions can ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access