Note (yyl_leftcurly) & restore (newATTRSUB_x) line numbers for anon subs#24396
Note (yyl_leftcurly) & restore (newATTRSUB_x) line numbers for anon subs#24396richardleach wants to merge 2 commits into
Conversation
Declaring an anonymous subroutine in the middle of a statement is likely
to result in an inaccurate line number being stored in the COP preceding
the statement. This is because line number information is discarded
during parsing and creation of the anonymous subroutine.
This commit attempts to store and restore a more accurate line number
for the COP. This will improve the accuracy of line numbers emitted by
diagnostic messages and `caller()`. **_Tests containing hardcoded line
numbers may require updating as a result of this commit._**
This (previously) TODO test from _caller.t_ shows the difference:
```
sub tagCall {
my ($package, $file, $line) = caller;
print "$line\n";
}
tagCall # Line number 6 correctly reported before & after
"abc";
tagCall # Line number 9 correctly reported with this commit
sub {}; # Line number 10 incorrectly reported previously
```
Changes in line numbering could also affect where breaking on a function
occurs in the perl debugger. This can be seen in the included change to
_perl5db.t_, where breaking on entry to `problem()` now occurs at the
start of the subroutine, rather than after the anonymous subroutine
declaration:
```
sub problem {
$SIG{__DIE__} = sub { # Breaking on problem() now lands here
die "<b problem> will set a break point here.\n";
}; # Breaking on problem() used to land here
```
|
From what I understand it's breaking on the same dbstate, it's just the line number is from the beginning of the statement rather than the end. I certainly prefer that. I could it briefly confusing people who are used to the old behaviour, but I think it's preferable (especially since the anonsub can be much longer. One issue I could see (for the debugger) is there will be different conflicts between which dbstate is saved in the IV of the A C debugger would likely set the breakpoint on every piece of generated code for that line, but we only store one address for each line, and compatibility makes that hard(er) to change (maybe store the extras in magic?).
I expect it will generate a painful amount of BBC. |
|
Note to future self, something like this can be used in test files to determine the behaviour at run time and then adjust expectations to match: |
|
While working through Test::Simple's test failures, it became apparent that this PR was incomplete. Pushed an additional commit so that the |
Declaring an anonymous subroutine in the middle of a statement is likely to result in an inaccurate line number being stored in the COP preceding the statement. This is because line number information is discarded during parsing and creation of the anonymous subroutine.
This commit attempts to store and restore a more accurate line number for the COP. This will improve the accuracy of line numbers emitted by diagnostic messages and
caller(). Tests containing hardcoded line numbers may require updating as a result of this commit.This (previously) TODO test from caller.t shows the difference:
Changes in line numbering could also affect where breaking on a function occurs in the perl debugger. This can be seen in the included change to perl5db.t, where breaking on entry to
problem()now occurs at the start of the subroutine, rather than after the anonymous subroutine declaration:Closes #4125