This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #118839] Make ‘n’ debugger cmd respect lv subs
authorFather Chrysostomos <sprout@cpan.org>
Sat, 13 Jul 2013 18:41:44 +0000 (11:41 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 13 Jul 2013 18:49:14 +0000 (11:49 -0700)
commitbf2614180a655fadfe4ad9de9bbcf01c42b29e7e
tree3f3869bd576d4ed5812f911e1863d2b9bc6fde1e
parentc4a26ef3f320212167cfd6d700bfcc92f04a6939
[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.
MANIFEST
lib/perl5db.pl
lib/perl5db.t
lib/perl5db/t/lsub-n [new file with mode: 0644]