Hi folks,
I recently stumbled upon a weird behaviour of the perl debugger that regularly causes me a hard time debugging because it stops with a DB prompt somewhere in the vague depth. Tried perl versions 5.14.2 and 5.18.2, both versions are affected. Destilled the behaviour to the following tiny script:
#!perl -d
use strict;
package Obj;
use overload q{""} => 'string';
sub new { bless { string => pop }, shift }
sub dostuff () {}
sub string {
dostuff; # These naughty lines (in a real module
dostuff; # they'd do probably something useful) simply
dostuff; # want to waste your time when debugging!
dostuff; # There is no exit, is one?
dostuff; # Thought there is a difference between
dostuff; # "n test" and "s test"? - Nope!
dostuff; # Try to "r"eturn, too - turns out it
dostuff; # takes you further than you intended.
dostuff; # Here comes "c 20" to your sole rescue:
dostuff; # It will graciously take you up to
shift->{string} # this line. Counting lines is fun, you know!
}
sub reply {
print "Hi lonely one!\n";
}
package main;
sub test {
my $o = Obj->new("World");
print "Hello $o!\n";
$o->reply();
}
test; # ... this by debugger command "s", then "s test" and/or "n test
+"
__END__
Here is my debugging session:
$ perl debugtest.pl
Loading DB routines from perl5db.pl version 1.39_10
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(debugtest.pl:35): test; # ... this by debugger command "
+s", then "s test" and/or "n test"
DB<1> s
main::test(debugtest.pl:30): my $o = Obj->new("World");
DB<1> n
main::test(debugtest.pl:31): print "Hello $o!\n";
DB<1>
Hello World!
main::test(debugtest.pl:32): $o->reply();
DB<1>
Hi lonely one!
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
DB<1> R
Warning: some settings and command-line options may be lost!
Loading DB routines from perl5db.pl version 1.39_10
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(debugtest.pl:35): test; # ... this by debugger command "
+s", then "s test" and/or "n test"
DB<0> s test
main::((eval 5)[/usr/share/perl5/core_perl/perl5db.pl:732]:3):
3: test;
DB<<1>> s
main::test(debugtest.pl:30): my $o = Obj->new("World");
DB<<1>> n
main::test(debugtest.pl:31): print "Hello $o!\n";
DB<<1>>
main::test(debugtest.pl:10): dostuff; # These naughty lines (i
+n a real module
DB<<1>>
main::test(debugtest.pl:11): dostuff; # they'd do probably som
+ething useful) simply
DB<<1>>
main::test(debugtest.pl:12): dostuff; # want to waste your tim
+e when debugging!
DB<<1>>
main::test(debugtest.pl:13): dostuff; # There is no exit, is o
+ne?
DB<<1>>
main::test(debugtest.pl:14): dostuff; # Thought there is a dif
+ference between
DB<<1>>
main::test(debugtest.pl:15): dostuff; # "n test" and "s test"?
+ - Nope!
DB<<1>>
main::test(debugtest.pl:16): dostuff; # Try to "r"eturn, too -
+ turns out it
DB<<1>>
main::test(debugtest.pl:17): dostuff; # takes you further than
+ you intended.
DB<<1>>
main::test(debugtest.pl:18): dostuff; # Here comes "c 20" to y
+our sole rescue:
DB<<1>>
main::test(debugtest.pl:19): dostuff; # It will graciously tak
+e you up to
DB<<1>>
main::test(debugtest.pl:20): shift->{string} # this line. Coun
+ting lines is fun, you know!
DB<<1>>
Hello World!
main::test(debugtest.pl:32): $o->reply();
DB<<1>>
Hi lonely one!
DB<1>
Hello World!
Hi lonely one!
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
DB<1> R
Warning: some settings and command-line options may be lost!
Loading DB routines from perl5db.pl version 1.39_10
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(debugtest.pl:35): test; # ... this by debugger command "
+s", then "s test" and/or "n test"
DB<1> n test
main::((eval 5)[/usr/share/perl5/core_perl/perl5db.pl:732]:3):
3: test;
DB<<2>> s
main::test(debugtest.pl:30): my $o = Obj->new("World");
DB<<2>> n
main::test(debugtest.pl:31): print "Hello $o!\n";
DB<<2>>
main::test(debugtest.pl:10): dostuff; # These naughty lines (i
+n a real module
DB<<2>> q
The respective string method in my real project is even stepped into from a dunno-how related Moose object accessor. To find myself thrown into that method every once in a while makes debugging tedious, so I would like to work around it. It seems to be a bug in the debugger, in overload pragma perhaps (forgotten $DB::single assignment?), in them both or just in my thinking.
What do you think and why, I appreciate your advice!
-- flowdy