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

Debugger Loses Names for Anonymous Subroutines #8357

Open
p5pRT opened this issue Mar 5, 2006 · 8 comments
Open

Debugger Loses Names for Anonymous Subroutines #8357

p5pRT opened this issue Mar 5, 2006 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 5, 2006

Migrated from rt.perl.org#38673 (status was 'stalled')

Searchable as RT38673$

@p5pRT
Copy link
Author

p5pRT commented Mar 5, 2006

From chromatic@wgz.org

Created by chromatic@wgz.org

Assigning to the *__ANON__ typeglob within an otherwise-anonymous subroutine
makes the name visible through caller()​:

  use strict;
  use warnings;

  my $sub = sub
  {
  local *__ANON__ = 'foo';
  bar();
  };

  sub bar
  {
  warn "Called from ", ( caller(1) )[3], "!\n";
  }

  $sub->();

This prints​:

  Called from main​::foo!

Running this through the debugger gives much different results however​:

  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​::(debanonsub.pl​:10)​: };
  DB<1> n
  main​::(debanonsub.pl​:17)​: $sub->();
  DB<1> n
  Called from main​::__ANON__[debanonsub.pl​:10]!
  at debanonsub.pl line 14
  main​::bar() called at debanonsub.pl line 9
  main​::__ANON__[debanonsub.pl​:10]() called at debanonsub.pl line 17

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.8.8:

Configured by Gentoo at Thu Feb  9 11:45:59 PST 2006.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.14-gentoo-r2, archname=powerpc-linux
    uname='linux windwheel 2.6.14-gentoo-r2 #1 mon nov 14 21:37:16 pst 2005 
ppc 7455, altivec supported powerbook3,5 gnulinux '
    config_args='-des -Darchname=powerpc-linux -Dcccdlflags=-fPIC 
-Dccdlflags=-rdynamic -Dcc=powerpc-unknown-linux-gnu-gcc -Dprefix=/usr 
-Dvendorprefix=/usr -Dsiteprefix=/usr -Dlocincpth=  -Doptimize=-O1 -pipe 
-mcpu=7400 -fsigned-char -mpowerpc-gfxopt -maltivec -mabi=altivec 
-Duselargefiles -Dd_semctl_semun -Dscriptdir=/usr/bin 
-Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 
-Dinstallman1dir=/usr/share/man/man1 -Dinstallman3dir=/usr/share/man/man3 
-Dman1ext=1 -Dman3ext=3pm -Dinc_version_list=5.8.0 5.8.0/powerpc-linux 5.8.2 
5.8.2/powerpc-linux 5.8.4 5.8.4/powerpc-linux 5.8.5 5.8.5/powerpc-linux 5.8.6 
5.8.6/powerpc-linux 5.8.7 5.8.7/powerpc-linux  -Dcf_by=Gentoo -Ud_csh 
-Di_ndbm -Di_gdbm -Di_db'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=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='powerpc-unknown-linux-gnu-gcc', ccflags ='-DDEBUGGING 
-fno-strict-aliasing -pipe -Wdeclaration-after-statement -D_LARGEFILE_SOURCE 
-D_FILE_OFFSET_BITS=64',
    optimize='-O1 -pipe -mcpu=7400 -fsigned-char -mpowerpc-gfxopt -maltivec 
-mabi=altivec',
    cppflags='-DDEBUGGING -fno-strict-aliasing -pipe 
-Wdeclaration-after-statement'
    ccversion='', gccversion='3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, 
pie-8.7.8)', 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='powerpc-unknown-linux-gnu-gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lpthread -lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.5.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.5'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.8.8:
    /etc/perl
    /usr/lib/perl5/vendor_perl/5.8.8/powerpc-linux
    /usr/lib/perl5/vendor_perl/5.8.8
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl/5.8.0/powerpc-linux
    /usr/lib/perl5/vendor_perl/5.8.2
    /usr/lib/perl5/vendor_perl/5.8.2/powerpc-linux
    /usr/lib/perl5/vendor_perl/5.8.6
    /usr/lib/perl5/vendor_perl/5.8.6/powerpc-linux
    /usr/lib/perl5/vendor_perl/5.8.7
    /usr/lib/perl5/vendor_perl/5.8.7/powerpc-linux
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/site_perl/5.8.8/powerpc-linux
    /usr/lib/perl5/site_perl/5.8.8
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/powerpc-linux
    /usr/lib/perl5/site_perl/5.8.2
    /usr/lib/perl5/site_perl/5.8.2/powerpc-linux
    /usr/lib/perl5/site_perl/5.8.6
    /usr/lib/perl5/site_perl/5.8.6/powerpc-linux
    /usr/lib/perl5/site_perl/5.8.7
    /usr/lib/perl5/site_perl/5.8.7/powerpc-linux
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/5.8.8/powerpc-linux
    /usr/lib/perl5/5.8.8
    /usr/local/lib/site_perl
    .


Environment for perl v5.8.8:
    HOME=/home/chromatic
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LC_ALL=en_US
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    
PATH=/usr/lib/ccache/bin:/usr/lib/ccache/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/powerpc-unknown-linux-gnu/gcc-bin/3.4.4:/opt/ghc/bin:/opt/blackdown-jdk-1.3.1/bin:/opt/blackdown-jdk-1.3.1/jre/bin:/usr/qt/3/bin:/usr/kde/3.4/bin:/usr/kde/3.3/bin:/usr/games/bin:/usr/sbin:/usr/local/bin:/usr/games/bin:/home/chromatic/bin:/usr/sbin:/usr/local/bin:/usr/games/bin:/home/chromatic/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Mar 11, 2006

