b2938d
From b334474a337421c6643b872388245fb2c11bf995 Mon Sep 17 00:00:00 2001
b2938d
From: Tony Cook <tony@develop-help.com>
b2938d
Date: Mon, 30 Mar 2020 16:32:46 +1100
b2938d
Subject: [PATCH] fix C where $obj is a lexical
b2938d
MIME-Version: 1.0
b2938d
Content-Type: text/plain; charset=UTF-8
b2938d
Content-Transfer-Encoding: 8bit
b2938d
b2938d
the DB::eval function depends on the special behaviour of eval ""
b2938d
within the DB package, which evaluates the string within the context
b2938d
of the first non-DB sub or eval scope, working up the call stack.
b2938d
b2938d
The debugger refactor moved handling for the 'i' command from the
b2938d
DB package to the DB::Obj package, so the eval in DB::eval was
b2938d
working in the context of the DB::Obj::cmd_i function, not in the
b2938d
calling scope.
b2938d
b2938d
Fixed by moving the handling for the i command back to DB.
b2938d
b2938d
Fixes #17661.
b2938d
b2938d
Signed-off-by: Petr Písař <ppisar@redhat.com>
b2938d
---
b2938d
 MANIFEST               |  1 +
b2938d
 lib/perl5db.pl         | 65 +++++++++++++++++++++---------------------
b2938d
 lib/perl5db.t          | 20 +++++++++++++
b2938d
 lib/perl5db/t/gh-17661 | 14 +++++++++
b2938d
 4 files changed, 68 insertions(+), 32 deletions(-)
b2938d
 create mode 100644 lib/perl5db/t/gh-17661
b2938d
b2938d
diff --git a/MANIFEST b/MANIFEST
b2938d
index 8c71995174..96af3618bd 100644
b2938d
--- a/MANIFEST
b2938d
+++ b/MANIFEST
b2938d
@@ -4808,6 +4808,7 @@ lib/perl5db/t/eval-line-bug	Tests for the Perl debugger
b2938d
 lib/perl5db/t/fact		Tests for the Perl debugger
b2938d
 lib/perl5db/t/filename-line-breakpoint		Tests for the Perl debugger
b2938d
 lib/perl5db/t/gh-17660		Tests for the Perl debugger
b2938d
+lib/perl5db/t/gh-17661		Tests for the Perl debugger
b2938d
 lib/perl5db/t/load-modules	Tests for the Perl debugger
b2938d
 lib/perl5db/t/lsub-n		Test script used by perl5db.t
b2938d
 lib/perl5db/t/lvalue-bug	Tests for the Perl debugger
b2938d
diff --git a/lib/perl5db.pl b/lib/perl5db.pl
b2938d
index 96e56d559f..b647d24fb8 100644
b2938d
--- a/lib/perl5db.pl
b2938d
+++ b/lib/perl5db.pl
b2938d
@@ -2512,6 +2512,37 @@ EOP
b2938d
     return;
b2938d
 }
b2938d
 
b2938d
+=head3 C<_DB__handle_i_command> - inheritance display
b2938d
+
b2938d
+Display the (nested) parentage of the module or object given.
b2938d
+
b2938d
+=cut
b2938d
+
b2938d
+sub _DB__handle_i_command {
b2938d
+    my $self = shift;
b2938d
+
b2938d
+    my $line = $self->cmd_args;
b2938d
+    require mro;
b2938d
+    foreach my $isa ( split( /\s+/, $line ) ) {
b2938d
+        $evalarg = "$isa";
b2938d
+        # The &-call is here to ascertain the mutability of @_.
b2938d
+        ($isa) = &DB::eval;
b2938d
+        no strict 'refs';
b2938d
+        print join(
b2938d
+            ', ',
b2938d
+            map {
b2938d
+                "$_"
b2938d
+                  . (
b2938d
+                    defined( ${"$_\::VERSION"} )
b2938d
+                    ? ' ' . ${"$_\::VERSION"}
b2938d
+                    : undef )
b2938d
+              } @{mro::get_linear_isa(ref($isa) || $isa)}
b2938d
+        );
b2938d
+        print "\n";
b2938d
+    }
b2938d
+    next CMD;
b2938d
+}
b2938d
+
b2938d
 # 't' is type.
b2938d
 # 'm' is method.
b2938d
 # 'v' is the value (i.e: method name or subroutine ref).
b2938d
@@ -2531,6 +2562,7 @@ BEGIN
b2938d
     'W' => { t => 'm', v => '_handle_W_command', },
b2938d
     'c' => { t => 's', v => \&_DB__handle_c_command, },
b2938d
     'f' => { t => 's', v => \&_DB__handle_f_command, },
