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