Repository navigation
Do not call DB::sub when overload::("" happens from DB:: namespace as it is documented in perldebguts #24001
Copy link
Copy link
Closed
Description
Module: core
Description
I tried to debug "Config.pm:59":
die "$0: Perl lib version (5.41.2) doesn't match executable '$^X' version ($])"
unless $^V; # line 59When line 59 is reached the debugger falls into infinite loop.
Steps to Reproduce
$ cat t.pl
1;
$ cat DB.pm
package Tt;
sub t { print "YES" }
package DB;
sub DB { print "next\n" }
sub sub {
print "$DB::sub called\n";
Tt::t(); # This does not cause `DB::sub` to be called
my $tmp = "$^V"; # This too should not cause `DB::sub` to be called
return &$DB::sub;
}
1;
PERL5DB="use DB" perl -I. -d t.pl
UNIVERSAL::import called
YESversion::("" called
...
YESversion::("" called
Segmentation fault
Expected behavior
Stringification of "$^V" ( call to version::("" from DB::sub ) should not cause recursive loop.
Because we are inside "DB::sub":
When execution of the program reaches a subroutine call, a call to &DB::sub(args) is made instead, with $DB::sub set to identify the called subroutine. (This doesn't happen if the calling subroutine was compiled in the DB package.)
https://perldoc.perl.org/perldebguts
Perl configuration
Details
perl -V
Summary of my perl5 (revision 5 version 41 subversion 2) configuration:
Platform:
osname=linux
osvers=6.5.0-1027-oem
archname=x86_64-linux
uname='linux work 6.5.0-1027-oem #28-ubuntu smp preempt_dynamic thu jul 25 13:32:46 utc 2024 x86_64 x86_64 x86_64 gnulinux '
config_args='-de -Dprefix=/home/kes/perl5/perlbrew/perls/perl-5.41.2 -Dusedevel -Aeval:scriptdir=/home/kes/perl5/perlbrew/perls/perl-5.41.2/bin'
hint=recommended
useposix=true
d_sigaction=define
useithreads=undef
usemultiplicity=undef
use64bitint=define
use64bitall=define
uselongdouble=undef
usemymalloc=n
default_inc_excludes_dot=define
Compiler:
cc='cc'
ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
optimize='-O2'
cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
ccversion=''
gccversion='13.1.0'
gccosandvers=''
intsize=4
longsize=8
ptrsize=8
doublesize=8
byteorder=12345678
doublekind=3
d_longlong=define
longlongsize=8
d_longdbl=define
longdblsize=16
longdblkind=3
ivtype='long'
ivsize=8
nvtype='double'
nvsize=8
Off_t='off_t'
lseeksize=8
alignbytes=8
prototype=define
Linker and Libraries:
ld='cc'
ldflags =' -fstack-protector-strong -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib/x86_64-linux-gnu /usr/lib /usr/lib64
libs=-lpthread -ldl -lm -lcrypt -lutil -lc
perllibs=-lpthread -ldl -lm -lcrypt -lutil -lc
libc=/lib/x86_64-linux-gnu/libc.so.6
so=so
useshrplib=false
libperl=libperl.a
gnulibc_version='2.35'
Dynamic Linking:
dlsrc=dl_dlopen.xs
dlext=so
d_dlsymun=undef
ccdlflags='-Wl,-E'
cccdlflags='-fPIC'
lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'
Characteristics of this binary (from libperl):
Compile-time options:
HAS_LONG_DOUBLE
HAS_STRTOLD
HAS_TIMES
PERLIO_LAYERS
PERL_COPY_ON_WRITE
PERL_DONT_CREATE_GVSV
PERL_HASH_FUNC_SIPHASH13
PERL_HASH_USE_SBOX32
PERL_MALLOC_WRAP
PERL_OP_PARENT
PERL_PRESERVE_IVUV
PERL_USE_DEVEL
PERL_USE_SAFE_PUTENV
USE_64_BIT_ALL
USE_64_BIT_INT
USE_LARGE_FILES
USE_LOCALE
USE_LOCALE_COLLATE
USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC
USE_LOCALE_TIME
USE_PERLIO
USE_PERL_ATOF
Built under linux
Compiled at Aug 17 2024 19:35:18
%ENV:
PERLBREW="command perlbrew"
PERLBREW_HOME="/home/kes/.perlbrew"
PERLBREW_MANPATH="/home/kes/perl5/perlbrew/perls/perl-5.41.2/man"
PERLBREW_PATH="/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.41.2/bin"
PERLBREW_PERL="perl-5.41.2"
PERLBREW_ROOT="/home/kes/perl5/perlbrew"
PERLBREW_SHELLRC_VERSION="0.98"
PERLBREW_VERSION="0.98"
@INC:
/home/kes/perl5/perlbrew/perls/perl-5.41.2/lib/site_perl/5.41.2/x86_64-linux
/home/kes/perl5/perlbrew/perls/perl-5.41.2/lib/site_perl/5.41.2
/home/kes/perl5/perlbrew/perls/perl-5.41.2/lib/5.41.2/x86_64-linux
/home/kes/perl5/perlbrew/perls/perl-5.41.2/lib/5.41.2
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
KES777 commentedon Dec 12, 2025
Slightly changed reproduction steps:
Because
DB::subis compiled inDB::package the call toTt::tfrom it do not causeDB::subcall.The same should happen for
version::(""call fromDB::sub. (DB::subshould not be triggered).Probably issue is that access to
$^Vis separate call to perl subroutine which switches context fromDB::toversion::and then the call toversion::(""is already subject forDB::sub.My suggestion is that stringification of
$^Vshould be done inside one subroutine.KES777 commentedon Dec 12, 2025
I think this is related https://perldoc.perl.org/overload#Overloadable-Operations:
I suppose something like this is happening: DB::sub --> overload::XXX --> overload::YYY. The call to
overload::YYYcauses recursion toDB::sub.I suppose calls should look like this: DB::sub --> overload::XXX --> returning to DB:: namespace --> overload::YYY. In this case the call to
overload::YYYwill not cause recursion toDB::subbecause it is done fromDB::namespace.KES777 commentedon Dec 12, 2025
Description of more wider problem:
When we want to track passed/returned values into/from subs and do dumps of them from
DB::subthe overloaded functions are called implicitly. In the case above it is stringificationversion::("".Because of this implicity we under debugger with tracking arguments enabled will get
Segmentation faults. As workaround we can return early fromDB::subif it was call tooverload::, but then it will not allow us to debug functions at that namespace.Leont commentedon Dec 12, 2025
Possibly, the debugger needs a
no overloading;to deal with this sort of thing.KES777 commentedon Dec 12, 2025
I changed this part:
@Leont Ok. This prevents
Segmentation fault. Output becomes:version=HASH(0x5612e83ea678).But this does not feels like the correct solution, because
DB::subshould not be called for a call toversion::(""fromDB::sub(DB::namespace) as it was documented inperldebguts.[-]Stringification of $^V causes `Segmentation fault` under debugger[/-][+]Do not call `DB::sub` when `overload::(""` happens from `DB::` namespace as it is documented in `perldebguts` [/+]Leont commentedon Dec 13, 2025
I'm not sure what you meant precisely with "as it was documented in perldebguts".
KES777 commentedon Dec 13, 2025
@Leont
I mean that stringification of "$^V" ( call to
version::("") happens fromDB::namespace. Because of this call toDB::subshould not happen.https://perldoc.perl.org/perldebguts states that:
The call to
version::(""should behave the same way as the call toTt::t.Leont commentedon Dec 13, 2025
Thanks, yeah that does make things a lot clearer.
KES777 commentedon Dec 14, 2025
Sorry, sometimes it is not clear to me to understand what is going wrong in this or that situation. And then took time to create a clear explanation. Usually a few approaches are required. Feel free to ask additional questions if you have any.
tonycoz commentedon Dec 16, 2025
At the point of call
PL_curstashisn't equal toPL_debstashso the OP generated in amagic_call() has the "breakable" flag (OPpENTERSUB_DB) set on it.Breaking on some other OP in the DB::sub sub shows the same.
PL_curstashis generally a compile-time thing, so I suspect the check against it is erroneous (though call_sv() does the same test).On a quick scan of pp_entersub and pp_nextstate I didn't see anything updating PL_curstash, which I'd expect if it was meant to track the stash of the current line being executed.
Perhaps it should be checking
CopSTASH(PL_curcop)instead.add TODO test for GH Perl#24001
$DB::sub: don't invoke DB::sub for overloads call from DB
amagic_call: don't invoke DB::sub for overloads called from DB
add TODO test for GH Perl#24001
amagic_call: don't invoke DB::sub for overloads called from DB
add TODO test for GH #24001
amagic_call: don't invoke DB::sub for overloads called from DB
call_sv: check the runtime package to decide whether DB::sub is callable
call_sv: check the runtime package to decide whether DB::sub is callable
call_sv: check the runtime package to decide whether DB::sub is callable
KES777 commentedon Jul 16, 2026
@tonycoz Thank you very much for the fix.