As you may know, currently perl cannot debug in the presence of
anonymous closures, trying to autoload a subroutine __ANON__ from the
package where the closure was defined.
The patch below is not definitive, it is just cosmetic: it avoids the
problem using some redundancy of the data. The real reason for the
problem is that anonymous closures somehow miss the SVpcv_ANON flag.
To demonstrate it I will use the updated specially for this occasion
Peek module (as usual, available on
ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl, changes with
respect to the previous version are 1) recursive dumping of hashes,
and 2) a lot of additional info about CV):
monk:~->perld -e 'use ExtUtils::Peek "Dump"; my $a; Dump sub {}'
SV = RV(0x16fc0c)
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x127a48
SV = PVCV(0x120908)
REFCNT = 2
FLAGS = (ANON)
IV = 0
NV = 0
STASH = main
START = 0x12efc8
ROOT = 0x12ecc8
XSUB = 0x0
XSUBANY = 0
GV = 0x1279d0 "__ANON__"
FILEGV = 0x11fd1c
DEPTH = 0
PADLIST = 0x1279dc
monk:~->perld -e 'use ExtUtils::Peek "Dump"; my $a; Dump sub {$a}'
SV = RV(0x16fc0c)
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x11fc38
SV = PVCV(0x120988)
REFCNT = 2
FLAGS = (CLONE,CLONED)
IV = 0
NV = 0
STASH = main
START = 0x12edc8
ROOT = 0x12ed08
XSUB = 0x0
XSUBANY = 0
GV = 0x1279f4 "__ANON__"
FILEGV = 0x11fd1c
DEPTH = 0
PADLIST = 0x135038
As you see, the closure has flags CLONE and CLONED, but misses the
flag ANON. The patch below just looks on additional info: name-of-GV
to see that the closure is actually anonymous. Sorry, I'm too lazy to
look for actual reason for perl (mis)behaviour.
The patch is active during debugging only, so should not substantially
slow down execution. Here it is:
*** pp_hot.c~ Thu Jun 22 07:28:06 1995
--- pp_hot.c Wed Sep 13 00:02:30 1995
***************
*** 1622,1628 ****
if ((op->op_private & OPpDEREF_DB) && !CvXSUB(cv)) {
sv = GvSV(DBsub);
save_item(sv);
! if (SvFLAGS(cv) & SVpcv_ANON) /* Is GV potentially non-unique? */
sv_setsv(sv, newRV((SV*)cv));
else {
gv = CvGV(cv);
--- 1622,1629 ----
if ((op->op_private & OPpDEREF_DB) && !CvXSUB(cv)) {
sv = GvSV(DBsub);
save_item(sv);
! if (SvFLAGS(cv) & SVpcv_ANON ||
! strcmp(GvNAME(CvGV(cv)),"__ANON__") == 0) /* Is GV potentially non-unique? */
sv_setsv(sv, newRV((SV*)cv));
else {
gv = CvGV(cv);
Enjoy,
Ilya
anonymous closures, trying to autoload a subroutine __ANON__ from the
package where the closure was defined.
The patch below is not definitive, it is just cosmetic: it avoids the
problem using some redundancy of the data. The real reason for the
problem is that anonymous closures somehow miss the SVpcv_ANON flag.
To demonstrate it I will use the updated specially for this occasion
Peek module (as usual, available on
ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl, changes with
respect to the previous version are 1) recursive dumping of hashes,
and 2) a lot of additional info about CV):
monk:~->perld -e 'use ExtUtils::Peek "Dump"; my $a; Dump sub {}'
SV = RV(0x16fc0c)
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x127a48
SV = PVCV(0x120908)
REFCNT = 2
FLAGS = (ANON)
IV = 0
NV = 0
STASH = main
START = 0x12efc8
ROOT = 0x12ecc8
XSUB = 0x0
XSUBANY = 0
GV = 0x1279d0 "__ANON__"
FILEGV = 0x11fd1c
DEPTH = 0
PADLIST = 0x1279dc
monk:~->perld -e 'use ExtUtils::Peek "Dump"; my $a; Dump sub {$a}'
SV = RV(0x16fc0c)
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x11fc38
SV = PVCV(0x120988)
REFCNT = 2
FLAGS = (CLONE,CLONED)
IV = 0
NV = 0
STASH = main
START = 0x12edc8
ROOT = 0x12ed08
XSUB = 0x0
XSUBANY = 0
GV = 0x1279f4 "__ANON__"
FILEGV = 0x11fd1c
DEPTH = 0
PADLIST = 0x135038
As you see, the closure has flags CLONE and CLONED, but misses the
flag ANON. The patch below just looks on additional info: name-of-GV
to see that the closure is actually anonymous. Sorry, I'm too lazy to
look for actual reason for perl (mis)behaviour.
The patch is active during debugging only, so should not substantially
slow down execution. Here it is:
*** pp_hot.c~ Thu Jun 22 07:28:06 1995
--- pp_hot.c Wed Sep 13 00:02:30 1995
***************
*** 1622,1628 ****
if ((op->op_private & OPpDEREF_DB) && !CvXSUB(cv)) {
sv = GvSV(DBsub);
save_item(sv);
! if (SvFLAGS(cv) & SVpcv_ANON) /* Is GV potentially non-unique? */
sv_setsv(sv, newRV((SV*)cv));
else {
gv = CvGV(cv);
--- 1622,1629 ----
if ((op->op_private & OPpDEREF_DB) && !CvXSUB(cv)) {
sv = GvSV(DBsub);
save_item(sv);
! if (SvFLAGS(cv) & SVpcv_ANON ||
! strcmp(GvNAME(CvGV(cv)),"__ANON__") == 0) /* Is GV potentially non-unique? */
sv_setsv(sv, newRV((SV*)cv));
else {
gv = CvGV(cv);
Enjoy,
Ilya