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

A #line "F" in a string eval doesn't update *{"_<F"} #10834

Closed
p5pRT opened this issue Nov 19, 2010 · 6 comments
Closed

A #line "F" in a string eval doesn't update *{"_<F"} #10834

p5pRT opened this issue Nov 19, 2010 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 19, 2010

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

Searchable as RT79442$

@p5pRT
Copy link
Author

p5pRT commented Nov 19, 2010

From @timbunce

Created by @timbunce

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

Here's a test script​:

------snip------
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();

END {
  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;
}
------snip------

and the output (using 5.12.2)​:

------snip------
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
  3​:
  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"
  3​:
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;
  5​:
  6​: a(); b(); c(); d();
  7​:
  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​: }
  17​:
File​: _<hashline.pl (hashline.pl) 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 => hashline.pl​:2-2
Sub​: main​::b => hash-line-first​:1-1
Sub​: main​::c => hash-line-second​:1-1
Sub​: main​::d => hash-line-eval​:1-1
------snip------

Things to note​:

a. There's no source code saved for hashline.pl 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.

Tim.

Perl Info

Flags:
    category=core
    severity=medium

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
  Platform:
    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
  Compiler:
    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',
    optimize='-g',
    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
    gnulibc_version=''
  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:
    /usr/local/perl512-dev/lib/site_perl/5.12.2/darwin-thread-multi-2level
    /usr/local/perl512-dev/lib/site_perl/5.12.2
    /usr/local/perl512-dev/lib/5.12.2/darwin-thread-multi-2level
    /usr/local/perl512-dev/lib/5.12.2
    /usr/local/perl512-dev/lib/site_perl/5.12.0/darwin-thread-multi-2level
    /usr/local/perl512-dev/lib/site_perl/5.12.0
    /usr/local/perl512-dev/lib/site_perl
    .


Environment for perl 5.12.2:
    DYLD_LIBRARY_PATH=:/usr/local/pgsql/lib/:/opt/local/lib/mysql5/mysql
    HOME=/Users/timbo
    LANG=en_IE.UTF-8
    LANGUAGE (unset)
    LC_ALL=en_IE.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/pgsql/bin:/Users/timbo/bin:/usr/local/perl512-dev/bin:/Users/timbo/perl6/rakudo/parrot_install/bin:/usr/local/mysql/bin:/usr/local/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
    PERLCRITIC=/Users/timbo/.setdev/perlcriticrc
    PERLTIDY=/Users/timbo/.setdev/perltidyrc
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Nov 21, 2010

From @cpansprout

On Fri Nov 19 04​:11​:52 2010, timbo wrote​:

but there's no source code in @​{"_<hash-line-eval"}.

I can reproduce this with threads, but not without.

@p5pRT
Copy link
Author

p5pRT commented Nov 21, 2010

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

@p5pRT
Copy link
Author

p5pRT commented Jan 4, 2011

From @timbunce

On Fri, Nov 19, 2010 at 04​:11​:52AM -0800, Tim Bunce wrote​:

# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=79442 >

Any chance this could get looked into before 5.14?

Tim.

@p5pRT
Copy link
Author

p5pRT commented Feb 27, 2011

From @cpansprout

On Tue Jan 04 05​:48​:38 2011, timbo wrote​:

On Fri, Nov 19, 2010 at 04​:11​:52AM -0800, Tim Bunce wrote​:

# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=79442 >

Any chance this could get looked into before 5.14?

Yes. :-)
http​://perl5.git.perl.org/perl.git/commitdiff/8818d40

@p5pRT
Copy link
Author

p5pRT commented Feb 27, 2011

@cpansprout - Status changed from 'open' 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