File Coverage

lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Breakpoints.pm
Criterion Covered Total %
statement 48 232 20.6
branch 0 96 0.0
condition 0 12 0.0
subroutine 16 24 66.6
pod n/a
total 64 364 17.5


line stmt bran cond sub pod time code
1             # -*- coding: utf-8 -*-
2             # Copyright (C) 2011-2012, 2014 Rocky Bernstein <rocky@cpan.org>
3 12     12   103 use warnings; use utf8;
  12     12   35  
  12     1   434  
  12     1   72  
  12         30  
  12         82  
  1         8  
  1         3  
  1         26  
  1         5  
  1         2  
  1         7  
4 12     12   337 use rlib '../../../../..';
  12     1   34  
  12         72  
  1         23  
  1         3  
  1         6  
5              
6             package Devel::Trepan::CmdProcessor::Command::Info::Breakpoints;
7 12     12   10154 use Devel::Trepan::CmdProcessor::Command::Subcmd::Core;
  12     1   48  
  12         368  
  1         377  
  1         3  
  1         20  
8              
9 12     12   78 use strict;
  12     1   31  
  12         285  
  1         5  
  1         2  
  1         23  
10 12     12   70 use vars qw(@ISA @SUBCMD_VARS);
  12     1   30  
  12         751  
  1         5  
  1         2  
  1         62  
11             @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd);
12             # Values inherited from parent
13 12     12   77 use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS;
  12     1   77  
  12         1991  
  1         5  
  1         3  
  1         152  
14              
15             our $SHORT_HELP = 'List breakpoint information';
16              
17             ## FIXME: do automatically.
18             our $CMD = "info breakpoints";
19              
20             our $HELP = <<'HELP';
21             =pod
22              
23             B<info breakpoints> [I<num1> ...] [B<verbose>]
24              
25             Show status of user-settable breakpoints. If no breakpoint numbers are
26             given, the show all breakpoints. Otherwise only those breakpoints
27             listed are shown and the order given. If B<verbose> is given, more
28             information provided about each breakpoint.
29              
30             =head2 Examples:
31              
32             trepanpl: info breakpoints
33             Num Type Disp Enb Where
34             1 breakpoint keep y at gcd.pl:8
35             breakpoint already hit 1 time
36             No actions.
37             No watch expressions defined.
38              
39             The I<Disp> column contains one of I<keep>, I<del>, the disposition of
40             the breakpoint after it gets hit.
41              
42             The I<Enb> column indicates whether the breakpoint is enabled.
43              
44             The I<Where> column indicates where the breakpoint is located.
45              
46             =head2 See also:
47              
48             L<C<break>|Devel::Trepan::CmdProcessor::Command::Action>,
49             L<C<break>|Devel::Trepan::CmdProcessor::Command::Break>,
50             L<C<disable>|<Devel::Trepan::CmdProcessor::Command::Disable>,
51             L<C<enable>|<Devel::Trepan::CmdProcessor::Command::Enable>,
52             L<C<watch>|<Devel::Trepan::CmdProcessor::Command::Watch>, and
53             L<C<help syntax location>|Devel::Trepan::CmdProcessor::Command::Help::location>.
54              
55              
56             =cut
57             HELP
58              
59             our $MIN_ABBREV = length('br');
60              
61 12     12   86 no warnings 'redefine';
  12     1   33  
  12         12518  
  1         5  
  1         3  
  1         910  
62             sub complete($$)
63             {
64 0     0     my ($self, $prefix) = @_;
  0     0      
65 0           my @completions = $self->{proc}{brkpts}->ids;
  0            
66 0           Devel::Trepan::Complete::complete_token(\@completions, $prefix);
  0            
67             }
68              
69             sub bpprint($$;$)
70             {
71 0     0     my ($self, $bp, $verbose) = @_;
  0     0      
72 0           my $proc = $self->{proc};
  0            
73 0 0         my $disp = ($bp->type eq 'tbreak') ? 'del ' : 'keep ';
  0 0          
74 0 0         $disp .= $bp->enabled ? 'y ' : 'n ';
  0 0          
75              
76 0           my $line_loc = sprintf('%s:%d', $proc->canonic_file($bp->filename),
  0            
77             $bp->line_num);
78              
79 0           my $mess = sprintf('%-4dbreakpoint %s at %s',
  0            
80             $bp->id, $disp, $line_loc);
81 0           $proc->msg($mess);
  0            
82              
83 0 0 0       if ($bp->condition && $bp->condition ne '1') {
  0 0 0        
84 0 0         my $msg = sprintf("\tstop %s %s",
  0 0          
85             $bp->negate ? "unless" : "only if",
86             $bp->condition);
87 0           $proc->msg($msg);
  0            
88             }
89 0 0         if ($bp->hits > 0) {
  0 0          
90 0 0         my $ss = ($bp->hits > 1) ? 's' : '';
  0 0          
91 0           my $msg = sprintf("\tbreakpoint already hit %d time%s",
  0            
92             $bp->hits, $ss);
93 0           $proc->msg($msg);
  0            
94             }
95             }
96              
97             sub action_print($$;$)
98             {
99 0     0     my ($self, $action, $verbose) = @_;
  0     0      
100 0           my $proc = $self->{proc};
  0            
101 0 0         my $disp = $action->enabled ? 'y ' : 'n ';
  0 0          
102              
103 0           my $line_loc = sprintf('%s:%d', $action->filename, $action->line_num);
  0            
104              
105 0           my $mess = sprintf('%-4daction %s at %s',
  0            
106             $action->id, $disp, $line_loc);
107 0           $proc->msg($mess);
  0            
108              
109 0 0 0       if ($action->condition && $action->condition ne '1') {
  0 0 0        
110 0           my $msg = sprintf("\texpression: %s", $action->condition);
  0            
111 0           $proc->msg($msg);
  0            
112             }
113 0 0         if ($action->hits > 0) {
  0 0          
114 0 0         my $ss = ($action->hits > 1) ? 's' : '';
  0 0          
115 0           my $msg = sprintf("\taction already hit %d time%s",
  0            
116             $action->hits, $ss);
117 0           $proc->msg($msg);
  0            
118             }
119             }
120              
121              
122             # sub save_command($)
123             # {
124             # my $self = shift;
125             # my $proc = $self->{proc};
126             # my $bpmgr = $proc->{brkpts};
127             # my @res = ();
128             # for my $bp ($bpmgr->list) {
129             # push @res, "break ${loc}";
130             # }
131             # return @res;
132             # }
133              
134             sub run($$) {
135 0     0     my ($self, $args) = @_;
  0     0      
136 0           my $verbose = 0;
  0            
137 0           my $proc = $self->{proc};
  0            
138 0 0         unless (scalar @$args) {
  0 0          
139 0 0         if ('verbose' eq $args->[-1]) {
  0 0          
140 0           $verbose = 1;
  0            
141 0           pop @{$args};
  0            
  0            
  0            
142             }
143             }
144              
145 0           my $show_all = 1;
  0            
146 0           my $show_actions = 1;
  0            
147 0           my $show_watch = 1;
  0            
148 0           my @args = ();
  0            
149 0 0         if (scalar @{$args} > 2) {
  0 0          
  0            
  0            
150 0           @args = splice(@{$args}, 2);
  0            
  0            
  0            
151 0           my $max = $proc->{brkpts}->max;
  0            
152 0           my $opts = {
  0            
153             msg_on_error =>
154             "An '${CMD}' argument must eval to a breakpoint between 1..${max}.",
155             min_value => 1,
156             max_value => $max
157             };
158 0           @args = $proc->get_int_list(\@args);
  0            
159 0           $show_all = $show_watch = $show_actions = 0;
  0            
160             }
161              
162 0           my $bpmgr = $proc->{brkpts};
  0            
163 0           $bpmgr->compact;
  0            
164 0           my @brkpts = @{$bpmgr->{list}};
  0            
  0            
  0            
165 0 0         if (0 == scalar @brkpts) {
  0 0          
166 0           $proc->msg('No breakpoints.');
  0            
167             } else {
168             # There's at least one
169 0           $proc->section("Num Type Disp Enb Where");
  0            
170 0 0         if ($show_all) {
  0 0          
171 0           for my $bp (@brkpts) {
  0            
172 0           $self->bpprint($bp, $verbose);
  0            
173             }
174             } else {
175 0           my @not_found = ();
  0            
176 0           for my $bp_num (@args) {
  0            
177 0 0         next unless $bp_num;
  0 0          
178 0           my $bp = $bpmgr->find($bp_num);
  0            
179 0 0         if ($bp) {
  0 0          
180 0           $self->bpprint($bp, $verbose);
  0            
181             } else {
182 0           push @not_found, $bp_num;
  0            
183             }
184             }
185 0 0         if (scalar @not_found) {
  0 0          
186 0           my $msg = sprintf("No breakpoint number(s) %s.\n",
  0            
187             join(', ', @not_found));
188 0           $proc->errmsg($msg);
  0            
189             }
190             }
191             }
192              
193 0 0         if ($show_actions) {
  0 0          
194 0           my $actmgr = $proc->{actions};
  0            
195 0           $actmgr->compact;
  0            
196 0           my @actions = @{$actmgr->{list}};
  0            
  0            
  0            
197 0 0         if (0 == scalar @actions) {
  0 0          
198 0           $proc->msg('No actions.');
  0            
199             } else {
200             # There's at least one
201 0           $proc->section("Num Type Enb Where");
  0            
202 0 0         if ($show_all) {
  0 0          
203 0           for my $action (@actions) {
  0            
204 0           $self->action_print($action, $verbose);
  0            
205             }
206             } else {
207 0           my @not_found = ();
  0            
208 0           for my $action_num (@args) {
  0            
209 0           my $action = $actmgr->find($action_num);
  0            
210 0 0         if ($action) {
  0 0          
211 0           $self->actino_print($action, $verbose);
  0            
212             } else {
213 0           push @not_found, $action_num;
  0            
214             }
215             }
216 0 0         unless (scalar @not_found) {
  0 0          
217 0           my $msg = sprintf("No action number(s) %s.\n",
  0            
218             join(', ', @not_found));
219 0           $proc->errmsg($msg);
  0            
220             }
221             }
222             }
223             }
224 0 0         if ($show_watch) {
  0 0          
225 0           $self->{proc}->run_command('info watch');
  0            
226             }
227             }
228              
229             if (caller) {
230             # Demo it.
231             # use rlib '../../mock'
232             # name = File.basename(__FILE__, '.rb')
233             # dbgr, cmd = MockDebugger::setup('info')
234             # subcommand = Trepan::Subcommand::InfoBreakpoints.new(cmd)
235              
236             # print '-' * 20
237             # subcommand.run(%w(info break))
238             # print '-' * 20
239             # subcommand.summary_help(name)
240             # print
241             # print '-' * 20
242              
243             # require 'thread_frame'
244             # tf = RubyVM::ThreadFrame.current
245             # pc_offset = tf.pc_offset
246             # sub foo
247             # 5
248             # end
249              
250             # brk_cmd = dbgr.core.processor.commands['break']
251             # brk_cmd.run(['break', "O${pc_offset}"])
252             # cmd.run(%w(info break))
253             # print '-' * 20
254             # brk_cmd.run(['break', 'foo'])
255             # subcommand.run(%w(info break))
256             # print '-' * 20
257             # print subcommand.save_command
258             }
259              
260             1;