-
Notifications
You must be signed in to change notification settings - Fork 589
Description
Module: perldb
Description
When calling a blessed coderef as a sub, perldb requires both q{eq} and q{""} overloads, but passes a non-object to those methods.
Steps to Reproduce
Here's a simple class which triggers on a missing q{eq} overload:
use v5.10;
package Bar {
use Scalar::Util 'blessed';
use overload
fallback => 0,
bool => sub { 1 },
;
sub new {
my $class = shift;
return bless sub { 'foo' }, $class;
}
}
say Bar->new->();
running under the debugger produces:
Operation "eq": no method found,
left argument in overloaded package Bar,
right argument has no overloaded magic at /home/dj/.plenv/versions/5.40/lib/perl5/5.40.0/perl5db.pl line 4475.
at /home/dj/.plenv/versions/5.40/lib/perl5/5.40.0/perl5db.pl line 4475.
Introducing an overload for q{eq}:
use v5.10;
package Bar {
use Scalar::Util 'blessed';
use overload
fallback => 0,
bool => sub { 1 },
eq => sub {
say 'Class: ', blessed( $_[0] ) // '<no class>';
say 'Ref: ', ref $_[0];
!!0;
},
;
sub new {
my $class = shift;
return bless sub { 'foo' }, $class;
}
}
say Bar->new->();
results in
Class: <no class>
Ref: CODE
Operation """": no method found, argument in overloaded package Bar at /home/dj/.plenv/versions/5.40/lib/perl5/5.40.0/perl5db.pl line 4481.
at /home/dj/.plenv/versions/5.40/lib/perl5/5.40.0/perl5db.pl line 4481.
Strangely, the first argument passed to the overload sub is no longer an object, just a plain CODE ref.
Adding the q{""} operator gets through the debugger,
use v5.10;
package Bar {
use Scalar::Util 'blessed';
use overload
fallback => 0,
bool => sub { 1 },
eq => sub {
say 'Class: ', blessed( $_[0] ) // '<no class>';
say 'Ref: ', ref $_[0];
!!0;
},
q{""} => sub {
say 'Class: ', blessed( $_[0] ) // '<no class>';
say 'Ref: ', ref $_[0];
'Bar';
},
;
sub new {
my $class = shift;
return bless sub { 'foo' }, $class;
}
}
say Bar->new->();
Class: <no class>
Ref: CODE
Class: <no class>
Ref: CODE
foo
Debugged program terminated. Use q to quit or R to restart,
With the same non-object passed to the q{""} overload sub.
Expected behavior
I think the debugger gets confused about coderefs which are blessed and makes assumptions about them which don't hold.
I expect that the debugger should handle blessed coderefs the same as ordinary coderefs and not require extra overloads from them (and if it does, that it passes the blessed object to them)
Perl configuration
Summary of my perl5 (revision 5 version 40 subversion 0) configuration:
Platform:
osname=linux
osvers=6.9.7+bpo-amd64
archname=x86_64-linux
uname='linux leafhopper 6.9.7+bpo-amd64 #1 smp preempt_dynamic debian 6.9.7-1~bpo12+1 (2024-07-03) x86_64 gnulinux '
config_args='-Dprefix=/home/dj/.plenv/versions/5.40 -de -Dversiononly -A'eval:scriptdir=/home/dj/.plenv/versions/5.40/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 -D_FORTIFY_SOURCE=2'
optimize='-O2'
cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
ccversion=''
gccversion='12.2.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.36'
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_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 5 2024 00:46:42
%ENV:
PERL_CPANM_OPT="--cascade-search --mirror-only --mirror /home/dj/Work/darkpan --mirror http://www.cpan.org"
PERL_CPAN_MIRROR_TINY_BASE="/home/dj/Work/darkpan"
PERL_DARKPAN="/home/dj/Work/darkpan"
@INC:
/home/dj/.plenv/versions/5.40/lib/perl5/site_perl/5.40.0/x86_64-linux
/home/dj/.plenv/versions/5.40/lib/perl5/site_perl/5.40.0
/home/dj/.plenv/versions/5.40/lib/perl5/5.40.0/x86_64-linux
/home/dj/.plenv/versions/5.40/lib/perl5/5.40.0