Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Debugging a program

by perrin (Chancellor)
on Aug 06, 2008 at 16:52 UTC ( [id://702681]=note: print w/replies, xml ) Need Help??


in reply to Re: Debugging a program
in thread Debugging a program

You could just run your code in the debugger and do this when you find a warning you want to stop on:
$DB::single = 1;

Replies are listed 'Best First'.
Re^3: Debugging a program
by hexcoder (Curate) on Aug 06, 2008 at 17:22 UTC
    Thanks, that saves the action of setting a breakpoint.

    But even better, I could shift the signal handler code into the debugger initialization file .perldb. Then I do not have to modify the original source code. Works great!

    This is the content of file .perldb (place it in the current or in the home directory):

    sub afterinit { $::SIG{'__WARN__'} = sub { my $warning = shift; if ( $warning =~ m{\s at \s \S+ \s line \s \d+ \. $}xms ) { $DB::single = 1; # debugger stops here automatically } warn $warning; }; print "sigwarn handler installed!\n"; return; }
      Addition
      ... and under Windows save it to file perldb.ini in your %HOMEDRIVE%%HOMEPATH% directory.

      Then make sure to set the file attributes to read-only. That way it is safe and the debugger is happy.

        With Strawberry Perl 5.26.2 (Windows 7) I got some complaints about unknown terminal window size when starting the debugger.
        Unable to get Terminal Size. The Win32 GetConsoleScreenBufferInfo call + didn't work. The COLUMNS and LINES environment variables didn't work +. at C:/Strawberry/perl/vendor/lib/Term/ReadLine/readline.pm line 410 +.

        These lines in sub afterinit take care of it:
        my ($cols, $lines) = split ' ', (grep { m{^\s*\d+\s+\d+\s}xms } `p +owershell -command "&{\$H=get-host;\$H.ui.rawui.WindowSize;}"`)[0]; $ENV{'COLUMNS'} = $cols; $ENV{'LINES'} = $lines; print "COLUMNS and LINES are set ($cols,$lines).\n";

        Powershell is used here to get the console property WindowSize. Then the environment variables COLUMNS and LINES are locally set and the readline.pm module is happy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://702681]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-24 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found