| 1 | package Parse::StackTrace::Type::GDB; | ||||||||||||||||||||||||||||||||||||||||||
| 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 Math::BigInt; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | extends 'Parse::StackTrace'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | our $WHITESPACE_ONLY = qr/^\s*$/; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use constant HAS_TRACE => qr/ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | ^\#\d+\s+ # #1 | ||||||||||||||||||||||||||||||||||||||||||
| 14 | (?: | ||||||||||||||||||||||||||||||||||||||||||
| 15 | (?:0x[A-Fa-f0-9]{4,}\s+in\b) # 0xdeadbeef in | ||||||||||||||||||||||||||||||||||||||||||
| 16 | | | ||||||||||||||||||||||||||||||||||||||||||
| 17 | (?:[A-Za-z_\*]\S+\s+\() # some_function_name | ||||||||||||||||||||||||||||||||||||||||||
| 18 | | | ||||||||||||||||||||||||||||||||||||||||||
| 19 | (?:<signal \s handler \s called>) | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | /mx; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use constant BIN_REGEX => qr/(?:Backtrace|Core) was generated (?:from|by) (?:`|')(.+)/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | #1num #2name | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use constant THREAD_START_REGEX => ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | qr/^Thread (\d+) \((.*)\):$/, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | qr/^\[Switching to Thread (.+) \((.+)\)\]$/, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use constant OPEN_PAREN_WITHOUT_CLOSE => qr/\s+\([^\)]*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use constant IGNORE_LINES => ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 'No symbol table info available.', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 'No locals.', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | '---Type <return> to continue, or q <return> to quit---', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | # If we just have the default thread, return it when asked for Thread 1. | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 40 | ▶ | sub thread_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
thread_number: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 40 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 40 | my ($number) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 40 | ▶ | if (scalar @{ $self->threads } == 1 and !$self->threads->[0]->has_number | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
scalar @{$self->threads;} == 1 and not $self->threads->[0]->has_number and $number == 1
scalar @{$self->threads;} == 1 and not $self->threads->[0]->has_number
MC/DC100%3/3
scalar @{$self->threads;} == 1 and not $self->threads->[0]->has_number and $number == 1
scalar @{$self->threads;} == 1
not $self->threads->[0]->has_number
$number == 1
Truth table100%4/4
A and not(B) and C
A= scalar @{$self->threads;} == 1B= not $self->threads->[0]->has_numberC= $number == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | and $number == 1) | ||||||||||||||||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | return $self->threads->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 31 | return $self->SUPER::thread_number(@_) | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # The most common parsing error during testing was that traces would be | ||||||||||||||||||||||||||||||||||||||||||
| 50 | # malformed with extra newlines in the "args" section. | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 2704 | ▶ | sub _get_next_trace_block { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_next_trace_block: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 2704 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 2704 | my $frame_lines = $self->SUPER::_get_next_trace_block(@_); | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2704 | my $frame_text = join(' ', @$frame_lines); | |||||||||||||||||||||||||||||||||||||||||
| 56 | # Check if the trace contains an open-paren after a space, but no | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # close-paren after it. | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 2704 | ▶ | if ($frame_text =~ OPEN_PAREN_WITHOUT_CLOSE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 12 | my ($lines) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 12 | my $next_line = $lines->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # If the next line is blank... | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 12 | ▶ | if (defined $next_line and $next_line =~ $WHITESPACE_ONLY) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $next_line and $next_line =~ /$Parse::StackTrace::Type::GDB::WHITESPACE_ONLY/
MC/DC100%2/2
defined $next_line and $next_line =~ /$Parse::StackTrace::Type::GDB::WHITESPACE_ONLY/
defined $next_line
$next_line =~ /$Parse::StackTrace::Type::GDB::WHITESPACE_ONLY/
Truth table100%3/3
A and B
A= defined $next_lineB= $next_line =~ /$Parse::StackTrace::Type::GDB::WHITESPACE_ONLY/
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Then get rid of it and re-parse the block. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | shift @$lines; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | unshift(@$lines, @$frame_lines); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | return $self->_get_next_trace_block(@_); | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | # Often people will cut up parts of a trace, and the very | ||||||||||||||||||||||||||||||||||||||||||
| 71 | # last frame wil have an open-paren with no close paren. | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # So, if the next line is an end to this frame (or an end to the whole | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # block of text being parsed), then we just have | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # a really bad trace that we should try to deal with anyway by | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # closing the parens on the actual line where the open-paren happens. | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 10 | ▶ | if (!defined $next_line or $self->_next_line_ends_frame($next_line)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $next_line or $self->_next_line_ends_frame($next_line)
MC/DC100%2/2
not defined $next_line or $self->_next_line_ends_frame($next_line)
not defined $next_line
$self->_next_line_ends_frame($next_line)
Truth table100%3/3
not(A) or B
A= not defined $next_lineB= $self->_next_line_ends_frame($next_line)
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 9 | my @real_frame_lines; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 9 | ▶ | while (my $line = shift @$frame_lines) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 9 | ▶ | if ($line =~ OPEN_PAREN_WITHOUT_CLOSE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 9 | $line .= ')'; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 9 | push(@real_frame_lines, $line); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 9 | last; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | push(@real_frame_lines, $line); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # Put the remaining lines back into $lines, so that we don't | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # think they're part of the trace. | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 9 | unshift(@$lines, @$frame_lines); | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 9 | return \@real_frame_lines; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 2693 | return $frame_lines; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | # We also want to ignore any lines containing gdb commands. | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 7226 | ▶ | sub _ignore_line { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ignore_line: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 7226 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 7226 | my $result = $class->SUPER::_ignore_line(@_); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 7226 | ▶ | return $result if $result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 5527 | my ($line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 5527 | ▶ | return $line =~ /^\(gdb\) / ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 4019 | ▶ | sub _line_starts_thread { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_line_starts_thread: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 4019 | my ($class, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 4019 | foreach my $re (THREAD_START_REGEX) { | |||||||||||||||||||||||||||||||||||||||||
| 111 | 7952 | ▶ | if ($line =~ $re) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 91 | my ($number, $desc) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 91 | ▶ | if ($number =~ /^0x/ or $number !~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$number =~ /^0x/ or not $number =~ /^\d+$/
MC/DC100%2/2
$number =~ /^0x/ or not $number =~ /^\d+$/
$number =~ /^0x/
not $number =~ /^\d+$/
Truth table100%3/3
A or not(B)
A= $number =~ /^0x/B= not $number =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | # Greater than 0xffffffff needs to be a BigInt for portability. | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 5 | $number =~ s/^0x//; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 5 | ▶ | if (length($number) > 8) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 5 | $number = Math::BigInt->new("0x$number"); | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $number = hex($number); | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 91 | return ($number, $desc); | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 3928 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||||||||||||||||