Is it possible to invoke the debugger from within a program

B

Bruce Horrocks

If I run a program with -d and then use c to continue running, is there
a way to have the program drop into the debugger at the appropriate line
when a run-time warning is displayed?

(This would help hugely because I'm effectively debugging the input data
rather than the program and the warnings can arise at multiple points.
Putting all these points into the necessary 'b <cond>' commands and
editing them every time the line numbering changes as the program is
modified is proving to be a chore.)

Regards,
 
P

Paul Lalli

Bruce said:
If I run a program with -d and then use c to continue running, is there
a way to have the program drop into the debugger at the appropriate line
when a run-time warning is displayed?

Set a warn handler in your code to execute the statement that tells the
debugger to pause (read the perldebug page for more info).

Basically, add this block to your code:
$SIG{__WARN__} = sub {
warn @_;
$DB::single = 1;
};

You may wish to put that in a BEGIN block if you want to capture
compile-time warnings as well.

Paul Lalli
 
B

Bruce Horrocks

Paul said:
Set a warn handler in your code to execute the statement that tells the
debugger to pause (read the perldebug page for more info).

Thank-you very much Paul. It's obvious now I know what to look for.
;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top