lib/Devel/Trepan/CmdProcessor/Command/Break.pm

filter: Statementstmt 43.3% 127 / 293 Branchbran 15.0% 16 / 106 Conditioncond 11.1% 2 / 18 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 80.5% 29 / 36 Podpod 0.0% 0 / 8 totaltotal 37.0% 175 / 473 CC 58 SCAR 51.4
CC
58
Cov
35%
run
265.9
run
265.9
run
265.9
CRAP 170.1
« blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Packages.pm ↑ Summary lib/Devel/Trepan/DB/Breakpoint.pm »
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2014 Rocky Bernstein <rocky@cpan.org>
3 12 ▶use warnings; no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
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
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use Devel::Trepan::DB::Sub;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
7 # require_relative '../../app/condition'
8  
9 package Devel::Trepan::CmdProcessor::Command::Break;
10 12 ▶use Devel::Trepan::DB::LineCache;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use if !@ISA, Devel::Trepan::CmdProcessor::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
13 12 ▶unless (@ISA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ISA) 11 1 12
14 12 ▶ eval <<'EOE';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
15 use constant ALIASES => qw(b);
16 use constant CATEGORY => 'breakpoints';
17 use constant SHORT_HELP => 'Set a breakpoint';
18 use constant MIN_ARGS => 0; # Need at least this many
19 use constant MAX_ARGS => undef; # Need at most this many - undef -> unlimited.
20 use constant NEED_STACK => 0;
21 EOE
22 }
23  
24 12 ▶use strict; use vars qw(@ISA); @ISA = @CMD_ISA;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
25 12 ▶use vars @CMD_VARS; # Value inherited from parent
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 2 our $NAME = set_name();
28 =head2 Synopsis:
29  
30 =cut
31 2 our $HELP = <<'HELP';
32 =pod
33  
34 B<break> [I<location>] [B<if> I<condition>]
35  
36 Set a breakpoint. If I<location> is given use the current stopping
37 point. An optional condition may be given.
38  
39 =head2 Examples:
40  
41 break # set a breakpoint on the current line
42 break gcd # set a breakpoint in function gcd
43 break gcd if $a == 1 # set a breakpoint in function gcd with
44 # condition $a == 1
45 break 10 # set breakpoint on line 10
46  
47 When a breakpoint is hit the event icon is C<xx>.
48  
49 =head2 See also:
50  
51 C<help breakpoints>, L<C<info
52 breakpoints>|Devel::Trepan::CmdProcessor::Command::Info::Breakpoints>,
53 and L<C<help syntax location>|Devel::Trepan::CmdProcessor::Command::Help::location>.
54  
55 =cut
56 HELP
57  
58 # FIXME: Should we include all files?
59 # Combine with LIST completion.
60 sub complete($$)
61 0 ▶{
Subroutine complete: not called CC=1 SCAR=3.5
Subroutine complete: not called CC=1 SCAR=3.5
Pod undocumented
Pod undocumented
62 0 ▶ my ($self, $prefix) = @_;
Subroutine complete: not called CC=1 SCAR=3.5
Pod undocumented
63 0 my $filename = $self->{proc}->filename;
64 0 my @completions = sort(('.', file_list, DB::subs,
65 trace_line_numbers($filename)));
66 0 Devel::Trepan::Complete::complete_token(\@completions, $prefix);
67 }
68  
69 # include Trepan::Condition
70  
71 # This method runs the command
72 0 ▶sub run($$) {
Subroutine run: not called CC=20 SCAR=55.8
Subroutine run: called CC=20 SCAR=55.8
Pod undocumented
Pod undocumented
73 0 ▶ my ($self, $args) = @_;
Subroutine run: not called CC=20 SCAR=55.8
Pod undocumented
74 0 my @args = @$args;
75 0 shift @args;
76 0 my $proc = $self->{proc};
77 0 my $bp;
78 0 my $arg_count = scalar @args;
79 0 ▶ if ($arg_count == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($arg_count == 0) { } 0 0 0
if ($arg_count == 0) { } 1 2 3
if ($arg_count == 0) { } 0 1 1
80 0 $bp = $self->{dbgr}->set_break($DB::filename, $DB::lineno);
81 } else {
82 0 my ($filename, $line_or_fn, $condition);
83 0 ▶ if ($arg_count > 2) {
Branch: 3 branches
BranchTrueFalseTotal
if ($arg_count > 2) { } 0 0 0
if ($arg_count > 2) { } 0 2 2
if ($arg_count > 2) { } 0 1 1
84 0 ▶ if ($args[0] eq 'if') {
Branch: 3 branches
BranchTrueFalseTotal
if ($args[0] eq 'if') { } 0 0 0
if ($args[0] eq 'if') { } 0 0 0
if ($args[0] eq 'if') { } 0 0 0
85 0 $line_or_fn = $DB::lineno;
86 0 $filename = $DB::filename;
87 0 unshift @args, $line_or_fn;
88 } else {
89 0 $filename = $args[0];
90 0 ▶ if ($args[1] =~ /\d+/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($args[1] =~ /\d+/) { } 0 0 0
elsif ($args[1] eq 'if') { } 0 0 0
if ($args[1] =~ /\d+/) { } 0 0 0
elsif ($args[1] eq 'if') { } 0 0 0
if ($args[1] =~ /\d+/) { } 0 0 0
elsif ($args[1] eq 'if') { } 0 0 0
91 0 $line_or_fn = $args[1];
92 0 shift @args;
93 } elsif ($args[1] eq 'if') {
94 0 $line_or_fn = $args[0];
95 } else {
96 0 $line_or_fn = $args[0];
97 }
98 }
99 } else {
100 # $arg_count <= 2.
101 0 $line_or_fn = $args[0];
102 0 ▶ if ($line_or_fn =~ /^\d+/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($line_or_fn =~ /^\d+/) { } 0 0 0
if ($line_or_fn =~ /^\d+/) { } 1 1 2
if ($line_or_fn =~ /^\d+/) { } 0 0 0
103 0 $filename = $DB::filename;
104 } else {
105 # FIXME: create a subroutine and combine with Deparse.
106 0 my @matches = $self->{dbgr}->subs($args[0]);
107 0 ▶ if (scalar(@matches) == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (scalar @matches == 1) { } 0 0 0
if (scalar @matches == 1) { } 1 0 1
if (scalar @matches == 1) { } 0 0 0
108 0 $filename = $matches[0][0];
109 } else {
110 0 $filename = $args[0];
111 0 my $canonic_name = map_file($filename);
112 0 ▶ if (is_cached($canonic_name)) {
Branch: 3 branches
BranchTrueFalseTotal
if (&is_cached($canonic_name)) 0 0 0
if (&is_cached($canonic_name)) 0 0 0
if (&is_cached($canonic_name)) 0 0 0
113 0 $filename = $canonic_name;
114 }
115 }
116 }
117 0 ▶ if ($arg_count == 2 && $args[1] =~ /\d+/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($arg_count == 2 and $args[1] =~ /\d+/) 0 0 0
if ($arg_count == 2 and $args[1] =~ /\d+/) 1 1 2
if ($arg_count == 2 and $args[1] =~ /\d+/) 0 0 0
Condition22%2/9
$arg_count == 2 and $args[1] =~ /\d+/
!ll&&!rl&&r
000
$arg_count == 2 and $args[1] =~ /\d+/
!ll&&!rl&&r
101
$arg_count == 2 and $args[1] =~ /\d+/
!ll&&!rl&&r
000
MC/DC0%0/2
$arg_count == 2 and $args[1] =~ /\d+/
$arg_count == 2 $args[1] =~ /\d+/
MC/DC50%1/2
$arg_count == 2 and $args[1] =~ /\d+/
$arg_count == 2 $args[1] =~ /\d+/
MC/DC0%0/2
$arg_count == 2 and $args[1] =~ /\d+/
$arg_count == 2 $args[1] =~ /\d+/
Truth table0%0/3
A and B
A= $arg_count == 2B= $args[1] =~ /\d+/
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= $arg_count == 2B= $args[1] =~ /\d+/
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $arg_count == 2B= $args[1] =~ /\d+/
ABresult
0X0
100
111
118 0 $line_or_fn = $args[1];
119 0 shift @args;
120 }
121 }
122 0 shift @args;
123 0 ▶ if (scalar @args) {
Branch: 3 branches
BranchTrueFalseTotal
if (scalar @args) 0 0 0
if (scalar @args) 0 2 2
if (scalar @args) 0 0 0
124 0 ▶ if ($args[0] eq 'if') {
Branch: 3 branches
BranchTrueFalseTotal
if ($args[0] eq 'if') { } 0 0 0
if ($args[0] eq 'if') { } 0 0 0
if ($args[0] eq 'if') { } 0 0 0
125 0 shift @args;
126 0 $condition = join(' ', @args);
127 } else {
128 0 $proc->errmsg("Expecting 'if' to start breakpoint condition;" .
129 " got ${args[0]}");
130 }
131 }
132 0 my $msg = $self->{dbgr}->break_invalid(\$filename, $line_or_fn);
133 0 my $force = 0;
134 0 ▶ if ($msg) {
Branch: 3 branches
BranchTrueFalseTotal
if ($msg) 0 0 0
if ($msg) 0 2 2
if ($msg) 0 0 0
135 0 ▶ if ($msg =~ /not known to be a trace line/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($msg =~ /not known to be a trace line/) 0 0 0
if ($msg =~ /not known to be a trace line/) 0 0 0
if ($msg =~ /not known to be a trace line/) 0 0 0
136 0 $proc->errmsg($msg);
137 0 $proc->msg("Use 'info file $filename brkpts' to see breakpoints I know about");
138 0 $force = $self->{proc}->confirm('Set breakpoint anyway?', 0);
139 0 ▶ return unless $force;
Branch: 3 branches
BranchTrueFalseTotal
unless $force 0 0 0
unless $force 0 0 0
unless $force 0 0 0
140 }
141 }
142 0 $bp = $self->{dbgr}->set_break($filename, $line_or_fn,
143 $condition, undef, undef, undef, $force);
144 }
145 0 ▶ if (defined($bp)) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $bp) 0 0 0
if (defined $bp) 0 3 3
if (defined $bp) 0 0 0
146 0 ▶ my $prefix = $bp->type eq 'tbrkpt' ?
Branch: 3 branches
BranchTrueFalseTotal
$bp->type eq 'tbrkpt' ? : 0 0 0
$bp->type eq 'tbrkpt' ? : 0 0 0
$bp->type eq 'tbrkpt' ? : 0 0 0
147 'Temporary breakpoint' : 'Breakpoint' ;
148 0 my $id = $bp->id;
149 0 my $filename = $proc->canonic_file($bp->filename);
150 0 my $line_num = $bp->line_num;
151 0 $proc->{brkpts}->add($bp);
152 0 $proc->msg("$prefix $id set in $filename at line $line_num");
153 # Warn if we are setting a breakpoint on a line that starts
154 # "use.."
155 0 my $text = getline($bp->filename, $line_num, {output => 'plain'});
156 0 ▶ if (defined($text) && $text =~ /^\s*use\s+/) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $text and $text =~ /^\s*use\s+/) 0 0 0
if (defined $text and $text =~ /^\s*use\s+/) 0 0 0
if (defined $text and $text =~ /^\s*use\s+/) 0 0 0
Condition0%0/9
defined $text and $text =~ /^\s*use\s+/
!ll&&!rl&&r
000
defined $text and $text =~ /^\s*use\s+/
!ll&&!rl&&r
000
defined $text and $text =~ /^\s*use\s+/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $text and $text =~ /^\s*use\s+/
defined $text $text =~ /^\s*use\s+/
MC/DC0%0/2
defined $text and $text =~ /^\s*use\s+/
defined $text $text =~ /^\s*use\s+/
MC/DC0%0/2
defined $text and $text =~ /^\s*use\s+/
defined $text $text =~ /^\s*use\s+/
Truth table0%0/3
A and B
A= defined $textB= $text =~ /^\s*use\s+/
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $textB= $text =~ /^\s*use\s+/
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $textB= $text =~ /^\s*use\s+/
ABresult
0X0
100
111
157 0 $proc->msg("Warning: 'use' statements get evaluated at compile time... You may have already passed this statement.");
158 }
159 }
160 }
161  
162 2 ▶unless (caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 12 12
163 # FIXME: DRY this code by putting in common location.
164 0 require Devel::Trepan::DB;
165 0 require Devel::Trepan::Core;
166 0 my $db = Devel::Trepan::Core->new;
167 0 my $intf = Devel::Trepan::Interface::User->new(undef, undef,
168 {readline => 0});
169 0 my $proc = Devel::Trepan::CmdProcessor->new([$intf], $db);
170 0 $proc->{stack_size} = 0;
171 0 my $cmd = __PACKAGE__->new($proc);
172  
173 eval {
174 0 ▶ sub db_setup() {
Subroutine db_setup: not called CC=1 SCAR=0.2
Subroutine db_setup: not called CC=1 SCAR=0.2
Pod undocumented
Pod undocumented
175 12 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
176 0 $DB::caller = [caller];
177 ($DB::package, $DB::filename, $DB::lineno, $DB::subroutine)
178 0 = @{$DB::caller};
179 }
180 10 };
181 0 db_setup();
182  
183 0 $cmd->run([$NAME]);
184 # $cmd->run([$NAME, "/usr/share/perl/5.14.2/File/Basename.pm", "3"]);
185 }
186  
187 2 1;
« blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Packages.pm ↑ Summary lib/Devel/Trepan/DB/Breakpoint.pm »