lib/Devel/Trepan/CmdProcessor/Frame.pm

filter: Statementstmt 13.1% 24 / 182 Branchbran 0.0% 0 / 112 Conditioncond 0.0% 0 / 26 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 50.0% 8 / 16 Podpod 0.0% 0 / 8 totaltotal 8.9% 32 / 358 CC 67 SCAR 60.7
CC
67
Cov
8%
print_stack_entry
673.0
print_stack_entry
673.0
print_stack_trace
42.0
CRAP 434.2
« lib/Devel/Trepan/CmdProcessor/Command/List.pm ↑ Summary blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Files.pm »
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2012, 2014-2015 Rocky Bernstein <rocky@cpan.org>
3 12 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use rlib '../../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Devel::Trepan::DB::LineCache; # for map_file and getline
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Devel::Trepan::Complete;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package Devel::Trepan::CmdProcessor;
9 12 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶my $have_deparse = eval q(use B::DeparseTree::Fragment; use Devel::Trepan::Deparse; 1);
Subroutine BEGIN: called CC=1 SCAR=1.2
12  
13 sub frame_complete($$;$)
14 0 ▶{
Subroutine frame_complete: not called CC=2 SCAR=17.9
Pod undocumented
15 0 ▶ my ($self, $prefix, $direction) = @_;
Subroutine frame_complete: not called CC=2 SCAR=17.9
Pod undocumented
16 0 ▶ $direction = 1 unless defined $direction;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $direction 0 0 0
unless defined $direction 0 0 0
17 0 my ($low, $high) = $self->frame_low_high($direction);
18 0 my @ary = ($low..$high);
19 0 Devel::Trepan::Complete::complete_token(\@ary, $prefix);
20 }
21  
22 sub print_stack_entry
23 0 ▶{
Subroutine print_stack_entry: not called CC=26 SCAR=65.1
Pod undocumented
24 0 ▶ my ($self, $frame, $i, $prefix, $opts) = @_;
Subroutine print_stack_entry: not called CC=26 SCAR=65.1
Pod undocumented
25 0 ▶ $opts->{maxstack} = 1e9 unless defined $opts->{maxstack};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $opts->{"maxstack"} 0 0 0
unless defined $opts->{"maxstack"} 0 0 0
26 # Set the separator so arrays print nice.
27 0 local $LIST_SEPARATOR = ', ';
28  
29 # Get the file name.
30 0 my $canonic_file = $self->canonic_file($frame->{file});
31 0 ▶ $canonic_file = '??' unless defined $canonic_file;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $canonic_file 0 0 0
unless defined $canonic_file 0 0 0
32  
33 # Put in a filename header if short is off.
34 0 ▶ my $file = ($canonic_file eq '-e') ? $canonic_file : "file `$canonic_file'" unless $opts->{short};
Branch: 4 branches
BranchTrueFalseTotal
unless $opts->{"short"} 0 0 0
$canonic_file eq '-e' ? : 0 0 0
unless $opts->{"short"} 0 0 0
$canonic_file eq '-e' ? : 0 0 0
35  
36 0 my $not_last_frame = $i != ($self->{stack_size}-1);
37 0 my $s = '';
38 my $args =
39 defined $frame->{args}
40 0 ▶ ? "(@{ $frame->{args} })"
Branch: 2 branches
BranchTrueFalseTotal
defined $frame->{'args'} ? : 0 0 0
defined $frame->{'args'} ? : 0 0 0
41 : '';
42 0 ▶ if ($not_last_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if ($not_last_frame) 0 0 0
if ($not_last_frame) 0 0 0
43 # Grab and stringify the arguments if they are there.
44  
45 # Shorten them up if $opts->{maxwidth} says they're too long.
46 $args = substr($args, 0, $opts->{maxwidth}-3) . '...'
47 0 ▶ if length($args) > $opts->{maxwidth};
Branch: 2 branches
BranchTrueFalseTotal
if length $args > $opts->{"maxwidth"} 0 0 0
if length $args > $opts->{"maxwidth"} 0 0 0
48  
49 # Get the actual sub's name, and shorten to $maxwidth's requirement.
50 0 ▶ if (exists($frame->{fn})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $frame->{"fn"}) 0 0 0
if (exists $frame->{"fn"}) 0 0 0
51 0 $s = $frame->{fn};
52 $s = substr($s, 0, $opts->{maxwidth}-3) . '...'
53 0 ▶ if length($s) > $opts->{maxwidth};
Branch: 2 branches
BranchTrueFalseTotal
if length $s > $opts->{"maxwidth"} 0 0 0
if length $s > $opts->{"maxwidth"} 0 0 0
54 }
55 }
56  
57 # Short report uses trimmed file and sub names.
58 0 my $want_array;
59 0 ▶ if (exists($frame->{wantarray})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $frame->{'wantarray'}) { } 0 0 0
if (exists $frame->{'wantarray'}) { } 0 0 0
60 0 $want_array = "$frame->{wantarray} = ";
61 } else {
62 0 $not_last_frame = 0;
63 0 $want_array = '' ;
64 }
65  
66 0 ▶ my $lineno = $frame->{line} || '??';
Condition0%0/4
$frame->{'line'} || '??'
l!l
00
$frame->{'line'} || '??'
l!l
00
MC/DC0%0/1
$frame->{'line'} || '??'
$frame->{'line'}
MC/DC0%0/1
$frame->{'line'} || '??'
$frame->{'line'}
Truth table0%0/2
A
A= $frame->{'line'}
Aresult
11
00
Truth table0%0/2
A
A= $frame->{'line'}
Aresult
11
00
67 0 ▶ my $addr = $opts->{displayop} && $frame->{addr} ? sprintf("0x%x ", $frame->{addr}) : '';
Branch: 2 branches
BranchTrueFalseTotal
$opts->{'displayop'} && $frame->{'addr'} ? : 0 0 0
$opts->{'displayop'} && $frame->{'addr'} ? : 0 0 0
Condition0%0/6
$opts->{"displayop"} and $frame->{"addr"}
!ll&&!rl&&r
000
$opts->{"displayop"} and $frame->{"addr"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"displayop"} and $frame->{"addr"}
$opts->{"displayop"} $frame->{"addr"}
MC/DC0%0/2
$opts->{"displayop"} and $frame->{"addr"}
$opts->{"displayop"} $frame->{"addr"}
Truth table0%0/3
A and B
A= $opts->{"displayop"}B= $frame->{"addr"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $opts->{"displayop"}B= $frame->{"addr"}
ABresult
0X0
100
111
68 0 ▶ if ($opts->{short}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'short'}) { } 0 0 0
if ($opts->{'short'}) { } 0 0 0
69 0 my $fn = $s; # @_ >= 4 ? $_[3] : $s;
70 0 my $msg = sprintf("%s%s%s%s from %s:%d",
71 $want_array, $addr, $fn, $args, $file, $lineno);
72 0 $self->msg($msg);
73 } else {
74 # Non-short report includes full names.
75 # Lose the DB::DB hook call if frame is 0.
76 0 ▶ my $call_str = $not_last_frame ? "$addr$want_array$s$args in " : $addr;
Branch: 2 branches
BranchTrueFalseTotal
$not_last_frame ? : 0 0 0
$not_last_frame ? : 0 0 0
77 0 my $prefix_call = "$prefix$call_str";
78 0 my $file_line = $file . " at line $lineno";
79  
80 0 ▶ if (length($prefix_call) + length($file_line) <= $opts->{maxwidth}) {
Branch: 2 branches
BranchTrueFalseTotal
if (length($prefix_call) + length($file_line) <= $opts->{'maxwidth'}) { } 0 0 0
if (length($prefix_call) + length($file_line) <= $opts->{'maxwidth'}) { } 0 0 0
81 0 $self->msg($prefix_call . $file_line);
82 } else {
83 0 $self->msg($prefix_call);
84 0 $self->msg("\t" . $file_line);
85 }
86 }
87 0 ▶ if ($opts->{source}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{"source"}) 0 0 0
if ($opts->{"source"}) 0 0 0
88 0 my $line = getline($canonic_file, $lineno, $opts);
89 0 ▶ $self->msg($line) if $line;
Branch: 2 branches
BranchTrueFalseTotal
if $line 0 0 0
if $line 0 0 0
90 }
91  
92  
93 0 ▶ if ($opts->{deparse} && $have_deparse && $addr) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{"deparse"} and $have_deparse and $addr) 0 0 0
if ($opts->{"deparse"} and $have_deparse and $addr) 0 0 0
Condition0%0/12
$opts->{"deparse"} and $have_deparse and $addr
!ll&&!rl&&r
000
$opts->{"deparse"} and $have_deparse
!ll&&!rl&&r
000
$opts->{"deparse"} and $have_deparse and $addr
!ll&&!rl&&r
000
$opts->{"deparse"} and $have_deparse
!ll&&!rl&&r
000
MC/DC0%0/3
$opts->{"deparse"} and $have_deparse and $addr
$opts->{"deparse"} $have_deparse $addr
MC/DC0%0/3
$opts->{"deparse"} and $have_deparse and $addr
$opts->{"deparse"} $have_deparse $addr
Truth table0%0/4
A and B and C
A= $opts->{"deparse"}B= $have_deparseC= $addr
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= $opts->{"deparse"}B= $have_deparseC= $addr
ABCresult
0XX0
10X0
1100
1111
94 0 ▶ my $funcname = $not_last_frame ? $frame->{fn} : "DB::DB";
Branch: 2 branches
BranchTrueFalseTotal
$not_last_frame ? : 0 0 0
$not_last_frame ? : 0 0 0
95 0 my $int_addr = $addr;
96 0 $int_addr =~ s/\s+$//g;
97 12 ▶ no warnings 'portable';
Subroutine BEGIN: called CC=1 SCAR=0.0
98 0 $int_addr = hex($int_addr);
99 0 my ($op_info) = deparse_offset($funcname, $int_addr);
100 0 ▶ if ($op_info) {
Branch: 2 branches
BranchTrueFalseTotal
if ($op_info) 0 0 0
if ($op_info) 0 0 0
101 0 ▶ if ($i != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i != 0) 0 0 0
if ($i != 0) 0 0 0
102 # All frames except the current frame we need to
103 # back up the op_info;
104 0 $op_info = get_prev_addr_info($op_info);
105 }
106 0 my $extract_texts = extract_node_info($op_info);
107 0 ▶ if ($extract_texts) {
Branch: 2 branches
BranchTrueFalseTotal
if ($extract_texts) { } 0 0 0
if ($extract_texts) { } 0 0 0
108 0 pmsg($self, join("\n", @$extract_texts))
109 } else {
110 0 pmsg($self, $op_info->{text});
111 }
112 }
113 }
114  
115 }
116  
117 sub print_stack_trace_from_to($$$$$)
118 0 ▶{
Subroutine print_stack_trace_from_to: not called CC=3 SCAR=24.8
Pod undocumented
119 0 ▶ my ($self, $from, $to, $frames, $opts) = @_;
Subroutine print_stack_trace_from_to: not called CC=3 SCAR=24.8
Pod undocumented
120 0 ▶ for (my $i=$from; $i <= $to; $i++) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i <= $to) 0 0 0
if ($i <= $to) 0 0 0
121 0 ▶ my $prefix = ($i == $opts->{current_pos}) ? '-->' : ' ';
Branch: 2 branches
BranchTrueFalseTotal
$i == $opts->{'current_pos'} ? : 0 0 0
$i == $opts->{'current_pos'} ? : 0 0 0
122 0 $prefix .= sprintf ' #%d ', $i;
123 0 $self->print_stack_entry($frames->[$i], $i, $prefix, $opts);
124 }
125 }
126  
127 # Print `count' frame entries
128 sub print_stack_trace($$$)
129 0 ▶{
Subroutine print_stack_trace: not called CC=6 SCAR=37.4
Pod undocumented
130 0 ▶ my ($self, $frames, $opts)=@_;
Subroutine print_stack_trace: not called CC=6 SCAR=37.4
Pod undocumented
131 0 ▶ $opts ||= {maxstack=>1e9, count=>1e9};
Condition0%0/4
$opts ||= {"maxstack", "1000000000", "count", "1000000000"}
l!l
00
$opts ||= {"maxstack", "1000000000", "count", "1000000000"}
l!l
00
MC/DC0%0/1
$opts ||= {"maxstack", "1000000000", "count", "1000000000"}
$opts
MC/DC0%0/1
$opts ||= {"maxstack", "1000000000", "count", "1000000000"}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
Truth table0%0/2
A
A= $opts
Aresult
11
00
132 0 my $start = 0;
133 0 my $n = scalar @{$frames};
134 0 my $halfstack = $opts->{maxstack} / 2;
135  
136 0 my $count = $opts->{count};
137 0 ▶ if ($count < 0) {
Branch: 4 branches
BranchTrueFalseTotal
if ($count < 0) { } 0 0 0
elsif ($count < $n) { } 0 0 0
if ($count < 0) { } 0 0 0
elsif ($count < $n) { } 0 0 0
138 0 $start = $n + $count;
139 0 $count = $n;
140 } elsif ($count < $n) {
141 0 $n = $count;
142 0 $halfstack = $n;
143 }
144  
145 # $opts = DEFAULT_STACK_TRACE_SETTINGS.merge(opts);
146 0 ▶ $n = $count if $opts->{count} < $n;
Branch: 2 branches
BranchTrueFalseTotal
if $opts->{"count"} < $n 0 0 0
if $opts->{"count"} < $n 0 0 0
147 0 ▶ if ($n > ($halfstack * 2)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($n > $halfstack * 2) { } 0 0 0
if ($n > $halfstack * 2) { } 0 0 0
148 0 $self->print_stack_trace_from_to($start, $halfstack-1, $frames, $opts);
149 0 my $msg = sprintf "... %d levels ...", ($n - $halfstack*2);
150 0 $self->msg($msg);
151 0 $self->print_stack_trace_from_to($n - $halfstack, $n-1, $frames, $opts);
152 } else {
153 0 $self->print_stack_trace_from_to($start, $n-1, $frames, $opts);
154 }
155 }
156  
157 12 1;
« lib/Devel/Trepan/CmdProcessor/Command/List.pm ↑ Summary blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Files.pm »