develooper Front page | perl.perl5.porters | Postings from January 2022

Re: Broken stack traces from use statements.

Thread Previous
From:
demerphq
Date:
January 13, 2022 11:30
Subject:
Re: Broken stack traces from use statements.
Message ID:
CANgJU+Uf8_D8QPGgEFKO2NnmsjDnsx+Vtgdom4zjZTH85zD+QQ@mail.gmail.com
On Thu, 13 Jan 2022, 18:45 Ovid, <curtis_ovid_poe@yahoo.com> wrote:

> Top-posting
>
> For those who want to know exactly what's going on and don't want to wade
> through the diff or tests:
>
> $ mkdir lib/{A,B,C}pack.pm
>
>
> And in each of those, add this:
>
> package Apack;
> use Bpack;
> 1;
>
> package Bpack;
> use Cpack;
> 1;
>
> package Cpack;
> my $i = 0;
>
> while ( my ( $package, $file, $line ) = caller( $i++ ) ) {
>     push @Cpack::callers, "$file:$line";
> }
> 1;
>
>
> And then create run.pl:
>
> #!/usr/bin/env perl
>
> use lib 'lib';
> use Apack;
> use Data::Dumper;
> print Dumper( \@Cpack::callers );
>
>
> If you have a patched Perl, you get this:
>
> $VAR1 = [
>           'lib/Bpack.pm:2',
>           'lib/Bpack.pm:2',
>           'lib/Bpack.pm:2',
>           'lib/Apack.pm:2',
>           'lib/Apack.pm:2',
>           'lib/Apack.pm:2',
>           'run.pl:4',
>           'run.pl:4',
>           'run.pl:4'
>         ];
>
>
> That's perfectly sane and you can figure out what's going on (though I
> confess I don't know why some stack frames are repeated).
>

The repeats come from the expansion of use into BEGIN, require, and the use
itself I believe.


> For an unpatched Perl, you get something like this:
>
> $VAR1 = [
>           'lib/Bpack.pm:2',
>           'lib/Cpack.pm:0',
>           'lib/Cpack.pm:0',
>           'lib/Apack.pm:2',
>           'lib/Cpack.pm:0',
>           'lib/Cpack.pm:0',
>           'run.pl:4',
>           'lib/Cpack.pm:0',
>           'lib/Cpack.pm:0'
>         ];
>
>
> I cannot use that stack trace for debugging.
>
> I have verified the buggy behavior all the way back to 5.8.9.
>
> The patch which reverted the fix notes the following:
>
> commit c0d05305c156c83e4f9f3a207451b3175fbb7f24 (HEAD)
> Merge: c6b2e294d8 79f75eaa71
> Author: David Mitchell <davem@iabyn.com>
> Date:   Mon Apr 27 22:04:23 2020 +0100
>
>     [MERGE] Revert BEGIN { caller() } fixups
>
>     These commits were intended to fix a problem with stack backtraces
>     reporting wrong file and line numbers in nested use's.
>
>     A side-effect of the commits was to fix the package name returned by
>     caller() too; but quite a few distributions were relying on the old
>     behaviour.
>
>     So for now, revert to the old behaviour and re-address after 5.32.0 is
>     released.
>
>     The reverted commits are:
>
>     v5.31.6-141-gf2f32cd638 avoid identical stack traces
>     v5.31.9-122-gee428a211d docs: clarify effect of $^H, %^H,
> ${^WARNING_BITS}
>     v5.31.9-162-gad89278aa2 fixup to "avoid identical stack traces" - try 2
>
>
> I don't know which distributions were failing or why, but having a few
> distributions making it harder for *all* Perl developers to debug their
> programs seems backwards.
>

Hearty agreement.


> What can we do to get this fixed?
>

Yves

>
>

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About