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

Seg-fault running t/io/fs.t under Devel::DProf #5455

Closed
p5pRT opened this issue May 13, 2002 · 23 comments
Closed

Seg-fault running t/io/fs.t under Devel::DProf #5455

p5pRT opened this issue May 13, 2002 · 23 comments

Comments

@p5pRT
Copy link

p5pRT commented May 13, 2002

Migrated from rt.perl.org#9321 (status was 'rejected')

Searchable as RT9321$

@p5pRT
Copy link
Author

p5pRT commented May 13, 2002

From sam@airtrout.tregar.com

Created by sam@airtrout.tregar.com

Running t/io/fs.t under Devel​::DProf seg-faults reliably​:

[sam@​airtrout bleadperl]$ cd t
[sam@​airtrout t]$ ../perl -I../lib -d​:DProf io/fs.t
1..32
ok 1 - umask
ok 2 - link a b
ok 3 - link b c
ok 4 - link count of triply-linked file
ok 5 - mode of triply-linked file
ok 6 - chmod succeeding
ok 7 - chmod going through
ok 8 - chmod two files
ok 9 - chmod going through to c
ok 10 - chmod going through to x
ok 11 - unlink two files
ok 12 - ino of removed file b should be undef
ok 13 - ino of removed file x should be undef
ok 14 - rename a b
ok 15 - ino of renamed file a should be undef
ok 16 - utime
ok 17 - non-zero inode num
# atime - 500000000 mtime - 500000001 delta - 1
ok 18 - atime
ok 19 - mtime
ok 20 - unlink b
ok 21 - ino of unlinked file b should be undef
ok 22 # skip​: Win32/Netware specific test
ok 23 # skip​: Win32/Netware specific test
ok 24 - truncation to five bytes
ok 25 - truncation to zero bytes
ok 26 - fh resize to 200
ok 27 - fh resize to 200 working (filename check)
ok 28 - fh resize to zero
ok 29 - fh resize to zero working (filename check)
ok 30 - rename working
not ok 31 - rename on directories
# Failed at io/fs.t line 347
ok 32 - rename on directories working
Segmentation fault (core dumped)

Looking at it under gdb, it's faulting at DProf.xs at line 319​:

  GV *gv = CvGV(cv);

This looks to be the same problem as the one I reported triggering through
Apache​::DProf
(http​://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-04/msg01559.html)

I plan to investigate further, although I don't know have high hopes for
fixing this on my own. DProf.xs makes frighteningly little sense to me.

-sam

Perl Info

Flags:
    category=library
    severity=medium

Site configuration information for perl v5.7.3:

Configured by sam at Mon May 13 15:46:02 EDT 2002.

Summary of my perl5 (revision 5.0 version 7 subversion 3 patch 16575) configuration:
  Platform:
    osname=linux, osvers=2.2.18, archname=i686-linux
    uname='linux airtrout 2.2.18 #4 fri dec 29 13:08:17 est 2000 i686 unknown '
    config_args='-d -D optimize=-g -Dusedevel'
    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='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-g',
    cppflags='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)', 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 -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lposix -lcrypt -lutil
    libc=/lib/libc-2.1.3.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    DEVEL16572


@INC for perl v5.7.3:
    lib
    /usr/local/lib/perl5/5.7.3/i686-linux
    /usr/local/lib/perl5/5.7.3
    /usr/local/lib/perl5/site_perl/5.7.3/i686-linux
    /usr/local/lib/perl5/site_perl/5.7.3
    /usr/local/lib/perl5/site_perl
    .


Environment for perl v5.7.3:
    HOME=/home/sam
    LANG=en_US
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/bin:/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/local/mysql/bin/:/usr/local/apache/bin:/usr/X11R6/bin:/home/sam/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


@p5pRT
Copy link
Author

p5pRT commented May 13, 2002

From @samtregar

On 13 May 2002 sam@​airtrout.tregar.com wrote​:

Looking at it under gdb, it's faulting at DProf.xs at line 319​:

GV *gv = CvGV(cv);

I've done some further investigation. The segfault occurs just before the
end of the file. It comes between the final statement and the execution
of END block in t/io/fs.t. However, removing the END block doesn't cure
the problem. If I start removing tests, any tests seemingly, then the
problem does go away.

In case it helps, here's the backtrace I forgot to include in the original
report​:

Program received signal SIGSEGV, Segmentation fault.
0x401e7901 in prof_mark (ptype=OP_LEAVESUB) at DProf.xs​:333
333 GV *gv = CvGV(cv);
(gdb) bt
#0 0x401e7901 in prof_mark (ptype=OP_LEAVESUB) at DProf.xs​:333
#1 0x401e831d in XS_DB_sub (cv=0x8183b4c) at DProf.xs​:554
#2 0x080cae7e in Perl_pp_entersub () at pp_hot.c​:2758
#3 0x080addcd in Perl_runops_debug () at dump.c​:1394
#4 0x080608c4 in S_run_body (oldscope=1) at perl.c​:1673
#5 0x08060468 in perl_run (my_perl=0x8166408) at perl.c​:1594
#6 0x0805cd79 in main (argc=4, argv=0xbffff7a4, env=0xbffff7b8)
  at perlmain.c​:85
#7 0x4007f177 in __libc_start_main (main=0x805cce0 <main>, argc=4,
  ubp_av=0xbffff7a4, init=0x805bdb4 <_init>, fini=0x8141880 <_fini>,
  rtld_fini=0x4000e184 <_dl_fini>, stack_end=0xbffff79c)
  at ../sysdeps/generic/libc-start.c​:129

@p5pRT
Copy link
Author

p5pRT commented May 13, 2002

From @jhi

On Mon, May 13, 2002 at 08​:19​:05PM -0400, Sam Tregar wrote​:

On 13 May 2002 sam@​airtrout.tregar.com wrote​:

Looking at it under gdb, it's faulting at DProf.xs at line 319​:

GV *gv = CvGV(cv);

I've done some further investigation. The segfault occurs just before the
end of the file. It comes between the final statement and the execution
of END block in t/io/fs.t. However, removing the END block doesn't cure
the problem. If I start removing tests, any tests seemingly, then the
problem does go away.

In case it helps, here's the backtrace I forgot to include in the original
report​:

Program received signal SIGSEGV, Segmentation fault.
0x401e7901 in prof_mark (ptype=OP_LEAVESUB) at DProf.xs​:333
333 GV *gv = CvGV(cv);

p cv
p *cv
call Perl_sv_dump(cv)

(being able to call B​::Deparse​::coderef2text() easily from gdb would be neat)

(gdb) bt
#0 0x401e7901 in prof_mark (ptype=OP_LEAVESUB) at DProf.xs​:333
#1 0x401e831d in XS_DB_sub (cv=0x8183b4c) at DProf.xs​:554
#2 0x080cae7e in Perl_pp_entersub () at pp_hot.c​:2758
#3 0x080addcd in Perl_runops_debug () at dump.c​:1394
#4 0x080608c4 in S_run_body (oldscope=1) at perl.c​:1673
#5 0x08060468 in perl_run (my_perl=0x8166408) at perl.c​:1594
#6 0x0805cd79 in main (argc=4, argv=0xbffff7a4, env=0xbffff7b8)
at perlmain.c​:85
#7 0x4007f177 in __libc_start_main (main=0x805cce0 <main>, argc=4,
ubp_av=0xbffff7a4, init=0x805bdb4 <_init>, fini=0x8141880 <_fini>,
rtld_fini=0x4000e184 <_dl_fini>, stack_end=0xbffff79c)
at ../sysdeps/generic/libc-start.c​:129

--
$jhi++; # http​://www.iki.fi/jhi/
  # There is this special biologist word we use for 'stable'.
  # It is 'dead'. -- Jack Cohen

@p5pRT
Copy link
Author

p5pRT commented May 13, 2002

From @samtregar

On Tue, 14 May 2002, Jarkko Hietaniemi wrote​:

p cv

(gdb) p cv
$1 = (CV *) 0x0

p *cv

(gdb) p *cv
Cannot access memory at address 0x0

call Perl_sv_dump(cv)

(gdb) call Perl_sv_dump(cv)
SV = 0

And, if you're wondering where cv, came from - it resulted from a
INT2PTR(CV*,SvIVX(Sub)). Sub is​:

(gdb) call Perl_sv_dump(Sub)
SV = PVIV(0x8166c90) at 0x81666b8
  REFCNT = 1
  FLAGS = (IOK,POK,pIOK,pPOK)
  IV = 0
  PV = 0x817a3c8 "135747636"\0
  CUR = 9
  LEN = 10

I think the PV value is an artifact of my having turned on DBG_SUB in
DProf.xs. I think it's also 0 with DBG_SUB off. I'd be happy to run the
test again with DBG_SUB off if that would help you.

-sam

@p5pRT
Copy link
Author

p5pRT commented May 13, 2002

From @jhi

On Mon, May 13, 2002 at 08​:35​:35PM -0400, Sam Tregar wrote​:

On Tue, 14 May 2002, Jarkko Hietaniemi wrote​:

p cv

(gdb) p cv
$1 = (CV *) 0x0

Well, dereferencing that (as CvGV() would do) leads nowhere. Or, as
the Ten Commandments for C Programmers quoth, "Thou shalt not follow
the NULL pointer, for chaos and madness await thee at its end."

p *cv

(gdb) p *cv
Cannot access memory at address 0x0

call Perl_sv_dump(cv)

(gdb) call Perl_sv_dump(cv)
SV = 0

And, if you're wondering where cv, came from - it resulted from a
INT2PTR(CV*,SvIVX(Sub)). Sub is​:

If I knew :​:DProf enough to what is supposed to be in the SvIVX
I would knowingly nod my head here.

(gdb) call Perl_sv_dump(Sub)
SV = PVIV(0x8166c90) at 0x81666b8
REFCNT = 1
FLAGS = (IOK,POK,pIOK,pPOK)
IV = 0
PV = 0x817a3c8 "135747636"\0
CUR = 9
LEN = 10

I think the PV value is an artifact of my having turned on DBG_SUB in
DProf.xs. I think it's also 0 with DBG_SUB off. I'd be happy to run the
test again with DBG_SUB off if that would help you.

Yes, please.

-sam

--
$jhi++; # http​://www.iki.fi/jhi/
  # There is this special biologist word we use for 'stable'.
  # It is 'dead'. -- Jack Cohen

@p5pRT
Copy link
Author

p5pRT commented May 13, 2002

From @samtregar

On Tue, 14 May 2002, Jarkko Hietaniemi wrote​:

Well, dereferencing that (as CvGV() would do) leads nowhere. Or, as
the Ten Commandments for C Programmers quoth, "Thou shalt not follow
the NULL pointer, for chaos and madness await thee at its end."

Amen brother. Preach it.

I've experimented with patches that just return() from prof_mark() if (cv
== NULL). It seems to work, but I worry about the implications for the
profiling output if we just start dropping subs.

And, if you're wondering where cv, came from - it resulted from a
INT2PTR(CV*,SvIVX(Sub)). Sub is​:

If I knew :​:DProf enough to what is supposed to be in the SvIVX
I would knowingly nod my head here.

Well, Sub comes from​:

  SV *Sub = GvSV(PL_DBsub); /* name of current sub */

And PL_DBsub is just a funny name for $DB​::sub, I think. And $DB​::sub is
some kind of funny dual-var that's supposed to have both the name of the
sub and its address. Except that I've never seen it have the name, at
least not while Devel​::DProf is around. On calls when doesn't crash
SvIVX(Sub) is the address of the CV currently being entered or left.

So does that ring any bells?

I think the PV value is an artifact of my having turned on DBG_SUB in
DProf.xs. I think it's also 0 with DBG_SUB off. I'd be happy to run the
test again with DBG_SUB off if that would help you.

Yes, please.

Ok. Here's Sub with DBG_SUB off​:

(gdb) call Perl_sv_dump(Sub)
SV = PVIV(0x8166c90) at 0x81666b8
  REFCNT = 1
  FLAGS = (IOK,pIOK)
  IV = 0
  PV = 0

And in case you're curious, here's PL_DBsub too​:

(gdb) call Perl_sv_dump(PL_DBsub)
SV = PVGV(0x816edc0) at 0x81666ac
  REFCNT = 1
  FLAGS = (GMG,SMG,MULTI)
  IV = 0
  NV = 0
  MAGIC = 0x816ee30
  MG_VIRTUAL = &PL_vtbl_glob
  MG_TYPE = PERL_MAGIC_glob(*)
  MG_OBJ = 0x81666ac
  NAME = "sub"
  NAMELEN = 3
  GvSTASH = 0x8166598 "DB"
  GP = 0x816edf8
  SV = 0x81666b8
  REFCNT = 1
  IO = 0x0
  FORM = 0x0
  AV = 0x0
  HV = 0x81666c4
  CV = 0x8183b4c
  CVGEN = 0x0
  GPFLAGS = 0x0
  LINE = 0
  FILE = ""
  FLAGS = 0x2
  EGV = 0x81666ac "sub"

-sam

@p5pRT
Copy link
Author

p5pRT commented May 13, 2002

From @jhi

Well, Sub comes from​:

SV *Sub = GvSV(PL_DBsub); /* name of current sub */

And PL_DBsub is just a funny name for $DB​::sub, I think. And $DB​::sub is
some kind of funny dual-var that's supposed to have both the name of the
sub and its address. Except that I've never seen it have the name, at
least not while Devel​::DProf is around. On calls when doesn't crash
SvIVX(Sub) is the address of the CV currently being entered or left.

So does that ring any bells?

Pretty silent around here, I'm afraid.

I think the PV value is an artifact of my having turned on DBG_SUB in
DProf.xs. I think it's also 0 with DBG_SUB off. I'd be happy to run the
test again with DBG_SUB off if that would help you.

Yes, please.

Ok. Here's Sub with DBG_SUB off​:

--
$jhi++; # http​://www.iki.fi/jhi/
  # There is this special biologist word we use for 'stable'.
  # It is 'dead'. -- Jack Cohen

@p5pRT
Copy link
Author

p5pRT commented May 14, 2002

From @samtregar

On Mon, 13 May 2002, Sam Tregar wrote​:

And PL_DBsub is just a funny name for $DB​::sub, I think. And $DB​::sub is
some kind of funny dual-var that's supposed to have both the name of the
sub and its address.

Wrong, me. It is a dual-var, but I'm pretty sure I don't know what it
contains. The PV side always has the same number in it ("135747668").
The IV side has the address of the currently executing CV, until it
doesn't and I get the seg-fault.

Actually, the PV side is in some kind of a quantum state. If I never do a
SvPV_nolen() on it for debugging purposes then it contains 0 when the
crash occurs. If I look at it at all then it gets the value "135747668"
and never changes. I'm guessing that means that the PV side is irrelevent
to Devel​::DProf - I can't find a place where it is used, anyway. That
begs the question - what is DBG_SUB supposed to do then? It prints the PV
side as a debugging aid.

I think the weirdness in PL_DBsub has something to do with Devel​::DProf
turning on PERLDBf_NONAME in PL_perldb. This flag is documented as​:

  #define PERLDBf_NONAME 0x40 /* For _SUB​: no name of the subr */

Which makes exactly no sense to me. The effect of PERLDBf_NONAME is to
cause PERLDB_SUB_NN to be true. This alters the way that PL_DBsub is
setup, I think.

Can anyone throw me a line? Is it possible that no one in all of p5p-dom
understands how Devel​::DProf works?

-sam

@p5pRT
Copy link
Author

p5pRT commented May 14, 2002

From @jhi

I think the weirdness in PL_DBsub has something to do with Devel​::DProf
turning on PERLDBf_NONAME in PL_perldb. This flag is documented as​:

#define PERLDBf_NONAME 0x40 /* For _SUB​: no name of the subr */

Which makes exactly no sense to me. The effect of PERLDBf_NONAME is to
cause PERLDB_SUB_NN to be true. This alters the way that PL_DBsub is
setup, I think.

Can anyone throw me a line? Is it possible that no one in all of p5p-dom
understands how Devel​::DProf works?

I think IlyaZ is the one to ask.

--
$jhi++; # http​://www.iki.fi/jhi/
  # There is this special biologist word we use for 'stable'.
  # It is 'dead'. -- Jack Cohen

@p5pRT
Copy link
Author

p5pRT commented May 14, 2002

From @samtregar

On Tue, 14 May 2002, Sam Tregar wrote​:

Can anyone throw me a line? Is it possible that no one in all of p5p-dom
understands how Devel​::DProf works?

Hey man. I did some checking and I managed to boil down your test case to
this tasty morsel​:

$ ./perl -Ilib -d​:DProf -e 'require "t/test.pl"; SKIP​: {skip("test")}'
ok 1 # skip​: test
Segmentation fault (core dumped)

I still don't know what the problem is, but I surmise it has something to
do with that mass of sticky code in pp_goto that's supposed to make this
stuff work. Maybe you should poke around in there?

Strangely, when I tried to add this as a test case to Devel​::DProf's tests
it didn't notice the core dump. Even when I planned two tests and then
dumped core between them the DProf.t harness didn't skip a beat. I think
it's pretty suspicious that Devel​::DProf - Perl's Most Likely to Seg-Fault
Module - has a test suite that ignore seg-faults. Is this a job for Super
Schwern or what?

-sam

@p5pRT
Copy link
Author

p5pRT commented May 14, 2002

From @samtregar

On Tue, 14 May 2002, Sam Tregar wrote​:

Strangely, when I tried to add this as a test case to Devel​::DProf's tests
it didn't notice the core dump. Even when I planned two tests and then
dumped core between them the DProf.t harness didn't skip a beat. I think
it's pretty suspicious that Devel​::DProf - Perl's Most Likely to Seg-Fault
Module - has a test suite that ignore seg-faults. Is this a job for Super
Schwern or what?

Whoa there dumbass. You must have misunderstood how Devel​::DProf's test
harness works. If you adjust the number of tests to include your new
tests then it will definitely notice a premature exit in a test file.
I've made the changes in your bleadperl checkout to show you what I mean.

Call off the Schwern!

-sam

@p5pRT
Copy link
Author

p5pRT commented May 14, 2002

From @samtregar

On Tue, 14 May 2002, Sam Tregar wrote​:

$ ./perl -Ilib -d​:DProf -e 'require "t/test.pl"; SKIP​: {skip("test")}'
ok 1 # skip​: test
Segmentation fault (core dumped)

Here's a way to trigger it without an external file​:

$ ./perl -w -Ilib -d​:DProf -e 'sub skip { last SKIP; } SKIP​: { skip; }'
Exiting subroutine via last at -e line 1.
Segmentation fault (core dumped)

Interestingly, that warning doesn't happen even after adding "-w" in the
quoted example.

Investigating pp_ctl.c leads me to think that pp_last() is to blame.
Unline pp_goto(), pp_last() doesn't have any code that looks at the
PERLDB* settings. It appears to be capable of exiting subroutines without
properly restoring the Devel​::DProf state. I think this is likely to be
the reason for the seg fault later down the road.

So, the task then is to figure out how to write code in pp_last() that
will do the same good work as pp_goto(). If this proves to be the
solution then it probably needs to be applied to pp_next() too.

-sam

@p5pRT
Copy link
Author

p5pRT commented May 14, 2002

From @samtregar

On Tue, 14 May 2002, Sam Tregar wrote​:

Investigating pp_ctl.c leads me to think that pp_last() is to blame.
Unline pp_goto(), pp_last() doesn't have any code that looks at the
PERLDB* settings.

Wow, can one man be wrong this often in one day? It looks like goto is
just as broken as last with Devel​::DProf​:

  $ ./perl -w -Ilib -d​:DProf -e 'sub foo { goto BAR; } foo(); BAR​: 1;'
  Segmentation fault (core dumped)

-sam

@p5pRT
Copy link
Author

p5pRT commented May 15, 2002

From @samtregar

I've concluded that I do not know how to fix [ID 20020513.015]. I think
it may actually exploit a basic flaw in Devel​::DProf's design.
Basically, Devel​::DProf expects that when it calls a subroutine that
subroutine will be the current subroutine when it returns. However, if
the subroutine exited via goto(LABEL), last(LABEL) or next(LABEL) that
will not be the case. Of course, it's much more complicated than that -
there's voodoo going on with curstash and curop that I don't pretend to
understand.

So, here's what I can do. This patch adds a test that catches the problem
before it can segfault and prints a mysterious error message with a good
description in perldiag.pod. I also documented the problem in the
Devel​::DProf pod. I have a couple questions about this patch​:

1) Is perldiag the right place to describe a croak() from a core module or
  should I only document it in DProf.pm?

2) How would I go about adding a test for something that should panic?
  The DProf.t harness seems ill-suited for this kind of test.

-sam

Inline Patch
diff -Naur bleadperl.0/ext/Devel/DProf/DProf.pm bleadperl/ext/Devel/DProf/DProf.pm
--- bleadperl.0/ext/Devel/DProf/DProf.pm	Fri Sep 21 14:11:58 2001
+++ bleadperl/ext/Devel/DProf/DProf.pm	Wed May 15 16:11:48 2002
@@ -154,6 +154,23 @@
 change the numeric slot (it will I<mark> it as invalid, but will not
 write over it).

+Another problem is that if a subroutine exits using goto(LABEL),
+last(LABEL) or next(LABEL) then Devel::DProf will die with the error:
+
+   panic: Devel::DProf inconsistent subroutine return
+
+For example, this code will break under Devel::DProf:
+
+   sub foo {
+     last FOO;
+   }
+   FOO: {
+     foo();
+   }
+
+A pattern like this is used by Test::More's skip() function, for
+example.  See L<perldiag> for more details.
+
 Mail bug reports and feature requests to the perl5-porters mailing list at
 F<E<lt>perl5-porters@perl.orgE<gt>>.

diff -Naur bleadperl.0/ext/Devel/DProf/DProf.xs bleadperl/ext/Devel/DProf/DProf.xs
--- bleadperl.0/ext/Devel/DProf/DProf.xs	Tue May 14 21:43:53 2002
+++ bleadperl/ext/Devel/DProf/DProf.xs	Wed May 15 15:35:31 2002
@@ -533,6 +533,7 @@
     dMARK;
     dORIGMARK;
     SV *Sub = GvSV(PL_DBsub);		/* name of current sub */
+    IV this_cv = SvIVX(Sub);		/* address of sub on entry  */

 #ifdef PERL_IMPLICIT_CONTEXT
     /* profile only the interpreter that loaded us */
@@ -554,6 +555,15 @@
         PUSHMARK(ORIGMARK);
         perl_call_sv(INT2PTR(SV*,SvIV(Sub)), GIMME_V | G_NODEBUG);
         PL_curstash = oldstash;
+
+	/* Make sure we returned from the sub we called. If the called
+	 * sub was exited via a goto, next or last then this will
+	 * croak() rather than allow prof_mark to segfault.  A better
+	 * solution would be to fix Devel::DProf to work with subs
+	 * that exit abnormally, but that is beyond my power. [Sam Tregar] */
+	if (SvIVX(GvSV(PL_DBsub)) != this_cv)
+	    croak("panic: Devel::DProf inconsistent subroutine return");
+
         prof_mark(aTHX_ OP_LEAVESUB);
 	g_depth--;
     }
diff -Naur bleadperl.0/pod/perldiag.pod bleadperl/pod/perldiag.pod
--- bleadperl.0/pod/perldiag.pod	Sun May 12 16:09:15 2002
+++ bleadperl/pod/perldiag.pod	Wed May 15 15:37:54 2002
@@ -2582,6 +2582,13 @@
 (P) Failed an internal consistency check while trying to reset a weak
 reference.

+=item panic: Devel::DProf inconsistent subroutine return
+
+(P) Devel::DProf called a subroutine but a different subroutine
+returned.  This can happen if a subroutine exits using goto(LABEL),
+last(LABEL) or next(LABEL).  This is a bug that will hopefully one day
+get fixed.
+
 =item panic: die %s

 (P) We popped the context stack to an eval context, and then discovered

@p5pRT
Copy link
Author

p5pRT commented May 15, 2002

From @samtregar

On Wed, 15 May 2002, Sam Tregar wrote​:

So, here's what I can do. This patch adds a test that catches the problem
before it can segfault and prints a mysterious error message with a good
description in perldiag.pod. I also documented the problem in the
Devel​::DProf pod.

Testing this patch with a larger application shows that it breaks some
cases where Devel​::DProf "works" now. I put works in quotes because if I
understand the logic of how Devel​::DProf works I don't see how it can
produce reasonable profiles in the face of a subroutine switching between
call and return... But it doesn't segfault, and I guess that means it
shouldn't just start croak()ing either.

So, cancel this patch. If I can't get any more traction I'll submit a doc
patch for Devel​::DProf describing the bug, at least.

-sam

@p5pRT
Copy link
Author

p5pRT commented Nov 1, 2005

From @smpeters

[RT_System - Wed May 15 06​:24​:58 2002]​:

I've concluded that I do not know how to fix [ID 20020513.015]. I
think
it may actually exploit a basic flaw in Devel​::DProf's design.
Basically, Devel​::DProf expects that when it calls a subroutine that
subroutine will be the current subroutine when it returns. However,
if
the subroutine exited via goto(LABEL), last(LABEL) or next(LABEL) that
will not be the case. Of course, it's much more complicated than that
-
there's voodoo going on with curstash and curop that I don't pretend
to
understand.

So, here's what I can do. This patch adds a test that catches the
problem
before it can segfault and prints a mysterious error message with a
good
description in perldiag.pod. I also documented the problem in the
Devel​::DProf pod. I have a couple questions about this patch​:

1) Is perldiag the right place to describe a croak() from a core
module or
should I only document it in DProf.pm?

2) How would I go about adding a test for something that should panic?
The DProf.t harness seems ill-suited for this kind of test.

-sam

diff -Naur bleadperl.0/ext/Devel/DProf/DProf.pm
bleadperl/ext/Devel/DProf/DProf.pm
--- bleadperl.0/ext/Devel/DProf/DProf.pm Fri Sep 21 14​:11​:58 2001
+++ bleadperl/ext/Devel/DProf/DProf.pm Wed May 15 16​:11​:48 2002
@​@​ -154,6 +154,23 @​@​
change the numeric slot (it will I<mark> it as invalid, but will not
write over it).

+Another problem is that if a subroutine exits using goto(LABEL),
+last(LABEL) or next(LABEL) then Devel​::DProf will die with the error​:
+
+ panic​: Devel​::DProf inconsistent subroutine return
+
+For example, this code will break under Devel​::DProf​:
+
+ sub foo {
+ last FOO;
+ }
+ FOO​: {
+ foo();
+ }
+
+A pattern like this is used by Test​::More's skip() function, for
+example. See L<perldiag> for more details.
+
Mail bug reports and feature requests to the perl5-porters mailing
list at
F<E<lt>perl5-porters@​perl.orgE<gt>>.

diff -Naur bleadperl.0/ext/Devel/DProf/DProf.xs
bleadperl/ext/Devel/DProf/DProf.xs
--- bleadperl.0/ext/Devel/DProf/DProf.xs Tue May 14 21​:43​:53 2002
+++ bleadperl/ext/Devel/DProf/DProf.xs Wed May 15 15​:35​:31 2002
@​@​ -533,6 +533,7 @​@​
dMARK;
dORIGMARK;
SV *Sub = GvSV(PL_DBsub); /* name of current sub */
+ IV this_cv = SvIVX(Sub); /* address of sub on entry */

#ifdef PERL_IMPLICIT_CONTEXT
/* profile only the interpreter that loaded us */
@​@​ -554,6 +555,15 @​@​
PUSHMARK(ORIGMARK);
perl_call_sv(INT2PTR(SV*,SvIV(Sub)), GIMME_V | G_NODEBUG);
PL_curstash = oldstash;
+
+ /* Make sure we returned from the sub we called. If the called
+ * sub was exited via a goto, next or last then this will
+ * croak() rather than allow prof_mark to segfault. A better
+ * solution would be to fix Devel​::DProf to work with subs
+ * that exit abnormally, but that is beyond my power. [Sam Tregar]
*/
+ if (SvIVX(GvSV(PL_DBsub)) != this_cv)
+ croak("panic​: Devel​::DProf inconsistent subroutine return");
+
prof_mark(aTHX_ OP_LEAVESUB);
g_depth--;
}
diff -Naur bleadperl.0/pod/perldiag.pod bleadperl/pod/perldiag.pod
--- bleadperl.0/pod/perldiag.pod Sun May 12 16​:09​:15 2002
+++ bleadperl/pod/perldiag.pod Wed May 15 15​:37​:54 2002
@​@​ -2582,6 +2582,13 @​@​
(P) Failed an internal consistency check while trying to reset a weak
reference.

+=item panic​: Devel​::DProf inconsistent subroutine return
+
+(P) Devel​::DProf called a subroutine but a different subroutine
+returned. This can happen if a subroutine exits using goto(LABEL),
+last(LABEL) or next(LABEL). This is a bug that will hopefully one
day
+get fixed.
+
=item panic​: die %s

(P) We popped the context stack to an eval context, and then
discovered

It appears that the patch above along with some other fixes went into
Perl with change #20034, and I get the panic on bleadperl. In 5.8.6,
though, I got a core dump. I'll need to investigate some more, but I
beleive it may be an unrelated problem with what is in this ticket.
I'll find out soon enough, though.

@p5pRT
Copy link
Author

p5pRT commented Aug 3, 2013

From @jkeenan

On Mon May 13 08​:22​:35 2002, sam@​airtrout.tregar.com wrote​:

This is a bug report for perl from sam@​airtrout.tregar.com,
generated with the help of perlbug 1.33 running under perl v5.7.3.

-----------------------------------------------------------------
[Please enter your report here]

Running t/io/fs.t under Devel​::DProf seg-faults reliably​:

[sam@​airtrout bleadperl]$ cd t
[sam@​airtrout t]$ ../perl -I../lib -d​:DProf io/fs.t
1..32
ok 1 - umask
ok 2 - link a b
ok 3 - link b c
ok 4 - link count of triply-linked file
ok 5 - mode of triply-linked file
ok 6 - chmod succeeding
ok 7 - chmod going through
ok 8 - chmod two files
ok 9 - chmod going through to c
ok 10 - chmod going through to x
ok 11 - unlink two files
ok 12 - ino of removed file b should be undef
ok 13 - ino of removed file x should be undef
ok 14 - rename a b
ok 15 - ino of renamed file a should be undef
ok 16 - utime
ok 17 - non-zero inode num
# atime - 500000000 mtime - 500000001 delta - 1
ok 18 - atime
ok 19 - mtime
ok 20 - unlink b
ok 21 - ino of unlinked file b should be undef
ok 22 # skip​: Win32/Netware specific test
ok 23 # skip​: Win32/Netware specific test
ok 24 - truncation to five bytes
ok 25 - truncation to zero bytes
ok 26 - fh resize to 200
ok 27 - fh resize to 200 working (filename check)
ok 28 - fh resize to zero
ok 29 - fh resize to zero working (filename check)
ok 30 - rename working
not ok 31 - rename on directories
# Failed at io/fs.t line 347
ok 32 - rename on directories working
Segmentation fault (core dumped)

Looking at it under gdb, it's faulting at DProf.xs at line 319​:

GV *gv = CvGV(cv);

This looks to be the same problem as the one I reported triggering
through
Apache​::DProf
(http​://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-
04/msg01559.html)

I plan to investigate further, although I don't know have high hopes
for
fixing this on my own. DProf.xs makes frighteningly little sense to
me.

-sam

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=library
severity=medium
---
Site configuration information for perl v5.7.3​:

Configured by sam at Mon May 13 15​:46​:02 EDT 2002.

Summary of my perl5 (revision 5.0 version 7 subversion 3 patch 16575)
configuration​:
Platform​:
osname=linux, osvers=2.2.18, archname=i686-linux
uname='linux airtrout 2.2.18 #4 fri dec 29 13​:08​:17 est 2000 i686
unknown '
config_args='-d -D optimize=-g -Dusedevel'
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='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-I/usr/include/gdbm',
optimize='-g',
cppflags='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include
-I/usr/include/gdbm'
ccversion='', gccversion='egcs-2.91.66 19990314/Linux (egcs-1.1.2
release)', 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 -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt -lutil
perllibs=-lnsl -ldl -lm -lc -lposix -lcrypt -lutil
libc=/lib/libc-2.1.3.so, so=so, useshrplib=false,
libperl=libperl.a
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-
rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches​:
DEVEL16572

---
@​INC for perl v5.7.3​:
lib
/usr/local/lib/perl5/5.7.3/i686-linux
/usr/local/lib/perl5/5.7.3
/usr/local/lib/perl5/site_perl/5.7.3/i686-linux
/usr/local/lib/perl5/site_perl/5.7.3
/usr/local/lib/perl5/site_perl
.

---
Environment for perl v5.7.3​:
HOME=/home/sam
LANG=en_US
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)

PATH=/usr/bin​:/bin​:/usr/local/bin​:/sbin​:/usr/sbin​:/usr/local/sbin​:/usr/local/bin​:/usr/local/mysql/bin/​:/usr/local/apache/bin​:/usr/X11R6/bin​:/home/sam/bin

PERL\_BADLANG \(unset\)
SHELL=/bin/bash

Devel​::DProf has been removed from the Perl 5 core distribution​:

######
$ corelist Devel​::DProf

Data for 2013-05-18
Devel​::DProf was first released with perl v5.6.0 and removed from v5.15.0
######

In fact, it has been deprecated in favor of Devel​::NYTProf.

Hence, I believe we don't need to explore this ticket further. I am
taking it for the purpose of closing it in 7 days unless someone wishes
to take it over and move the discussion forward.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Aug 3, 2013

From @jkeenan

On Sat Aug 03 09​:28​:12 2013, jkeenan wrote​:

Devel​::DProf has been removed from the Perl 5 core distribution​:

######
$ corelist Devel​::DProf

Data for 2013-05-18
Devel​::DProf was first released with perl v5.6.0 and removed from
v5.15.0
######

In fact, it has been deprecated in favor of Devel​::NYTProf.

Hence, I believe we don't need to explore this ticket further. I am
taking it for the purpose of closing it in 7 days unless someone
wishes
to take it over and move the discussion forward.

Thank you very much.
Jim Keenan

Correction​: I see that Steve Peters had previously taken this ticket,
so I won't Steal it. But I still believe it's closable.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Aug 3, 2013

From @cpansprout

On Sat Aug 03 09​:28​:12 2013, jkeenan wrote​:

On Mon May 13 08​:22​:35 2002, sam@​airtrout.tregar.com wrote​:

This is a bug report for perl from sam@​airtrout.tregar.com,
generated with the help of perlbug 1.33 running under perl v5.7.3.

-----------------------------------------------------------------
[Please enter your report here]

Running t/io/fs.t under Devel​::DProf seg-faults reliably​:

[sam@​airtrout bleadperl]$ cd t
[sam@​airtrout t]$ ../perl -I../lib -d​:DProf io/fs.t
1..32
ok 1 - umask
ok 2 - link a b
ok 3 - link b c
ok 4 - link count of triply-linked file
ok 5 - mode of triply-linked file
ok 6 - chmod succeeding
ok 7 - chmod going through
ok 8 - chmod two files
ok 9 - chmod going through to c
ok 10 - chmod going through to x
ok 11 - unlink two files
ok 12 - ino of removed file b should be undef
ok 13 - ino of removed file x should be undef
ok 14 - rename a b
ok 15 - ino of renamed file a should be undef
ok 16 - utime
ok 17 - non-zero inode num
# atime - 500000000 mtime - 500000001 delta - 1
ok 18 - atime
ok 19 - mtime
ok 20 - unlink b
ok 21 - ino of unlinked file b should be undef
ok 22 # skip​: Win32/Netware specific test
ok 23 # skip​: Win32/Netware specific test
ok 24 - truncation to five bytes
ok 25 - truncation to zero bytes
ok 26 - fh resize to 200
ok 27 - fh resize to 200 working (filename check)
ok 28 - fh resize to zero
ok 29 - fh resize to zero working (filename check)
ok 30 - rename working
not ok 31 - rename on directories
# Failed at io/fs.t line 347
ok 32 - rename on directories working
Segmentation fault (core dumped)

Looking at it under gdb, it's faulting at DProf.xs at line 319​:

GV *gv = CvGV(cv);

This looks to be the same problem as the one I reported triggering
through
Apache​::DProf
(http​://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-
04/msg01559.html)

I plan to investigate further, although I don't know have high hopes
for
fixing this on my own. DProf.xs makes frighteningly little sense to
me.

-sam

Devel​::DProf has been removed from the Perl 5 core distribution​:

######
$ corelist Devel​::DProf

Data for 2013-05-18
Devel​::DProf was first released with perl v5.6.0 and removed from
v5.15.0
######

In fact, it has been deprecated in favor of Devel​::NYTProf.

Hence, I believe we don't need to explore this ticket further. I am
taking it for the purpose of closing it in 7 days unless someone
wishes
to take it over and move the discussion forward.

If DProf (on CPAN) still crashes (on panics) with the latest blead, then
we should probably transfer this to DProf’s bug tracker.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Aug 3, 2013

From @jkeenan

On Sat Aug 03 10​:19​:46 2013, sprout wrote​:

Devel​::DProf has been removed from the Perl 5 core distribution​:

######
$ corelist Devel​::DProf

Data for 2013-05-18
Devel​::DProf was first released with perl v5.6.0 and removed from
v5.15.0
######

In fact, it has been deprecated in favor of Devel​::NYTProf.

If DProf (on CPAN) still crashes (on panics) with the latest blead, then
we should probably transfer this to DProf’s bug tracker.

Unfortunately, I can't get far enough in installing Devel​::DProf to run
t/io/fs.t​:

#####
/usr/local/bin/perl /usr/local/lib/perl5/5.18.0/ExtUtils/xsubpp
-typemap /usr/local/lib/perl5/5.18.0/ExtUtils/typemap DProf.xs >
DProf.xsc && mv DProf.xsc DProf.c
Please specify prototyping behavior for DProf.xs (see perlxs manual)
cc -c -fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe
-I/usr/local/include -I/opt/local/include -O3
-DVERSION=\"20110802.00\" -DXS_VERSION=\"20110802.00\"
"-I/usr/local/lib/perl5/5.18.0/darwin-2level/CORE" DProf.c
DProf.c​:852​: error​: static declaration of ‘XS_Devel__DProf_END’ follows
non-static declaration
DProf.xs​:107​: error​: previous declaration of ‘XS_Devel__DProf_END’ was here
make​: *** [DProf.o] Error 1
  FLORA/Devel-DProf-20110802.00.tar.gz
  /usr/bin/make -- NOT OK
Running make test
  Can't test without successful make
Running make install
  Make had returned bad status, install seems impossible
Failed during this command​:
FLORA/Devel-DProf-20110802.00.tar.gz : make NO
#####

I've never had to "specify prototyping behavior for DProf.xs" and don't
intend to start for a module which is quite prominently labelled as
deprecated.

So I recommend that we close this RT regardless of the status or
installability of Devel​::DProf on CPAN.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2016

From @dcollinsn

Devel​::DProf is deprecated and has not been in core, or updated, since 5.14. Closing.

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2016

From [Unknown Contact. See original ticket]

Devel​::DProf is deprecated and has not been in core, or updated, since 5.14. Closing.

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2016

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

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