Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set breakpoint on a particular file in Perl program?

Tags:

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.

like image 676
everbox Avatar asked Jan 19 '12 02:01

everbox


People also ask

How do I create a breakpoint in a Perl script?

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.

How do you set a breakpoint to 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.

How do I debug a .pm file?

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.


1 Answers

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.

like image 195
socket puppet Avatar answered Oct 12 '22 09:10

socket puppet