Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] caller() skips frames (such as eval() frames) if $^P set #7888

Closed
p5pRT opened this issue Apr 20, 2005 · 5 comments
Closed

[PATCH] caller() skips frames (such as eval() frames) if $^P set #7888

p5pRT opened this issue Apr 20, 2005 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Apr 20, 2005

Migrated from rt.perl.org#35059 (status was 'resolved')

Searchable as RT35059$

@p5pRT
Copy link
Author

p5pRT commented Apr 20, 2005

From glasser@tang-eleven-seventy-nine.mit.edu

Created by glasser@tang-eleven-seventy-nine.mit.edu

If the glob DB​::sub exists but the subroutine &DB​::sub does not, caller() can
get confused and skip certain frames -- especially frames created by eval.
This situation will occur if $^P is set and the debugger has not been loaded.
A patch is provided, including some test cases.

This is the same issue that was addressed by change 21842, but that change only
addressed a symptom of this problem. My patch reverses change 21842 (I'm not
sure if this has been applied in the 5.8 branch yet, but if it hasn't the mg.c
changes should just be ignored). This patch didn't come with test cases, but
my patch does seem to fix the symptom seen in the message which sent it in.
(Note that the old patch did not fully fix the problem that was observed, since
'perl pb 16' still displayed the erroneous behavior even under the old patch.)

Inline Patch
diff -ruN bleadperl.orig/mg.c bleadperl/mg.c
--- bleadperl.orig/mg.c	Tue Apr 19 06:26:03 2005
+++ bleadperl/mg.c	Wed Apr 20 13:11:18 2005
@@ -2162,8 +2162,7 @@
 	break;
     case '\020':	/* ^P */
 	PL_perldb = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
-	if ((PERLDB_SUB || PERLDB_LINE || PERLDB_SUBLINE || PERLDB_ASSERTION)
-		&& !PL_DBsingle)
+	if (PL_perldb && !PL_DBsingle)
 	    init_debugger();
 	break;
     case '\024':	/* ^T */
diff -ruN bleadperl.orig/pp_ctl.c bleadperl/pp_ctl.c
--- bleadperl.orig/pp_ctl.c	Mon Apr 18 08:44:18 2005
+++ bleadperl/pp_ctl.c	Wed Apr 20 13:55:24 2005
@@ -1567,7 +1567,8 @@
             }
 	    RETURN;
 	}
-	if (PL_DBsub && cxix >= 0 &&
+	/* caller() should not report the automatic calls to &DB::sub */
+	if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 &&
 		ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
 	    count++;
 	if (!count--)
@@ -1580,7 +1581,8 @@
         dbcxix = dopoptosub_at(ccstack, cxix - 1);
 	/* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the
 	   field below is defined for any cx. */
-	if (PL_DBsub && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
+	/* caller() should not report the automatic calls to &DB::sub */
+	if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub))
 	    cx = &ccstack[dbcxix];
     }
 
diff -ruN bleadperl.orig/t/op/caller.t bleadperl/t/op/caller.t
--- bleadperl.orig/t/op/caller.t	Fri Apr  8 08:45:08 2005
+++ bleadperl/t/op/caller.t	Wed Apr 20 14:06:25 2005
@@ -5,7 +5,7 @@
     chdir 't' if -d 't';
     @INC = '../lib';
     require './test.pl';
-    plan( tests => 27 );
+    plan( tests => 31 );
 }
 
 my @c;
@@ -87,3 +87,32 @@
     BEGIN { is( ${^WARNING_BITS}, "UUUUUUUUUUUU", 'warning bits on via "use warnings::register"' ) }
     testwarn("UUUUUUUUUUUU","#3");
 }
+
+
+# The next two cases test for a bug where caller ignored evals if
+# the DB::sub glob existed but &DB::sub did not (for example, if 
+# $^P had been set but no debugger has been loaded).  The tests
+# thus assume that there is no &DB::sub: if there is one, they 
+# should both pass  no matter whether or not this bug has been
+# fixed.
+
+my $debugger_test =  q<
+    my @stackinfo = caller(0);
+    return scalar @stackinfo;
+>;
+
+sub pb { return (caller(0))[3] }
+
+my $i = eval $debugger_test;
+is( $i, 10, "do not skip over eval (and caller returns 10 elements)" );
+
+is( eval 'pb()', 'main::pb', "actually return the right function name" );
+
+my $saved_perldb = $^P;
+$^P = 16;
+$^P = $saved_perldb;
+
+$i = eval $debugger_test;
+is( $i, 10, 'do not skip over eval even if $^P had been on at some point' );
+is( eval 'pb()', 'main::pb', 'actually return the right function name even if $^P had been on at some point' );
+
Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.9.3:

Configured by glasser at Wed Apr 20 14:35:33 EDT 2005.

Summary of my perl5 (revision 5 version 9 subversion 3 patch 24260) configuration:
  Platform:
    osname=darwin, osvers=7.9.0, archname=darwin-2level
    uname='darwin tang-eleven-seventy-nine.mit.edu 7.9.0 darwin kernel version 7.9.0: wed mar 30 20:11:17 pst 2005; root:xnuxnu-517.12.7.obj~1release_ppc power macintosh powerpc '
    config_args='-Dusedevel -Dprefix=/opt/blead/perl -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -I/usr/local/include',
    optimize='-Os',
    cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='3.3 20030304 (Apple Computer, Inc. build 1671)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib
    libs=-ldbm -ldl -lm -lc
    perllibs=-ldl -lm -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.9.3:
    /sw/lib/perl5
    /sw/lib/perl5/darwin
    /opt/blead/perl/lib/5.9.3/darwin-2level
    /opt/blead/perl/lib/5.9.3
    /opt/blead/perl/lib/site_perl/5.9.3/darwin-2level
    /opt/blead/perl/lib/site_perl/5.9.3
    /opt/blead/perl/lib/site_perl
    .


Environment for perl v5.9.3:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/glasser
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin:/usr/X11R6/bin:/Users/glasser/bin
    PERL5LIB=/sw/lib/perl5:/sw/lib/perl5/darwin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Apr 20, 2005

From @iabyn

On Wed, Apr 20, 2005 at 07​:28​:14PM -0000, glasser @​ tang-eleven-seventy-nine. mit. edu wrote​:

If the glob DB​::sub exists but the subroutine &DB​::sub does not, caller() can
get confused and skip certain frames -- especially frames created by eval.
This situation will occur if $^P is set and the debugger has not been loaded.
A patch is provided, including some test cases.

thanks, applied as change #24265

--
"The GPL violates the U.S. Constitution, together with copyright,
antitrust and export control laws"
  -- SCO smoking crack again.

@p5pRT
Copy link
Author

p5pRT commented Apr 20, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Apr 20, 2005

@iabyn - Status changed from 'open' to 'rejected'

@p5pRT p5pRT closed this as completed Apr 20, 2005
@p5pRT
Copy link
Author

p5pRT commented Apr 20, 2005

@iabyn - Status changed from 'rejected' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant