Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bizzare copy of **** in stack args #11

Open
autarch opened this issue Dec 7, 2016 · 6 comments
Open

Bizzare copy of **** in stack args #11

autarch opened this issue Dec 7, 2016 · 6 comments

Comments

@autarch
Copy link
Member

autarch commented Dec 7, 2016

Migrated from rt.cpan.org #50447 (status was 'open')

Requestors:

Attachments:

From [email protected] on 2009-10-13 14:12:36:

Simple (but awful) code, that raise error:

use Devel::StackTrace;

sub do_work {
my $s = Devel::StackTrace->new(
'no_refs' => 1,
);
}

sub call_with_args {
my ($arg_hash, $func) = @_;
$func->( @{$arg_hash->{'args'}} );
}

my $h = {};

my $arg_hash = { 'args' => [ undef ] };

call_with_args(
$arg_hash, sub {
$arg_hash->{'args'} = [];
do_work( sub { $h; } );
}
);

I propose this solution (in StackTrace.pm)

sub _record_caller_data
{
my $self = shift;

# We exclude this method by starting one frame back.
my $x = 1;
while ( my @c =
        do { package DB; @DB::args = (); caller($x++) } )
{
    my @args;

    foreach ( @DB::args )
    {
        my $arg;

        local $@;

        eval 
        {
            $arg = $self->{'no_refs'} && ref $_ ? $self->_ref_to_string( $_ ) : $_;
        };

        if ( $@ =~ /^Bizarre copy of \w+/ )
        {
            $arg = $&;
        }

        push @args, $arg;
    }

    push @{ $self->{raw} },
        { 'caller' => \@c,
          'args'   => \@args,
        };
}

}

@autarch
Copy link
Member Author

autarch commented Dec 7, 2016

From [email protected] (@autarch) on 2010-06-26 19:55:57:

Sorry for the slow reply.

This is really a bug in the Perl core, and should probably be reported
there.

As for a hackaround in Devel::StackTrace, any such thing would need to
not use $& to be useful.

@autarch
Copy link
Member Author

autarch commented Dec 7, 2016

From [email protected] on 2010-10-03 17:22:30:

On Sat Jun 26 15:55:57 2010, DROLSKY wrote:

This is really a bug in the Perl core, and should probably be
reported
there.

I've just submitted a report to [email protected]. I've written a
stripped-down amalgamation of Alexandre's test case and
Devel::StackTrace, which I attach here.

Graeme Hewson

@autarch
Copy link
Member Author

autarch commented Dec 7, 2016

From [email protected] on 2010-10-03 18:03:02:

My report is now at
http://rt.perl.org/rt3/Public/Bug/Display.html?id=78186

@autarch
Copy link
Member Author

autarch commented Dec 7, 2016

From [email protected] on 2010-10-04 17:52:07:

OK, so the core problem is not realistically fixable. It seems a
workaround is the best we could do.

I don't know if this has any relevance, which I happened to notice in
perl5134delta ("what is new for perl v5.13.4"):

"Carp"
Upgraded from version 1.16 to 1.18.

Carp now detects incomplete caller() overrides and avoids using
bogus @DB::args. To provide backtraces, Carp relies on particular
behaviour of the caller built-in. Carp now detects if other code
has overridden this with an incomplete implementation, and modifies
its backtrace accordingly. Previously incomplete overrides would
cause incorrect values in backtraces (best case), or obscure fatal
errors (worst case)

This fixes certain cases of "Bizarre copy of ARRAY" caused by
modules overriding "caller()" incorrectly.

@autarch
Copy link
Member Author

autarch commented Dec 7, 2016

From [email protected] (@SineSwiper) on 2012-04-23 00:56:54:

Getting hit by this, too, via Perl 5.14.2. So, it's not really fixed in
CORE, and it might never be. Since this thing is used for
Exception::Class, I think whatever workaround that can be implemented
should be. We certainly don't want stuff to crash on us DURING the
Exception, before we even get to print it.

@autarch
Copy link
Member Author

autarch commented Dec 7, 2016

From [email protected] (@autarch) on 2012-04-23 01:36:22:

On Sun Apr 22 20:56:54 2012, BBYRD wrote:

Getting hit by this, too, via Perl 5.14.2. So, it's not really fixed
in
CORE, and it might never be. Since this thing is used for
Exception::Class, I think whatever workaround that can be implemented
should be. We certainly don't want stuff to crash on us DURING the
Exception, before we even get to print it.

A good patch would be welcome. Bonus points for stealing the code from
Carp that fixes some of these bugs (but not all, I'm sure).

I think the linked rt.perl ticket might provide a good test case.

pali added a commit to pali/Devel-StackTrace that referenced this issue May 23, 2019
Same workaround was added to Carp.pm module based on patch:
https://rt.perl.org/Public/Bug/Display.html?id=131046

It is not fix just a workaround which may work.

See also:
houseabsolute#11
https://rt.perl.org/Public/Bug/Display.html?id=52610
pali added a commit to pali/Devel-StackTrace that referenced this issue May 23, 2019
Same workaround was added to Carp.pm module based on patch:
https://rt.perl.org/Public/Bug/Display.html?id=131046

It is not fix just a workaround which may work.

See also:
houseabsolute#11
https://rt.perl.org/Public/Bug/Display.html?id=52610
autarch pushed a commit that referenced this issue May 24, 2019
Same workaround was added to Carp.pm module based on patch:
https://rt.perl.org/Public/Bug/Display.html?id=131046

It is not fix just a workaround which may work.

See also:
#11
https://rt.perl.org/Public/Bug/Display.html?id=52610
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant