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

[PATCHES] Add tests to the perl debugger and refactor it #12450

Closed
p5pRT opened this issue Sep 30, 2012 · 88 comments
Closed

[PATCHES] Add tests to the perl debugger and refactor it #12450

p5pRT opened this issue Sep 30, 2012 · 88 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 30, 2012

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

Searchable as RT115084$

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

Hi all,

this series of patches adds more tests to the perl debugger and starts
to refactor it. It can also be found here​:

https://github.com/shlomif/perl/tree/shlomif-perl-d-refactoring

Please apply it.

Regards,

  Shlomi Fish

--


Shlomi Fish http​://www.shlomifish.org/
UNIX Fortune Cookies - http​://www.shlomifish.org/humour/fortunes/

Doing linear scans over an associative array is like trying to club someone to
death with a loaded Uzi. — Larry Wall

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

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0001-Add-a-test-for-the-and-commands-together.patch
From c03f546959d4fce67f86d6ecf68c9f66bec17fed Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 10:22:26 +0300
Subject: [PATCH 01/81] Add a test for the < and > commands together.

---
 lib/perl5db.t | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 10b87ad..51b1cf0 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(73);
+plan(74);
 
 my $rc_filename = '.perldb';
 
@@ -1644,6 +1644,32 @@ package main;
     );
 }
 
+# Test the < and > commands together
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                q/$::lorem = 0;/,
+                q/< $::lorem += 10;/,
+                q/> print "\nLOREM=<$::lorem>\n"/,
+                q/b 7/,
+                q/b 5/,
+                'c',
+                'c',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/disable-breakpoints-1',
+        }
+    );
+
+    $wrapper->output_like(qr#
+        ^LOREM=<10>\n
+        #msx,
+        q#Test < and > commands. #,
+    );
+}
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0002-Test-for-the-and-commands.patch
From ba9d26f3a8479c92a9f410e7baac0431fa47143d Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 10:47:19 +0300
Subject: [PATCH 02/81] Test for the { and { ? commands.

---
 lib/perl5db.t | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 51b1cf0..81e04d3 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(74);
+plan(75);
 
 my $rc_filename = '.perldb';
 
@@ -1670,6 +1670,40 @@ package main;
     );
 }
 
+# Test the { ? and { [command] commands.
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                q/{ ?/,
+                q/{ l/,
+                q/{ ?/,
+                q/b 5/,
+                q/c/,
+                q/q/,
+            ],
+            prog => '../lib/perl5db/t/disable-breakpoints-1',
+        }
+    );
+
+    $wrapper->contents_like(qr#
+        ^No\ pre-debugger\ actions\.\n
+        .*?
+        ^pre-debugger\ commands:\n
+        \s+\{\ --\ l\n
+        .*?
+        ^5==>b\s+\$x\ =\ "FirstVal";\n
+        6\s*\n
+        7:\s+\$dummy\+\+;\n
+        8\s*\n
+        9:\s+\$x\ =\ "SecondVal";\n
+
+        #msx,
+        'Test the pre-prompt debugger commands',
+    );
+}
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0003-Convert-to-a-different-quoting.patch
From 1b5fdd73944ece7f50aa2925529407ad4d0e0383 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 10:52:12 +0300
Subject: [PATCH 03/81] Convert to a different quoting.

This was done so gvim won't be confused with the bracket-matching.
I'll report the problem to the perl.vim project.
---
 lib/perl5db.t | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 81e04d3..23346d0 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -1676,9 +1676,9 @@ package main;
         {
             cmds =>
             [
-                q/{ ?/,
-                q/{ l/,
-                q/{ ?/,
+                '{ ?',
+                '{ l',
+                '{ ?',
                 q/b 5/,
                 q/c/,
                 q/q/,
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0004-Test-the-command.patch
From 07adf055565800399a9fc6052d84f330406c17b0 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 10:56:54 +0300
Subject: [PATCH 04/81] Test the { * command.

---
 lib/perl5db.t | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 23346d0..7a65c3b 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(75);
+plan(77);
 
 my $rc_filename = '.perldb';
 
@@ -1704,6 +1704,34 @@ package main;
     );
 }
 
+# Test the { * command.
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                '{ q',
+                '{ *',
+                q/b 5/,
+                q/c/,
+                q/print (("One" x 5), "\n");/,
+                q/q/,
+            ],
+            prog => '../lib/perl5db/t/disable-breakpoints-1',
+        }
+    );
+
+    $wrapper->contents_like(qr#
+        ^All\ \{\ actions\ cleared\.\n
+        #msx,
+        'Test the { * command',
+    );
+
+    $wrapper->output_like(qr/OneOneOneOneOne/,
+        '{ * test - output is OK.',
+    );
+}
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0005-Test-the-command.patch
From b961084799d3237e79896636487819d226095308 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 12:56:51 +0300
Subject: [PATCH 05/81] Test the ! command.

---
 lib/perl5db.t | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 7a65c3b..aa046cb 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(77);
+plan(78);
 
 my $rc_filename = '.perldb';
 
@@ -1732,6 +1732,32 @@ package main;
     );
 }
 
+# Test the ! command.
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'l 3-5',
+                '!',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/disable-breakpoints-1',
+        }
+    );
+
+    $wrapper->contents_like(qr#
+        (^3:\s+my\ \$dummy\ =\ 0;\n
+        4\s*\n
+        5:\s+\$x\ =\ "FirstVal";)\n
+        .*?
+        ^l\ 3-5\n
+        \1
+        #msx,
+        'Test the ! command (along with l 3-5)',
+    );
+}
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0006-Add-a-test-for-l-num.patch
From c2dca0df1aecc6b9ffb3706ecadf293469d41531 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 13:35:43 +0300
Subject: [PATCH 06/81] Add a test for l -num.

---
 lib/perl5db.t | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index aa046cb..c559666 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(78);
+plan(79);
 
 my $rc_filename = '.perldb';
 
@@ -1758,6 +1758,35 @@ package main;
     );
 }
 
+# Test the ! -number command.
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'l 3-5',
+                'l 2',
+                '! -1',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/disable-breakpoints-1',
+        }
+    );
+
+    $wrapper->contents_like(qr#
+        (^3:\s+my\ \$dummy\ =\ 0;\n
+        4\s*\n
+        5:\s+\$x\ =\ "FirstVal";)\n
+        .*?
+        ^2==\>\s+my\ \$x\ =\ "One";\n
+        .*?
+        ^l\ 3-5\n
+        \1
+        #msx,
+        'Test the ! -n command (along with l)',
+    );
+}
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0007-Convert-a-perl5db.t-test-to-DebugWrap.patch
From ef82511b9f8f3fad6c02f07129829637a63733df Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 15:59:12 +0300
Subject: [PATCH 07/81] Convert a perl5db.t test to DebugWrap.

---
 lib/perl5db.t | 56 +++++++++++++++++++++++++-------------------------------
 1 file changed, 25 insertions(+), 31 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index c559666..b48b191 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -65,37 +65,6 @@ sub _out_contents
     return _slurp($out_fn);
 }
 
-{
-    my $target = '../lib/perl5db/t/eval-line-bug';
-
-    rc(
-        <<"EOF",
-    &parse_options("NonStop=0 TTY=db.out LineInfo=db.out");
-
-    sub afterinit {
-        push(\@DB::typeahead,
-            'b 23',
-            'n',
-            'n',
-            'n',
-            'c', # line 23
-            'n',
-            "p \\\@{'main::_<$target'}",
-            'q',
-        );
-    }
-EOF
-    );
-
-    {
-        local $ENV{PERLDB_OPTS} = "ReadLine=0";
-        runperl(switches => [ '-d' ], progfile => $target);
-    }
-}
-
-like(_out_contents(), qr/sub factorial/,
-    'The ${main::_<filename} variable in the debugger was not destroyed'
-);
 
 {
     my $target = '../lib/perl5db/t/eval-line-bug';
@@ -411,6 +380,31 @@ sub contents_unlike {
 
 package main;
 
+{
+    local $ENV{PERLDB_OPTS} = "ReadLine=0";
+    my $target = '../lib/perl5db/t/eval-line-bug';
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'b 23',
+                'n',
+                'n',
+                'n',
+                'c', # line 23
+                'n',
+                "p \@{'main::_<$target'}",
+                'q',
+            ],
+            prog => $target,
+        }
+    );
+    $wrapper->contents_like(
+        qr/sub factorial/,
+        'The ${main::_<filename} variable in the debugger was not destroyed',
+    );
+}
+
 # Testing that we can set a line in the middle of the file.
 {
     my $wrapper = DebugWrap->new(
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0008-Convert-a-test-to-DebugWrap.patch
From ddfe3e3f4d7527445328bd7ba4c29c2cf822c282 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 16:08:16 +0300
Subject: [PATCH 08/81] Convert a test to DebugWrap.

---
 lib/perl5db.t | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index b48b191..94a923e 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -65,10 +65,7 @@ sub _out_contents
     return _slurp($out_fn);
 }
 
-
 {
-    my $target = '../lib/perl5db/t/eval-line-bug';
-
     rc(
         <<"EOF",
     &parse_options("NonStop=0 TTY=db.out LineInfo=db.out");
@@ -84,17 +81,8 @@ sub _out_contents
     }
 EOF
     );
-
-    {
-        local $ENV{PERLDB_OPTS} = "ReadLine=0";
-        runperl(switches => [ '-d' ], progfile => $target);
-    }
 }
 
-like(_out_contents(), qr/new_var = <Foo>/,
-    "no strict 'vars' in evaluated lines.",
-);
-
 {
     local $ENV{PERLDB_OPTS} = "ReadLine=0";
     my $output = runperl(switches => [ '-d' ], progfile => '../lib/perl5db/t/lvalue-bug');
@@ -405,6 +393,27 @@ package main;
     );
 }
 
+{
+    local $ENV{PERLDB_OPTS} = "ReadLine=0";
+    my $target = '../lib/perl5db/t/eval-line-bug';
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'b 23',
+                'n',
+                '$new_var = "Foo"',
+                'x "new_var = <$new_var>\\n"',
+                'q',
+            ],
+            prog => $target,
+        }
+    );
+
+    $wrapper->contents_like( qr/new_var = <Foo>/,
+        "no strict 'vars' in evaluated lines.",
+    );
+}
 # Testing that we can set a line in the middle of the file.
 {
     my $wrapper = DebugWrap->new(
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0009-Extract-a-constructor.patch
From 3af057fdc97d7be72e6dc29454a40b7303fd3a34 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 16:29:46 +0300
Subject: [PATCH 09/81] Extract a constructor.

This will help in converting the other instances to DebugWrap.
---
 lib/perl5db.t | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 94a923e..ad92dc8 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -393,10 +393,12 @@ package main;
     );
 }
 
+sub calc_new_var_wrapper
 {
-    local $ENV{PERLDB_OPTS} = "ReadLine=0";
-    my $target = '../lib/perl5db/t/eval-line-bug';
-    my $wrapper = DebugWrap->new(
+    my ($target, $extra_opts) = @_;
+    $extra_opts ||= '';
+    local $ENV{PERLDB_OPTS} = "ReadLine=0" . $extra_opts;
+    return DebugWrap->new(
         {
             cmds =>
             [
@@ -409,11 +411,16 @@ package main;
             prog => $target,
         }
     );
+}
 
-    $wrapper->contents_like( qr/new_var = <Foo>/,
-        "no strict 'vars' in evaluated lines.",
-    );
+{
+    calc_new_var_wrapper('../lib/perl5db/t/eval-line-bug')
+        ->contents_like(
+            qr/new_var = <Foo>/,
+            "no strict 'vars' in evaluated lines.",
+        );
 }
+
 # Testing that we can set a line in the middle of the file.
 {
     my $wrapper = DebugWrap->new(
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0010-Convert-another-test-to-DebugWrap.patch
From 574dcb497beff8093b039cf39daffc90a9ee4470 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 16:51:50 +0300
Subject: [PATCH 10/81] Convert another test to DebugWrap.

---
 lib/perl5db.t | 59 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 48 insertions(+), 11 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index ad92dc8..9e40776 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -84,12 +84,6 @@ EOF
 }
 
 {
-    local $ENV{PERLDB_OPTS} = "ReadLine=0";
-    my $output = runperl(switches => [ '-d' ], progfile => '../lib/perl5db/t/lvalue-bug');
-    like($output, qr/foo is defined/, 'lvalue subs work in the debugger');
-}
-
-{
     local $ENV{PERLDB_OPTS} = "ReadLine=0 NonStop=1";
     my $output = runperl(switches => [ '-d' ], progfile => '../lib/perl5db/t/symbol-table-bug');
     like($output, qr/Undefined symbols 0/, 'there are no undefined values in the symbol table');
@@ -251,6 +245,29 @@ sub _include_t
     return $self->{_include_t};
 }
 
+sub _stderr_val
+{
+    my $self = shift;
+
+    if (@_)
+    {
+        $self->{_stderr_val} = shift;
+    }
+
+    return $self->{_stderr_val};
+}
+
+sub field
+{
+    my $self = shift;
+
+    if (@_)
+    {
+        $self->{field} = shift;
+    }
+
+    return $self->{field};
+}
 sub _contents
 {
     my $self = shift;
@@ -285,6 +302,8 @@ sub _init
 
     $self->_include_t($args->{include_t} ? 1 : 0);
 
+    $self->_stderr_val(exists($args->{stderr}) ? $args->{stderr} : 1);
+
     $self->_run();
 
     return;
@@ -327,7 +346,10 @@ sub _run {
                 '-d',
                 ($self->_include_t ? ('-I', '../lib/perl5db/t') : ())
             ],
-            stderr => 1,
+            (defined($self->_stderr_val())
+                ? (stderr => $self->_stderr_val())
+                : ()
+            ),
             progfile => $self->_prog()
         );
 
@@ -395,7 +417,9 @@ package main;
 
 sub calc_new_var_wrapper
 {
-    my ($target, $extra_opts) = @_;
+    my $args = shift;
+
+    my $extra_opts = delete($args->{extra_opts});
     $extra_opts ||= '';
     local $ENV{PERLDB_OPTS} = "ReadLine=0" . $extra_opts;
     return DebugWrap->new(
@@ -403,24 +427,37 @@ sub calc_new_var_wrapper
             cmds =>
             [
                 'b 23',
-                'n',
+                'c',
                 '$new_var = "Foo"',
                 'x "new_var = <$new_var>\\n"',
                 'q',
             ],
-            prog => $target,
+            prog => delete($args->{prog}),
+            %$args,
         }
     );
 }
 
 {
-    calc_new_var_wrapper('../lib/perl5db/t/eval-line-bug')
+    calc_new_var_wrapper({ prog => '../lib/perl5db/t/eval-line-bug'})
         ->contents_like(
             qr/new_var = <Foo>/,
             "no strict 'vars' in evaluated lines.",
         );
 }
 
+{
+    calc_new_var_wrapper(
+        {
+            prog => '../lib/perl5db/t/lvalue-bug',
+            stderr => undef(),
+        },
+    )->output_like(
+            qr/foo is defined/,
+             'lvalue subs work in the debugger',
+         );
+}
+
 # Testing that we can set a line in the middle of the file.
 {
     my $wrapper = DebugWrap->new(
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0011-Convert-another-test-to-DebugWrap.patch
From 329de394214994576913c72f5bf63ecae0a26892 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 16:54:30 +0300
Subject: [PATCH 11/81] Convert another test to DebugWrap.

---
 lib/perl5db.t | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 9e40776..017e54f 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -83,12 +83,6 @@ EOF
     );
 }
 
-{
-    local $ENV{PERLDB_OPTS} = "ReadLine=0 NonStop=1";
-    my $output = runperl(switches => [ '-d' ], progfile => '../lib/perl5db/t/symbol-table-bug');
-    like($output, qr/Undefined symbols 0/, 'there are no undefined values in the symbol table');
-}
-
 SKIP: {
     if ( $Config{usethreads} ) {
         skip('This perl has threads, skipping non-threaded debugger tests');
@@ -458,6 +452,19 @@ sub calc_new_var_wrapper
          );
 }
 
+{
+    calc_new_var_wrapper(
+        {
+            prog =>  '../lib/perl5db/t/symbol-table-bug',
+            extra_opts => "NonStop=1",
+            stderr => undef(),
+        }
+    )->output_like(
+        qr/Undefined symbols 0/,
+        'there are no undefined values in the symbol table',
+    );
+}
+
 # Testing that we can set a line in the middle of the file.
 {
     my $wrapper = DebugWrap->new(
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0012-Convert-another-test-to-DebugWrap.patch
From 8e994b8adeafb89c9857a44ceb628ca664836cbf Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 17:01:16 +0300
Subject: [PATCH 12/81] Convert another test to DebugWrap.

---
 lib/perl5db.t | 50 +++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 39 insertions(+), 11 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 017e54f..6efb74e 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -85,16 +85,6 @@ EOF
 
 SKIP: {
     if ( $Config{usethreads} ) {
-        skip('This perl has threads, skipping non-threaded debugger tests');
-    } else {
-        my $error = 'This Perl not built to support threads';
-        my $output = runperl( switches => [ '-dt' ], stderr => 1 );
-        like($output, qr/$error/, 'Perl debugger correctly complains that it was not built with threads');
-    }
-
-}
-SKIP: {
-    if ( $Config{usethreads} ) {
         local $ENV{PERLDB_OPTS} = "ReadLine=0 NonStop=1";
         my $output = runperl(switches => [ '-dt' ], progfile => '../lib/perl5db/t/symbol-table-bug');
         like($output, qr/Undefined symbols 0/, 'there are no undefined values in the symbol table when running with thread support');
@@ -262,6 +252,19 @@ sub field
 
     return $self->{field};
 }
+
+sub _switches
+{
+    my $self = shift;
+
+    if (@_)
+    {
+        $self->{_switches} = shift;
+    }
+
+    return $self->{_switches};
+}
+
 sub _contents
 {
     my $self = shift;
@@ -298,6 +301,11 @@ sub _init
 
     $self->_stderr_val(exists($args->{stderr}) ? $args->{stderr} : 1);
 
+    if (exists($args->{switches}))
+    {
+        $self->_switches($args->{switches});
+    }
+
     $self->_run();
 
     return;
@@ -337,7 +345,7 @@ sub _run {
         ::runperl(
             switches =>
             [
-                '-d',
+                ($self->_switches ? (@{$self->_switches()}) : ('-d')),
                 ($self->_include_t ? ('-I', '../lib/perl5db/t') : ())
             ],
             (defined($self->_stderr_val())
@@ -465,6 +473,26 @@ sub calc_new_var_wrapper
     );
 }
 
+SKIP:
+{
+    if ( $Config{usethreads} ) {
+        skip('This perl has threads, skipping non-threaded debugger tests');
+    }
+    else {
+        my $error = 'This Perl not built to support threads';
+        calc_new_var_wrapper(
+            {
+                prog => '../lib/perl5db/t/eval-line-bug',
+                switches => ['-dt',],
+                stderr => 1,
+            }
+        )->output_like(
+            qr/\Q$error\E/,
+            'Perl debugger correctly complains that it was not built with threads',
+        );
+    }
+}
+
 # Testing that we can set a line in the middle of the file.
 {
     my $wrapper = DebugWrap->new(
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0013-Convert-another-test-to-DebugWrap.patch
From 15e68b510adfd1137ce1052d723e2e0e85eaa3f9 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 17:03:48 +0300
Subject: [PATCH 13/81] Convert another test to DebugWrap.

---
 lib/perl5db.t | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 6efb74e..33fe9bb 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -83,17 +83,6 @@ EOF
     );
 }
 
-SKIP: {
-    if ( $Config{usethreads} ) {
-        local $ENV{PERLDB_OPTS} = "ReadLine=0 NonStop=1";
-        my $output = runperl(switches => [ '-dt' ], progfile => '../lib/perl5db/t/symbol-table-bug');
-        like($output, qr/Undefined symbols 0/, 'there are no undefined values in the symbol table when running with thread support');
-    } else {
-        skip("This perl is not threaded, skipping threaded debugger tests");
-    }
-}
-
-
 # Test [perl #61222]
 {
     local $ENV{PERLDB_OPTS};
@@ -493,6 +482,25 @@ SKIP:
     }
 }
 
+SKIP:
+{
+    if ( $Config{usethreads} ) {
+        calc_new_var_wrapper(
+            {
+                prog =>  '../lib/perl5db/t/symbol-table-bug',
+                switches => [ '-dt', ],
+                stderr => 1,
+            }
+        )->output_like(
+            qr/Undefined symbols 0/,
+            'there are no undefined values in the symbol table when running with thread support',
+        );
+    }
+    else {
+        skip("This perl is not threaded, skipping threaded debugger tests");
+    }
+}
+
 # Testing that we can set a line in the middle of the file.
 {
     my $wrapper = DebugWrap->new(
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0014-Prepend-with-an-underscore.patch
From 459bc35def63c74d3471ff0083c752fad3de7ee5 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 17:04:49 +0300
Subject: [PATCH 14/81] Prepend with an underscore.

To make it an internally-used subroutine.
---
 lib/perl5db.t | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 33fe9bb..f12898f 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -406,7 +406,7 @@ package main;
     );
 }
 
-sub calc_new_var_wrapper
+sub _calc_new_var_wrapper
 {
     my $args = shift;
 
@@ -430,7 +430,7 @@ sub calc_new_var_wrapper
 }
 
 {
-    calc_new_var_wrapper({ prog => '../lib/perl5db/t/eval-line-bug'})
+    _calc_new_var_wrapper({ prog => '../lib/perl5db/t/eval-line-bug'})
         ->contents_like(
             qr/new_var = <Foo>/,
             "no strict 'vars' in evaluated lines.",
@@ -438,7 +438,7 @@ sub calc_new_var_wrapper
 }
 
 {
-    calc_new_var_wrapper(
+    _calc_new_var_wrapper(
         {
             prog => '../lib/perl5db/t/lvalue-bug',
             stderr => undef(),
@@ -450,7 +450,7 @@ sub calc_new_var_wrapper
 }
 
 {
-    calc_new_var_wrapper(
+    _calc_new_var_wrapper(
         {
             prog =>  '../lib/perl5db/t/symbol-table-bug',
             extra_opts => "NonStop=1",
@@ -469,7 +469,7 @@ SKIP:
     }
     else {
         my $error = 'This Perl not built to support threads';
-        calc_new_var_wrapper(
+        _calc_new_var_wrapper(
             {
                 prog => '../lib/perl5db/t/eval-line-bug',
                 switches => ['-dt',],
@@ -485,7 +485,7 @@ SKIP:
 SKIP:
 {
     if ( $Config{usethreads} ) {
-        calc_new_var_wrapper(
+        _calc_new_var_wrapper(
             {
                 prog =>  '../lib/perl5db/t/symbol-table-bug',
                 switches => [ '-dt', ],
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0015-Remove-some-no-longer-used-code.patch
From efb55281a10ed7250a10b8036fc675d4ff8773bf Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 17:06:27 +0300
Subject: [PATCH 15/81] Remove some no-longer used code.

---
 lib/perl5db.t | 18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index f12898f..9e2171d 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -65,24 +65,6 @@ sub _out_contents
     return _slurp($out_fn);
 }
 
-{
-    rc(
-        <<"EOF",
-    &parse_options("NonStop=0 TTY=db.out LineInfo=db.out");
-
-    sub afterinit {
-        push(\@DB::typeahead,
-            'b 23',
-            'c',
-            '\$new_var = "Foo"',
-            'x "new_var = <\$new_var>\\n";',
-            'q',
-        );
-    }
-EOF
-    );
-}
-
 # Test [perl #61222]
 {
     local $ENV{PERLDB_OPTS};
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0016-Extract-_calc_threads_wrapper.patch
From 4c7491b48d8bfc53b5a078c63e962b7a0523245d Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 17:08:40 +0300
Subject: [PATCH 16/81] Extract _calc_threads_wrapper.

---
 lib/perl5db.t | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 9e2171d..bf2d539 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -411,6 +411,19 @@ sub _calc_new_var_wrapper
     );
 }
 
+sub _calc_threads_wrapper
+{
+    my $args = shift;
+
+    return _calc_new_var_wrapper(
+        {
+            switches => [ '-dt', ],
+            stderr => 1,
+            %$args
+        }
+    );
+}
+
 {
     _calc_new_var_wrapper({ prog => '../lib/perl5db/t/eval-line-bug'})
         ->contents_like(
@@ -451,11 +464,9 @@ SKIP:
     }
     else {
         my $error = 'This Perl not built to support threads';
-        _calc_new_var_wrapper(
+        _calc_threads_wrapper(
             {
                 prog => '../lib/perl5db/t/eval-line-bug',
-                switches => ['-dt',],
-                stderr => 1,
             }
         )->output_like(
             qr/\Q$error\E/,
@@ -467,11 +478,9 @@ SKIP:
 SKIP:
 {
     if ( $Config{usethreads} ) {
-        _calc_new_var_wrapper(
+        _calc_threads_wrapper(
             {
                 prog =>  '../lib/perl5db/t/symbol-table-bug',
-                switches => [ '-dt', ],
-                stderr => 1,
             }
         )->output_like(
             qr/Undefined symbols 0/,
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0017-Convert-the-61222-test-to-DebugWrap.patch
From 269b714845919a0dc77ececb7ca9a406be899f34 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Wed, 12 Sep 2012 17:13:32 +0300
Subject: [PATCH 17/81] Convert the 61222 test to DebugWrap.

---
 lib/perl5db.t | 39 ++++++++++++++++++---------------------
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index bf2d539..1b21f0f 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -65,27 +65,6 @@ sub _out_contents
     return _slurp($out_fn);
 }
 
-# Test [perl #61222]
-{
-    local $ENV{PERLDB_OPTS};
-    rc(
-        <<'EOF',
-        &parse_options("NonStop=0 TTY=db.out LineInfo=db.out");
-
-        sub afterinit {
-            push(@DB::typeahead,
-                'm Pie',
-                'q',
-            );
-        }
-EOF
-    );
-
-    my $output = runperl(switches => [ '-d' ], stderr => 1, progfile => '../lib/perl5db/t/rt-61222');
-    unlike(_out_contents(), qr/INCORRECT/, "[perl #61222]");
-}
-
-
 
 # Test for Proxy constants
 {
@@ -492,6 +471,24 @@ SKIP:
     }
 }
 
+# Test [perl #61222]
+{
+    local $ENV{PERLDB_OPTS};
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'm Pie',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/rt-61222',
+        }
+    );
+
+    $wrapper->contents_unlike(qr/INCORRECT/, "[perl #61222]");
+}
+
+
 # Testing that we can set a line in the middle of the file.
 {
     my $wrapper = DebugWrap->new(
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0018-Convert-more-to-DebugWrap.patch
From a85fa0bb99698de0440e68402c8d8009019e57e5 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Thu, 13 Sep 2012 14:26:55 +0300
Subject: [PATCH 18/81] Convert more to DebugWrap.

---
 lib/perl5db.t | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 1b21f0f..89a3f28 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -94,7 +94,6 @@ EOF
     like($output, "All tests successful.", "[perl #66110]");
 }
 
-# [perl 104168] level option for tracing
 {
     rc(<<'EOF');
 &parse_options("NonStop=0 TTY=db.out LineInfo=db.out");
@@ -108,11 +107,6 @@ sub afterinit {
 
 }
 EOF
-
-    my $output = runperl(switches => [ '-d' ], stderr => 1, progfile => '../lib/perl5db/t/rt-104168');
-    my $contents = _out_contents();
-    like($contents, qr/level 2/, "[perl #104168]");
-    unlike($contents, qr/baz/, "[perl #104168]");
 }
 
 # taint tests
@@ -488,6 +482,33 @@ SKIP:
     $wrapper->contents_unlike(qr/INCORRECT/, "[perl #61222]");
 }
 
+sub _calc_foo_wrapper
+{
+    my $args = shift;
+
+    my $extra_opts = delete($args->{extra_opts});
+    $extra_opts ||= '';
+    local $ENV{PERLDB_OPTS} = "ReadLine=0" . $extra_opts;
+    return DebugWrap->new(
+        {
+            cmds =>
+            [
+                't 2',
+                'c',
+                'q',
+            ],
+            prog => delete($args->{prog}),
+            %$args,
+        }
+    );
+}
+
+# [perl 104168] level option for tracing
+{
+    my $wrapper = _calc_foo_wrapper({ prog =>  '../lib/perl5db/t/rt-104168' });
+    $wrapper->contents_like(qr/level 2/, "[perl #104168] - level 2 appears");
+    $wrapper->contents_unlike(qr/baz/, "[perl #104168] - no 'baz'");
+}
 
 # Testing that we can set a line in the middle of the file.
 {
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0019-Convert-to-DebugWrap.patch
From cf3e15fa03fd578e930a86291200e4075b8ca370 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Thu, 13 Sep 2012 14:32:41 +0300
Subject: [PATCH 19/81] Convert to DebugWrap.

---
 lib/perl5db.t | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 89a3f28..e538c61 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -109,16 +109,6 @@ sub afterinit {
 EOF
 }
 
-# taint tests
-
-{
-    local $ENV{PERLDB_OPTS} = "ReadLine=0 NonStop=1";
-    my $output = runperl(switches => [ '-d', '-T' ], stderr => 1,
-        progfile => '../lib/perl5db/t/taint');
-    chomp $output if $^O eq 'VMS'; # newline guaranteed at EOF
-    is($output, '[$^X][done]', "taint");
-}
-
 package DebugWrap;
 
 sub new {
@@ -306,6 +296,11 @@ sub _run {
     return;
 }
 
+sub get_output
+{
+    return shift->_output();
+}
+
 sub output_like {
     my ($self, $re, $msg) = @_;
 
@@ -510,6 +505,21 @@ sub _calc_foo_wrapper
     $wrapper->contents_unlike(qr/baz/, "[perl #104168] - no 'baz'");
 }
 
+# taint tests
+{
+    my $wrapper = _calc_foo_wrapper(
+        {
+            prog => '../lib/perl5db/t/taint',
+            extra_opts => ' NonStop=1',
+            switches => [ '-d', '-T', ],
+        }
+    );
+
+    my $output = $wrapper->get_output();
+    chomp $output if $^O eq 'VMS'; # newline guaranteed at EOF
+    is($output, '[$^X][done]', "taint");
+}
+
 # Testing that we can set a line in the middle of the file.
 {
     my $wrapper = DebugWrap->new(
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0020-Rename-to-something-more-meaningful.patch
From 8de8ead4ff0dca1f4578cac5c74387924e894296 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Thu, 13 Sep 2012 14:34:18 +0300
Subject: [PATCH 20/81] Rename to something more meaningful.

---
 lib/perl5db.t | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index e538c61..d612b6e 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -477,7 +477,7 @@ SKIP:
     $wrapper->contents_unlike(qr/INCORRECT/, "[perl #61222]");
 }
 
-sub _calc_foo_wrapper
+sub _calc_trace_wrapper
 {
     my $args = shift;
 
@@ -500,14 +500,14 @@ sub _calc_foo_wrapper
 
 # [perl 104168] level option for tracing
 {
-    my $wrapper = _calc_foo_wrapper({ prog =>  '../lib/perl5db/t/rt-104168' });
+    my $wrapper = _calc_trace_wrapper({ prog =>  '../lib/perl5db/t/rt-104168' });
     $wrapper->contents_like(qr/level 2/, "[perl #104168] - level 2 appears");
     $wrapper->contents_unlike(qr/baz/, "[perl #104168] - no 'baz'");
 }
 
 # taint tests
 {
-    my $wrapper = _calc_foo_wrapper(
+    my $wrapper = _calc_trace_wrapper(
         {
             prog => '../lib/perl5db/t/taint',
             extra_opts => ' NonStop=1',
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0021-Extract-a-common-subroutine.patch
From 464b777e8c3797f2eba7a9c1fde1e84d975aa0e3 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Thu, 13 Sep 2012 14:41:59 +0300
Subject: [PATCH 21/81] Extract a common subroutine.

---
 lib/perl5db.t | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index d612b6e..5b60c54 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -356,7 +356,7 @@ package main;
     );
 }
 
-sub _calc_new_var_wrapper
+sub _calc_generic_wrapper
 {
     my $args = shift;
 
@@ -365,6 +365,18 @@ sub _calc_new_var_wrapper
     local $ENV{PERLDB_OPTS} = "ReadLine=0" . $extra_opts;
     return DebugWrap->new(
         {
+            cmds => delete($args->{cmds}),
+            prog => delete($args->{prog}),
+            %$args,
+        }
+    );
+}
+
+sub _calc_new_var_wrapper
+{
+    my ($args) = @_;
+    return _calc_generic_wrapper(
+        {
             cmds =>
             [
                 'b 23',
@@ -373,7 +385,6 @@ sub _calc_new_var_wrapper
                 'x "new_var = <$new_var>\\n"',
                 'q',
             ],
-            prog => delete($args->{prog}),
             %$args,
         }
     );
@@ -479,12 +490,9 @@ SKIP:
 
 sub _calc_trace_wrapper
 {
-    my $args = shift;
+    my ($args) = @_;
 
-    my $extra_opts = delete($args->{extra_opts});
-    $extra_opts ||= '';
-    local $ENV{PERLDB_OPTS} = "ReadLine=0" . $extra_opts;
-    return DebugWrap->new(
+    return _calc_generic_wrapper(
         {
             cmds =>
             [
@@ -492,7 +500,6 @@ sub _calc_trace_wrapper
                 'c',
                 'q',
             ],
-            prog => delete($args->{prog}),
             %$args,
         }
     );
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0022-Add-a-test-for-the-source-command.patch
From f0dbcd6e0b08be7e6f69cf02747cf871deb2f558 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Thu, 13 Sep 2012 16:52:54 +0300
Subject: [PATCH 22/81] Add a test for the source command.

---
 MANIFEST                             |  1 +
 lib/perl5db.t                        | 34 +++++++++++++++++++++++++++++++++-
 lib/perl5db/t/source-cmd-test.perldb |  2 ++
 3 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 lib/perl5db/t/source-cmd-test.perldb

diff --git a/MANIFEST b/MANIFEST
index 6ac316d..a1df910 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4328,6 +4328,7 @@ lib/perl5db/t/proxy-constants	Tests for the Perl debugger
 lib/perl5db/t/rt-104168		Tests for the Perl debugger
 lib/perl5db/t/rt-61222		Tests for the Perl debugger
 lib/perl5db/t/rt-66110		Tests for the Perl debugger
+lib/perl5db/t/source-cmd-test.perldb		TTests for the Perl debugger
 lib/perl5db/t/symbol-table-bug	Tests for the Perl debugger
 lib/perl5db/t/taint		Tests for the Perl debugger
 lib/perl5db/t/test-l-statement-1	Tests for the Perl debugger
diff --git a/lib/perl5db.t b/lib/perl5db.t
index 5b60c54..a9d49d6 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(79);
+plan(80);
 
 my $rc_filename = '.perldb';
 
@@ -1903,6 +1903,38 @@ sub _calc_trace_wrapper
     );
 }
 
+# Test the 'source' command.
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'source ../lib/perl5db/t/source-cmd-test.perldb',
+                # If we have a 'q' here, then the typeahead will override the
+                # input, and so it won't be reached - solution:
+                # put a q inside the .perldb commands.
+                # ( This may be a bug or a misfeature. )
+            ],
+            prog => '../lib/perl5db/t/disable-breakpoints-1',
+        }
+    );
+
+    $wrapper->contents_like(qr#
+        ^3:\s+my\ \$dummy\ =\ 0;\n
+        4\s*\n
+        5:\s+\$x\ =\ "FirstVal";\n
+        6\s*\n
+        7:\s+\$dummy\+\+;\n
+        8\s*\n
+        9:\s+\$x\ =\ "SecondVal";\n
+        10\s*\n
+        #msx,
+        'Test the source command (along with l)',
+    );
+
+    print $wrapper->get_output(), "\n";
+}
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
diff --git a/lib/perl5db/t/source-cmd-test.perldb b/lib/perl5db/t/source-cmd-test.perldb
new file mode 100644
index 0000000..41a7365
--- /dev/null
+++ b/lib/perl5db/t/source-cmd-test.perldb
@@ -0,0 +1,2 @@
+l 3-10
+q
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0023-perl5db-Fix-source-cmd-from-typeahead.patch
From 1a2f20dcf84a93c17f8c0b2c70b6ece5a0740fe1 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Thu, 13 Sep 2012 17:08:58 +0300
Subject: [PATCH 23/81] [perl5db] Fix source cmd from typeahead.

With a test.
---
 MANIFEST                                  |  1 +
 lib/perl5db.pl                            | 26 ++++++++++++++------------
 lib/perl5db.t                             | 29 +++++++++++++++++++++++++++--
 lib/perl5db/t/source-cmd-test-no-q.perldb |  1 +
 4 files changed, 43 insertions(+), 14 deletions(-)
 create mode 100644 lib/perl5db/t/source-cmd-test-no-q.perldb

diff --git a/MANIFEST b/MANIFEST
index a1df910..aac99ac 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4328,6 +4328,7 @@ lib/perl5db/t/proxy-constants	Tests for the Perl debugger
 lib/perl5db/t/rt-104168		Tests for the Perl debugger
 lib/perl5db/t/rt-61222		Tests for the Perl debugger
 lib/perl5db/t/rt-66110		Tests for the Perl debugger
+lib/perl5db/t/source-cmd-test-no-q.perldb		TTests for the Perl debugger
 lib/perl5db/t/source-cmd-test.perldb		TTests for the Perl debugger
 lib/perl5db/t/symbol-table-bug	Tests for the Perl debugger
 lib/perl5db/t/taint		Tests for the Perl debugger
diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 4f517d0..54cabdc 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -6517,6 +6517,20 @@ sub readline {
     # Localize to prevent it from being smashed in the program being debugged.
     local $.;
 
+    # If there are stacked filehandles to read from ...
+    # (Handle it before the typeahead, because we may call source/etc. from
+    # the typeahead.)
+    while (@cmdfhs) {
+
+        # Read from the last one in the stack.
+        my $line = CORE::readline( $cmdfhs[-1] );
+
+        # If we got a line ...
+        defined $line
+          ? ( print $OUT ">> $line" and return $line )    # Echo and return
+          : close pop @cmdfhs;                            # Pop and close
+    } ## end while (@cmdfhs)
+
     # Pull a line out of the typeahead if there's stuff there.
     if (@typeahead) {
 
@@ -6542,18 +6556,6 @@ sub readline {
     local $frame = 0;
     local $doret = -2;
 
-    # If there are stacked filehandles to read from ...
-    while (@cmdfhs) {
-
-        # Read from the last one in the stack.
-        my $line = CORE::readline( $cmdfhs[-1] );
-
-        # If we got a line ...
-        defined $line
-          ? ( print $OUT ">> $line" and return $line )    # Echo and return
-          : close pop @cmdfhs;                            # Pop and close
-    } ## end while (@cmdfhs)
-
     # Nothing on the filehandle stack. Socket?
     if ( ref $OUT and UNIVERSAL::isa( $OUT, 'IO::Socket::INET' ) ) {
 
diff --git a/lib/perl5db.t b/lib/perl5db.t
index a9d49d6..66cee89 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(80);
+plan(81);
 
 my $rc_filename = '.perldb';
 
@@ -1931,8 +1931,33 @@ sub _calc_trace_wrapper
         #msx,
         'Test the source command (along with l)',
     );
+}
+
+# Test the 'source' command being traversed from withing typeahead.
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'source ../lib/perl5db/t/source-cmd-test-no-q.perldb',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/disable-breakpoints-1',
+        }
+    );
 
-    print $wrapper->get_output(), "\n";
+    $wrapper->contents_like(qr#
+        ^3:\s+my\ \$dummy\ =\ 0;\n
+        4\s*\n
+        5:\s+\$x\ =\ "FirstVal";\n
+        6\s*\n
+        7:\s+\$dummy\+\+;\n
+        8\s*\n
+        9:\s+\$x\ =\ "SecondVal";\n
+        10\s*\n
+        #msx,
+        'Test the source command inside a typeahead',
+    );
 }
 
 END {
diff --git a/lib/perl5db/t/source-cmd-test-no-q.perldb b/lib/perl5db/t/source-cmd-test-no-q.perldb
new file mode 100644
index 0000000..6a6fddd
--- /dev/null
+++ b/lib/perl5db/t/source-cmd-test-no-q.perldb
@@ -0,0 +1 @@
+l 3-10
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0024-perl5db-Add-a-test-for-H-7.patch
From e11742906eb04012d8e5bbaed19be081b35f6a26 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sat, 15 Sep 2012 15:35:07 +0300
Subject: [PATCH 24/81] [perl5db] Add a test for H -7.

---
 lib/perl5db.t | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 66cee89..3c69fa8 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(81);
+plan(82);
 
 my $rc_filename = '.perldb';
 
@@ -1960,6 +1960,38 @@ sub _calc_trace_wrapper
     );
 }
 
+# Test the 'H -number' command.
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'l 1-10',
+                'l 5-10',
+                'x "Hello World"',
+                'l 1-5',
+                'b 3',
+                'x (20+4)',
+                'H -7',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/disable-breakpoints-1',
+        }
+    );
+
+    $wrapper->contents_like(qr#
+        ^\d+:\s+H\ -7\n
+        \d+:\s+x\ \(20\+4\)\n
+        \d+:\s+b\ 3\n
+        \d+:\s+l\ 1-5\n
+        \d+:\s+x\ "Hello\ World"\n
+        \d+:\s+l\ 5-10\n
+        \d+:\s+l\ 1-10\n
+        #msx,
+        'Test the source command (along with l)',
+    );
+}
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0025-Add-a-test-for-the-H-command.patch
From 05e3ae74ae6322667ffefc0b6fb31f2bd162e17b Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sat, 15 Sep 2012 15:40:21 +0300
Subject: [PATCH 25/81] Add a test for the H command.

---
 lib/perl5db.t | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 3c69fa8..12dd99e 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(82);
+plan(83);
 
 my $rc_filename = '.perldb';
 
@@ -1992,6 +1992,37 @@ sub _calc_trace_wrapper
     );
 }
 
+# Add a test for H (without arguments)
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'l 1-10',
+                'l 5-10',
+                'x "Hello World"',
+                'l 1-5',
+                'b 3',
+                'x (20+4)',
+                'H',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/disable-breakpoints-1',
+        }
+    );
+
+    $wrapper->contents_like(qr#
+        ^\d+:\s+x\ \(20\+4\)\n
+        \d+:\s+b\ 3\n
+        \d+:\s+l\ 1-5\n
+        \d+:\s+x\ "Hello\ World"\n
+        \d+:\s+l\ 5-10\n
+        \d+:\s+l\ 1-10\n
+        #msx,
+        'Test the source command (along with l)',
+    );
+}
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0026-Correct-the-test-blurbs.patch
From 388c43a75cbb7a332d3788011bd762f9bef01d43 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sat, 15 Sep 2012 16:29:55 +0300
Subject: [PATCH 26/81] Correct the test blurbs.

---
 lib/perl5db.t | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 12dd99e..c449146 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -1988,7 +1988,7 @@ sub _calc_trace_wrapper
         \d+:\s+l\ 5-10\n
         \d+:\s+l\ 1-10\n
         #msx,
-        'Test the source command (along with l)',
+        'Test the H -num command',
     );
 }
 
@@ -2019,7 +2019,7 @@ sub _calc_trace_wrapper
         \d+:\s+l\ 5-10\n
         \d+:\s+l\ 1-10\n
         #msx,
-        'Test the source command (along with l)',
+        'Test the H command (without a number.)',
     );
 }
 
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0027-perl5db-Test-the-command.patch
From 57e67b1900a665ea1c0a932c07d164c8bc2af6b0 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sat, 15 Sep 2012 16:46:35 +0300
Subject: [PATCH 27/81] [perl5db] Test the = command.

---
 lib/perl5db.t | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index c449146..2bb8ffd 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(83);
+plan(84);
 
 my $rc_filename = '.perldb';
 
@@ -2023,6 +2023,32 @@ sub _calc_trace_wrapper
     );
 }
 
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                '= quit q',
+                '= foobar l',
+                'foobar',
+                'quit',
+            ],
+            prog => '../lib/perl5db/t/test-l-statement-1',
+        }
+    );
+
+    $wrapper->contents_like(
+        qr/
+            ^1==>\s+\$x\ =\ 1;\n
+            2:\s+print\ "1\\n";\n
+            3\s*\n
+            4:\s+\$x\ =\ 2;\n
+            5:\s+print\ "2\\n";\n
+        /msx,
+        'Test the = (command alias) command.',
+    );
+}
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0028-Test-the-m-command.patch
From ea022ed86b15bc78891d14f1dfc92f15750a5fd1 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sat, 15 Sep 2012 16:54:24 +0300
Subject: [PATCH 28/81] Test the m command.

---
 lib/perl5db.t | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/lib/perl5db.t b/lib/perl5db.t
index 2bb8ffd..0e00d49 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(84);
+plan(86);
 
 my $rc_filename = '.perldb';
 
@@ -2049,6 +2049,32 @@ sub _calc_trace_wrapper
     );
 }
 
+# Add a test for H (without arguments)
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'm main',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/disable-breakpoints-1',
+        }
+    );
+
+    $wrapper->contents_like(qr#
+        ^via\ UNIVERSAL:\ DOES$
+        #msx,
+        "Test m for main - 1",
+    );
+
+    $wrapper->contents_like(qr#
+        ^via\ UNIVERSAL:\ can$
+        #msx,
+        "Test m for main - 2",
+    );
+}
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0029-Test-more-for-the-m-staetement.patch
From df93ba75f4523371037540311f8c58482c410152 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sat, 15 Sep 2012 17:10:13 +0300
Subject: [PATCH 29/81] Test more for the m staetement.

---
 MANIFEST                         |  1 +
 lib/perl5db.t                    | 28 ++++++++++++++++++++++++--
 lib/perl5db/t/test-m-statement-1 | 43 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 2 deletions(-)
 create mode 100644 lib/perl5db/t/test-m-statement-1

diff --git a/MANIFEST b/MANIFEST
index aac99ac..aa9d568 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4334,6 +4334,7 @@ lib/perl5db/t/symbol-table-bug	Tests for the Perl debugger
 lib/perl5db/t/taint		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-r-statement	Tests for the Perl debugger
 lib/perl5db/t/test-w-statement-1	Tests for the Perl debugger
 lib/perl5db/t/uncalled-subroutine	Tests for the Perl debugger
diff --git a/lib/perl5db.t b/lib/perl5db.t
index 0e00d49..086c466 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -28,7 +28,7 @@ BEGIN {
     }
 }
 
-plan(86);
+plan(88);
 
 my $rc_filename = '.perldb';
 
@@ -2049,7 +2049,7 @@ sub _calc_trace_wrapper
     );
 }
 