b2938d
+    'i' => { t => 's', v => \&_DB__handle_i_command, },
b2938d
     'm' => { t => 's', v => \&_DB__handle_m_command, },
b2938d
     'n' => { t => 'm', v => '_handle_n_command', },
b2938d
     'p' => { t => 'm', v => '_handle_p_command', },
b2938d
@@ -2551,7 +2583,7 @@ BEGIN
b2938d
         { t => 's', v => \&_DB__handle_restart_and_rerun_commands, },
b2938d
         } qw(R rerun)),
b2938d
     (map { $_ => {t => 'm', v => '_handle_cmd_wrapper_commands' }, }
b2938d
-        qw(a A b B e E h i l L M o O v w W)),
b2938d
+        qw(a A b B e E h l L M o O v w W)),
b2938d
 );
b2938d
 };
b2938d
 
b2938d
@@ -5468,37 +5500,6 @@ sub cmd_h {
b2938d
     }
b2938d
 } ## end sub cmd_h
b2938d
 
b2938d
-=head3 C<cmd_i> - inheritance display
b2938d
-
b2938d
-Display the (nested) parentage of the module or object given.
b2938d
-
b2938d
-=cut
b2938d
-
b2938d
-sub cmd_i {
b2938d
-    my $cmd  = shift;
b2938d
-    my $line = shift;
b2938d
-
b2938d
-    require mro;
b2938d
-
b2938d
-    foreach my $isa ( split( /\s+/, $line ) ) {
b2938d
-        $evalarg = $isa;
b2938d
-        # The &-call is here to ascertain the mutability of @_.
b2938d
-        ($isa) = &DB::eval;
b2938d
-        no strict 'refs';
b2938d
-        print join(
b2938d
-            ', ',
b2938d
-            map {
b2938d
-                "$_"
b2938d
-                  . (
b2938d
-                    defined( ${"$_\::VERSION"} )
b2938d
-                    ? ' ' . ${"$_\::VERSION"}
b2938d
-                    : undef )
b2938d
-              } @{mro::get_linear_isa(ref($isa) || $isa)}
b2938d
-        );
b2938d
-        print "\n";
b2938d
-    }
b2938d
-} ## end sub cmd_i
b2938d
-
b2938d
 =head3 C<cmd_l> - list lines (command)
b2938d
 
b2938d
 Most of the command is taken up with transforming all the different line
b2938d
diff --git a/lib/perl5db.t b/lib/perl5db.t
b2938d
index 913a301d98..ffa659a215 100644
b2938d
--- a/lib/perl5db.t
b2938d
+++ b/lib/perl5db.t
b2938d
@@ -2946,6 +2946,26 @@ SKIP:
b2938d
        );
b2938d
 }
b2938d
 
b2938d
+{
b2938d
+    # gh #17661
b2938d
+    my $wrapper = DebugWrap->new(
b2938d
+        {
b2938d
+            cmds =>
b2938d
+            [
b2938d
+                'c',
b2938d
+                'i $obj',
b2938d
+                'q',
b2938d
+            ],
b2938d
+            prog => '../lib/perl5db/t/gh-17661',
b2938d
+        }
b2938d
+    );
b2938d
+
b2938d
+    $wrapper->output_like(
b2938d
+        qr/C5, C1, C2, C3, C4/,
b2938d
+        q/check for reasonable result/,
b2938d
+       );
b2938d
+}
b2938d
+
b2938d
 SKIP:
b2938d
 {
b2938d
     $Config{usethreads}
b2938d
diff --git a/lib/perl5db/t/gh-17661 b/lib/perl5db/t/gh-17661
b2938d
new file mode 100644
b2938d
index 0000000000..0d85977b35
b2938d
--- /dev/null
b2938d
+++ b/lib/perl5db/t/gh-17661
b2938d
@@ -0,0 +1,14 @@
b2938d
+use v5.10.0;
b2938d
+
b2938d
+{ package C1; sub c1 { } our @ISA = qw(C2) }
b2938d
+{ package C2; sub c2 { } our @ISA = qw(C3) }
b2938d
+{ package C3; sub c3 { } our @ISA = qw(  ) }
b2938d
+{ package C4; sub c4 { } our @ISA = qw(  ) }
b2938d
+{ package C5; sub c5 { } our @ISA = qw(C1 C4) }
b2938d
+
b2938d
+my $obj = bless {}, 'C5';
b2938d
+$main::global = bless {}, 'C5';
b2938d
+
b2938d
+$DB::single = 1;
b2938d
+
b2938d
+say "Done.";
b2938d
-- 
b2938d
2.25.4
b2938d