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

subroutine arguments are no longer shown in perl debugger ( x @_ in perl -d) #12991

Closed
p5pRT opened this issue May 25, 2013 · 16 comments
Closed

Comments

@p5pRT
Copy link

p5pRT commented May 25, 2013

Migrated from rt.perl.org#118169 (status was 'resolved')

Searchable as RT118169$

@p5pRT
Copy link
Author

p5pRT commented May 25, 2013

From dotandimet@gmail.com

This is a bug report for perl from dotan@​corky.net,
generated with the help of perlbug 1.39 running under perl 5.18.0.


In perl 5.18.0, @​_ isn't visible in the debugger (perl -d).
You can't insepct it with x (eval/dump) or w (watch).

Example​:
perl -dE 'sub f { say $_ for (@​_); $a = $_[1]; say $a;}; f(4,25,7);'
  DB<1> s
  ...
  DB<1> x @​_
  empty array



Flags​:
  category=core
  severity=high


Site configuration information for perl 5.18.0​:

Configured by dotandimet at Mon May 20 22​:37​:44 IDT 2013.

Summary of my perl5 (revision 5 version 18 subversion 0) configuration​:

  Platform​:
  osname=darwin, osvers=12.3.0, archname=darwin-2level
  uname='darwin ariel.local 12.3.0 darwin kernel version 12.3.0​: sun
jan 6 22​:37​:10 pst 2013; root​:xnu-2050.22.13~1release_x86_64 x86_64 '
  config_args='-de
-Dprefix=/Users/dotandimet/perl5/perlbrew/perls/perl-5.18.0
-Aeval​:scriptdir=/Users/dotandimet/perl5/perlbrew/perls/perl-5.18.0/bin'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=undef, usemultiplicity=undef
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing
-pipe -fstack-protector -I/usr/local/include',
  optimize='-O3',
  cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.2.1 Compatible Apple LLVM 4.2
(clang-425.0.28)', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags ='
-fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /usr/lib
  libs=-ldbm -ldl -lm -lutil -lc
  perllibs=-ldl -lm -lutil -lc
  libc=, so=dylib, useshrplib=false, libperl=libperl.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup
-L/usr/local/lib -fstack-protector'

Locally applied patches​:


@​INC for perl 5.18.0​:
/Users/dotandimet/perl5/perlbrew/perls/perl-5.18.0/lib/site_perl/5.18.0/darwin-2level
/Users/dotandimet/perl5/perlbrew/perls/perl-5.18.0/lib/site_perl/5.18.0
/Users/dotandimet/perl5/perlbrew/perls/perl-5.18.0/lib/5.18.0/darwin-2level
  /Users/dotandimet/perl5/perlbrew/perls/perl-5.18.0/lib/5.18.0
  .


Environment for perl 5.18.0​:
  DYLD_LIBRARY_PATH (unset)
  HOME=/Users/dotandimet
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LC_CTYPE=UTF-8
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
PATH=/Users/dotandimet/perl5/perlbrew/bin​:/Users/dotandimet/perl5/perlbrew/perls/perl-5.18.0/bin​:/usr/local/bin​:/usr/bin​:/bin​:/usr/sbin​:/sbin​:/usr/local/bin​:/opt/X11/bin​:/Users/dotandimet/bin​:/Developer/usr/bin
  PERLBREW_BASHRC_VERSION=0.58
  PERLBREW_HOME=/Users/dotandimet/.perlbrew
PERLBREW_MANPATH=/Users/dotandimet/perl5/perlbrew/perls/perl-5.18.0/man
PERLBREW_PATH=/Users/dotandimet/perl5/perlbrew/bin​:/Users/dotandimet/perl5/perlbrew/perls/perl-5.18.0/bin
  PERLBREW_PERL=perl-5.18.0
  PERLBREW_ROOT=/Users/dotandimet/perl5/perlbrew
  PERLBREW_VERSION=0.58
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

From @jkeenan

On Fri May 24 22​:24​:07 2013, dotandimet@​gmail.com wrote​:

This is a bug report for perl from dotan@​corky.net,
generated with the help of perlbug 1.39 running under perl 5.18.0.

-----------------------------------------------------------------
In perl 5.18.0, @​_ isn't visible in the debugger (perl -d).
You can't inspect it with x (eval/dump) or w (watch).

Example​:
perl -dE 'sub f { say $_ for (@​_); $a = $_[1]; say $a;}; f(4,25,7);'
DB<1> s
...
DB<1> x @​_
empty array

-----------------------------------------------------------------
---
Flags​:
category=core
severity=high
---
Site configuration information for perl 5.18.0​:

Configured by dotandimet at Mon May 20 22​:37​:44 IDT 2013.

Summary of my perl5 (revision 5 version 18 subversion 0)
configuration​:

This does seem to be a regression from 5.16.0​:

#####
$ /usr/local/bin/perl5.16.0 -d 118169-debug.pl

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

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

main​::(118169-debug.pl​:4)​: use Data​::Dumper;$Data​::Dumper​::Indent=1;
  DB<1> n
main​::(118169-debug.pl​:7)​: f(4,25,7);
  DB<1> s
main​::f(118169-debug.pl​:10)​: say $_ for (@​_);
  DB<1> x @​_
0 4
1 25
2 7
#####

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

From @cpansprout

On Sat May 25 17​:33​:45 2013, jkeenan wrote​:

On Fri May 24 22​:24​:07 2013, dotandimet@​gmail.com wrote​:

This is a bug report for perl from dotan@​corky.net,
generated with the help of perlbug 1.39 running under perl 5.18.0.

-----------------------------------------------------------------
In perl 5.18.0, @​_ isn't visible in the debugger (perl -d).
You can't inspect it with x (eval/dump) or w (watch).

Example​:
perl -dE 'sub f { say $_ for (@​_); $a = $_[1]; say $a;}; f(4,25,7);'
DB<1> s
...
DB<1> x @​_
empty array

-----------------------------------------------------------------
---
Flags​:
category=core
severity=high
---
Site configuration information for perl 5.18.0​:

Configured by dotandimet at Mon May 20 22​:37​:44 IDT 2013.

Summary of my perl5 (revision 5 version 18 subversion 0)
configuration​:

This does seem to be a regression from 5.16.0​:

#####
$ /usr/local/bin/perl5.16.0 -d 118169-debug.pl

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

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

main​::(118169-debug.pl​:4)​: use Data​::Dumper;$Data​::Dumper​::Indent=1;
DB<1> n
main​::(118169-debug.pl​:7)​: f(4,25,7);
DB<1> s
main​::f(118169-debug.pl​:10)​: say $_ for (@​_);
DB<1> x @​_
0 4
1 25
2 7
#####

It was caused by​:

commit 7c54f46
Author​: Shlomi Fish <shlomif@​shlomifish.org>
Date​: Mon Oct 1 20​:40​:13 2012 +0200

  perl5db​: no longer passing arguments to DB​::eval().
 
  It didn't accept any arguments anyway.

Inline Patch
diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 54de27a..87713a5 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -741,7 +741,7 @@ sub eval {
     # Since we're only saving $@, we only have to localize the array
element   \# that it will be stored in\.   local $saved\[0\]; \# Preserve the old value of $@​ \- eval \{ &DB​::save \}; \+ eval \{ DB​::save\(\) \};

  # Now see whether we need to report an error back to the user.
  if ($at) {
@​@​ -1929,7 +1929,7 @​@​ If there are any preprompt actions, execute those
as well.
=cut

  # If there's an action, do it now.
- $evalarg = $action, DB​::eval(@​_) if $action;
+ $evalarg = $action, DB​::eval() if $action;

  # Are we nested another level (e.g., did we evaluate a function
  # that had a breakpoint in it at the debugger prompt)?
@​@​ -1940,7 +1940,7 @​@​ If there are any preprompt actions, execute those
as well.

  # Do any pre-prompt actions.
  foreach $evalarg (@​$pre) {
- DB​::eval(@​_);
+ DB​::eval();
  }

  # Complain about too much recursion if we passed the limit.
@​@​ -3273,7 +3273,7 @​@​ any variables we might want to address in the
C<DB> package.
  $evalarg = "\$^D = \$^D | \$DB​::db_stop;\n$cmd";

  # Run *our* eval that executes in the caller's context.
- DB​::eval(@​_);
+ DB​::eval();

  # Turn off the one-time-dump stuff now.
  if ($onetimeDump) {
@​@​ -3374,7 +3374,7 @​@​ again.

  # Evaluate post-prompt commands.
  foreach $evalarg (@​$post) {
- DB​::eval(@​_);
+ DB​::eval();
  }
  } # if ($single || $signal)

@​@​ -3477,7 +3477,7 @​@​ sub _DB__handle_watch_expressions

  # Fix context DB​::eval() wants to return an array, but
  # we need a scalar here.
- my ($val) = join( "', '", DB​::eval(@​_) );
+ my ($val) = join( "', '", DB​::eval() );
  $val = ( ( defined $val ) ? "'$val'" : 'undef' );

  # Did it change?
@​@​ -5075,7 +5075,7 @​@​ sub cmd_i {
  my $line = shift;
  foreach my $isa ( split( /\s+/, $line ) ) {
  $evalarg = $isa;
- ($isa) = DB​::eval(@​_);
+ ($isa) = DB​::eval();
  no strict 'refs';
  print join(
  ', ',
@​@​ -5120,7 +5120,7 @​@​ sub cmd_l {
  # Set up for DB​::eval() - evaluate in *user* context.
  $evalarg = $1;
  # $evalarg = $2;
- my ($s) = DB​::eval(@​_);
+ my ($s) = DB​::eval();

  # Ooops. Bad scalar.
  if ($@​) {
@​@​ -5523,7 +5523,7 @​@​ sub _add_watch_expr {
  # in the user's context. This version can handle expressions which
  # return a list value.
  $evalarg = $expr;
- my ($val) = join( ' ', DB​::eval(@​_) );
+ my ($val) = join( ' ', DB​::eval() );
  $val = ( defined $val ) ? "'$val'" : 'undef';

  # Save the current value of the expression.
@​@​ -9744,7 +9744,7 @​@​ sub cmd_pre580_W {
  # Get the current value of the expression.
  # Doesn't handle expressions returning list values!
  $evalarg = $1;
- my ($val) = DB​::eval(@​_);
+ my ($val) = DB​::eval();
  $val = ( defined $val ) ? "'$val'" : 'undef';

  # Save it.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

From @jkeenan

On Sun May 26 01​:29​:38 2013, sprout wrote​:
[snip]

It was caused by​:

commit 7c54f46
Author​: Shlomi Fish <shlomif@​shlomifish.org>
Date​: Mon Oct 1 20​:40​:13 2012 +0200

perl5db&#8203;: no longer passing arguments to DB&#8203;::eval\(\)\.

It didn't accept any arguments anyway\.

The patch attached represents *manual* corrections to the commit in
question. (I tried git-revert, but there were conflicts, perhaps
because there were intervening commits in the same file.)

The patch appears to correct the 'x @​_' case reported by the OP and
confirmed by me yesterday.

#####
$ ./perl -I./lib -d ~/p5p/118169-debug.pl

Loading DB routines from perl5db.pl version 1.39_10
Editor support available.

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

main​::(/home/jkeenan/p5p/118169-debug.pl​:7)​:
7​: f(4,25,7);
  DB<1> s
main​::f(/home/jkeenan/p5p/118169-debug.pl​:10)​:
10​: say $_ for (@​_);
  DB<1> x @​_
0 4
1 25
2 7
  DB<2> w @​_
  DB<3> n
4
25
7
#####

I'm not familiar enough with 'w' to say whether my patch remedies that
problem. In either case, even if this patch is satisfactory, we'll have
to figure out a way to write a regression test.

Please review.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

From @jkeenan

118169-Manual-corrections-pass-_-to-eval.patch
From f057ecd027ba98f928a1d1e3996e93637a455e84 Mon Sep 17 00:00:00 2001
From: James E Keenan <jkeenan@cpan.org>
Date: Sun, 26 May 2013 14:40:15 +0200
Subject: [PATCH] Manual corrections: pass @_ to eval().

Intended to have the effect of reverting
7c54f46a95be02b1ca921f4d4521122267d801cd.  For RT #118169.
---
 lib/perl5db.pl |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 0705341..ca6c97d 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -744,7 +744,7 @@ sub eval {
     # Since we're only saving $@, we only have to localize the array element
     # that it will be stored in.
     local $saved[0];    # Preserve the old value of $@
-    eval { DB::save() };
+    eval { &DB::save };
 
     # Now see whether we need to report an error back to the user.
     if ($at) {
@@ -2655,7 +2655,7 @@ If there are any preprompt actions, execute those as well.
     # If there's an action, do it now.
     if ($action) {
         $evalarg = $action;
-        DB::eval();
+        DB::eval(@_);
     }
 
     # Are we nested another level (e.g., did we evaluate a function
@@ -2667,7 +2667,7 @@ If there are any preprompt actions, execute those as well.
 
         # Do any pre-prompt actions.
         foreach $evalarg (@$pre) {
-            DB::eval();
+            DB::eval(@_);
         }
 
         # Complain about too much recursion if we passed the limit.
@@ -3082,7 +3082,7 @@ any variables we might want to address in the C<DB> package.
             $evalarg = "\$^D = \$^D | \$DB::db_stop;\n$cmd";
 
             # Run *our* eval that executes in the caller's context.
-            DB::eval();
+            DB::eval(@_);
 
             # Turn off the one-time-dump stuff now.
             if ($onetimeDump) {
@@ -3128,7 +3128,7 @@ again.
 
         # Evaluate post-prompt commands.
         foreach $evalarg (@$post) {
-            DB::eval();
+            DB::eval(@_);
         }
     }    # if ($single || $signal)
 
@@ -5431,7 +5431,7 @@ sub cmd_i {
     my $line = shift;
     foreach my $isa ( split( /\s+/, $line ) ) {
         $evalarg = $isa;
-        ($isa) = DB::eval();
+        ($isa) = DB::eval(@_);
         no strict 'refs';
         print join(
             ', ',
@@ -5494,7 +5494,7 @@ sub _cmd_l_handle_var_name {
 
     $evalarg = $var_name;
 
-    my ($s) = DB::eval();
+    my ($s) = DB::eval(@_);
 
     # Ooops. Bad scalar.
     if ($@) {
@@ -6000,7 +6000,7 @@ sub _add_watch_expr {
     # in the user's context. This version can handle expressions which
     # return a list value.
     $evalarg = $expr;
-    my ($val) = join( ' ', DB::eval() );
+    my ($val) = join( ' ', DB::eval(@_) );
     $val = ( defined $val ) ? "'$val'" : 'undef';
 
     # Save the current value of the expression.
@@ -10122,7 +10122,7 @@ sub cmd_pre580_W {
         # Get the current value of the expression.
         # Doesn't handle expressions returning list values!
         $evalarg = $1;
-        my ($val) = DB::eval();
+        my ($val) = DB::eval(@_);
         $val = ( defined $val ) ? "'$val'" : 'undef';
 
         # Save it.
-- 
1.7.1

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

From @shlomif

Hi all,

On Sun May 26 05​:51​:24 2013, jkeenan wrote​:

On Sun May 26 01​:29​:38 2013, sprout wrote​:
[snip]

It was caused by​:

commit 7c54f46
Author​: Shlomi Fish <shlomif@​shlomifish.org>
Date​: Mon Oct 1 20​:40​:13 2012 +0200

perl5db&#8203;: no longer passing arguments to DB&#8203;::eval\(\)\.

It didn't accept any arguments anyway\.

The patch attached represents *manual* corrections to the commit in
question. (I tried git-revert, but there were conflicts, perhaps
because there were intervening commits in the same file.)

Attached is my own patch which appears to correct the problem (at least
with x). I also added a test. Sorry for not noticing that earlier and
making James work on it as well.

You can also find it at this github branch​:

https://github.com/shlomif/perl/tree/rt118169_fix_perl_debugger_at_underscore_in_x

Regards,

-- Shlomi Fish

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

From @shlomif

0001-Fix-for-RT-118169.patch
From c4670f079de4be1ffd036f5eac53f3e8870ae292 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 26 May 2013 16:35:04 +0300
Subject: [PATCH] Fix for RT #118169 .

https://rt.perl.org/rt3/Public/Bug/Display.html?id=118169

subroutine arguments are no longer shown in perl debugger ( x @_ in perl
-d) .

Regression from perl-5.16.x due to the perl -d refactoring. Fixed with a
test.
---
 MANIFEST                                          |  1 +
 lib/perl5db.pl                                    | 18 ++++++++---------
 lib/perl5db.t                                     | 24 ++++++++++++++++++++++-
 lib/perl5db/t/test-passing-at-underscore-to-x-etc | 15 ++++++++++++++
 4 files changed, 48 insertions(+), 10 deletions(-)
 create mode 100644 lib/perl5db/t/test-passing-at-underscore-to-x-etc

diff --git a/MANIFEST b/MANIFEST
index e3e3b8f..f861073 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4155,6 +4155,7 @@ lib/perl5db/t/test-frame-option-1	Tests for the Perl debugger
 lib/perl5db/t/test-l-statement-1	Tests for the Perl debugger
 lib/perl5db/t/test-l-statement-2	Tests for the Perl debugger
 lib/perl5db/t/test-m-statement-1	Tests for the Perl debugger
+lib/perl5db/t/test-passing-at-underscore-to-x-etc	Tests for the Perl debugger
 lib/perl5db/t/test-PrintRet-option-1	Tests for the Perl debugger
 lib/perl5db/t/test-r-statement	Tests for the Perl debugger
 lib/perl5db/t/test-warnLevel-option-1	Tests for the Perl debugger
diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 0705341..1be7581 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -744,7 +744,7 @@ sub eval {
     # Since we're only saving $@, we only have to localize the array element
     # that it will be stored in.
     local $saved[0];    # Preserve the old value of $@
-    eval { DB::save() };
+    eval { &DB::save };
 
     # Now see whether we need to report an error back to the user.
     if ($at) {
@@ -1793,7 +1793,7 @@ sub _DB__determine_if_we_should_break
         # see if we should stop. If so, remove the one-time sigil.
         elsif ($stop) {
             $evalarg = "\$DB::signal |= 1 if do {$stop}";
-            DB::eval();
+            DB::eval(@_);
             # If the breakpoint is temporary, then delete its enabled status.
             if ($dbline{$line} =~ s/;9($|\0)/$1/) {
                 _cancel_breakpoint_temp_enabled_status($filename, $line);
@@ -2655,7 +2655,7 @@ If there are any preprompt actions, execute those as well.
     # If there's an action, do it now.
     if ($action) {
         $evalarg = $action;
-        DB::eval();
+        DB::eval(@_);
     }
 
     # Are we nested another level (e.g., did we evaluate a function
@@ -2667,7 +2667,7 @@ If there are any preprompt actions, execute those as well.
 
         # Do any pre-prompt actions.
         foreach $evalarg (@$pre) {
-            DB::eval();
+            DB::eval(@_);
         }
 
         # Complain about too much recursion if we passed the limit.
@@ -3082,7 +3082,7 @@ any variables we might want to address in the C<DB> package.
             $evalarg = "\$^D = \$^D | \$DB::db_stop;\n$cmd";
 
             # Run *our* eval that executes in the caller's context.
-            DB::eval();
+            DB::eval(@_);
 
             # Turn off the one-time-dump stuff now.
             if ($onetimeDump) {
@@ -3128,7 +3128,7 @@ again.
 
         # Evaluate post-prompt commands.
         foreach $evalarg (@$post) {
-            DB::eval();
+            DB::eval(@_);
         }
     }    # if ($single || $signal)
 
@@ -5431,7 +5431,7 @@ sub cmd_i {
     my $line = shift;
     foreach my $isa ( split( /\s+/, $line ) ) {
         $evalarg = $isa;
-        ($isa) = DB::eval();
+        ($isa) = DB::eval(@_);
         no strict 'refs';
         print join(
             ', ',
@@ -6000,7 +6000,7 @@ sub _add_watch_expr {
     # in the user's context. This version can handle expressions which
     # return a list value.
     $evalarg = $expr;
-    my ($val) = join( ' ', DB::eval() );
+    my ($val) = join( ' ', DB::eval(@_) );
     $val = ( defined $val ) ? "'$val'" : 'undef';
 
     # Save the current value of the expression.
@@ -10122,7 +10122,7 @@ sub cmd_pre580_W {
         # Get the current value of the expression.
         # Doesn't handle expressions returning list values!
         $evalarg = $1;
-        my ($val) = DB::eval();
+        my ($val) = DB::eval(@_);
         $val = ( defined $val ) ? "'$val'" : 'undef';
 
         # Save it.
diff --git a/lib/perl5db.t b/lib/perl5db.t
index 81bd5da..d4d7bd4 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(114);
+plan(115);
 
 my $rc_filename = '.perldb';
 
@@ -812,6 +812,28 @@ sub _calc_trace_wrapper
     );
 }
 
+# Tests for x with @_
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'b 10',
+                'c',
+                'x @_',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/test-passing-at-underscore-to-x-etc',
+        }
+    );
+
+    $wrapper->contents_like(
+        # qr/^0\s+HASH\([^\)]+\)\n\s+500 => 600\n/,
+        qr/Arg1.*?Capsula.*GreekHumor.*Socrates/ms,
+        q/x command test with '@_'./,
+    );
+}
+
 # Tests for x with AutoTrace=1.
 {
     my $wrapper = DebugWrap->new(
diff --git a/lib/perl5db/t/test-passing-at-underscore-to-x-etc b/lib/perl5db/t/test-passing-at-underscore-to-x-etc
new file mode 100644
index 0000000..ff14df6
--- /dev/null
+++ b/lib/perl5db/t/test-passing-at-underscore-to-x-etc
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+print "One\n";
+
+sub my_pass_args_to
+{
+    print "Two\n";
+}
+
+my_pass_args_to ("Arg1", "Capsula", "GreekHumor", "Socrates");
+
+print "Three\n";
-- 
1.8.1.5

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

From @shlomif

Hi Jim,

On Sun May 26 05​:51​:24 2013, jkeenan wrote​:

On Sun May 26 01​:29​:38 2013, sprout wrote​:
[snip]

It was caused by​:

commit 7c54f46
Author​: Shlomi Fish <shlomif@​shlomifish.org>
Date​: Mon Oct 1 20​:40​:13 2012 +0200

perl5db&#8203;: no longer passing arguments to DB&#8203;::eval\(\)\.

It didn't accept any arguments anyway\.

The patch attached represents *manual* corrections to the commit in
question. (I tried git-revert, but there were conflicts, perhaps
because there were intervening commits in the same file.)

The patch appears to correct the 'x @​_' case reported by the OP and
confirmed by me yesterday.

#####
$ ./perl -I./lib -d ~/p5p/118169-debug.pl

Loading DB routines from perl5db.pl version 1.39_10
Editor support available.

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

main​::(/home/jkeenan/p5p/118169-debug.pl​:7)​:
7​: f(4,25,7);
DB<1> s
main​::f(/home/jkeenan/p5p/118169-debug.pl​:10)​:
10​: say $_ for (@​_);
DB<1> x @​_
0 4
1 25
2 7
DB<2> w @​_
DB<3> n
4
25
7
#####

I'm not familiar enough with 'w' to say whether my patch remedies that
problem. In either case, even if this patch is satisfactory, we'll have
to figure out a way to write a regression test.

My patch contains a regression test, but its regex can be made more
specific for the x test.

Please review.

Well, this patch still needs a regression test.

Thank you very much.
Jim Keenan

Regards,

-- Shlomi Fish

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

From @cpansprout

On Sun May 26 06​:45​:09 2013, shlomif wrote​:

Hi all,

On Sun May 26 05​:51​:24 2013, jkeenan wrote​:

On Sun May 26 01​:29​:38 2013, sprout wrote​:
[snip]

It was caused by​:

commit 7c54f46
Author​: Shlomi Fish <shlomif@​shlomifish.org>
Date​: Mon Oct 1 20​:40​:13 2012 +0200

perl5db&#8203;: no longer passing arguments to DB&#8203;::eval\(\)\.

It didn't accept any arguments anyway\.

The patch attached represents *manual* corrections to the commit in
question. (I tried git-revert, but there were conflicts, perhaps
because there were intervening commits in the same file.)

Attached is my own patch which appears to correct the problem (at
least
with x). I also added a test. Sorry for not noticing that earlier and
making James work on it as well.

You can also find it at this github branch​:

https://github.com/shlomif/perl/tree/rt118169_fix_perl_debugger_at_underscore_in_x

I haven’t had a chance to test your patch yet. But also consider
manipulability of @​_​:

$ perl -v

This is perl 5, version 12, subversion 4 (v5.12.4) built for
darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)

Copyright 1987-2010, Larry Wall

Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http​://www.perl.org/, the Perl Home Page.

$ perl -de 'BEGIN{@​DB​::typeahead=("s","shift \@​_", "c", "q");} sub f {
chop; print "-----> @​_\n" } f(1,2,3)'

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

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

main​::(-e​:1)​: BEGIN{@​DB​::typeahead=("s","shift \@​_", "c", "q");} sub f {
chop; print "-----> @​_\n" } f(1,2,3)
auto(-4) DB<1> s
main​::f(-e​:1)​: BEGIN{@​DB​::typeahead=("s","shift \@​_", "c", "q");} sub f
{ chop; print "-----> @​_\n" } f(1,2,3)
auto(-3) DB<1> shift @​_

auto(-2) DB<2> c
-----> 2 3
Debugged program terminated. Use q to quit or R to restart,
  use o inhibit_exit to avoid stopping after program termination,
  h q, h R or h o to get additional info.
auto(-1) DB<2> q
__END__

That fails in current blead (prints ‘1 2 3’). I haven’t checked whether
your patch addresses that.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

From @shlomif

Hi Father C,

On Sun May 26 07​:44​:41 2013, sprout wrote​:

On Sun May 26 06​:45​:09 2013, shlomif wrote​:

Hi all,

On Sun May 26 05​:51​:24 2013, jkeenan wrote​:

On Sun May 26 01​:29​:38 2013, sprout wrote​:
[snip]

It was caused by​:

commit 7c54f46
Author​: Shlomi Fish <shlomif@​shlomifish.org>
Date​: Mon Oct 1 20​:40​:13 2012 +0200

perl5db&#8203;: no longer passing arguments to DB&#8203;::eval\(\)\.

It didn't accept any arguments anyway\.

The patch attached represents *manual* corrections to the commit
in
question. (I tried git-revert, but there were conflicts, perhaps
because there were intervening commits in the same file.)

Attached is my own patch which appears to correct the problem (at
least
with x). I also added a test. Sorry for not noticing that earlier
and
making James work on it as well.

You can also find it at this github branch​:

https://github.com/shlomif/perl/tree/rt118169_fix_perl_debugger_at_underscore_in_x

I haven’t had a chance to test your patch yet. But also consider
manipulability of @​_​:

$ perl -v

This is perl 5, version 12, subversion 4 (v5.12.4) built for
darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)

Copyright 1987-2010, Larry Wall

Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source
kit.

Complete documentation for Perl, including FAQ lists, should be found
on
this system using "man perl" or "perldoc perl". If you have access to
the
Internet, point your browser at http​://www.perl.org/, the Perl Home
Page.

$ perl -de 'BEGIN{@​DB​::typeahead=("s","shift \@​_", "c", "q");} sub f {
chop; print "-----> @​_\n" } f(1,2,3)'

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

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

main​::(-e​:1)​: BEGIN{@​DB​::typeahead=("s","shift \@​_", "c", "q");} sub f
{
chop; print "-----> @​_\n" } f(1,2,3)
auto(-4) DB<1> s
main​::f(-e​:1)​: BEGIN{@​DB​::typeahead=("s","shift \@​_", "c", "q");} sub
f
{ chop; print "-----> @​_\n" } f(1,2,3)
auto(-3) DB<1> shift @​_

auto(-2) DB<2> c
-----> 2 3
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
auto(-1) DB<2> q
__END__

That fails in current blead (prints ‘1 2 3’). I haven’t checked
whether
your patch addresses that.

Checked now, and it didn't. I've written another patch to address it in
my branch, and it's attached to this message. It should be applied on
top of the previous patch. See​:

https://github.com/shlomif/perl/tree/rt118169_fix_perl_debugger_at_underscore_in_x

Regards,

-- Shlomi Fish

@p5pRT
Copy link
Author

p5pRT commented May 26, 2013

From @shlomif

0001-Fix-the-mutability-of-_-in-perl-d.patch
From 35ead187368d8990f8cbd03fecbcd9458d8067b4 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 26 May 2013 18:55:48 +0300
Subject: [PATCH] Fix the mutability of @_ in perl -d.

With a test.

See Father C.'s comment on RT #118169.
---
 lib/perl5db.pl | 27 ++++++++++++++++++---------
 lib/perl5db.t  | 24 +++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 1be7581..9afe3f3 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -1793,7 +1793,8 @@ sub _DB__determine_if_we_should_break
         # see if we should stop. If so, remove the one-time sigil.
         elsif ($stop) {
             $evalarg = "\$DB::signal |= 1 if do {$stop}";
-            DB::eval(@_);
+            # The &-call is here to ascertain the mutability of @_.
+            &DB::eval;
             # If the breakpoint is temporary, then delete its enabled status.
             if ($dbline{$line} =~ s/;9($|\0)/$1/) {
                 _cancel_breakpoint_temp_enabled_status($filename, $line);
@@ -2562,7 +2563,8 @@ sub DB {
     # Last line in the program.
     $max = $#dbline;
 
-    _DB__determine_if_we_should_break(@_);
+    # The &-call is here to ascertain the mutability of @_.
+    &_DB__determine_if_we_should_break;
 
     # Preserve the current stop-or-not, and see if any of the W
     # (watch expressions) has changed.
@@ -2655,7 +2657,8 @@ If there are any preprompt actions, execute those as well.
     # If there's an action, do it now.
     if ($action) {
         $evalarg = $action;
-        DB::eval(@_);
+        # The &-call is here to ascertain the mutability of @_.
+        &DB::eval;
     }
 
     # Are we nested another level (e.g., did we evaluate a function
@@ -2667,7 +2670,8 @@ If there are any preprompt actions, execute those as well.
 
         # Do any pre-prompt actions.
         foreach $evalarg (@$pre) {
-            DB::eval(@_);
+            # The &-call is here to ascertain the mutability of @_.
+            &DB::eval;
         }
 
         # Complain about too much recursion if we passed the limit.
@@ -3082,7 +3086,8 @@ any variables we might want to address in the C<DB> package.
             $evalarg = "\$^D = \$^D | \$DB::db_stop;\n$cmd";
 
             # Run *our* eval that executes in the caller's context.
-            DB::eval(@_);
+            # The &-call is here to ascertain the mutability of @_.
+            &DB::eval;
 
             # Turn off the one-time-dump stuff now.
             if ($onetimeDump) {
@@ -3128,7 +3133,8 @@ again.
 
         # Evaluate post-prompt commands.
         foreach $evalarg (@$post) {
-            DB::eval(@_);
+            # The &-call is here to ascertain the mutability of @_.
+            &DB::eval;
         }
     }    # if ($single || $signal)
 
@@ -5431,7 +5437,8 @@ sub cmd_i {
     my $line = shift;
     foreach my $isa ( split( /\s+/, $line ) ) {
         $evalarg = $isa;
-        ($isa) = DB::eval(@_);
+        # The &-call is here to ascertain the mutability of @_.
+        ($isa) = &DB::eval;
         no strict 'refs';
         print join(
             ', ',
@@ -6000,7 +6007,8 @@ sub _add_watch_expr {
     # in the user's context. This version can handle expressions which
     # return a list value.
     $evalarg = $expr;
-    my ($val) = join( ' ', DB::eval(@_) );
+    # The &-call is here to ascertain the mutability of @_.
+    my ($val) = join( ' ', &DB::eval);
     $val = ( defined $val ) ? "'$val'" : 'undef';
 
     # Save the current value of the expression.
@@ -10122,7 +10130,8 @@ sub cmd_pre580_W {
         # Get the current value of the expression.
         # Doesn't handle expressions returning list values!
         $evalarg = $1;
-        my ($val) = DB::eval(@_);
+        # The &-call is here to ascertain the mutability of @_.
+        my ($val) = &DB::eval;
         $val = ( defined $val ) ? "'$val'" : 'undef';
 
         # Save it.
diff --git a/lib/perl5db.t b/lib/perl5db.t
index 8b81c6a..34aed9f 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(115);
+plan(116);
 
 my $rc_filename = '.perldb';
 
@@ -834,6 +834,28 @@ sub _calc_trace_wrapper
     );
 }
 
+# Tests for mutating @_
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'b 10',
+                'c',
+                'shift(@_)',
+                'print "\n\n\n(((" . join(",", @_) . ")))\n\n\n"',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/test-passing-at-underscore-to-x-etc',
+        }
+    );
+
+    $wrapper->output_like(
+        qr/^\(\(\(Capsula,GreekHumor,Socrates\)\)\)$/ms,
+        q/Mutating '@_'./,
+    );
+}
+
 # Tests for x with AutoTrace=1.
 {
     my $wrapper = DebugWrap->new(
-- 
1.8.1.5

@p5pRT
Copy link
Author

p5pRT commented Jun 10, 2013

From @rjbs

Thanks. I have applied Shlomi's patches to blead and am now smoking them on maint-5.18 for
application before v5.18.1.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Jun 10, 2013

From [Unknown Contact. See original ticket]

Thanks. I have applied Shlomi's patches to blead and am now smoking them on maint-5.18 for
application before v5.18.1.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Jun 10, 2013

@rjbs - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed Jun 10, 2013
@p5pRT
Copy link
Author

p5pRT commented Jun 11, 2013

From @shlomif

On Mon, 10 Jun 2013 15​:24​:45 -0700
"Ricardo SIGNES via RT" <perlbug-comment@​perl.org> wrote​:

Thanks. I have applied Shlomi's patches to blead and am now smoking them on
maint-5.18 for application before v5.18.1.

Thanks for applying the patches.

Regards,

  Shlomi Fish

--


Shlomi Fish http​://www.shlomifish.org/
Interview with Ben Collins-Sussman - http​://shlom.in/sussman

One of Buffy the Vampire Slayer’s episodes took place in the NSA headquarters,
but had to be destroyed, because all of the test audience had uncontrollable
panic attacks.
  — http​://www.shlomifish.org/humour/bits/facts/NSA/

Please reply to list if it's a mailing list post - http​://shlom.in/reply .

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

1 participant