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

filter: Statementstmt 31.4% 67 / 213 Branchbran 5.8% 4 / 68 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.0% 18 / 29 Podpod 0.0% 0 / 11 totaltotal 27.7% 89 / 321 CC 43 SCAR 33.5
CC
43
Cov
25%
run
63.3
run
63.3
run
63.3
CRAP 28.5
« lib/Devel/Trepan/CmdProcessor/Command/Quit.pm ↑ Summary blib/lib/Devel/Trepan/CmdProcessor/Command/Subcmd/SubMgr.pm »
1 # Copyright (C) 2011-2012, 2014 Rocky Bernstein <rocky@cpan.org>
2 # -*- coding: utf-8 -*-
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 # disable breakpoint command. The difference however is that the
7 # parameter to @proc.en_disable_breakpoint_by_number is different (set
8 # as ENABLE_PARM below).
9 #
10 # NOTE: The enable command subclasses this, so beware when changing!
11 package Devel::Trepan::CmdProcessor::Command::Enable;
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 1 ▶unless (@ISA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ISA) 0 1 1
14 0 ▶ 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
15 use constant CATEGORY => 'breakpoints';
16 use constant SHORT_HELP => 'Enable some breakpoints';
17 use constant MIN_ARGS => 0; # Need at least this many
18 use constant MAX_ARGS => undef; # Need at most this many - undef -> unlimited.
19 EOE
20 }
21  
22 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
23 12 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 @ISA = @CMD_ISA;
26 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
27  
28 # require_relative '../breakpoint'
29 # require_relative '../../app/util'
30  
31 1 our $NAME = set_name();
32 =pod
33  
34 =head2 Synopsis:
35  
36 =cut
37 1 our $HELP = <<"HELP";
38 =pod
39  
40 B<enable> I<num> [I<num> ...]
41  
42 Enables breakpoints, watch expressions or actions given as a space
43 separated list of numbers which may be prefaces with an 'a', 'b', or 'w'.
44 The prefaces are interpreted as follows:
45  
46 =over
47  
48 =item a E<mdash> action number
49  
50 =item b E<mdash> breakpoint number
51  
52 =item w E<mdash> expression number
53  
54 =back
55  
56 If I<num> is starts with a digit, I<num> is taken to be a breakpoint number.
57  
58 =head2 Examples:
59  
60 enable 1 2 # Enable breakpoint 1 and 2
61 enable b1 b2 # Same as above
62 enable a4 # Enable action 4
63 enable w1 2 # Enable watch expression 1 and breakpoint 2
64  
65 =head2 See also:
66  
67 L<C<info break>|Devel::Trepan::CmdProcessor::Command::Info::Break> to
68 get a list of breakpoints, and
69 L<C<disable>|<Devel::Trepan::CmdProcessor::Command::Disable> to
70 disable breakpoints.
71  
72 =cut
73 HELP
74  
75 ### FIXME: parameterize and combine these. Also combine with disable.
76 0 ▶sub enable_breakpoint($$) {
Subroutine enable_breakpoint: not called CC=3 SCAR=24.8
Subroutine enable_breakpoint: not called CC=3 SCAR=24.8
Pod undocumented
Pod undocumented
77 0 ▶ my ($proc, $i) = @_;
Subroutine enable_breakpoint: not called CC=3 SCAR=24.8
Pod undocumented
78 0 my $bp = $proc->{brkpts}->find($i);
79 0 my $msg;
80 0 ▶ if ($bp) {
Branch: 3 branches
BranchTrueFalseTotal
if ($bp) { } 0 0 0
if ($bp) { } 0 0 0
if ($bp) { } 0 0 0
81 0 ▶ if ($bp->enabled) {
Branch: 3 branches
BranchTrueFalseTotal
if ($bp->enabled) { } 0 0 0
if ($bp->enabled) { } 0 0 0
if ($bp->enabled) { } 0 0 0
82 0 $msg = sprintf("Breakpoint %d already enabled", $bp->id);
83 0 $proc->errmsg($msg);
84 } else {
85 0 $bp->enabled(1);
86 0 $msg = sprintf("Breakpoint %d enabled", $bp->id);
87 0 $proc->msg($msg);
88 }
89 } else {
90 0 $msg = sprintf("No breakpoint %d found", $i);
91 0 $proc->errmsg($msg);
92 }
93 }
94  
95 0 ▶sub enable_watchpoint($$) {
Subroutine enable_watchpoint: not called CC=3 SCAR=24.8
Subroutine enable_watchpoint: not called CC=3 SCAR=24.8
Pod undocumented
Pod undocumented
96 0 ▶ my ($proc, $i) = @_;
Subroutine enable_watchpoint: not called CC=3 SCAR=24.8
Pod undocumented
97 0 my $wp = $proc->{dbgr}{watch}->find($i);
98 0 my $msg;
99 0 ▶ if ($wp) {
Branch: 3 branches
BranchTrueFalseTotal
if ($wp) { } 0 0 0
if ($wp) { } 0 0 0
if ($wp) { } 0 0 0
100 0 ▶ if ($wp->enabled) {
Branch: 3 branches
BranchTrueFalseTotal
if ($wp->enabled) { } 0 0 0
if ($wp->enabled) { } 0 0 0
if ($wp->enabled) { } 0 0 0
101 0 $msg = sprintf("Watch expression %d already enabled", $wp->id);
102 0 $proc->errmsg($msg);
103 } else {
104 0 $wp->enabled(1);
105 0 $msg = sprintf("Watch expression %d enabled", $wp->id);
106 0 $proc->msg($msg);
107 }
108 } else {
109 0 $msg = sprintf("No watchpoint %d found", $i);
110 0 $proc->errmsg($msg);
111 }
112 }
113  
114 0 ▶sub enable_action($$) {
Subroutine enable_action: not called CC=3 SCAR=24.8
Subroutine enable_action: not called CC=3 SCAR=24.8
Pod undocumented
Pod undocumented
115 0 ▶ my ($proc, $i) = @_;
Subroutine enable_action: not called CC=3 SCAR=24.8
Pod undocumented
116 0 my $act = $proc->{actions}->find($i);
117 0 my $msg;
118 0 ▶ if ($act) {
Branch: 3 branches
BranchTrueFalseTotal
if ($act) { } 0 0 0
if ($act) { } 0 0 0
if ($act) { } 0 0 0
119 0 ▶ if ($act->enabled) {
Branch: 3 branches
BranchTrueFalseTotal
if ($act->enabled) { } 0 0 0
if ($act->enabled) { } 0 0 0
if ($act->enabled) { } 0 0 0
120 0 $msg = sprintf("Action %d already enabled", $act->id);
121 0 $proc->errmsg($msg);
122 } else {
123 0 $act->enabled(1);
124 0 $msg = sprintf("Action %d enabled", $act->id);
125 0 $proc->msg($msg);
126 }
127 } else {
128 0 $msg = sprintf("No action %d found", $i);
129 0 $proc->errmsg($msg);
130 }
131 }
132  
133 sub run($$)
134 0 ▶{
Subroutine run: not called CC=9 SCAR=41.5
Subroutine run: not called CC=9 SCAR=41.5
Pod undocumented
Pod undocumented
135 0 my ($self, $args) = @_;
136 0 my $proc = $self->{proc};
137 0 my @args = @{$args};
138 0 ▶ if (scalar @args == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @args == 1) 0 0 0
if (scalar @args == 1) 11 0 11
139 0 $proc->errmsg('No breakpoint number given.');
140 0 return;
141 }
142 0 my $first = shift @args;
143 0 for my $num_str (@args) {
144 0 my $type = lc(substr($num_str,0,1));
145 0 ▶ if ($type !~ /[0-9baw]/) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($type =~ /[0-9baw]/) 0 0 0
unless ($type =~ /[0-9baw]/) 0 11 11
146 0 $proc->errmsg("Invalid prefix $type. Argument $num_str ignored");
147 0 next;
148 }
149 0 ▶ if ($type =~ /[0-9]/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ /[0-9]/) { } 0 0 0
if ($type =~ /[0-9]/) { } 0 0 0
150 0 $type='b';
151 } else {
152 0 $num_str = substr($num_str, 1);
153 }
154 0 my $i = $proc->get_an_int($num_str);
155 0 ▶ if (defined $i) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $i) 0 0 0
if (defined $i) 0 0 0
156 0 ▶ if ('a' eq $type) {
Branch: 6 branches
BranchTrueFalseTotal
if ('a' eq $type) { } 0 0 0
elsif ('b' eq $type) { } 0 0 0
elsif ('w' eq $type) { } 0 0 0
if ('a' eq $type) { } 0 0 0
elsif ('b' eq $type) { } 0 0 0
elsif ('w' eq $type) { } 0 0 0
157 0 enable_action($proc, $i);
158 } elsif ('b' eq $type) {
159 0 enable_breakpoint($proc, $i);
160 } elsif ('w' eq $type) {
161 0 enable_watchpoint($proc, $i);
162 }
163 }
164 }
165 }
166  
167 1 ▶unless (caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 1 1
168 # require_relative '../mock'
169 # dbgr, cmd = MockDebugger::setup
170 # cmd.run([cmd.name])
171 # cmd.run([cmd.name, '1'])
172 # cmdproc = dbgr.core.processor
173 # cmds = cmdproc.commands
174 # break_cmd = cmds['break']
175 # break_cmd.run(['break', cmdproc.frame.source_location[0].to_s])
176 # # require_relative '../../lib/trepanning'
177 # # Trepan.debug
178 # cmd.run([cmd.name, '1'])
179 }
180  
181 1 1;
« lib/Devel/Trepan/CmdProcessor/Command/Quit.pm ↑ Summary blib/lib/Devel/Trepan/CmdProcessor/Command/Subcmd/SubMgr.pm »