I want the perl program launch debugger when some condition hit. Some other language has debug() statement supported by library, is there any similar statement in perl?
To set a breakpoint in source code: Click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.
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.
A breakpoint is a point in the program where the code will stop executing. For example, if the programmer amended the logic error in the trace table example they may wish to trigger a break point at line 5 in the algorithm.
If I understand you correctly, you need to use a specific debugger variable in your code - $DB::single
. Setting this to a true value in your code will cause the debugger to stop on that line.
$x = 1234;
$DB::single = 1;
enter_problematic_sub_now();
Your code will then stop at the line with $DB::single set to 1.
Of course, if you can't actually ensure that your code is running in the debugger then you have another problem entirely. You will need to run your code via perl -d
as well.
Have you tried adding the -d switch to the shebang line at the top of your script? Something like
#!/usr/bin/perl -d
use strict;
use warnings;
$|=1;$\="\n";
print "Test";
It really depends exactly how it gets launched, but at least in simple cases this should start the debugger.
Edit: You can then set a breakpoint on a specific line with a certain condition using
> b [line] [condition]
and hit
> c
to continue with running the script - the debugger will stop at the specified line when the condition is met
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