Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Int-3 equivalent?

by tachyon (Chancellor)
on Jun 10, 2004 at 01:12 UTC ( [id://362955]=note: print w/replies, xml ) Need Help??


in reply to Int-3 equivalent?

You can get the desired behaviour as follows. Set perldb.ini as follows (in the current dir):

C:\>type perldb.ini $ENV{PERLDB_OPTS}="NonStop frame=2";

Because perl5db.pl (the debugger in X:\\Perl\lib\perl5db.pl on Win32) is Unix centric it will refuse to read this file due to permissions being too open. A quick patch is to skip the is_safe_file() test on Win32 circa line 317 with something like:

unless (is_safe_file($file) or $^O =~ m/Win32/ ) {

There are other options to set the NonStop feature (ie .perldb and set PERLDB_OPTS env var) but that was the only one that worked (after the patch) on Win32 and I was too lazy to debug the debugger any deeper. Anyway here is an example that happily flips into and out of the interactive debugger:

C:\>type test.pl print "Hello\n"; print "World!\n"; assert( 1 == 0 ); print "In interactive Debugger!\n"; $a = "Still in debugger!\n"; print $a; assert( 1 == 1 ); print "Escaped Debugger!\n"; print "Still Free!\n"; assert( 0 ); print "Debugger again!\n"; sub assert { $DB::single = $_[0] ? 0 : 1 } C:\>perl test.pl Hello World! In interactive Debugger! Still in debugger! Escaped Debugger! Still Free! Debugger again! C:\>perl -d test.pl Default die handler restored. Package test.pl. Hello World! entering main::assert exited main::assert 4: print "In interactive Debugger!\n"; DB<1> n In interactive Debugger! 5: $a = "Still in debugger!\n"; DB<1> n 6: print $a; DB<1> n Still in debugger! 7: assert( 1 == 1 ); DB<1> c entering main::assert exited main::assert Escaped Debugger! Still Free! entering main::assert exited main::assert 11: print "Debugger again!\n"; DB<1> c Debugger again! Debugged program terminated. Use q to quit or R to restart, use O inhibit_exit to avoid stopping after program termination, h q, h R or h O to get additional info. DB<1> q C:\>

cheers

tachyon

Replies are listed 'Best First'.
Re^2: Int-3 equivalent?
by sfink (Deacon) on Jun 10, 2004 at 06:51 UTC
    Yes, the exact equivalent of what the OP was looking for can be done with $DB::single = 1. I often insert this into my code when running it under the debugger; there's no compile/link cycle to worry about, so this is convenient enough. (tachyon's response already contained this information, but I never bother with perldb.ini files or anything.)

    Another useful hint is to put this chunk of code near the beginning of your file:

    BEGIN { $SIG{__WARN__} = sub { print STDERR @_; $DB::single = 1; } }
    This will make you drop into the debugger immediately after printing a warning. (It won't take effect until the following statement, so you don't have to worry about stepping out of the BEGIN block or anything.)

    My other main tool for using the perl debugger is my debug script, which you can simply add as a prefix to your perl command line and it'll pop up emacs running the debugger in a window. (Note that the script is also for running gdb on non-perl files, so watch out if it says (gdb) instead of DB<>.)

    Update: I can't believe I originally wrote $ENV{__WARN__} instead of $SIG{__WARN___}...

Re^2: Int-3 equivalent?
by BrowserUk (Patriarch) on Jun 10, 2004 at 01:45 UTC

    That's neat! tachyon++

    I looked at perldb.ini a long while ago but in never seemed to work. Now I know why:)

    Wrap that little assert sub up in a source filter along with the code to read and invoke comment embedded db commands and it has the making of a really useful tool.

    Off to read more...Thanks.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
Re^2: Int-3 equivalent?
by toma (Vicar) on Jun 10, 2004 at 07:11 UTC
    Nice trick!

    On linux I used:

    BEGIN { $ENV{PERLDB_OPTS}="NonStop frame=2"; }
    which seems to work fine. This technique also works with the ptkdb debugger.

    Using it this way with ptkdb on linux, the debugger window appears at the start of the program. I can press 'Run' and the program runs until the equivalent of a 'breakpoint', which is set with the assert() routine.

    I wonder if there is a way to get the ptkdb window to appear for the first time when the assert function is called? That way, my program could run normally and only pull up ptkdb when something goes wrong.

    It should work perfectly the first time! - toma
Re^2: Int-3 equivalent?
by dfaure (Chaplain) on Jun 10, 2004 at 06:42 UTC

    (++) Definitely the sort of thing I was seeking for a (very) long time!

    Would it be nice having a Categorized Q&A entry of it?

    Update: The perl5db.pl included into ActivePerl 5.8.3, is v1.23 and the line number is 1271. Personally, I prefered alter function is_safe_file with the following first line:

    return 1 if $^O =~ m/Win32/;
    HTH, Dominique
Re^2: Int-3 equivalent?
by bmann (Priest) on Jun 10, 2004 at 07:08 UTC
    Excellent! I wish I could give more than one ++.

    For anyone else looking, you could also set the environment variable PERL5DB_OPTS="NonStop frame=2", then execute the script with the -d command line switch (perl -d script.pl).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-20 02:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found