Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

[BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


shlomif at iglu

Nov 10, 2006, 10:56 AM

Post #1 of 16 (568 views)
Permalink
[BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive

Hi all!

Put the following in a file called "Test2.pl" (with a capital "T"):

<<<<<<<<<<<<<<<<<<<<
#!/usr/bin/perl

use strict;
use warnings;

eval "
#line 5 Test2.pl
print 6*2, \"\n\";
";

for my $i (1 .. 10)
{
print "$i\n";
}

sub factorial
{
my $i = 0;
if ($i < 2)
{
return 1;
}
else
{
return $i*factorial($i-1);
}
}

for my $num (1 .. 10)
{
print $num, ": ", factorial($num), "\n";
}
>>>>>>>>>>>>>>>>>>>>>>>>

Run it under perl -d in perl-5.8.8 and press n a few times. As can be seen
after a while the current line content display disappears. This is caused due
to the fact that the eval with the "#line 5 Test2.pl" resets the file
contents that are supplied to the debugger in @{$main::{'_<Test2.pl'}}:

<<<<<<<<<<<<<<<<<<<
shlomi:~/progs/perl/itself/debugger/bugs/trunk$
~/apps/perl/perl-5.8.8-debug/bin/perl -d Test2.pl

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::(Test2.pl:6): eval "
DB<1> n
main::(Test2.pl:5): ;
DB<1> n
12
main::(Test2.pl:11):
DB<1> n
main::(Test2.pl:13):
DB<1> x @{$main::{'_<Test2.pl'}}
0 undef
1 '
'
2 '#line 5 Test2.pl
'
3 'print 6*2, "\\n";
'
4 '
'
5 ';'
>>>>>>>>>>>>>>>>>>>>>>>>

This doesn't happen with perl-5.6.2. I've spent some time today when
svn.perl.org was offline isolating this bug. I'd like to write a patch too,
but it may take some time due to the fact I'm not an expert in the Perl
internals.

I found this bug triggered by the like(...) statement in Test::More via an
eval statement in Test::Builder. And you can attribute it as a positive
outcome of the Chicago.pm hackathon. (which I followed from remote).

Regards,

Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish shlomif [at] iglu
Homepage: http://www.shlomifish.org/

Chuck Norris wrote a complete Perl 6 implementation in a day but then
destroyed all evidence with his bare hands, so no one will know his secrets.


rgarciasuarez at gmail

Nov 12, 2006, 7:53 AM

Post #2 of 16 (535 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On 10/11/06, Shlomi Fish <shlomif [at] iglu> wrote:
> Run it under perl -d in perl-5.8.8 and press n a few times. As can be seen
> after a while the current line content display disappears. This is caused due
> to the fact that the eval with the "#line 5 Test2.pl" resets the file
> contents that are supplied to the debugger in @{$main::{'_<Test2.pl'}}:

One can note that this bug doesn't happen with 5.8.7, so it is
relatively recent.


Richard.Foley at rfi

Nov 13, 2006, 3:16 AM

Post #3 of 16 (550 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On Sunday 12 November 2006 16:53, Rafael Garcia-Suarez wrote:
> On 10/11/06, Shlomi Fish <shlomif [at] iglu> wrote:
> > Run it under perl -d in perl-5.8.8 and press n a few times. As can be seen
> > after a while the current line content display disappears. This is caused
due
> > to the fact that the eval with the "#line 5 Test2.pl" resets the file
> > contents that are supplied to the debugger in @{$main::{'_<Test2.pl'}}:
>
> One can note that this bug doesn't happen with 5.8.7, so it is
> relatively recent.
>
>
Doesn't happen to me with perl-5.8.8, unless I'm doing something different or
have misunderstood you, as you can see from the output below. perl -V
included in case it is related to your/my installation...?

--
Richard Foley
Ciao - shorter than aufwiedersehen

http://www.rfi.net/


richard [at] linux22:~> perl -d Test2.pl

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::(Test2.pl:6): eval "
DB<1> x @{$main::{'_<Test2.pl'}}
0 'BEGIN { require \'perl5db.pl\' };
'
1 '#!/usr/bin/perl
'
2 '
'
3 'use strict;
'
4 'use warnings;
'
5 '
'
6 'eval "
'
7 '#line 5 Test2.pl
'
8 'print 6*2, \\"\\n\\";
'
9 '";
'
10 '
'
11 'for my $i (1 .. 10)
'
12 '{
'
13 ' print "$i\\n";
'
14 '}
'
15 '
'
16 'sub factorial
'
17 '{
'
18 ' my $i = 0;
'
19 ' if ($i < 2)
'
20 ' {
'
21 ' return 1;
'
22 ' }
'
23 ' else
'
24 ' {
'
25 ' return $i*factorial($i-1);
'
26 ' }
'
27 '}
'
28 '
'
29 'for my $num (1 .. 10)
'
30 '{
'
31 ' print $num, ": ", factorial($num), "\\n";
'
32 '}
'
33 '
'
DB<2> n
main::(Test2.pl:5):
DB<2> n
12
main::(Test2.pl:11): for my $i (1 .. 10)
main::(Test2.pl:12): {
DB<2> n
main::(Test2.pl:13): print "$i\n";
DB<2> x @{$main::{'_<Test2.pl'}}
0 'BEGIN { require \'perl5db.pl\' };
'
1 '#!/usr/bin/perl
'
2 '
'
3 'use strict;
'
4 'use warnings;
'
5 '
'
6 'eval "
'
7 '#line 5 Test2.pl
'
8 'print 6*2, \\"\\n\\";
'
9 '";
'
10 '
'
11 'for my $i (1 .. 10)
'
12 '{
'
13 ' print "$i\\n";
'
14 '}
'
15 '
'
16 'sub factorial
'
17 '{
'
18 ' my $i = 0;
'
19 ' if ($i < 2)
'
20 ' {
'
21 ' return 1;
'
22 ' }
'
23 ' else
'
24 ' {
'
25 ' return $i*factorial($i-1);
'
26 ' }
'
27 '}
'
28 '
'
29 'for my $num (1 .. 10)
'
30 '{
'
31 ' print $num, ": ", factorial($num), "\\n";
'
32 '}
'
33 '
'
DB<3> n
1
main::(Test2.pl:13): print "$i\n";
DB<3> n
2
main::(Test2.pl:13): print "$i\n";
DB<3> n
3
main::(Test2.pl:13): print "$i\n";
DB<3> x @{$main::{'_<Test2.pl'}}
0 'BEGIN { require \'perl5db.pl\' };
'
1 '#!/usr/bin/perl
'
2 '
'
3 'use strict;
'
4 'use warnings;
'
5 '
'
6 'eval "
'
7 '#line 5 Test2.pl
'
8 'print 6*2, \\"\\n\\";
'
9 '";
'
10 '
'
11 'for my $i (1 .. 10)
'
12 '{
'
13 ' print "$i\\n";
'
14 '}
'
15 '
'
16 'sub factorial
'
17 '{
'
18 ' my $i = 0;
'
19 ' if ($i < 2)
'
20 ' {
'
21 ' return 1;
'
22 ' }
'
23 ' else
'
24 ' {
'
25 ' return $i*factorial($i-1);
'
26 ' }
'
27 '}
'
28 '
'
29 'for my $num (1 .. 10)
'
30 '{
'
31 ' print $num, ": ", factorial($num), "\\n";
'
32 '}
'
33 '
'
DB<4> n
4
main::(Test2.pl:13): print "$i\n";
DB<4> n
5
main::(Test2.pl:13): print "$i\n";
DB<4> n
6
main::(Test2.pl:13): print "$i\n";
DB<4> x @{$main::{'_<Test2.pl'}}
0 'BEGIN { require \'perl5db.pl\' };
'
1 '#!/usr/bin/perl
'
2 '
'
3 'use strict;
'
4 'use warnings;
'
5 '
'
6 'eval "
'
7 '#line 5 Test2.pl
'
8 'print 6*2, \\"\\n\\";
'
9 '";
'
10 '
'
11 'for my $i (1 .. 10)
'
12 '{
'
13 ' print "$i\\n";
'
14 '}
'
15 '
'
16 'sub factorial
'
17 '{
'
18 ' my $i = 0;
'
19 ' if ($i < 2)
'
20 ' {
'
21 ' return 1;
'
22 ' }
'
23 ' else
'
24 ' {
'
25 ' return $i*factorial($i-1);
'
26 ' }
'
27 '}
'
28 '
'
29 'for my $num (1 .. 10)
'
30 '{
'
31 ' print $num, ": ", factorial($num), "\\n";
'
32 '}
'
33 '
'
DB<5> n
7
main::(Test2.pl:13): print "$i\n";
DB<5> n
8
main::(Test2.pl:13): print "$i\n";
DB<5> n
9
main::(Test2.pl:13): print "$i\n";
DB<5> x @{$main::{'_<Test2.pl'}}
0 'BEGIN { require \'perl5db.pl\' };
'
1 '#!/usr/bin/perl
'
2 '
'
3 'use strict;
'
4 'use warnings;
'
5 '
'
6 'eval "
'
7 '#line 5 Test2.pl
'
8 'print 6*2, \\"\\n\\";
'
9 '";
'
10 '
'
11 'for my $i (1 .. 10)
'
12 '{
'
13 ' print "$i\\n";
'
14 '}
'
15 '
'
16 'sub factorial
'
17 '{
'
18 ' my $i = 0;
'
19 ' if ($i < 2)
'
20 ' {
'
21 ' return 1;
'
22 ' }
'
23 ' else
'
24 ' {
'
25 ' return $i*factorial($i-1);
'
26 ' }
'
27 '}
'
28 '
'
29 'for my $num (1 .. 10)
'
30 '{
'
31 ' print $num, ": ", factorial($num), "\\n";
'
32 '}
'
33 '
'
DB<6> n
10
main::(Test2.pl:29): for my $num (1 .. 10)
main::(Test2.pl:30): {
DB<6> n
main::(Test2.pl:31): print $num, ": ", factorial($num), "\n";
DB<6> n
1: 1
main::(Test2.pl:31): print $num, ": ", factorial($num), "\n";
DB<6> x @{$main::{'_<Test2.pl'}}
0 'BEGIN { require \'perl5db.pl\' };
'
1 '#!/usr/bin/perl
'
2 '
'
3 'use strict;
'
4 'use warnings;
'
5 '
'
6 'eval "
'
7 '#line 5 Test2.pl
'
8 'print 6*2, \\"\\n\\";
'
9 '";
'
10 '
'
11 'for my $i (1 .. 10)
'
12 '{
'
13 ' print "$i\\n";
'
14 '}
'
15 '
'
16 'sub factorial
'
17 '{
'
18 ' my $i = 0;
'
19 ' if ($i < 2)
'
20 ' {
'
21 ' return 1;
'
22 ' }
'
23 ' else
'
24 ' {
'
25 ' return $i*factorial($i-1);
'
26 ' }
'
27 '}
'
28 '
'
29 'for my $num (1 .. 10)
'
30 '{
'
31 ' print $num, ": ", factorial($num), "\\n";
'
32 '}
'
33 '
'
DB<7> n
2: 1
main::(Test2.pl:31): print $num, ": ", factorial($num), "\n";
DB<7> n
3: 1
main::(Test2.pl:31): print $num, ": ", factorial($num), "\n";
DB<7> n
4: 1
main::(Test2.pl:31): print $num, ": ", factorial($num), "\n";
DB<7> x @{$main::{'_<Test2.pl'}}
0 'BEGIN { require \'perl5db.pl\' };
'
1 '#!/usr/bin/perl
'
2 '
'
3 'use strict;
'
4 'use warnings;
'
5 '
'
6 'eval "
'
7 '#line 5 Test2.pl
'
8 'print 6*2, \\"\\n\\";
'
9 '";
'
10 '
'
11 'for my $i (1 .. 10)
'
12 '{
'
13 ' print "$i\\n";
'
14 '}
'
15 '
'
16 'sub factorial
'
17 '{
'
18 ' my $i = 0;
'
19 ' if ($i < 2)
'
20 ' {
'
21 ' return 1;
'
22 ' }
'
23 ' else
'
24 ' {
'
25 ' return $i*factorial($i-1);
'
26 ' }
'
27 '}
'
28 '
'
29 'for my $num (1 .. 10)
'
30 '{
'
31 ' print $num, ": ", factorial($num), "\\n";
'
32 '}
'
33 '
'
DB<8> n
5: 1
main::(Test2.pl:31): print $num, ": ", factorial($num), "\n";
DB<8> n
6: 1
main::(Test2.pl:31): print $num, ": ", factorial($num), "\n";
DB<8> n
7: 1
main::(Test2.pl:31): print $num, ": ", factorial($num), "\n";
DB<8> x @{$main::{'_<Test2.pl'}}
0 'BEGIN { require \'perl5db.pl\' };
'
1 '#!/usr/bin/perl
'
2 '
'
3 'use strict;
'
4 'use warnings;
'
5 '
'
6 'eval "
'
7 '#line 5 Test2.pl
'
8 'print 6*2, \\"\\n\\";
'
9 '";
'
10 '
'
11 'for my $i (1 .. 10)
'
12 '{
'
13 ' print "$i\\n";
'
14 '}
'
15 '
'
16 'sub factorial
'
17 '{
'
18 ' my $i = 0;
'
19 ' if ($i < 2)
'
20 ' {
'
21 ' return 1;
'
22 ' }
'
23 ' else
'
24 ' {
'
25 ' return $i*factorial($i-1);
'
26 ' }
'
27 '}
'
28 '
'
29 'for my $num (1 .. 10)
'
30 '{
'
31 ' print $num, ": ", factorial($num), "\\n";
'
32 '}
'
33 '
'
DB<9> n
8: 1
main::(Test2.pl:31): print $num, ": ", factorial($num), "\n";
DB<9> n
9: 1
main::(Test2.pl:31): print $num, ": ", factorial($num), "\n";
DB<9> n
10: 1
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
DB<9> x @{$main::{'_<Test2.pl'}}
0 'BEGIN { require \'perl5db.pl\' };
'
1 '#!/usr/bin/perl
'
2 '
'
3 'use strict;
'
4 'use warnings;
'
5 '
'
6 'eval "
'
7 '#line 5 Test2.pl
'
8 'print 6*2, \\"\\n\\";
'
9 '";
'
10 '
'
11 'for my $i (1 .. 10)
'
12 '{
'
13 ' print "$i\\n";
'
14 '}
'
15 '
'
16 'sub factorial
'
17 '{
'
18 ' my $i = 0;
'
19 ' if ($i < 2)
'
20 ' {
'
21 ' return 1;
'
22 ' }
'
23 ' else
'
24 ' {
'
25 ' return $i*factorial($i-1);
'
26 ' }
'
27 '}
'
28 '
'
29 'for my $num (1 .. 10)
'
30 '{
'
31 ' print $num, ": ", factorial($num), "\\n";
'
32 '}
'
33 '
'
DB<10> .
main::(Test2.pl:31): print $num, ": ", factorial($num), "\n";
DB<10> n
Use `q' to quit or `R' to restart. `h q' for details.
DB<10> q
richard [at] linux22:~>

richard [at] linux22:~> perl -V
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
Platform:
osname=linux, osvers=2.6.13-15-smp, archname=i686-linux-thread-multi
uname='linux linux225 2.6.13-15-smp #1 smp tue sep 13 14:56:15 utc 2005
i686 i686 i386 gnulinux '
config_args='-des
-Dotherlibdirs=/usr/lib/perl5/5.8.7:/usr/lib/perl5/5.8.7/i586-linux-thread-multi:/usr/lib/perl5/site_perl:/usr/lib/perl5/site_perl/5.8.7:/usr/lib/perl5/site_perl/5.8.7/i586-linux-thread-multi:/usr/lib/perl5/vendor_perl:/usr/lib/perl5/vendor_perl/5.8.7:/usr/lib/perl5/vendor_perl/5.8.7/i586-linux-thread-multi
-Dinstallusrbinperl -Dusethreads'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef 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 ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-fno-strict-aliasing -pipe -Wdeclaration-after-statement
-I/usr/local/include'
ccversion='', gccversion='4.0.2 20050901 (prerelease) (SUSE Linux)',
gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -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='-Wl,-E'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT
PERL_MALLOC_WRAP THREADS_HAVE_PIDS USE_ITHREADS
USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API
Built under linux
Compiled at Oct 20 2006 15:27:16
@INC:
/usr/local/lib/perl5/5.8.8/i686-linux-thread-multi
/usr/local/lib/perl5/5.8.8
/usr/local/lib/perl5/site_perl/5.8.8/i686-linux-thread-multi
/usr/local/lib/perl5/site_perl/5.8.8
/usr/local/lib/perl5/site_perl
/usr/lib/perl5/5.8.7
/usr/lib/perl5/5.8.7/i586-linux-thread-multi
/usr/lib/perl5/site_perl
/usr/lib/perl5/site_perl/5.8.7
/usr/lib/perl5/site_perl/5.8.7/i586-linux-thread-multi
/usr/lib/perl5/vendor_perl
/usr/lib/perl5/vendor_perl/5.8.7
/usr/lib/perl5/vendor_perl/5.8.7/i586-linux-thread-multi


shlomif at iglu

Nov 13, 2006, 4:54 AM

Post #4 of 16 (542 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

Hi all!

On Monday 13 November 2006 13:16, Richard Foley wrote:
> On Sunday 12 November 2006 16:53, Rafael Garcia-Suarez wrote:
> > On 10/11/06, Shlomi Fish <shlomif [at] iglu> wrote:
> > > Run it under perl -d in perl-5.8.8 and press n a few times. As can be
> > > seen after a while the current line content display disappears. This is
> > > caused
>
> due
>
> > > to the fact that the eval with the "#line 5 Test2.pl" resets the file
> > > contents that are supplied to the debugger in @{$main::{'_<Test2.pl'}}:
> >
> > One can note that this bug doesn't happen with 5.8.7, so it is
> > relatively recent.
>
> Doesn't happen to me with perl-5.8.8, unless I'm doing something different
> or have misunderstood you, as you can see from the output below. perl -V
> included in case it is related to your/my installation...?

That's because your perl has ithreads enabled, which #ifdef out this code for
some reason. The code at question is found at toke.c at the function
S_incline:

<<<<<<<<<<<<
if (t - s > 0) {
#ifndef USE_ITHREADS
const char *cf = CopFILE(PL_curcop);
if (cf && strlen(cf) > 7 && strnEQ(cf, "(eval ", 6)) {
/* must copy *{"::_<(eval N)[oldfilename:L]"}
* to *{"::_<newfilename"} */
char smallbuf[256], smallbuf2[256];
char *tmpbuf, *tmpbuf2;
GV **gvp, *gv2;
STRLEN tmplen = strlen(cf);
STRLEN tmplen2 = strlen(s);
if (tmplen + 3 < sizeof smallbuf)
tmpbuf = smallbuf;
else
Newx(tmpbuf, tmplen + 3, char);
if (tmplen2 + 3 < sizeof smallbuf2)
tmpbuf2 = smallbuf2;
else
Newx(tmpbuf2, tmplen2 + 3, char);
tmpbuf[0] = tmpbuf2[0] = '_';
tmpbuf[1] = tmpbuf2[1] = '<';
memcpy(tmpbuf + 2, cf, ++tmplen);
memcpy(tmpbuf2 + 2, s, ++tmplen2);
++tmplen; ++tmplen2;
gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
if (gvp) {
gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
if (!isGV(gv2))
gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
/* adjust ${"::_<newfilename"} to store the new file name */
GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
}
if (tmpbuf != smallbuf) Safefree(tmpbuf);
if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
}
#endif
>>>>>>>>>>>>

(line 690 in perl-5.8.8).

This is cancelled if ithreads is defined. Ani-_ on IRC found the following
relevant patches:

http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&patch_num=25409
http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&patch_num=25411
http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&patch_num=25915
http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&patch_num=26050

Anyway the code in question runs over the contents of _<. It should either
leave them alone or possibly preferably use a local-like mechanism for the
duration of the eval "".

Regards,

Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish shlomif [at] iglu
Homepage: http://www.shlomifish.org/

Chuck Norris wrote a complete Perl 6 implementation in a day but then
destroyed all evidence with his bare hands, so no one will know his secrets.


shlomif at iglu

Nov 13, 2006, 5:04 AM

Post #5 of 16 (553 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On Sunday 12 November 2006 17:53, Rafael Garcia-Suarez wrote:
> On 10/11/06, Shlomi Fish <shlomif [at] iglu> wrote:
> > Run it under perl -d in perl-5.8.8 and press n a few times. As can be
> > seen after a while the current line content display disappears. This is
> > caused due to the fact that the eval with the "#line 5 Test2.pl" resets
> > the file contents that are supplied to the debugger in
> > @{$main::{'_<Test2.pl'}}:
>
> One can note that this bug doesn't happen with 5.8.7, so it is
> relatively recent.

Indeed it does not:

<<<<
--- perl-5.8.7/toke.c 2005-05-30 16:28:41.000000000 +0300
+++ perl-5.8.8/toke.c 2006-01-08 22:59:55.000000000 +0200
.
.
.
+#ifndef USE_ITHREADS
+ const char *cf = CopFILE(PL_curcop);
+ if (cf && strlen(cf) > 7 && strnEQ(cf, "(eval ", 6)) {
+ /* must copy *{"::_<(eval N)[oldfilename:L]"}
+ * to *{"::_<newfilename"} */
+ char smallbuf[256], smallbuf2[256];
+ char *tmpbuf, *tmpbuf2;
.
.
.
>>>>

Regards,

Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish shlomif [at] iglu
Homepage: http://www.shlomifish.org/

Chuck Norris wrote a complete Perl 6 implementation in a day but then
destroyed all evidence with his bare hands, so no one will know his secrets.


Richard.Foley at rfi

Nov 13, 2006, 5:14 AM

Post #6 of 16 (554 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

Looks suspiciously like you hit the nail right on the head there, Shlomi.
Nicely tracked down - now we just need some bright spark to fix it...

:-)

R.

On Monday 13 November 2006 13:54, Shlomi Fish wrote:
> Hi all!
>
> On Monday 13 November 2006 13:16, Richard Foley wrote:
> > On Sunday 12 November 2006 16:53, Rafael Garcia-Suarez wrote:
> > > On 10/11/06, Shlomi Fish <shlomif [at] iglu> wrote:
> > > > Run it under perl -d in perl-5.8.8 and press n a few times. As can be
> > > > seen after a while the current line content display disappears. This
is
> > > > caused
> >
> > due
> >
> > > > to the fact that the eval with the "#line 5 Test2.pl" resets the file
> > > > contents that are supplied to the debugger in @{$main::
{'_<Test2.pl'}}:
> > >
> > > One can note that this bug doesn't happen with 5.8.7, so it is
> > > relatively recent.
> >
> > Doesn't happen to me with perl-5.8.8, unless I'm doing something different
> > or have misunderstood you, as you can see from the output below. perl -V
> > included in case it is related to your/my installation...?
>
> That's because your perl has ithreads enabled, which #ifdef out this code
for
> some reason. The code at question is found at toke.c at the function
> S_incline:
>
> <<<<<<<<<<<<
> if (t - s > 0) {
> #ifndef USE_ITHREADS
> const char *cf = CopFILE(PL_curcop);
> if (cf && strlen(cf) > 7 && strnEQ(cf, "(eval ", 6)) {
> /* must copy *{"::_<(eval N)[oldfilename:L]"}
> * to *{"::_<newfilename"} */
> char smallbuf[256], smallbuf2[256];
> char *tmpbuf, *tmpbuf2;
> GV **gvp, *gv2;
> STRLEN tmplen = strlen(cf);
> STRLEN tmplen2 = strlen(s);
> if (tmplen + 3 < sizeof smallbuf)
> tmpbuf = smallbuf;
> else
> Newx(tmpbuf, tmplen + 3, char);
> if (tmplen2 + 3 < sizeof smallbuf2)
> tmpbuf2 = smallbuf2;
> else
> Newx(tmpbuf2, tmplen2 + 3, char);
> tmpbuf[0] = tmpbuf2[0] = '_';
> tmpbuf[1] = tmpbuf2[1] = '<';
> memcpy(tmpbuf + 2, cf, ++tmplen);
> memcpy(tmpbuf2 + 2, s, ++tmplen2);
> ++tmplen; ++tmplen2;
> gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
> if (gvp) {
> gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
> if (!isGV(gv2))
> gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
> /* adjust ${"::_<newfilename"} to store the new file name */
> GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
> GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
> GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
> }
> if (tmpbuf != smallbuf) Safefree(tmpbuf);
> if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);
> }
> #endif
> >>>>>>>>>>>>
>
> (line 690 in perl-5.8.8).
>
> This is cancelled if ithreads is defined. Ani-_ on IRC found the following
> relevant patches:
>
>
http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&patch_num=25409
>
http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&patch_num=25411
>
http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&patch_num=25915
>
http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&patch_num=26050
>
> Anyway the code in question runs over the contents of _<. It should either
> leave them alone or possibly preferably use a local-like mechanism for the
> duration of the eval "".
>
> Regards,
>
> Shlomi Fish
>
> ---------------------------------------------------------------------
> Shlomi Fish shlomif [at] iglu
> Homepage: http://www.shlomifish.org/
>
> Chuck Norris wrote a complete Perl 6 implementation in a day but then
> destroyed all evidence with his bare hands, so no one will know his secrets.
>
>

--
Richard Foley
Ciao - shorter than aufwiedersehen

http://www.rfi.net/


rgarciasuarez at gmail

Nov 13, 2006, 7:06 AM

Post #7 of 16 (548 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On 13/11/06, Shlomi Fish <shlomif [at] iglu> wrote:
> This is cancelled if ithreads is defined. Ani-_ on IRC found the following
> relevant patches:
>
> http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&patch_num=25409
> http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&patch_num=25411
> http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&patch_num=25915
> http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&patch_num=26050
>
> Anyway the code in question runs over the contents of _<. It should either
> leave them alone or possibly preferably use a local-like mechanism for the
> duration of the eval "".

Thanks for that detective work. I fixed the bug as change #29263 in bleadperl:

==== //depot/perl/toke.c#714 - /home/rafael/p4blead/toke.c ====
--- /home/rafael/tmp/tmp.30412.0 2006-11-13 16:03:41.000000000 +0100
+++ /home/rafael/p4blead/toke.c 2006-11-13 16:03:36.000000000 +0100
@@ -774,12 +774,13 @@ S_incline(pTHX_ char *s)
gvp = (GV**)hv_fetch(PL_defstash, tmpbuf, tmplen, FALSE);
if (gvp) {
gv2 = *(GV**)hv_fetch(PL_defstash, tmpbuf2, tmplen2, TRUE);
- if (!isGV(gv2))
+ if (!isGV(gv2)) {
gv_init(gv2, PL_defstash, tmpbuf2, tmplen2, FALSE);
- /* adjust ${"::_<newfilename"} to store the new file name */
- GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
- GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
- GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
+ /* adjust ${"::_<newfilename"} to store the new file name */
+ GvSV(gv2) = newSVpvn(tmpbuf2 + 2, tmplen2 - 2);
+ GvHV(gv2) = (HV*)SvREFCNT_inc(GvHV(*gvp));
+ GvAV(gv2) = (AV*)SvREFCNT_inc(GvAV(*gvp));
+ }
}
if (tmpbuf != smallbuf) Safefree(tmpbuf);
if (tmpbuf2 != smallbuf2) Safefree(tmpbuf2);


shlomif at iglu

Nov 13, 2006, 8:44 AM

Post #8 of 16 (551 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On Monday 13 November 2006 17:06, Rafael Garcia-Suarez wrote:
> On 13/11/06, Shlomi Fish <shlomif [at] iglu> wrote:
> > This is cancelled if ithreads is defined. Ani-_ on IRC found the
> > following relevant patches:
> >
> > http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&pa
> >tch_num=25409
> > http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&pa
> >tch_num=25411
> > http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&pa
> >tch_num=25915
> > http://public.activestate.com/cgi-bin/perlbrowse?show_patch=Show+Patch&pa
> >tch_num=26050
> >
> > Anyway the code in question runs over the contents of _<. It should
> > either leave them alone or possibly preferably use a local-like mechanism
> > for the duration of the eval "".
>
> Thanks for that detective work. I fixed the bug as change #29263 in
> bleadperl:

You're welcome and thanks. RGS++.

BTW, did you also add a regression test for this bug? I have an idea for how
to write one and can write one if you're interested.

Regards,

Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish shlomif [at] iglu
Homepage: http://www.shlomifish.org/

Chuck Norris wrote a complete Perl 6 implementation in a day but then
destroyed all evidence with his bare hands, so no one will know his secrets.


rgarciasuarez at gmail

Nov 13, 2006, 8:54 AM

Post #9 of 16 (548 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On 13/11/06, Shlomi Fish <shlomif [at] iglu> wrote:
> BTW, did you also add a regression test for this bug? I have an idea for how
> to write one and can write one if you're interested.

No, I didn't, and yes, I am. (not having good ideas about how to test
the debugger)


Richard.Foley at rfi

Nov 14, 2006, 12:40 AM

Post #10 of 16 (538 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On Monday 13 November 2006 17:54, Rafael Garcia-Suarez wrote:
> On 13/11/06, Shlomi Fish <shlomif [at] iglu> wrote:
> > BTW, did you also add a regression test for this bug? I have an idea for
how
> > to write one and can write one if you're interested.
>
> No, I didn't, and yes, I am. (not having good ideas about how to test
> the debugger)
>
>
I don't think the debugger has a test suite [at all]. I wanted to start one
and managed to run out of tuits. It would be good to see t/libs/perl5db.t or
somesuch. Maybe you'll encourage others to join in too.

--
Richard Foley
Ciao - shorter than aufwiedersehen

http://www.rfi.net/


shlomif at iglu

Nov 14, 2006, 5:40 AM

Post #11 of 16 (534 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On Monday 13 November 2006 18:54, Rafael Garcia-Suarez wrote:
> On 13/11/06, Shlomi Fish <shlomif [at] iglu> wrote:
> > BTW, did you also add a regression test for this bug? I have an idea for
> > how to write one and can write one if you're interested.
>
> No, I didn't, and yes, I am. (not having good ideas about how to test
> the debugger)

See:

http://eskimo.shlomifish.org/Files/files/code/perl/dbgr-bug.tar.gz

This archive contains three files:

1. script.pl - a script that calls the offending "eval ... #line " code.

2. Devel/DebCont.pm - a DB module that debugs it and when it reaches line 20
outputs the contents of the @{main::_<script.pl} variable into a file.

3. test.t - the Test::More-based test file. It runs script.pl with -d:DebCont
and then checks the contents of the file outputted by Devel/DebCont.pm for
some code that appears in script.pl.

Note that it's still in standalone format, and I didn't yet prepare a patch
for the perl distribution. I looked at the t/ directory and I'm a bit
confused about the exact way of preparing a test for the core in that way.

But it's a start.

Regards,

Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish shlomif [at] iglu
Homepage: http://www.shlomifish.org/

Chuck Norris wrote a complete Perl 6 implementation in a day but then
destroyed all evidence with his bare hands, so no one will know his secrets.


rgarciasuarez at gmail

Nov 14, 2006, 8:07 AM

Post #12 of 16 (546 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On 14/11/06, Richard Foley <Richard.Foley [at] rfi> wrote:
> I had a syntax error in the first one, so I'm closer but no potato yet (no
> data in the db.out file). Feel free to tell me your way is better.

OK, with my changes this now looks like this : (see below)

Changes are:
* use test.pl instead of Test::More
* die on open failure
* add a q command at the end so the test terminates
* use runperl() instead of system() (more portable)
* use like() instead of ok() (diagnostics)
* use unlink() to really remove temp files

However the test is still a bit noisy since the debugger output goes
to stderr. Any idea how to silence this?

#!/usr/bin/perl

BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
}