-# Add a test for H (without arguments)
+# Test the m statement.
 {
     my $wrapper = DebugWrap->new(
         {
@@ -2075,6 +2075,30 @@ sub _calc_trace_wrapper
     );
 }
 
+# Test the m statement.
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                'b 41',
+                'c',
+                'm $obj',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/test-m-statement-1',
+        }
+    );
+
+    $wrapper->contents_like(qr#^greet$#ms,
+        "Test m for obj - 1",
+    );
+
+    $wrapper->contents_like(qr#^via UNIVERSAL: can$#ms,
+        "Test m for obj - 1",
+    );
+}
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
diff --git a/lib/perl5db/t/test-m-statement-1 b/lib/perl5db/t/test-m-statement-1
new file mode 100644
index 0000000..a699ed3
--- /dev/null
+++ b/lib/perl5db/t/test-m-statement-1
@@ -0,0 +1,43 @@
+use strict;
+use warnings;
+
+package MyClass;
+
+sub new
+{
+    my $class = shift;
+
+    my $self = bless {}, $class;
+
+    $self->_init(@_);
+
+    return $self;
+}
+
+sub _init
+{
+    my $self = shift;
+
+    $self->{foo} = 'bar';
+
+    return;
+}
+
+sub greet
+{
+    my ($self, $msg) = @_;
+
+    print "$msg - $self->{foo}\n";
+
+    return;
+}
+
+1;
+
+package main;
+
+my $obj = MyClass->new;
+
+$obj->greet("Hello");
+
+1;
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0060-perl5db-refactoring-minor-bug-fix.patch
From 0632858e8af47abf508be25e6b014300521ca0ff Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 00:18:40 +0200
Subject: [PATCH 60/81] [perl5db] refactoring + minor bug-fix.

The regex h\s* matches for every string that starts with "h". It should
match only if h is the only thing so a \z is needed.
---
 lib/perl5db.pl | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index bfc37ae..d4a0669 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -4839,18 +4839,15 @@ sub cmd_h {
     my $line = shift || '';
 
     # 'h h'. Print the long-format help.
-    if ( $line =~ /^h\s*/ ) {
+    if ( $line =~ /\Ah\s*\z/ ) {
         print_help($help);
     }
 
     # 'h <something>'. Search for the command and print only its help.
-    elsif ( $line =~ /^(\S.*)$/ ) {
+    elsif ( my ($asked) = $line =~ /\A(\S.*)\z/ ) {
 
         # support long commands; otherwise bogus errors
         # happen when you ask for h on <CR> for example
-        my $asked = $1;    # the command requested
-                           # (for proper error message)
-
         my $qasked = quotemeta($asked);    # for searching; we don't
                                            # want to use it as a pattern.
                                            # XXX: finds CR but not <CR>
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0061-perl5db-refactor-Remove-leading-ampersands.patch
From b51878b90e264927bd7aa0eb8ae6b017e389453f Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 00:26:38 +0200
Subject: [PATCH 61/81] [perl5db-refactor] Remove leading ampersands.

From subroutine calls.
---
 lib/perl5db.pl | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index d4a0669..eb06086 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -4958,7 +4958,7 @@ sub cmd_l {
         $line = "$1 $s";
 
         # Call self recursively to really do the command.
-        &cmd_l( 'l', $s );
+        cmd_l( 'l', $s );
     } ## end if ($line =~ /^(\$.*)/s)
 
     # l name. Try to find a sub by that name.
@@ -5012,7 +5012,7 @@ sub cmd_l {
 
             # Call self recursively to list the range.
             $line = $subrange;
-            &cmd_l( 'l', $subrange );
+            cmd_l( 'l', $subrange );
         } ## end if ($subrange)
 
         # Couldn't find it.
@@ -5029,7 +5029,7 @@ sub cmd_l {
         $line = $start . '-' . ( $start + $incr );
 
         # Recurse to do it.
-        &cmd_l( 'l', $line );
+        cmd_l( 'l', $line );
     }
 
     # l [start]+number_of_lines
@@ -5045,7 +5045,7 @@ sub cmd_l {
 
         # Create a line range we'll understand, and recurse to do it.
         $line = $start . '-' . ( $start + $incr );
-        &cmd_l( 'l', $line );
+        cmd_l( 'l', $line );
     } ## end elsif ($line =~ /^(\d*)\+(\d*)$/)
 
     # l start-stop or l start,stop
@@ -5324,7 +5324,7 @@ sub cmd_v {
         $line = $start . '-' . ( $start + $incr );
 
         # List the lines.
-        &cmd_l( 'l', $line );
+        cmd_l( 'l', $line );
     } ## end if ($line =~ /^(\d*)$/)
 } ## end sub cmd_v
 
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0062-perl5db-Refactored-more.patch
From 903610a18368f70d271d8fad8d3d780f1dbeb257 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 00:46:07 +0200
Subject: [PATCH 62/81] [perl5db] Refactored more.

---
 lib/perl5db.pl | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index eb06086..9877110 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -4950,11 +4950,14 @@ sub cmd_l {
         my ($s) = &eval;
 
         # Ooops. Bad scalar.
-        print( $OUT "Error: $@\n" ), next CMD if $@;
+        if ($@) {
+            print {$OUT} "Error: $@\n";
+            next CMD;
+        }
 
         # Good scalar. If it's a reference, find what it points to.
         $s = CvGV_name($s);
-        print( $OUT "Interpreted as: $1 $s\n" );
+        print {$OUT} "Interpreted as: $1 $s\n";
         $line = "$1 $s";
 
         # Call self recursively to really do the command.
@@ -4962,8 +4965,8 @@ sub cmd_l {
     } ## end if ($line =~ /^(\$.*)/s)
 
     # l name. Try to find a sub by that name.
-    elsif ( $line =~ /^([\':A-Za-z_][\':\w]*(\[.*\])?)/s ) {
-        my $s = $subname = $1;
+    elsif ( ($subname) = $line =~ /\A([\':A-Za-z_][\':\w]*(?:\[.*\])?)/s ) {
+        my $s = $subname;
 
         # De-Perl4.
         $subname =~ s/\'/::/;
@@ -5022,7 +5025,7 @@ sub cmd_l {
     } ## end elsif ($line =~ /^([\':A-Za-z_][\':\w]*(\[.*\])?)/s)
 
     # Bare 'l' command.
-    elsif ( $line =~ /^\s*$/ ) {
+    elsif ( $line !~ /\S/ ) {
 
         # Compute new range to list.
         $incr = $window - 1;
@@ -5033,14 +5036,14 @@ sub cmd_l {
     }
 
     # l [start]+number_of_lines
-    elsif ( $line =~ /^(\d*)\+(\d*)$/ ) {
+    elsif ( my ($new_start, $new_incr) = $line =~ /\A(\d*)\+(\d*)\z/ ) {
 
         # Don't reset start for 'l +nnn'.
-        $start = $1 if $1;
+        $start = $new_start if $new_start;
 
         # Increment for list. Use window size if not specified.
         # (Allows 'l +' to work.)
-        $incr = $2;
+        $incr = $new_incr;
         $incr = $window - 1 unless $incr;
 
         # Create a line range we'll understand, and recurse to do it.
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0063-perl5db-Avoid-predeclaration.patch
From 51d37dada8331e143e468a3fdc3b46655bddfdf3 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 00:54:56 +0200
Subject: [PATCH 63/81] [perl5db] Avoid predeclaration.

---
 lib/perl5db.pl | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 9877110..e078d25 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -5209,12 +5209,10 @@ sub cmd_L {
     # If there are any, list them.
     if ( @have and ( $break_wanted or $action_wanted ) ) {
         print $OUT "Postponed breakpoints in files:\n";
-        my ( $file, $line );
-
-        for $file ( keys %postponed_file ) {
+        for my $file ( keys %postponed_file ) {
             my $db = $postponed_file{$file};
             print $OUT " $file:\n";
-            for $line ( sort { $a <=> $b } keys %$db ) {
+            for my $line ( sort { $a <=> $b } keys %$db ) {
                 print $OUT "  $line:\n";
                 my ( $stop, $action ) = split( /\0/, $$db{$line} );
                 print $OUT "    break if (", $stop, ")\n"
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0064-Refactored-a-loop.patch
From 5d2ea92bea2cedd28eef5b229cae2536364256cb Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 01:09:02 +0200
Subject: [PATCH 64/81] Refactored a loop.

---
 lib/perl5db.pl | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index e078d25..8587dd2 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -5227,11 +5227,10 @@ sub cmd_L {
         } ## end for $file (keys %postponed_file)
     } ## end if (@have and ($break_wanted...
     if ( %break_on_load and $break_wanted ) {
-        print $OUT "Breakpoints on load:\n";
-        my $file;
-        for $file ( keys %break_on_load ) {
-            print $OUT " $file\n";
-            last if $signal;
+        print {$OUT} "Breakpoints on load:\n";
+        BREAK_ON_LOAD: for my $filename ( keys %break_on_load ) {
+            print {$OUT} " $filename\n";
+            last BREAK_ON_LOAD if $signal;
         }
     } ## end if (%break_on_load and...
     if ($watch_wanted) {
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0065-Add-more.patch
From b76604643822c3fa647b31586e209dbbd602659e Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 01:14:56 +0200
Subject: [PATCH 65/81] Add more.

---
 lib/perl5db.pl | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 8587dd2..7983bdf 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -5235,10 +5235,10 @@ sub cmd_L {
     } ## end if (%break_on_load and...
     if ($watch_wanted) {
         if ( $trace & 2 ) {
-            print $OUT "Watch-expressions:\n" if @to_watch;
-            for my $expr (@to_watch) {
-                print $OUT " $expr\n";
-                last if $signal;
+            print {$OUT} "Watch-expressions:\n" if @to_watch;
+            TO_WATCH: for my $expr (@to_watch) {
+                print {$OUT} " $expr\n";
+                last TO_WATCH if $signal;
             }
         } ## end if ($trace & 2)
     } ## end if ($watch_wanted)
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0066-perl5db-refactor-Merge-two-conditionals.patch
From 96d0700c323547432f2faa1aa2f1792c3137290e Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 01:24:07 +0200
Subject: [PATCH 66/81] [perl5db-refactor] Merge two conditionals.

---
 lib/perl5db.pl | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 7983bdf..a0976e1 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -5233,15 +5233,13 @@ sub cmd_L {
             last BREAK_ON_LOAD if $signal;
         }
     } ## end if (%break_on_load and...
-    if ($watch_wanted) {
-        if ( $trace & 2 ) {
-            print {$OUT} "Watch-expressions:\n" if @to_watch;
-            TO_WATCH: for my $expr (@to_watch) {
-                print {$OUT} " $expr\n";
-                last TO_WATCH if $signal;
-            }
-        } ## end if ($trace & 2)
-    } ## end if ($watch_wanted)
+    if ($watch_wanted and ( $trace & 2 )) {
+        print {$OUT} "Watch-expressions:\n" if @to_watch;
+        TO_WATCH: for my $expr (@to_watch) {
+            print {$OUT} " $expr\n";
+            last TO_WATCH if $signal;
+        }
+    }
 } ## end sub cmd_L
 
 =head3 C<cmd_M> - list modules (command)
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0067-perl5db-Remove-ampersand.patch
From b45d4204e8b10b046b7e05d9c6d4b35c4013ecd7 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 01:31:27 +0200
Subject: [PATCH 67/81] [perl5db] Remove ampersand.

---
 lib/perl5db.pl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index a0976e1..7632af7 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -5249,7 +5249,9 @@ Just call C<list_modules>.
 =cut
 
 sub cmd_M {
-    &list_modules();
+    list_modules();
+
+    return;
 }
 
 =head3 C<cmd_o> - options (command)
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0068-More-refactoring.patch
From 6b9d4d66c62c0f2862e528e7194e1796ab3389e6 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 02:30:27 +0200
Subject: [PATCH 68/81] More refactoring.

---
 lib/perl5db.pl | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 7632af7..4df4de8 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -4632,7 +4632,7 @@ sub cmd_B {
 
     # No line spec? Use dbline.
     # If there is one, use it if it's non-zero, or wipe it out if it is.
-    my $line   = ( $_[0] =~ /^\./ ) ? $dbline : shift || '';
+    my $line   = ( $_[0] =~ /\A\./ ) ? $dbline : (shift || '');
     my $dbline = shift;
 
     # If the line was dot, make the line the current one.
@@ -4640,23 +4640,27 @@ sub cmd_B {
 
     # If it's * we're deleting all the breakpoints.
     if ( $line eq '*' ) {
-        eval { &delete_breakpoint(); 1 } or print $OUT $@ and return;
+        if (not eval { &delete_breakpoint(); 1 }) {
+            print {$OUT} $@;
+        }
     }
 
     # If there is a line spec, delete the breakpoint on that line.
-    elsif ( $line =~ /^(\S.*)/ ) {
+    elsif ( $line =~ /\A(\S.*)/ ) {
         if (not eval { &delete_breakpoint( $line || $dbline ); 1 }) {
             local $\ = '';
-            print $OUT $@ and return;
+            print {$OUT} $@;
         }
     } ## end elsif ($line =~ /^(\S.*)/)
 
     # No line spec.
     else {
-        print $OUT
+        print {$OUT}
           "Deleting a breakpoint requires a line number, or '*' for all\n"
           ;    # hint
     }
+
+    return;
 } ## end sub cmd_B
 
 =head3 delete_breakpoint([line]) (API)
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0069-perl5db-Remove-leading-ampersands-in-sub-calls.patch
From 9b637c9d0872408cebd434ebac31d4b331d22a36 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 02:36:09 +0200
Subject: [PATCH 69/81] [perl5db] Remove leading ampersands in sub calls.

---
 lib/perl5db.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 4df4de8..15ee326 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -4640,14 +4640,14 @@ sub cmd_B {
 
     # If it's * we're deleting all the breakpoints.
     if ( $line eq '*' ) {
-        if (not eval { &delete_breakpoint(); 1 }) {
+        if (not eval { delete_breakpoint(); 1 }) {
             print {$OUT} $@;
         }
     }
 
     # If there is a line spec, delete the breakpoint on that line.
     elsif ( $line =~ /\A(\S.*)/ ) {
-        if (not eval { &delete_breakpoint( $line || $dbline ); 1 }) {
+        if (not eval { delete_breakpoint( $line || $dbline ); 1 }) {
             local $\ = '';
             print {$OUT} $@;
         }
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0070-perl5db-refactor-Extract-_delete_all_breakpoints.patch
From b40cf3aa98f5fcf53e68c1285f044d599e30d4ca Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 02:51:07 +0200
Subject: [PATCH 70/81] [perl5db-refactor] Extract _delete_all_breakpoints.

---
 lib/perl5db.pl | 94 +++++++++++++++++++++++++++++++---------------------------
 1 file changed, 51 insertions(+), 43 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 15ee326..ca58b71 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -4688,6 +4688,53 @@ are no magical debugger structures associated with them.
 
 =cut
 
+sub _delete_all_breakpoints {
+    print {$OUT} "Deleting all breakpoints...\n";
+
+    # %had_breakpoints lists every file that had at least one
+    # breakpoint in it.
+    for my $fn ( keys %had_breakpoints ) {
+
+        # Switch to the desired file temporarily.
+        local *dbline = $main::{ '_<' . $fn };
+
+        $max = $#dbline;
+        my $was;
+
+        # For all lines in this file ...
+        for my $i (1 .. $max) {
+
+            # If there's a breakpoint or action on this line ...
+            if ( defined $dbline{$i} ) {
+
+                # ... remove the breakpoint.
+                $dbline{$i} =~ s/\A[^\0]+//;
+                if ( $dbline{$i} =~ s/\A\0?\z// ) {
+
+                    # Remove the entry altogether if no action is there.
+                    delete $dbline{$i};
+                    _delete_breakpoint_data_ref($fn, $i);
+                }
+            } ## end if (defined $dbline{$i...
+        } ## end for $i (1 .. $max)
+
+        # If, after we turn off the "there were breakpoints in this file"
+        # bit, the entry in %had_breakpoints for this file is zero,
+        # we should remove this file from the hash.
+        if ( not $had_breakpoints{$fn} &= (~1) ) {
+            delete $had_breakpoints{$fn};
+        }
+    } ## end for my $fn (keys %had_breakpoints)
+
+    # Kill off all the other breakpoints that are waiting for files that
+    # haven't been loaded yet.
+    undef %postponed;
+    undef %postponed_file;
+    undef %break_on_load;
+
+    return;
+}
+
 sub delete_breakpoint {
     my $i = shift;
 
@@ -4700,7 +4747,7 @@ sub delete_breakpoint {
         die "Line $i not breakable.\n" if $dbline[$i] == 0;
 
         # Kill the condition, but leave any action.
-        $dbline{$i} =~ s/^[^\0]*//;
+        $dbline{$i} =~ s/\A[^\0]*//;
 
         # Remove the entry entirely if there's no action left.
         if ($dbline{$i} eq '') {
@@ -4711,49 +4758,10 @@ sub delete_breakpoint {
 
     # No line; delete them all.
     else {
-        print $OUT "Deleting all breakpoints...\n";
-
-        # %had_breakpoints lists every file that had at least one
-        # breakpoint in it.
-        for my $file ( keys %had_breakpoints ) {
-
-            # Switch to the desired file temporarily.
-            local *dbline = $main::{ '_<' . $file };
-
-            $max = $#dbline;
-            my $was;
-
-            # For all lines in this file ...
-            for $i (1 .. $max) {
-
-                # If there's a breakpoint or action on this line ...
-                if ( defined $dbline{$i} ) {
-
-                    # ... remove the breakpoint.
-                    $dbline{$i} =~ s/^[^\0]+//;
-                    if ( $dbline{$i} =~ s/^\0?$// ) {
-
-                        # Remove the entry altogether if no action is there.
-                        delete $dbline{$i};
-                        _delete_breakpoint_data_ref($file, $i);
-                    }
-                } ## end if (defined $dbline{$i...
-            } ## end for $i (1 .. $max)
-
-            # If, after we turn off the "there were breakpoints in this file"
-            # bit, the entry in %had_breakpoints for this file is zero,
-            # we should remove this file from the hash.
-            if ( not $had_breakpoints{$file} &= ~1 ) {
-                delete $had_breakpoints{$file};
-            }
-        } ## end for my $file (keys %had_breakpoints)
-
-        # Kill off all the other breakpoints that are waiting for files that
-        # haven't been loaded yet.
-        undef %postponed;
-        undef %postponed_file;
-        undef %break_on_load;
+        _delete_all_breakpoints();
     } ## end else [ if (defined($i))
+
+    return;
 } ## end sub delete_breakpoint
 
 =head3 cmd_stop (command)
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0071-perl5db-refactor-Extract-a-method.patch
From bf0bc3670d88020b0e1fcfd023fddc05d73b8f94 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 12:37:31 +0200
Subject: [PATCH 71/81] [perl5db-refactor] Extract a method.

---
 lib/perl5db.pl | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index ca58b71..4ee0043 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -4688,6 +4688,15 @@ are no magical debugger structures associated with them.
 
 =cut
 
+sub _remove_breakpoint_entry {
+    my ($fn, $i) = @_;
+
+    delete $dbline{$i};
+    _delete_breakpoint_data_ref($fn, $i);
+
+    return;
+}
+
 sub _delete_all_breakpoints {
     print {$OUT} "Deleting all breakpoints...\n";
 
@@ -4710,10 +4719,8 @@ sub _delete_all_breakpoints {
                 # ... remove the breakpoint.
                 $dbline{$i} =~ s/\A[^\0]+//;
                 if ( $dbline{$i} =~ s/\A\0?\z// ) {
-
                     # Remove the entry altogether if no action is there.
-                    delete $dbline{$i};
-                    _delete_breakpoint_data_ref($fn, $i);
+                    _remove_breakpoint_entry($fn, $i);
                 }
             } ## end if (defined $dbline{$i...
         } ## end for $i (1 .. $max)
@@ -4751,8 +4758,7 @@ sub delete_breakpoint {
 
         # Remove the entry entirely if there's no action left.
         if ($dbline{$i} eq '') {
-            delete $dbline{$i};
-            _delete_breakpoint_data_ref($fn, $i);
+            _remove_breakpoint_entry($fn, $i);
         }
     }
 
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0072-perl5db-Remove-a-stray-declaration.patch
From 988ff41628fc9ff97b40408009889a9d1c6af89d Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 13:42:13 +0200
Subject: [PATCH 72/81] [perl5db] Remove a stray declaration.

---
 lib/perl5db.pl | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 4ee0043..11515fd 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -4708,7 +4708,6 @@ sub _delete_all_breakpoints {
         local *dbline = $main::{ '_<' . $fn };
 
         $max = $#dbline;
-        my $was;
 
         # For all lines in this file ...
         for my $i (1 .. $max) {
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0073-perl5db-Extract-a-function.patch
From 1f068478640a7316a6a42c44ab1b67e6b6b7fd33 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 14:17:09 +0200
Subject: [PATCH 73/81] [perl5db] Extract a function.

---
 lib/perl5db.pl | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 11515fd..6044fb5 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -4741,33 +4741,37 @@ sub _delete_all_breakpoints {
     return;
 }
 
-sub delete_breakpoint {
-    my $i = shift;
+sub _delete_breakpoint_from_line {
+    my ($i) = @_;
 
-    my $fn = $filename;
+    # Woops. This line wasn't breakable at all.
+    die "Line $i not breakable.\n" if $dbline[$i] == 0;
 
-    # If we got a line, delete just that one.
-    if ( defined($i) ) {
+    # Kill the condition, but leave any action.
+    $dbline{$i} =~ s/\A[^\0]*//;
 
-        # Woops. This line wasn't breakable at all.
-        die "Line $i not breakable.\n" if $dbline[$i] == 0;
+    # Remove the entry entirely if there's no action left.
+    if ($dbline{$i} eq '') {
+        _remove_breakpoint_entry($filename, $i);
+    }
 
-        # Kill the condition, but leave any action.
-        $dbline{$i} =~ s/\A[^\0]*//;
+    return;
+}
 
-        # Remove the entry entirely if there's no action left.
-        if ($dbline{$i} eq '') {
-            _remove_breakpoint_entry($fn, $i);
-        }
-    }
+sub delete_breakpoint {
+    my $i = shift;
 
+    # If we got a line, delete just that one.
+    if ( defined($i) ) {
+        _delete_breakpoint_from_line($i);
+    }
     # No line; delete them all.
     else {
         _delete_all_breakpoints();
-    } ## end else [ if (defined($i))
+    }
 
     return;
-} ## end sub delete_breakpoint
+}
 
 =head3 cmd_stop (command)
 
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0074-perl5db-refactor-convert-to-use-vars-and-s.patch
From 19a80340e3ce57d7ce9720b392bd19d69425d620 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 15:14:09 +0200
Subject: [PATCH 74/81] [perl5db-refactor] convert to use vars and &s.

---
 lib/perl5db.pl | 43 +++++++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 6044fb5..9be4b6a 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -868,27 +868,26 @@ BEGIN {
   }
 }
 
-# This would probably be better done with "use vars", but that wasn't around
-# when this code was originally written. (Neither was "use strict".) And on
-# the principle of not fiddling with something that was working, this was
-# left alone.
-warn(               # Do not ;-)
-    # These variables control the execution of 'dumpvar.pl'.
-    $dumpvar::hashDepth,
-    $dumpvar::arrayDepth,
-    $dumpvar::dumpDBFiles,
-    $dumpvar::dumpPackages,
-    $dumpvar::quoteHighBit,
-    $dumpvar::printUndef,
-    $dumpvar::globPrint,
-    $dumpvar::usageOnly,
-
-    # used to control die() reporting in diesignal()
-    $Carp::CarpLevel,
-
+# These variables control the execution of 'dumpvar.pl'.
+{
+    package dumpvar;
+    use vars qw(
+    $hashDepth
+    $arrayDepth
+    $dumpDBFiles
+    $dumpPackages
+    $quoteHighBit
+    $printUndef
+    $globPrint
+    $usageOnly
+    );
+}
 
-  )
-  if 0;
+# used to control die() reporting in diesignal()
+{
+    package Carp;
+    use vars qw($CarpLevel);
+}
 
 # without threads, $filename is not defined until DB::DB is called
 foreach my $k (keys (%INC)) {
@@ -1133,8 +1132,8 @@ setman();
 
 # Set up defaults for command recall and shell escape (note:
 # these currently don't work in linemode debugging).
-&recallCommand("!") unless defined $prc;
-&shellBang("!")     unless defined $psh;
+recallCommand("!") unless defined $prc;
+shellBang("!")     unless defined $psh;
 
 =pod
 
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0075-perl5db-refactor-Refactoring.patch
From d75f4e5a3d7c3517d6c8fcaaa2232a592d3c2490 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 15:28:23 +0200
Subject: [PATCH 75/81] [perl5db-refactor] Refactoring.

---
 lib/perl5db.pl | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 9be4b6a..baee447 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -891,7 +891,7 @@ BEGIN {
 
 # without threads, $filename is not defined until DB::DB is called
 foreach my $k (keys (%INC)) {
-	&share(\$main::{'_<'.$filename}) if defined $filename;
+	share(\$main::{'_<'.$filename}) if defined $filename;
 };
 
 # Command-line + PERLLIB:
@@ -1224,14 +1224,11 @@ running interactively, this is C<.perldb>; if not, it's C<perldb.ini>.
 # As noted, this test really doesn't check accurately that the debugger
 # is running at a terminal or not.
 
-my $dev_tty = '/dev/tty';
-   $dev_tty = 'TT:' if ($^O eq 'VMS');
 use vars qw($rcfile);
-if ( -e $dev_tty ) {                      # this is the wrong metric!
-    $rcfile = ".perldb";
-}
-else {
-    $rcfile = "perldb.ini";
+{
+    my $dev_tty = (($^O eq 'VMS') ? 'TT:' : '/dev/tty');
+    # this is the wrong metric!
+    $rcfile = ((-e $dev_tty) ? ".perldb" : "perldb.ini");
 }
 
 =pod
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0076-perl5db-Extract-a-subroutine.patch
From b1b8db656e5875c0363b5ef0d64dc66a67f97929 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 15:49:18 +0200
Subject: [PATCH 76/81] [perl5db] Extract a subroutine.

---
 lib/perl5db.pl | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index baee447..0ff2770 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -1379,23 +1379,10 @@ back into the appropriate spots in the debugger.
 
 use vars qw(@hist @truehist %postponed_file @typeahead);
 
-if ( exists $ENV{PERLDB_RESTART} ) {
-
-    # We're restarting, so we don't need the flag that says to restart anymore.
-    delete $ENV{PERLDB_RESTART};
+sub _restore_breakpoints_and_actions {
 
-    # $restart = 1;
-    @hist          = get_list('PERLDB_HIST');
-    %break_on_load = get_list("PERLDB_ON_LOAD");
-    %postponed     = get_list("PERLDB_POSTPONE");
-
-	share(@hist);
-	share(@truehist);
-	share(%break_on_load);
-	share(%postponed);
-
-    # restore breakpoints/actions
     my @had_breakpoints = get_list("PERLDB_VISITED");
+
     for my $file_idx ( 0 .. $#had_breakpoints ) {
         my $filename = $had_breakpoints[$file_idx];
         my %pf = get_list("PERLDB_FILE_$file_idx");
@@ -1411,6 +1398,26 @@ if ( exists $ENV{PERLDB_RESTART} ) {
         }
     }
 
+    return;
+}
+
+if ( exists $ENV{PERLDB_RESTART} ) {
+
+    # We're restarting, so we don't need the flag that says to restart anymore.
+    delete $ENV{PERLDB_RESTART};
+
+    # $restart = 1;
+    @hist          = get_list('PERLDB_HIST');
+    %break_on_load = get_list("PERLDB_ON_LOAD");
+    %postponed     = get_list("PERLDB_POSTPONE");
+
+    share(@hist);
+    share(@truehist);
+    share(%break_on_load);
+    share(%postponed);
+
+    _restore_breakpoints_and_actions();
+
     # restore options
     my %opt = get_list("PERLDB_OPT");
     my ( $opt, $val );
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0077-perl5db-refactor-Extract-a-function.patch
From fa5790e95dbf8bcffe0f75687f18b3a5fdfd5fa6 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 15:56:49 +0200
Subject: [PATCH 77/81] [perl5db-refactor] Extract a function.

_restore_options_after_restart() .
---
 lib/perl5db.pl | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 0ff2770..a7db086 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -1401,6 +1401,18 @@ sub _restore_breakpoints_and_actions {
     return;
 }
 
+sub _restore_options_after_restart
+{
+    my %options_map = get_list("PERLDB_OPT");
+
+    while ( my ( $opt, $val ) = each %options_map ) {
+        $val =~ s/[\\\']/\\$1/g;
+        parse_options("$opt'$val'");
+    }
+
+    return;
+}
+
 if ( exists $ENV{PERLDB_RESTART} ) {
 
     # We're restarting, so we don't need the flag that says to restart anymore.
@@ -1419,12 +1431,7 @@ if ( exists $ENV{PERLDB_RESTART} ) {
     _restore_breakpoints_and_actions();
 
     # restore options
-    my %opt = get_list("PERLDB_OPT");
-    my ( $opt, $val );
-    while ( ( $opt, $val ) = each %opt ) {
-        $val =~ s/[\\\']/\\$1/g;
-        parse_options("$opt'$val'");
-    }
+    _restore_options_after_restart();
 
     # restore original @INC
     @INC     = get_list("PERLDB_INC");
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0078-Extract-_restore_globals_after_restart.patch
From 70f7edb0be7657c3fc192a8e9e7a5905d57f092c Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 16:14:15 +0200
Subject: [PATCH 78/81] Extract _restore_globals_after_restart.

---
 lib/perl5db.pl | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index a7db086..6782246 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -1413,6 +1413,21 @@ sub _restore_options_after_restart
     return;
 }
 
+sub _restore_globals_after_restart
+{
+    # restore original @INC
+    @INC     = get_list("PERLDB_INC");
+    @ini_INC = @INC;
+
+    # return pre/postprompt actions and typeahead buffer
+    $pretype   = [ get_list("PERLDB_PRETYPE") ];
+    $pre       = [ get_list("PERLDB_PRE") ];
+    $post      = [ get_list("PERLDB_POST") ];
+    @typeahead = get_list( "PERLDB_TYPEAHEAD", @typeahead );
+
+    return;
+}
+
 if ( exists $ENV{PERLDB_RESTART} ) {
 
     # We're restarting, so we don't need the flag that says to restart anymore.
@@ -1433,15 +1448,7 @@ if ( exists $ENV{PERLDB_RESTART} ) {
     # restore options
     _restore_options_after_restart();
 
-    # restore original @INC
-    @INC     = get_list("PERLDB_INC");
-    @ini_INC = @INC;
-
-    # return pre/postprompt actions and typeahead buffer
-    $pretype   = [ get_list("PERLDB_PRETYPE") ];
-    $pre       = [ get_list("PERLDB_PRE") ];
-    $post      = [ get_list("PERLDB_POST") ];
-    @typeahead = get_list( "PERLDB_TYPEAHEAD", @typeahead );
+    _restore_globals_after_restart();
 } ## end if (exists $ENV{PERLDB_RESTART...
 
 =head2 SETTING UP THE TERMINAL
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0079-Extract-_restore_shared_globals_after_restart.patch
From f745e891410389a3d40ca0b638f47e42f5fe8f31 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 16:27:39 +0200
Subject: [PATCH 79/81] Extract _restore_shared_globals_after_restart.

---
 lib/perl5db.pl | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 6782246..8b82c8d 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -1379,6 +1379,18 @@ back into the appropriate spots in the debugger.
 
 use vars qw(@hist @truehist %postponed_file @typeahead);
 
+sub _restore_shared_globals_after_restart
+{
+    @hist          = get_list('PERLDB_HIST');
+    %break_on_load = get_list("PERLDB_ON_LOAD");
+    %postponed     = get_list("PERLDB_POSTPONE");
+
+    share(@hist);
+    share(@truehist);
+    share(%break_on_load);
+    share(%postponed);
+}
+
 sub _restore_breakpoints_and_actions {
 
     my @had_breakpoints = get_list("PERLDB_VISITED");
@@ -1428,20 +1440,14 @@ sub _restore_globals_after_restart
     return;
 }
 
+
 if ( exists $ENV{PERLDB_RESTART} ) {
 
     # We're restarting, so we don't need the flag that says to restart anymore.
     delete $ENV{PERLDB_RESTART};
 
     # $restart = 1;
-    @hist          = get_list('PERLDB_HIST');
-    %break_on_load = get_list("PERLDB_ON_LOAD");
-    %postponed     = get_list("PERLDB_POSTPONE");
-
-    share(@hist);
-    share(@truehist);
-    share(%break_on_load);
-    share(%postponed);
+    _restore_shared_globals_after_restart();
 
     _restore_breakpoints_and_actions();
 
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0080-perl5db-More-refactoring.patch
From bec5acfa01e7ee8da6401b21392a76e1500eda3a Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 17:15:18 +0200
Subject: [PATCH 80/81] [perl5db] More refactoring.

---
 lib/perl5db.pl | 47 +++++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 8b82c8d..c6b9446 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -1486,9 +1486,10 @@ else {
 
     # Is Perl being run from a slave editor or graphical debugger?
     # If so, don't use readline, and set $slave_editor = 1.
-    $slave_editor =
-      ( ( defined $main::ARGV[0] ) and ( $main::ARGV[0] eq '-emacs' ) );
-    $rl = 0, shift(@main::ARGV) if $slave_editor;
+    if ($slave_editor = ( @main::ARGV && ( $main::ARGV[0] eq '-emacs' ) )) {
+        $rl = 0;
+        shift(@main::ARGV);
+    }
 
     #require Term::ReadLine;
 
@@ -1648,7 +1649,10 @@ and if we can.
 
         # Keep copies of the filehandles so that when the pager runs, it
         # can close standard input without clobbering ours.
-        $IN = \*IN, $OUT = \*OUT if $console or not defined $console;
+        if ($console or (not defined($console))) {
+            $IN = \*IN;
+            $OUT = \*OUT;
+        }
     } ## end elsif (from if(defined $remoteport))
 
     # Unbuffer DB::OUT. We need to see responses right away.
@@ -1703,7 +1707,7 @@ and then call the C<afterinit()> subroutine if there is one.
 # If there was an afterinit() sub defined, call it. It will get
 # executed in our scope, so it can fiddle with debugger globals.
 if ( defined &afterinit ) {    # May be defined in $rcfile
-    &afterinit();
+    afterinit();
 }
 
 # Inform us about "Stack dump during die enabled ..." in dieLevel().
@@ -1755,19 +1759,8 @@ use vars qw(
     $end
 );
 
-sub DB {
-
-    # lock the debugger and get the thread id for the prompt
-	lock($DBGR);
-	my $tid;
-	my $position;
-	my ($prefix, $after, $infix);
-	my $pat;
-
-	if ($ENV{PERL5DB_THREADED}) {
-		$tid = eval { "[".threads->tid."]" };
-	}
-
+sub _DB_on_init__initialize_globals
+{
     # Check for whether we should be running continuously or not.
     # _After_ the perl program is compiled, $single is set to 1:
     if ( $single and not $second_time++ ) {
@@ -1801,6 +1794,24 @@ sub DB {
     # has occurred, turn off non-stop mode.
     $runnonstop = 0 if $single or $signal;
 
+    return;
+}
+
+sub DB {
+
+    # lock the debugger and get the thread id for the prompt
+    lock($DBGR);
+    my $tid;
+    my $position;
+    my ($prefix, $after, $infix);
+    my $pat;
+
+    if ($ENV{PERL5DB_THREADED}) {
+        $tid = eval { "[".threads->tid."]" };
+    }
+
+    _DB_on_init__initialize_globals();
+
     # Preserve current values of $@, $!, $^E, $,, $/, $\, $^W.
     # The code being debugged may have altered them.
     &save;
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @shlomif

0081-Extract-_DB__determine_if_we_should_break.patch
From 4dbb8bfc78cdcc2c3f0b99b9141072711acc818a Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 30 Sep 2012 17:22:28 +0200
Subject: [PATCH 81/81] Extract _DB__determine_if_we_should_break() .

---
 lib/perl5db.pl | 59 ++++++++++++++++++++++++++++++----------------------------
 1 file changed, 31 insertions(+), 28 deletions(-)

diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index c6b9446..a17ebde 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -1797,6 +1797,36 @@ sub _DB_on_init__initialize_globals
     return;
 }
 
+sub _DB__determine_if_we_should_break
+{
+    # if we have something here, see if we should break.
+    # $stop is lexical and local to this block - $action on the other hand
+    # is global.
+    my $stop;
+
+    if ( $dbline{$line}
+        && _is_breakpoint_enabled($filename, $line)
+        && (( $stop, $action ) = split( /\0/, $dbline{$line} ) ) )
+    {
+
+        # Stop if the stop criterion says to just stop.
+        if ( $stop eq '1' ) {
+            $signal |= 1;
+        }
+
+        # It's a conditional stop; eval it in the user's context and
+        # see if we should stop. If so, remove the one-time sigil.
+        elsif ($stop) {
+            $evalarg = "\$DB::signal |= 1 if do {$stop}";
+            &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);
+            }
+        }
+    } ## end if ($dbline{$line} && ...
+}
+
 sub DB {
 
     # lock the debugger and get the thread id for the prompt
@@ -1835,34 +1865,7 @@ sub DB {
     # Last line in the program.
     $max = $#dbline;
 
-    # if we have something here, see if we should break.
-    {
-        # $stop is lexical and local to this block - $action on the other hand
-        # is global.
-        my $stop;
-
-        if ( $dbline{$line}
-            && _is_breakpoint_enabled($filename, $line)
-            && (( $stop, $action ) = split( /\0/, $dbline{$line} ) ) )
-        {
-
-            # Stop if the stop criterion says to just stop.
-            if ( $stop eq '1' ) {
-                $signal |= 1;
-            }
-
-            # It's a conditional stop; eval it in the user's context and
-            # see if we should stop. If so, remove the one-time sigil.
-            elsif ($stop) {
-                $evalarg = "\$DB::signal |= 1 if do {$stop}";
-                &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);
-                }
-            }
-        } ## end if ($dbline{$line} && ...
-    }
+    _DB__determine_if_we_should_break();
 
     # Preserve the current stop-or-not, and see if any of the W
     # (watch expressions) has changed.
-- 
1.7.12.1

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

From @rjbs

* "shlomif@​shlomifish.org" <perlbug-followup@​perl.org> [2012-09-30T11​:29​:59]

this series of patches adds more tests to the perl debugger and starts
to refactor it. It can also be found here​:

https://github.com/shlomif/perl/tree/shlomif-perl-d-refactoring

Please apply it.

I think it needs a bit of review before it's applied, as it's quite large. I
can try to get to it, but I'm not sure when that will happen. In the meantime,
I've pushed it to a smoke-me branch.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 2012

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

@p5pRT
Copy link
Author

p5pRT commented May 28, 2013

From @shlomif

These patches were already applied, so this ticket should be resolved.
Trying to resolve it - let's see if it worked.

@p5pRT
Copy link
Author

p5pRT commented May 28, 2013

From @shlomif

OK, it didn't - I guess someone will have to resolve this ticket.

@p5pRT
Copy link
Author

p5pRT commented May 28, 2013

From @tonycoz

On Mon May 27 23​:26​:13 2013, shlomif wrote​:

OK, it didn't - I guess someone will have to resolve this ticket.

Done

@p5pRT
Copy link
Author

p5pRT commented May 28, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant