Skip to content

Commit 0b035da

Browse files
committed
perl5db.pl: apply the "break on first line" fix to b postpone subname
and just plain fix "b postpone subname", which didn't stop at all on my postponed sub test code at all as far back at 5.10. Fixes #799
1 parent 6507a1d commit 0b035da

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

lib/perl5db.pl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6273,13 +6273,23 @@ sub postponed_sub {
62736273

62746274
# find_sub's value is 'fullpath-filename:start-stop'. It's
62756275
# possible that the filename might have colons in it too.
6276-
my ( $file, $i ) = ( find_sub($subname) =~ /^(.*):(\d+)-.*$/ );
6276+
my ($file, $i);
6277+
local $\ = '';
6278+
if ( $offset =~ /^\+?0$/) {
6279+
( $file, $i ) = eval { subroutine_first_breakable_line($subname) }
6280+
or print $OUT $@;
6281+
}
6282+
else {
6283+
if (( $file, $i ) = ( find_sub($subname) =~ /^(.*):(\d+)-.*$/ )) {
6284+
# We got the start line. Add the offset '+<n>' from
6285+
# $postponed{subname}.
6286+
$i += $offset;
6287+
}
6288+
else {
6289+
print $OUT "Subroutine $subname not found.\n";
6290+
}
6291+
}
62776292
if ($i) {
6278-
6279-
# We got the start line. Add the offset '+<n>' from
6280-
# $postponed{subname}.
6281-
$i += $offset;
6282-
62836293
# Switch to the file this sub is in, temporarily.
62846294
local *dbline = $main::{ '_<' . $file };
62856295

@@ -6298,13 +6308,9 @@ sub postponed_sub {
62986308

62996309
# Copy the breakpoint in and delete it from %postponed.
63006310
$dbline{$i} = delete $postponed{$subname};
6301-
} ## end if ($i)
63026311

6303-
# find_sub didn't find the sub.
6304-
else {
6305-
local $\ = '';
6306-
print $OUT "Subroutine $subname not found.\n";
6307-
}
6312+
_set_breakpoint_enabled_status($file, $i, 1);
6313+
} ## end if ($i)
63086314
return;
63096315
} ## end if ($postponed{$subname...
63106316
elsif ( $postponed{$subname} eq 'compile' ) { $signal = 1 }

lib/perl5db.t

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,6 +3565,43 @@ EOS
35653565
$wrapper->contents_like(qr/Cannot break on XSUB B::svref_2object/, "can't break on XSUB");
35663566
}
35673567

3568+
{
3569+
my $wrapper = DebugWrap->new(
3570+
{
3571+
cmds =>
3572+
[
3573+
"b problem", # should fail
3574+
"b postpone problem",
3575+
"L",
3576+
"c",
3577+
"q"
3578+
],
3579+
prog => \<<'EOS'
3580+
print "1\n";
3581+
eval <<'EOC';
3582+
sub problem {
3583+
$SIG{__DIE__} = sub {
3584+
die "<b problem> will set a break point here.\n";
3585+
}; # The break point _should_ be set here.
3586+
warn "This line will run even if you enter <c problem>.\n";
3587+
}
3588+
EOC
3589+
print "2\n";
3590+
problem();
3591+
print "3\n";
3592+
EOS
3593+
}
3594+
);
3595+
$wrapper->contents_like(qr/Subroutine main::problem not found/,
3596+
"problem not defined yet");
3597+
$wrapper->contents_like(qr/Postponed\ breakpoints\ in\ subroutines:
3598+
\s+main::problem\s+break\s\+0\sif\s1/x,
3599+
"check postponed breakpoint present");
3600+
$wrapper->contents_like(qr/The break point _should_/, "break at right place (c)");
3601+
$wrapper->output_unlike(qr/This line will run even if you enter <c problem>\./,
3602+
"didn't run the wrong code");
3603+
}
3604+
35683605
done_testing();
35693606

35703607
END {

0 commit comments

Comments
 (0)