From chromatic@wgz.org

On Saturday 04 March 2006 16​:07, chromatic wrote​:

Assigning to the *__ANON__ typeglob within an otherwise-anonymous
subroutine makes the name visible through caller()​:
Running this through the debugger gives much different results....

Applying this patch (which merely deletes code) fixes my problem. All tests
still pass. This bothers me almost as much as trying to figure out the logic
in this function.

Then again, I'm having a bit of trouble figuring out how to write a test for
this anyway without mocking up half of the debugger.

-- c

@p5pRT
Copy link
Author

p5pRT commented Mar 11, 2006

From chromatic@wgz.org

fix_anon_debugger.patch
--- op.c~	2006-03-11 03:01:46.000000000 -0800
+++ op.c	2006-03-11 03:03:01.000000000 -0800
@@ -4918,7 +4918,6 @@
 Perl_newATTRSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
 {
     dVAR;
-    const char *aname;
     GV *gv;
     const char *ps;
     STRLEN ps_len;
@@ -4942,19 +4941,8 @@
     else
 	ps = NULL;
 
-    if (!name && PERLDB_NAMEANON && CopLINE(PL_curcop)) {
-	SV * const sv = sv_newmortal();
-	Perl_sv_setpvf(aTHX_ sv, "%s[%s:%"IVdf"]",
-		       PL_curstash ? "__ANON__" : "__ANON__::__ANON__",
-		       CopFILE(PL_curcop), (IV)CopLINE(PL_curcop));
-	aname = SvPVX_const(sv);
-    }
-    else
-	aname = NULL;
-
     gv = name ? gv_fetchsv(cSVOPo->op_sv, gv_fetch_flags, SVt_PVCV)
-	: gv_fetchpv(aname ? aname
-		     : (PL_curstash ? "__ANON__" : "__ANON__::__ANON__"),
+	: gv_fetchpv(PL_curstash ? "__ANON__" : "__ANON__::__ANON__",
 		     gv_fetch_flags, SVt_PVCV);
 
     if (!PL_madskills) {
@@ -5225,9 +5213,9 @@
 	    CvCONST_on(cv);
     }
 
-    if (name || aname) {
+    if (name) {
 	const char *s;
-	const char * const tname = (name ? name : aname);
+	const char * const tname = name;
 
 	if (PERLDB_SUBLINE && PL_curstash != PL_debstash) {
 	    SV * const sv = newSV(0);

@p5pRT
Copy link
Author

p5pRT commented Mar 14, 2006

From @rgs

chromatic wrote​:

On Saturday 04 March 2006 16​:07, chromatic wrote​:

Assigning to the *__ANON__ typeglob within an otherwise-anonymous
subroutine makes the name visible through caller()​:
Running this through the debugger gives much different results....

Applying this patch (which merely deletes code) fixes my problem. All tests
still pass. This bothers me almost as much as trying to figure out the logic
in this function.

I don't like it.

Basically your patch removes the functionality given by the
PERLDBf_NAMEANON debugging flag, which is set by the debugger by default
(corresponding to the sub-item "0x200" of the $^P entry in perlvar, yes,
the docs could be more clear, and give the same symbolic names as the
debugger uses...)

IMO if you want avoid the debugger messing with your anon sub names
you need to remove PERLDBf_NAMEANON from the DollarCaretP option
with the 'o' command. There might be ways to make the debugger more
dwimmy, but patching it scares me a bit.

(OTOH a doc patch for DollarCaretP's allowed values would be welcome.)

@p5pRT
Copy link
Author

p5pRT commented Mar 14, 2006

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

@p5pRT
Copy link
Author

p5pRT commented Mar 14, 2006

From chromatic@wgz.org

On Tuesday 14 March 2006 02​:24, Rafael Garcia-Suarez wrote​:

Applying this patch (which merely deletes code) fixes my problem. All
tests still pass. This bothers me almost as much as trying to figure out
the logic in this function.

I don't like it.

Basically your patch removes the functionality given by the
PERLDBf_NAMEANON debugging flag, which is set by the debugger by default
(corresponding to the sub-item "0x200" of the $^P entry in perlvar, yes,
the docs could be more clear, and give the same symbolic names as the
debugger uses...)

IMO if you want avoid the debugger messing with your anon sub names
you need to remove PERLDBf_NAMEANON from the DollarCaretP option
with the 'o' command. There might be ways to make the debugger more
dwimmy, but patching it scares me a bit.

I'm not sure the problem is the debugger. If the code I deleted instead
stored the file and line information in the same place that assigning to
*__ANON__ does, wouldn't this solve the problem for both cases? With a
normal unnamed anonymous subroutine, having that information is valuable. It
shouldn't prevent someone from naming an anonymous subroutine instance
though.

I must admit to getting very lost in figuring out how *__ANON__ and the
CV/GV/stash stuff all work together though.

(OTOH a doc patch for DollarCaretP's allowed values would be welcome.)

I will look at that.

-- c

@p5pRT
Copy link
Author

p5pRT commented Mar 14, 2006

From @nwc10

On Tue, Mar 14, 2006 at 12​:00​:49PM -0800, chromatic wrote​:

I must admit to getting very lost in figuring out how *__ANON__ and the
CV/GV/stash stuff all work together though.

I'm not convinced that it's bug free. Sometimes I can see very strange
strings as CvNAME, but I can't see how they got there, nor can valgrind
see anything wrong.

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented May 16, 2008

p5p@spam.wizbit.be - Status changed from 'open' to 'stalled'

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

2 participants