develooper Front page | perl.perl5.porters | Postings from April 2000

Re: stack backtrace confusion

From:
Gurusamy Sarathy
Date:
April 23, 2000 21:58
Subject:
Re: stack backtrace confusion
Message ID:
200004240458.VAA26019@maul.ActiveState.com
On Wed, 22 Mar 2000 11:07:28 MST, Tom Christiansen wrote:
>I don't know whether it's cluck or me or both, but this output seems weird
>at best.
>
>    use Carp qw/cluck/;
>
>    backtrace();
>
>    END { backtrace() }
>    END { cluck "And now we're done" }
>    BEGIN { cluck "Let's start it all rolling" }
>    END { cluck "I was done first!" }
>
>
>    sub backtrace  {
>	print "DUMP BACKTRACE:\n";
>	my $i = 0;
>	while (my($pack, $file, $line, $sub) = caller($i++)) {
>	    print "\tCALLED: $pack $file $line $sub\n";
>	}
>    }
>
>Makes:
>
>    Let's start it all rolling at /tmp/x line 7
>	    main::BEGIN() called at /tmp/x line 7
>	    require 0 called at /tmp/x line 7
>    DUMP BACKTRACE:
>	    CALLED: main /tmp/x 3 main::backtrace
>    I was done first! at /tmp/x line 8
>	    main::END() called at /tmp/x line 0
>	    require 0 called at /tmp/x line 0
>    And now we're done at /tmp/x line 6
>	    main::END() called at /tmp/x line 0
>	    require 0 called at /tmp/x line 0
>    DUMP BACKTRACE:
>	    CALLED: main /tmp/x 5 main::backtrace
>	    CALLED: main /tmp/x 0 main::END
>	    CALLED: main /tmp/x 0 (eval)

Here's a fix for this.  The bugs database has at least one dup of the
same problem, 20000405.013.


Sarathy
gsar@ActiveState.com
-----------------------------------8<-----------------------------------
Change 5914 by gsar@auger on 2000/04/24 04:56:08

	caller() wasn't returning the right number of elements for
	eval {...}

Affected files ...

... //depot/perl/pp_ctl.c#195 edit
... //depot/perl/t/pragma/warn/9enabled#3 edit

Differences ...

==== //depot/perl/pp_ctl.c#195 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c.~1~	Sun Apr 23 21:56:11 2000
+++ perl/pp_ctl.c	Sun Apr 23 21:56:11 2000
@@ -1521,15 +1521,21 @@
     else
 	PUSHs(sv_2mortal(newSViv(gimme & G_ARRAY)));
     if (CxTYPE(cx) == CXt_EVAL) {
+	/* eval STRING */
 	if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
 	    PUSHs(cx->blk_eval.cur_text);
 	    PUSHs(&PL_sv_no);
 	}
-	/* try blocks have old_namesv == 0 */
+	/* require */
 	else if (cx->blk_eval.old_namesv) {
 	    PUSHs(sv_2mortal(newSVsv(cx->blk_eval.old_namesv)));
 	    PUSHs(&PL_sv_yes);
 	}
+	/* eval BLOCK (try blocks have old_namesv == 0) */
+	else {
+	    PUSHs(&PL_sv_undef);
+	    PUSHs(&PL_sv_undef);
+	}
     }
     else {
 	PUSHs(&PL_sv_undef);

==== //depot/perl/t/pragma/warn/9enabled#3 (xtext) ====
Index: perl/t/pragma/warn/9enabled
--- perl/t/pragma/warn/9enabled.~1~	Sun Apr 23 21:56:11 2000
+++ perl/t/pragma/warn/9enabled	Sun Apr 23 21:56:11 2000
@@ -332,7 +332,7 @@
 EXPECT
 Usage: warnings::warn([category,] 'message') at - line 4
 unknown warnings category 'fred' at - line 6
-	require 0 called at - line 6
+	eval {...} called at - line 6
 ########
 
 --FILE-- abc.pm
End of Patch.



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