My Perl program looks like:
foo/ foo/bar/ for/bar/test.pm foo.pm foo/bar.pm test.pl
and use perl test.pl
to start the program. I want to debug a sub in foo/bar/test.pm. How to set a breakpoint on that sub?
How can I do this?
Thanks.
b-command is used to set a breakpoint in a program. Whenever a specified line is about to be executed, this command tells the debugger to halt the program. Note : There can be any number of breakpoints in a program.
You can set a breakpoint at a line number, using the stop at command, where n is a source code line number and filename is an optional program file name qualifier. If the line specified is not an executable line of source code, dbx sets the breakpoint at the next executable line.
Another way to debug compile-time code is to start the debugger, set a breakpoint on the load of some module: DB<7> b load f:/perllib/lib/Carp.pm Will stop on load of 'f:/perllib/lib/Carp.pm'. and then restart the debugger using the R command (if possible). One can use b compile subname for the same purpose.
To debug a perl script, use the -d
switch to invoke the debugger.
perl -d test.pl
Within the debugger you can use b <line no>
to set a breakpoint in the current file. Sometimes it is a hassle to set a breakpoint in a file that hasn't been loaded yet or that was loaded a long time ago, so you can also put the line
$DB::single = 1;
anywhere in any perl program, and the debugger will break immediately after it executes that line. This is also a good way (the only way?) to set a breakpoint in code that will be run at compile time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With