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

The Perl debugger does not honor 'use strict' for expression evaluation #22206

Open
hexcoder- opened this issue May 10, 2024 · 2 comments
Open

Comments

@hexcoder-
Copy link

Module: perl5db.pl or DB.pm

Description

When starting the debugger with
perl -Mstrict -wde 1

the "use strict" has no effect on subsequent expressions used with the x command (e.g for DB::eval):

x join('', BARE, WORD)
-> 0 'BAREWORD'

This is in contrast WRT the same setup in an oneliner:

perl -Mstrict -we "print join('', BARE, WORD)"
Bareword "BARE" not allowed while "strict subs" in use at -e line 1.
Bareword "WORD" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.

Steps to Reproduce

perl -Mstrict -wde 1
x join('', BARE, WORD)
gives
0 'BAREWORD'

Expected behavior

When use strict is in effect, BAREWORDs should be errors also in evaluated expressions for consistency.

Perl configuration

# perl -V output goes here
Summary of my perl5 (revision 5 version 38 subversion 0) configuration:

  Platform:
    osname=MSWin32
    osvers=10.0.17763.4499
    archname=MSWin32-x64-multi-thread
    uname='Win32 strawberry-perl 5.38.0.1 # 12:34:49 Thu July 06 2023 x64'
    config_args='undef'
    hint=recommended
    useposix=true
    d_sigaction=undef
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=undef
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='gcc'
    ccflags =' -DWIN32 -DWIN64 -DPERL_TEXTMODE_SCRIPTS -DMULTIPLICITY -DPERL_IMPLICIT_SYS -DUSE_PERLIO -D__USE_MINGW_ANSI_STDIO -fwrapv -fno-strict-aliasing -mms-bitfields'
    optimize='-Os'
    cppflags='-DWIN32'
    ccversion=''
    gccversion='13.1.0'
    gccosandvers=''
    intsize=4
    longsize=4
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='long long'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='g++'
    ldflags ='-s -L"C:\STRAWB~1.38_\perl\lib\CORE" -L"C:\STRAWB~1.38_\c\lib" -L"C:\STRAWB~1.38_\c\x86_64-w64-mingw32\lib" -L"C:\STRAWB~1.38_\c\lib\gcc\x86_64-w64-mingw32\13.1.0"'
    libpth=C:\STRAWB~1.38_\c\lib C:\STRAWB~1.38_\c\x86_64-w64-mingw32\lib C:\STRAWB~1.38_\c\lib\gcc\x86_64-w64-mingw32\13.1.0 C:\STRAWB~1.38_\c\x86_64-w64-mingw32\lib C:\STRAWB~1.38_\c\lib\gcc\x86_64-w64-mingw32\13.1.0
    libs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    perllibs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    libc=
    so=dll
    useshrplib=true
    libperl=libperl538.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs
    dlext=xs.dll
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags='-shared -s -L"C:\STRAWB~1.38_\perl\lib\CORE" -L"C:\STRAWB~1.38_\c\lib" -L"C:\STRAWB~1.38_\c\x86_64-w64-mingw32\lib" -L"C:\STRAWB~1.38_\c\lib\gcc\x86_64-w64-mingw32\13.1.0"'


Characteristics of this binary (from libperl):
  Compile-time options:
    HAS_LONG_DOUBLE
    HAS_TIMES
    HAVE_INTERP_INTERN
    MULTIPLICITY
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_HASH_FUNC_SIPHASH13
    PERL_HASH_USE_SBOX32
    PERL_IMPLICIT_SYS
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_SAFE_PUTENV
    USE_64_BIT_INT
    USE_ITHREADS
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under MSWin32
  Compiled at Jul  6 2023 22:36:11
  @INC:
    C:/Strawberry5.38_64/perl/site/lib
    C:/Strawberry5.38_64/perl/vendor/lib
    C:/Strawberry5.38_64/perl/lib```
@tonycoz
Copy link
Contributor

tonycoz commented May 21, 2024

The debugger itself historically didn't use strict, when it was re-worked and used strict itself, the eval context was modified to allow that.

I don't think we would change the default, but I could see adding an option to control it.

The DB::eval behaviour the debugger uses to compile and execute the code in the parent lexical scope doesn't appear to propagate strict from that scope.

It seems to use features (as in use feature '...') from the debugger scope too, which could be confusing, though the only case I can think of is switch:

$ ./perl -Ilib -Mfeature=switch -de 'print "Hello\n"'

Loading DB routines from perl5db.pl version 1.80
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(-e:1):   print "Hello\n"
  DB<1> x no warnings; do { given (1) { when (1) { say "One!" } } };
syntax error at (eval 9)[lib/perl5db.pl:742] line 2, near ") {"
Execution of (eval 9)[lib/perl5db.pl:742] aborted due to compilation errors.
 at (eval 9)[lib/perl5db.pl:742] line 2.
        eval 'no strict; ($@, $!, $^E, $,, $/, $\\, $^W) = @DB::saved;package main; $^D = $^D | $DB::db_stop;
  no warnings; do { given (1) { when (1) { say "One!" } } };;
' called at lib/perl5db.pl line 742
        DB::eval called at lib/perl5db.pl line 3444
        DB::DB called at -e line 1
  DB<2> x use feature "switch"; no warnings; do { given (1) { when (1) { say "One!" } } };
One!
0  1
  DB<3> 

Using switch in an x expression seems unlikely though.

@hexcoder-
Copy link
Author

Thanks, an option would be appreciated!
I often use the debugger to evaluate small code snippets before doing a correction in my script. It would be really nice, if the evaluation would behave the same as the script run.

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

3 participants