Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I insert break point into source perl program?

Tags:

debugging

perl

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?

like image 637
Thomson Avatar asked Jan 14 '11 13:01

Thomson


People also ask

How do you insert a break point in source code?

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.

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.

What is a break point in coding?

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.


2 Answers

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.

like image 184
Nic Gibson Avatar answered Oct 03 '22 19:10

Nic Gibson


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

like image 32
ivancho Avatar answered Oct 03 '22 18:10

ivancho