[perl #118839] Make ‘n’ debugger cmd respect lv subs
The ‘n’ debugger command, which is supposed to step over subs, was not
stepping over lvalue subs.
This is a regression from 5.8, but 5.8 was worse.
This bug did not occur in 5.8 because there was no mechanism back then
for handling lvalue subs specially (via DB::lsub), so assignment to an
lvalue sub was completely broken under the debugger.
Perl 5.10 introduced DB::lsub. The implementation in perl5db.pl
contains these lines at the end of the sub:
# Pop the single-step value back off the stack.
$single |= $stack[ $stack_depth-- ];
# call the original lvalue sub.
&$sub;
The regular DB::sub does this:
{
no strict 'refs';
@ret = &$sub;
}
# Pop the single-step value back off the stack.
$single |= $stack[ $stack_depth-- ];
Notice how $single (i.e., $DB::single) is modified before and after
the sub call, respectively. The order is different.
There are two types of lvalue list context for lvalue subs. (foo)=3
will allow sub foo:lvalue{@a} to return the array itself. \(foo) and
bar(foo) will flatten the array.
So there is no way in pure Perl to capture the return value and have
it returned to the caller unchanged. That is why DB::lsub has to call
the sub last of all (and have the context propagated).
The solution here is to use localisation to accomplish the assigment
to $single after the lvalue sub exits.