Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

break on warning in debugger

by confused_newbie (Initiate)
on Sep 25, 2007 at 12:43 UTC ( #640915=perlquestion: print w/replies, xml ) Need Help??
confused_newbie has asked for the wisdom of the Perl Monks concerning the following question:

Hi how can I get the debugger to enter break mode whenever a warning is written to the screen? thanks!

Replies are listed 'Best First'.
Re: break on warning in debugger
by grinder (Bishop) on Sep 25, 2007 at 13:41 UTC

    You can use some trickery and get the warning to kick the debugger into single-step mode:

    use strict; use warnings; $SIG{__WARN__} = sub { $DB::single = 1 }; my $c = 3; my $d = 'foo'; my $e = $c + $d; print "$e\n";

    This will stop the program after the warning that caused the error (the addition of $c and $d). It is a much more difficult proposition to stop the program before the warning. Then again, this is probably sufficient 99.99% percent of the time.

    Note that you still have to run the program under the debugger: perl -d myprogram. The gain is that you just have to <r>un the program, and it will churn away until a warning is raised.

    • another intruder with the mooring in the heart of the Perl

      The gain is that you just have to <r>un the program, and it will churn away until a warning is raised.

      The 'r' command in the debugger does "return from current subroutine" (which means run the code until just after the code decides to return from the current subroutine, in case some find the former wording a bit unclear like I do). It doesn't mean "run", though it has a similar effect in that specific context. A more appropriate command is 'c' for 'continue'.

      In the debugger, if you are curious what a command does, type "h r" or "h c" to get a short description of just the "r" or "c" commands, BTW.

      - tye        

Re: break on warning in debugger
by tcf03 (Deacon) on Sep 25, 2007 at 13:26 UTC
    From perldoc perldebug
    b b [line] [condition] b subname [condition] b postpone subname [condition]
    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
      --Ralph Waldo Emerson

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://640915]
Approved by Corion
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2017-05-26 17:53 GMT
Find Nodes?
    Voting Booth?