develooper Front page | perl.perl5.porters | Postings from July 2008

Re: [perl #57016] debugger: o warn=0 die=0 ignored

Thread Next
From:
Tye McQueen
Date:
July 29, 2008 07:09
Subject:
Re: [perl #57016] debugger: o warn=0 die=0 ignored
Message ID:
f57370570807282332i32d00e4flf7d5af03d067352@mail.gmail.com
On Sat, Jul 26, 2008 at 11:30 AM, Bram via RT <perlbug-followup@perl.org>wrote:

> Thanks for the bug report/patch.
>
> Can you also provide an example of where it doesn't behave as you
> expected?
>

Um, just start the debugger, type "o warn=0 die=0" and then use warn or die
and notice that lots of extraneous stack trace is still displayed.

If you are unable to notice the difference, then just simulate what it
should do via:

$SIG{__WARN__}= $SIG{__DIE__}= 0

and then try warn/die and see how unadorned the output is.

Oh, to start the debugger, you can use "perl -debug".  A full demonstration:

========================================

 $ perl -debug

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(-e:1):   bug
  DB<1> warn "extra junk!\n"
extra junk!
 at (eval 5)[/usr/local/lib/perl5/5.8.7/perl5db.pl:628] line 2
        eval '($@, $!, $^E, $,, $/, $\\, $^W) = @saved;package main; $^D =
$^D |
 $DB::db_stop;
warn "extra junk!\\n";

;' called at /usr/local/lib/perl5/5.8.7/perl5db.pl line 628
        DB::eval called at /usr/local/lib/perl5/5.8.7/perl5db.pl line 3410
        DB::DB called at -e line 1

  DB<2> o warn=0
           warnLevel = '0'
  DB<3> warn "junk?\n"
junk?
 at (eval 6)[/usr/local/lib/perl5/5.8.7/perl5db.pl:628] line 2
        eval '($@, $!, $^E, $,, $/, $\\, $^W) = @saved;package main; $^D =
$^D |
 $DB::db_stop;
warn "junk?\\n";

;' called at /usr/local/lib/perl5/5.8.7/perl5db.pl line 628
        DB::eval called at /usr/local/lib/perl5/5.8.7/perl5db.pl line 3410
        DB::DB called at -e line 1

  DB<4> $SIG{__WARN__}= 0

  DB<5> warn "just this!\n"
just this!

  DB<6> q
 $

========================================

Note that I've verified that this is broken in standard 5.8.7, 5.8.8, and
5.10.  However, Strawberry Perl 5.8.8 appears to have patched this to fix it
and also to set the default warnLevel to 0 instead of to 1, as shown below.
Does it really take this long for patches to arrive from Strawberry or just
for them to get applied?

========================================

 > perl -debug

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(-e:1):   bug

SetConsoleMode failed, LastError=|6| at
C:/strawberry-perl/perl/site/lib/Term/Re
adKey.pm line 265.
  DB<1> o warn?
           warnLevel = '0'

  DB<2> warn "just this\n"
just this


  DB<3> o warn=1
           warnLevel = '1'

  DB<4> warn "junk!\n"
junk!
 at (eval 11)[C:/strawberry-perl/perl/lib/perl5db.pl:628] line 2
        eval '($@, $!, $^E, $,, $/, $\\, $^W) = @saved;package main; $^D =
$^D |
 $DB::db_stop;
warn "junk!\\n";

;' called at C:/strawberry-perl/perl/lib/perl5db.pl line 628
        DB::eval called at C:/strawberry-perl/perl/lib/perl5db.pl line 3410
        DB::DB called at -e line 1


  DB<5> o warn=0
           warnLevel = '0'

  DB<6> warn "Just this!\n"
Just this!


  DB<7> q

 >

========================================

Oh, the Strawberry Perl fix is simpler than the fix I proposed, just replace
the "elsif"s with plain "else"s:

sub warnLevel {
    if (@_) {
        $prevwarn = $SIG{__WARN__} unless $warnLevel;
        $warnLevel = shift;
        if ($warnLevel) {
            $SIG{__WARN__} = \&DB::dbwarn;
        }
        else {
            $SIG{__WARN__} = $prevwarn;
        }
    } ## end if (@_)
    $warnLevel;
} ## end sub warnLevel

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About