develooper Front page | perl.perl5.porters | Postings from November 2010

[perl #79442] A #line "F" in a string eval doesn't update *{"_<F"}

Thread Previous | Thread Next
Tim Bunce
November 20, 2010 02:38
[perl #79442] A #line "F" in a string eval doesn't update *{"_<F"}
Message ID:
# New Ticket Created by  Tim Bunce 
# Please include the string:  [perl #79442]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.39 running under perl 5.12.2.

[Please describe your issue here]

I'm trying to improve how NYTProf works with Class::MOP/Moose
and other code that uses #line directives.

Here's a test script:

BEGIN { $^P |= 0x400|0x100|0x10 }
sub a { 0 } 1;
#line 1 "hash-line-first"
sub b { 1 }
#line 1 "hash-line-second"
sub c { 2 }
eval qq{#line 1 "hash-line-eval"
sub d { 3 } 1
} or die;

a(); b(); c(); d();

    for my $file (sort grep { m/_</ } keys %{'main::'}) {
        print "File: $file  ($$file)  Source:\n";
        my $src = \@$file;
        print for map { "\t$_: $src->[$_]" } 1..@$src;
        print "\n";
    print "Sub:  $_ => $DB::sub{$_}\n" for sort keys %DB::sub;

and the output (using 5.12.2):

File: _<(eval 1)[hash-line-second:2]  ((eval 1)[hash-line-second:2])  Source:
	1: #line 1 "hash-line-eval"
	2: sub d { 3 } 1
	4: ;	5: 
File: _<hash-line-eval  (hash-line-eval)  Source:

File: _<hash-line-first  (hash-line-first)  Source:
	1: sub b { 1 }
	2: #line 1 "hash-line-second"
File: _<hash-line-second  (hash-line-second)  Source:
	1: sub c { 2 }
	2: eval qq{#line 1 "hash-line-eval"
	3: sub d { 3 } 1
	4: } or die;
	6: a(); b(); c(); d();
	8: END {
	9:     for my $file (sort grep { m/_</ } keys %{'main::'}) {
	10:         print "File: $file  ($$file)  Source:\n";
	11:         my $src = \@$file;
	12:         print for map { "\t$_: $src->[$_]" } 1..@$src;
	13:         print "\n";
	14:     }
	15:     print "Sub:  $_ => $DB::sub{$_}\n" for sort keys %DB::sub;
	16: }
File: _<  (  Source:

File: _<mro.c  (mro.c)  Source:

File: _<perl.c  (perl.c)  Source:

File: _<perlio.c  (perlio.c)  Source:

File: _<perlmain.c  (perlmain.c)  Source:

File: _<universal.c  (universal.c)  Source:

Sub:  main::END => hash-line-second:8-16
Sub:  main::a =>
Sub:  main::b => hash-line-first:1-1
Sub:  main::c => hash-line-second:1-1
Sub:  main::d => hash-line-eval:1-1

Things to note:

a. There's no source code saved for itself because $^P is
   set too late to capture the source. perl -d ... works. Not a problem.

b. #line 1 "hash-line-first" and #line 1 "hash-line-second" work as expected.

c. The subroutines all get recorded in %DB::sub with the correct filename.

d. The #line inside the string eval does not work as expected.
   The initial *{"_<(eval 1)[...]"} is created and populated, fine.
   Then when it sees the #line it creates a *{"_<hash-line-eval"} glob
   but doesn't store the source code in the array. That's a bug.

So %DB::sub says subroutine d() was defined in the file "hash-line-eval"
but there's no source code in @{"_<hash-line-eval"}.

The upshot is that the portion of the source code of a string eval after
a #line directive isn't where it should be, so NYTProf can't find it.
The debugger won't be able to find it either.


[Please do not change anything below this line]
Site configuration information for perl 5.12.2:

Configured by timbo at Sun Oct  3 16:42:33 IST 2010.

Summary of my perl5 (revision 5 version 12 subversion 2) configuration:
  Commit id: 7a3b65c9d99f69553fffe01f73d49fe9abf95120
    osname=darwin, osvers=10.4.0, archname=darwin-thread-multi-2level
    uname='darwin timac.local 10.4.0 darwin kernel version 10.4.0: fri apr 23 18:28:53 pdt 2010; root:xnu-1504.7.4~1release_i386 i386 '
    config_args='-des -Doptimize=-g -DEBUGGING=both -Dusethreads -Dusemultiplicity -Dusesitecustomize -Dusedevel -Uversiononly -Dprefix=/usr/local/perl512-dev'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -I/opt/local/include',
    cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -no-cpp-precomp -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -I/opt/local/include'
    ccversion='', gccversion='4.2.1 (Apple Inc. build 5664)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    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 =' -fstack-protector -L/usr/local/lib -L/opt/local/lib'
    libpth=/usr/local/lib /opt/local/lib /usr/lib
    libs=-lgdbm -ldbm -ldl -lm -lutil -lc
    perllibs=-ldl -lm -lutil -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib -fstack-protector'

Locally applied patches:

@INC for perl 5.12.2:

Environment for perl 5.12.2:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About