houseabsolute / Devel-StackTrace

An object representing a stack trace
https://metacpan.org/release/Devel-StackTrace/
Other
7 stars 13 forks source link

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

Open autarch opened 7 years ago

autarch commented 7 years ago

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

Requestors:

Attachments:

From alexandre.gorobets@gmail.com 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 ($arghash, $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 commented 7 years ago

From drolsky@cpan.org (@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 commented 7 years ago

From ghewson@wormhole.me.uk 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 perlbug@perl.org. I've written a stripped-down amalgamation of Alexandre's test case and Devel::StackTrace, which I attach here.

Graeme Hewson

autarch commented 7 years ago

From ghewson@wormhole.me.uk on 2010-10-03 18:03:02:

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

autarch commented 7 years ago

From ghewson@wormhole.me.uk 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 commented 7 years ago

From bbyrd@cpan.org (@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 commented 7 years ago

From drolsky@cpan.org (@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.