Skip to content

Using signatures makes the debugger harder to use #22602

Open
@Ovid

Description

@Ovid

Description

When using the debugger (perl -d $program), you can use the s command to step through lines of code, one at a time. However, this is not true for subroutine signatures. When you step through one of these subs, you have to step through the signature at N+1 times, where N is the number of variables in the signature. These extra steps are not obvious, because nothing visible is happening, and they can be confusing. More than once I've accidentally stepped over the first line of a sub/method because I hit "return" too many times on a signatures.

This makes using the already cumbersome debugger CLI even more cumbersone.

It does not affect subroutines without signatures, even if they have a prototype (since the latter is compile-time, not run time).

This appears to affect all versions of Perl which allow signatures, whether by default, or when using the experimental signatures feature.

Steps to Reproduce

Run the following program with perl -d:

#!/usr/bin/env perl

use v5.40.0;

sub no_signature { # we will not step into this line
    say "No signature was used.";
}

sub with_prototype :prototype($$;$) { # we will not step into this line
    say "This is a subroutine with a prototype.";
}

sub no_args() { # we will step into this line 1 time
    say "No arguments were passed.";
}

sub one_arg($one) { # we will step into this line 2 times
    say "One argument was passed: $one";
}

sub two_args ( $one, $two ) { # we will step into this line 3 times
    say "Two arguments were passed: $one and $two";
}

sub three_args ( $one, $two, $three ) { # we will step into this line 4 times
    say "Three arguments were passed: $one, $two, and $three";
}

sub four_args ( $one, $two, $three, $four ) { # we will step into this line 5 times
    say
      "Four arguments were passed: $one, $two, $three, and $four";
}

no_signature();
with_prototype( 'one', 'two' );
no_args();
one_arg('one');
two_args( 'one', 'two' );
three_args( 'one', 'two', 'three' );
four_args( 'one', 'two', 'three', 'four' );

Expected behavior

When running the above program with the debugger, when you try to step into the first sub, you immediately get into the body of the sub:

5 	sub no_signature {
6==>	    say "No signature was used.";
7 	}

I expect the debugger to never stop on the signature line, or at minimum, to only stop once (because we might need to see the defaults).

However, for all subs with signatures, you must repeat the s (or just hit "return" to reuse the last step command) N+1 times for every variable in the signature, even though it's not obvious to the programmer that runtime behavior is occurring here:

9==>	sub empty_signature () {
10:	    say "Empty signature was used.";
11 	}

However, you can verify runtime behavior if you print out the value of those variables after every step:

main::(subs.pl:43):	two_args( 'one', 'two' );
  DB<1> s
main::two_args(subs.pl:25):	sub two_args ( $one, $two ) {
  DB<1> x [$one,$two]
0  ARRAY(0x15385afe0)
   0  undef
   1  undef
  DB<2> s
main::two_args(subs.pl:25):	sub two_args ( $one, $two ) {
  DB<2> x [$one,$two]
0  ARRAY(0x153074888)
   0  undef
   1  undef
  DB<3> s
main::two_args(subs.pl:25):	sub two_args ( $one, $two ) {
  DB<3> x [$one,$two]
0  ARRAY(0x1530748b8)
   0  'one'
   1  undef
  DB<4> s
main::two_args(subs.pl:25):	sub two_args ( $one, $two ) {
  DB<4> x [$one,$two]
0  ARRAY(0x15385b3e8)
   0  'one'
   1  'two'
  DB<5> s
main::two_args(subs.pl:26):	    say "Two arguments were passed: $one and $two";

That being said, I've never felt the need to dump signature variables while they're being individually assigned.

Perl configuration

Summary of my perl5 (revision 5 version 40 subversion 0) configuration:
   
  Platform:
    osname=darwin
    osvers=23.5.0
    archname=darwin-2level
    uname='darwin ovids-m1-laptop.local 23.5.0 darwin kernel version 23.5.0: wed may 1 20:12:58 pdt 2024; root:xnu-10063.121.3~5release_arm64_t6000 arm64 '
    config_args='-de -Dprefix=/Users/ovid/perl5/perlbrew/perls/perl-5.40.0 -Aeval:scriptdir=/Users/ovid/perl5/perlbrew/perls/perl-5.40.0/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 ='-fno-common -DPERL_DARWIN -mmacosx-version-min=14.5 -DNO_THREAD_SAFE_QUERYLOCALE -DNO_POSIX_2008_LOCALE -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -I/opt/local/include'
    optimize='-O3'
    cppflags='-fno-common -DPERL_DARWIN -mmacosx-version-min=14.5 -DNO_THREAD_SAFE_QUERYLOCALE -DNO_POSIX_2008_LOCALE -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -I/opt/local/include'
    ccversion=''
    gccversion='Apple LLVM 15.0.0 (clang-1500.3.9.4)'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=8
    longdblkind=0
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -mmacosx-version-min=14.5 -fstack-protector-strong -L/usr/local/lib -L/opt/local/lib'
    libpth=/usr/local/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /opt/local/lib /usr/lib
    libs=-lgdbm
    perllibs=
    libc=
    so=dylib
    useshrplib=false
    libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=bundle
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags=' -mmacosx-version-min=14.5 -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/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 darwin
  Compiled at Jul  2 2024 09:26:02
  %ENV:
    PERL5LIB="/Users/ovid/perlcustom/lib"
    PERLBREW_HOME="/Users/ovid/.perlbrew"
    PERLBREW_MANPATH="/Users/ovid/perl5/perlbrew/perls/perl-5.40.0/man"
    PERLBREW_PATH="/Users/ovid/perl5/perlbrew/bin:/Users/ovid/perl5/perlbrew/perls/perl-5.40.0/bin"
    PERLBREW_PERL="perl-5.40.0"
    PERLBREW_ROOT="/Users/ovid/perl5/perlbrew"
    PERLBREW_SHELLRC_VERSION="0.98"
    PERLBREW_VERSION="0.98"
  @INC:
    /Users/ovid/perlcustom/lib
    /Users/ovid/perl5/perlbrew/perls/perl-5.40.0/lib/site_perl/5.40.0/darwin-2level
    /Users/ovid/perl5/perlbrew/perls/perl-5.40.0/lib/site_perl/5.40.0
    /Users/ovid/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0/darwin-2level
    /Users/ovid/perl5/perlbrew/perls/perl-5.40.0/lib/5.40.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions