lib/Devel/Trepan/Processor/Frame.pm

filter: Statementstmt 23.7% 43 / 181 Branchbran 2.7% 2 / 72 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 39.2% 11 / 28 Podpod 0.0% 0 / 20 totaltotal 17.0% 56 / 329 CC 45 SCAR 40.7
CC
45
Cov
17%
frame_setup
135.4
frame_setup
135.4
get_frame
42.0
CRAP 58.4
« blib/lib/Devel/Trepan/CmdProcessor/Location.pm ↑ Summary blib/lib/Devel/Trepan/SigHandler.pm »
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2012-2015, 2018 Rocky Bernstein <rocky@cpan.org>
3 12 ▶use strict; use warnings; use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
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
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::Processor;
9  
10 12 ▶use vars qw(@EXPORT @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 @EXPORT = qw( adjust_frame );
12 12 @ISA = qw(Exporter);
13  
14 12 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 sub adjust_frame($$$)
17 0 ▶{
Subroutine adjust_frame: not called CC=3 SCAR=24.8
Pod undocumented
18 0 ▶ my ($self, $frame_num, $absolute_pos) = @_;
Subroutine adjust_frame: not called CC=3 SCAR=24.8
Pod undocumented
19 0 my $frame;
20 0 ($frame, $frame_num) = $self->get_frame($frame_num, $absolute_pos);
21 0 ▶ if ($frame) {
Branch: 2 branches
BranchTrueFalseTotal
if ($frame) { } 0 0 0
if ($frame) { } 0 0 0
22 0 $self->{frame} = $frame;
23 0 $self->{frame_index} = $frame_num;
24 0 ▶ unless ($self->{settings}{traceprint}) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->{"settings"}{"traceprint"}) 0 0 0
unless ($self->{"settings"}{"traceprint"}) 0 0 0
25 my $opts = {
26 basename => $self->{settings}{basename},
27 current_pos => $frame_num,
28 maxwidth => $self->{settings}{maxwidth},
29 displayop => $self->{settings}{displayop},
30 0 };
31 0 $self->print_stack_trace_from_to($frame_num, $frame_num, $self->{frames}, $opts);
32 0 $self->print_location ;
33 }
34 0 $self->{list_line} = $self->line();
35 0 $self->{list_filename} = $self->filename();
36 0 $self->{frame};
37 } else {
38 undef
39 0 }
40 }
41  
42 sub frame_low_high($;$)
43 0 ▶{
Subroutine frame_low_high: not called CC=3 SCAR=24.8
Pod undocumented
44 0 ▶ my ($self, $direction) = @_;
Subroutine frame_low_high: not called CC=3 SCAR=24.8
Pod undocumented
45 0 ▶ $direction = 1 unless defined $direction;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $direction 0 0 0
unless defined $direction 0 0 0
46 0 my $stack_size = $self->{stack_size};
47 0 my ($low, $high) = (-$stack_size, $stack_size-1);
48 0 ▶ ($low, $high) = ($high, $low) if ($direction < 0);
Branch: 2 branches
BranchTrueFalseTotal
if $direction < 0 0 0 0
if $direction < 0 0 0 0
49 0 return ($low, $high);
50 }
51  
52 sub frame_setup($$)
53 1 ▶{
Subroutine frame_setup: called CC=13 SCAR=49.1
Pod undocumented
54 0 ▶ my ($self, $frame_aref) = @_;
Subroutine frame_setup: not called CC=13 SCAR=49.1
Pod undocumented
55  
56 0 ▶ if (defined $frame_aref) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $frame_aref) { } 1 0 1
if (defined $frame_aref) { } 0 0 0
57 0 $self->{frames} = $frame_aref;
58 0 $self->{stack_size} = $#{$self->{frames}}+1;
59 } else {
60 ### FIXME: look go over this code.
61 # $stack_size contains the stack ignoring frames
62 # of this debugger.
63 0 my $stack_size = $DB::stack_depth;
64 0 my @frames = $self->{dbgr}->tbacktrace(0);
65 0 ▶ @frames = splice(@frames, 2) if $self->{dbgr}{caught_signal};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"dbgr"}{"caught_signal"} 0 0 0
if $self->{"dbgr"}{"caught_signal"} 0 0 0
66  
67 0 ▶ if ($self->{event} eq 'post-mortem') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'event'} eq 'post-mortem') { } 0 0 0
if ($self->{'event'} eq 'post-mortem') { } 0 0 0
68 0 $stack_size = 0;
69 0 for my $frame (@frames) {
70 0 ▶ next unless defined($frame) && exists($frame->{file});
Branch: 2 branches
BranchTrueFalseTotal
unless defined $frame and exists $frame->{"file"} 0 0 0
unless defined $frame and exists $frame->{"file"} 0 0 0
Condition0%0/6
defined $frame and exists $frame->{"file"}
!ll&&!rl&&r
000
defined $frame and exists $frame->{"file"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $frame and exists $frame->{"file"}
defined $frame exists $frame->{"file"}
MC/DC0%0/2
defined $frame and exists $frame->{"file"}
defined $frame exists $frame->{"file"}
Truth table0%0/3
A and B
A= defined $frameB= exists $frame->{"file"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $frameB= exists $frame->{"file"}
ABresult
0X0
100
111
71 0 $stack_size ++;
72 }
73 } else {
74  
75 # Figure out how many frames this debugger put in.
76 0 my $debugger_frames_to_skip=0;
77 0 ▶ while (my ($pkg, $file, $line, $fn) =
Branch: 2 branches
BranchTrueFalseTotal
if (() = caller $debugger_frames_to_skip++) 0 0 0
if (() = caller $debugger_frames_to_skip++) 0 0 0
78 caller($debugger_frames_to_skip++)) {
79 0 ▶ last if 'DB::DB' eq $fn or ('DB' eq $pkg && 'DB' eq $fn);
Branch: 2 branches
BranchTrueFalseTotal
if "DB::DB" eq $fn or "DB" eq $pkg and "DB" eq $fn 0 0 0
if "DB::DB" eq $fn or "DB" eq $pkg and "DB" eq $fn 0 0 0
Condition0%0/12
"DB::DB" eq $fn or "DB" eq $pkg and "DB" eq $fn
l!l&&r!l&&!r
000
"DB" eq $pkg and "DB" eq $fn
!ll&&!rl&&r
000
"DB::DB" eq $fn or "DB" eq $pkg and "DB" eq $fn
l!l&&r!l&&!r
000
"DB" eq $pkg and "DB" eq $fn
!ll&&!rl&&r
000
MC/DC0%0/3
"DB::DB" eq $fn or "DB" eq $pkg and "DB" eq $fn
"DB::DB" eq $fn "DB" eq $pkg "DB" eq $fn
MC/DC0%0/3
"DB::DB" eq $fn or "DB" eq $pkg and "DB" eq $fn
"DB::DB" eq $fn "DB" eq $pkg "DB" eq $fn
Truth table0%0/4
A or B and C
A= "DB::DB" eq $fnB= "DB" eq $pkgC= "DB" eq $fn
ABCresult
1XX1
0111
00X0
0100
Truth table0%0/4
A or B and C
A= "DB::DB" eq $fnB= "DB" eq $pkgC= "DB" eq $fn
ABCresult
1XX1
0111
00X0
0100
80 }
81  
82 # Dynamic debugging might not have set $DB::stack_depth
83 # correctly. So we'll doublecheck it here.
84 # $stack_size_with_debugger contains the stack depth
85 # *including* frames added by this debugger.
86 0 my $stack_size_with_debugger = $debugger_frames_to_skip;
87 0 ▶ $stack_size_with_debugger++ while defined caller($stack_size_with_debugger);
Branch: 2 branches
BranchTrueFalseTotal
defined caller $stack_size_with_debugger and do { ++$stack_size_with_debugger } 0 0 0
defined caller $stack_size_with_debugger and do { ++$stack_size_with_debugger } 0 0 0
88  
89 # Adjust for the fact that caller starts at 0;
90 0 $stack_size_with_debugger++;
91  
92 0 my $computed_stack_depth =
93 $stack_size_with_debugger - $debugger_frames_to_skip;
94  
95 # printf("+++ debugger_frames_to_skip: %d, stack_size_with_debugger %d\n",
96 # $debugger_frames_to_skip, $stack_size_with_debugger);
97 # printf("+++ computed_stack_depth: %d DB::stack_depth\n", $computed_stack_depth, $DB::stack_depth);
98 # use Carp qw(cluck); cluck('testing');
99  
100 ## This sometimes happens, but it confused Dmitrios, so remove
101 ## for now...
102 # if ((!defined $DB::stack_depth
103 # or $DB::stack_depth < $computed_stack_depth)
104 # and !$self->{gave_stack_trunc_warning}) {
105 # $self->errmsg(
106 # "Call stack depth recorded in DB module is short. We've adjusted it.");
107 # $self->{gave_stack_trunc_warning} = 1;
108 # }
109  
110 0 $stack_size = $computed_stack_depth;
111 0 ▶ $stack_size++ if $self->{event} eq 'call';
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"event"} eq "call" 0 0 0
if $self->{"event"} eq "call" 0 0 0
112 }
113 0 $self->{frames} = \@frames;
114 0 $self->{stack_size} = $stack_size;
115 }
116  
117 0 $self->{frame_index} = 0;
118 0 $self->{hide_level} = 0;
119 0 $self->{frame} = $self->{frames}[0];
120 0 $self->{list_line} = $self->line();
121 0 $self->{list_filename} = $self->filename();
122 }
123  
124 sub filename($)
125 1 ▶{
Subroutine filename: called CC=2 SCAR=11.2
Pod undocumented
126 0 ▶ my $self = shift;
Subroutine filename: not called CC=2 SCAR=11.2
Pod undocumented
127 0 my $filename = $self->{frame}{file};
128 0 ▶ if (filename_is_eval($filename)) {
Branch: 2 branches
BranchTrueFalseTotal
if (&filename_is_eval($filename)) { } 0 1 1
if (&filename_is_eval($filename)) { } 0 0 0
129 0 return $filename;
130 } else {
131 0 return map_file($filename);
132 }
133 }
134  
135 sub funcname($)
136 0 ▶{
Subroutine funcname: not called CC=1 SCAR=6.9
Pod undocumented
137 0 ▶ my $self = shift;
Subroutine funcname: not called CC=1 SCAR=6.9
Pod undocumented
138 0 $self->{frame}{fn};
139 }
140  
141 sub get_frame($$$)
142 0 ▶{
Subroutine get_frame: not called CC=6 SCAR=37.4
Pod undocumented
143 0 ▶ my ($self, $frame_num, $absolute_pos) = @_;
Subroutine get_frame: not called CC=6 SCAR=37.4
Pod undocumented
144 0 my $stack_size = $self->{stack_size};
145  
146 0 ▶ if ($absolute_pos) {
Branch: 2 branches
BranchTrueFalseTotal
if ($absolute_pos) { } 0 0 0
if ($absolute_pos) { } 0 0 0
147 0 ▶ $frame_num += $stack_size if $frame_num < 0;
Branch: 2 branches
BranchTrueFalseTotal
if $frame_num < 0 0 0 0
if $frame_num < 0 0 0 0
148 } else {
149 0 $frame_num += $self->{frame_index};
150 }
151  
152 0 ▶ if ($frame_num < 0) {
Branch: 4 branches
BranchTrueFalseTotal
if ($frame_num < 0) { } 0 0 0
elsif ($frame_num >= $stack_size) { } 0 0 0
if ($frame_num < 0) { } 0 0 0
elsif ($frame_num >= $stack_size) { } 0 0 0
153 0 $self->errmsg('Adjusting would put us beyond the newest frame.');
154 0 return (undef, undef);
155 } elsif ($frame_num >= $stack_size) {
156 0 $self->errmsg('Adjusting would put us beyond the oldest frame.');
157 0 return (undef, undef);
158 }
159  
160 0 my $frames = $self->{frames};
161 0 ▶ unless ($frames->[$frame_num]) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($frames->[$frame_num]) 0 0 0
unless ($frames->[$frame_num]) 0 0 0
162 0 my @new_frames = $self->{dbgr}->tbacktrace(0);
163 0 $self->{frames}[$frame_num] = $new_frames[$frame_num];
164 }
165 0 $self->{frame} = $frames->[$frame_num];
166 0 return ($self->{frame}, $frame_num);
167 }
168  
169 sub line($)
170 1 ▶{
Subroutine line: called CC=1 SCAR=1.2
Pod undocumented
171 0 ▶ my $self = shift;
Subroutine line: not called CC=1 SCAR=1.2
Pod undocumented
172 0 $self->{frame}{line};
173 }
174  
175 sub print_stack_entry()
176 0 ▶{
Subroutine print_stack_entry: not called CC=1 SCAR=6.9
Pod undocumented
177 0 ▶ die "This should have been implemented somewhere else"
Subroutine print_stack_entry: not called CC=1 SCAR=6.9
Pod undocumented
178 }
179  
180 sub print_stack_trace_from_to($$$$$)
181 0 ▶{
Subroutine print_stack_trace_from_to: not called CC=1 SCAR=6.9
Pod undocumented
182 0 ▶ die "This should have been implemented somewhere else"
Subroutine print_stack_trace_from_to: not called CC=1 SCAR=6.9
Pod undocumented
183 }
184  
185 # Print `count' frame entries
186 sub print_stack_trace($$$)
187 0 ▶{
Subroutine print_stack_trace: not called CC=1 SCAR=6.9
Pod undocumented
188 0 ▶ die "This should have been implemented somewhere else"
Subroutine print_stack_trace: not called CC=1 SCAR=6.9
Pod undocumented
189 }
190  
191 12 1;
« blib/lib/Devel/Trepan/CmdProcessor/Location.pm ↑ Summary blib/lib/Devel/Trepan/SigHandler.pm »