use strict;
use warnings;

plan(1);

sub rc {
open RC, ">", ".perldb" or die $!;
print RC @_;
close(RC);
}

rc(
qq|
&parse_options("NonStop=0 LineInfo=db.out");
\n|,

qq|
sub afterinit {
push(\@DB::typeahead,
"DB::print_lineinfo(\@{'main::_<perl5db/eval-line-bug'})",
'b 23',
'c',
'q',
);
}\n|,
);

runperl(switches => [ '-d' ], progfile => '../lib/perl5db/eval-line-bug');

my $contents;
{
local $/;
open I, "<", 'db.out' or die $!;
$contents = <I>;
close(I);
}

like($contents, qr/factorial/,
'The ${main::_<filename} variable in the debugger was not destroyed'
);

# clean up.

END {
unlink '.perldb', 'db.out';
}


rgarciasuarez at gmail

Nov 14, 2006, 9:01 AM

Post #13 of 16 (542 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On 14/11/06, Rafael Garcia-Suarez wrote:
> However the test is still a bit noisy since the debugger output goes
> to stderr. Any idea how to silence this?

I commited this as change #29274, after having added to options
"TTY=/dev/null". Also, the test is skipped if /dev/null is not a
character special file. So the test will run only on unixes, which is
better than nothing. Portability nits welcome.
Thanks to both!


davem at iabyn

Nov 14, 2006, 1:27 PM

Post #14 of 16 (546 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On Tue, Nov 14, 2006 at 06:01:27PM +0100, Rafael Garcia-Suarez wrote:
> On 14/11/06, Rafael Garcia-Suarez wrote:
> >However the test is still a bit noisy since the debugger output goes
> >to stderr. Any idea how to silence this?
>
> I commited this as change #29274, after having added to options
> "TTY=/dev/null". Also, the test is skipped if /dev/null is not a
> character special file. So the test will run only on unixes, which is
> better than nothing. Portability nits welcome.
> Thanks to both!

As of 29274 on one of my systems (FC5, umask 00002), my builds are hanging
at the debug prompt:


[davem [at] cyri t]$ ./TEST ../lib/perl5db.t
t/../lib/perl5db....perldb: Must not source insecure rcfile ./.perldb.
You or the superuser must be the owner, and it must not
be writable by anyone but its owner.

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::(../lib/perl5db/eval-line-bug:6):
6: my $i = 5;
DB<1>

while on another system (FC6, umask 0022), the same 29274 build works fine.

--
"Strange women lying in ponds distributing swords is no basis for a system
of government. Supreme executive power derives from a mandate from the
masses, not from some farcical aquatic ceremony."
-- Dennis, "Monty Python and the Holy Grail"


rgarciasuarez at gmail

Nov 14, 2006, 1:32 PM

Post #15 of 16 (545 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On 14/11/06, Dave Mitchell <davem [at] iabyn> wrote:
>
> As of 29274 on one of my systems (FC5, umask 00002), my builds are hanging
> at the debug prompt:
>
>
> [davem [at] cyri t]$ ./TEST ../lib/perl5db.t
> t/../lib/perl5db....perldb: Must not source insecure rcfile ./.perldb.
> You or the superuser must be the owner, and it must not
> be writable by anyone but its owner.

Interesting. I suppose that a simple C<chmod 0644, ".perldb"> after
the file is written by the test should be enough to silence this ?


davem at iabyn

Nov 14, 2006, 3:26 PM

Post #16 of 16 (546 views)
Permalink
Re: [BUG] Perl Debugger Interface Resets the $main::{"_<$filename"} upon eval with a "#line $filename" directive [In reply to]

On Tue, Nov 14, 2006 at 10:32:49PM +0100, Rafael Garcia-Suarez wrote:
> On 14/11/06, Dave Mitchell <davem [at] iabyn> wrote:
> >
> >As of 29274 on one of my systems (FC5, umask 00002), my builds are hanging
> >at the debug prompt:
> >
> >
> >[davem [at] cyri t]$ ./TEST ../lib/perl5db.t
> >t/../lib/perl5db....perldb: Must not source insecure rcfile ./.perldb.
> > You or the superuser must be the owner, and it must not
> > be writable by anyone but its owner.
>
> Interesting. I suppose that a simple C<chmod 0644, ".perldb"> after
> the file is written by the test should be enough to silence this ?

yep


Change 29275 by davem [at] davem-monke on 2006/11/14 23:24:45

debugger test could hang if run with umask 0002

Affected files ...

... //depot/perl/lib/perl5db.t#2 edit

Differences ...

==== //depot/perl/lib/perl5db.t#2 (text) ====

@@ -22,6 +22,9 @@
open RC, ">", ".perldb" or die $!;
print RC @_;
close(RC);
+ # overly permissive perms gives "Must not source insecure rcfile"
+ # and hangs at the DB(1> prompt
+ chmod 0644, ".perldb";
}

rc(

--
A major Starfleet emergency breaks out near the Enterprise, but
fortunately some other ships in the area are able to deal with it to
everyone's satisfaction.
-- Things That Never Happen in "Star Trek" #13

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.