Chapter 18. The Perl Debugger
First of all, have you tried the warnings pragma?
If you invoke Perl with the –d
switch, your program will be run inside the Perl debugger. This works
like an interactive Perl environment, prompting for debugger commands that
let you examine source code, set breakpoints, dump out your function-call
stack, change the values of variables, and so on. Any command not recognized
by the debugger is executed directly (using eval) as Perl code in the package of the code
currently being debugged. (The debugger uses the DB package for its own
state information, to avoid trampling yours.) This is so wonderfully
convenient that people often fire up the debugger just to test out Perl
constructs interactively. In that case, it doesn’t matter what program you
tell Perl to debug, so we’ll choose one without much meaning:
% perl –de 42In Perl, the debugger is not a program completely separate from the one
being debugged the way it usually is in a typical programming environment.
Instead, the –d flag tells the compiler
to insert source information into the parse trees it’s about to hand off to
the interpreter. That means your code must first compile correctly for the
debugger to work on it. If that is successful, the interpreter preloads a
special Perl library file containing the debugger itself.
% perl –d /path/to/programThe program will halt immediately before the first runtime executable statement (but see the next section, Using the Debugger, regarding compile-time ...
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