| 1 | package Parse::StackTrace::Type::GDB::Frame; | ||||||||||||||||||||||
| 2 | 2 | ▶ | use Moose; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | 2 | ▶ | use Parse::StackTrace::Exceptions; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | 2 | extends 'Parse::StackTrace::Frame'; | |||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 2 | has 'memory_location' => (is => 'ro', isa => 'Str'); | |||||||||||||||||||||
| 9 | 2 | has 'lib_tag' => (is => 'ro', isa => 'Str'); | |||||||||||||||||||||
| 10 | 2 | has 'library' => (is => 'ro', isa => 'Str'); | |||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | # This describes a valid function name. | ||||||||||||||||||||||
| 13 | 2 | our $FUNCTION = qr/(?:[^\@]+?(?:\(.*\))?)|\S+/; | |||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | 2 | our $FRAME_REGEX = qr/ | |||||||||||||||||||||
| 16 | ^\# (\d+) # 1 level | ||||||||||||||||||||||
| 17 | \s+ (?:(0x[A-Fa-f0-9]+)\s+in\s+)? # 2 location | ||||||||||||||||||||||
| 18 | ($FUNCTION) # 3 function | ||||||||||||||||||||||
| 19 | (?:\@+([\w\.]+))? # 4 libtag | ||||||||||||||||||||||
| 20 | \s+ \(([^\)]*)\) # 5 args | ||||||||||||||||||||||
| 21 | \s* (?:from\s(\S+))? # 6 library | ||||||||||||||||||||||
| 22 | \s* (?:at\s+([^:]+) # 7 file | ||||||||||||||||||||||
| 23 | : (\d+))? # 8 line | ||||||||||||||||||||||
| 24 | /x; | ||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | # This is a strange frame format we get occasionally without a function. | ||||||||||||||||||||||
| 27 | 2 | our $FUNCTIONLESS_FRAME = qr/^#(\d+)\s+(0x[A-Fa-f0-9]+)\s+in\s+\(\)$/; | |||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 29 | # Sometimes people try to parse traces that don't contain parentheses for | ||||||||||||||||||||||
| 30 | # the arguments, which are actually the key part of the regex above. | ||||||||||||||||||||||
| 31 | # (Without them, some of the craziness doesn't work.) So for these | ||||||||||||||||||||||
| 32 | # particular frames, we just grab what we can (the function, memory_loc, etc.) | ||||||||||||||||||||||
| 33 | 2 | our $PARENLESS_FRAME = qr/^#(\d+)\s+(0x[A-Fa-f0-9]+)\s+in\s+($FUNCTION)$/; | |||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | 1598 | ▶ | sub parse { | ||||||||||||||||||||
|
Subroutine
parse: called CC=9 SCAR=22.7
Pod
undocumented
| |||||||||||||||||||||||
| 36 | 1598 | my ($class, %params) = @_; | |||||||||||||||||||||
| 37 | 1598 | my $lines = $params{'lines'}; | |||||||||||||||||||||
| 38 | 1598 | my $debug = $params{'debug'}; | |||||||||||||||||||||
| 39 | |||||||||||||||||||||||
| 40 | 1598 | my $text = join(' ', @$lines); | |||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | 1598 | my %parsed; | |||||||||||||||||||||
| 43 | 1598 | ▶ | if ($text =~ $FRAME_REGEX) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 44 | 1578 | %parsed = (number => $1, memory_location => $2, | |||||||||||||||||||||
| 45 | function => $3, lib_tag => $4, args => $5, | ||||||||||||||||||||||
| 46 | library => $6, file => $7, line => $8); | ||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||
| 48 | elsif ($text =~ $FUNCTIONLESS_FRAME) { | ||||||||||||||||||||||
| 49 | 0 | %parsed = (number => $1, memory_location => $2, function => '??'); | |||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||
| 51 | elsif ($text =~ $PARENLESS_FRAME) { | ||||||||||||||||||||||
| 52 | 4 | %parsed = (number => $1, memory_location => $2, function => $3); | |||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||
| 54 | elsif ($text =~ /^#(\d+)\s+(<signal handler called>)/) { | ||||||||||||||||||||||
| 55 | 16 | %parsed = (number => $1, function => $2, is_crash => 1); | |||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | 1598 | ▶ | if (!%parsed) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 59 | 0 | Parse::StackTrace::Exception::NotAFrame->throw( | |||||||||||||||||||||
| 60 | "Not a valid GDB stack frame: " . join("\n", @$lines) | ||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | 1598 | foreach my $key (keys %parsed) { | |||||||||||||||||||||
| 65 | 12684 | ▶ | delete $parsed{$key} if !defined $parsed{$key}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | 1598 | ▶ | print STDERR "Parsed As: " . Dumper(\%parsed) if $debug; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 68 | 1598 | return $class->new(%parsed); | |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||
| 70 | |||||||||||||||||||||||
| 71 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | 2 | 1; | |||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||