| 1 |
|
| # -*- coding: utf-8 -*- |
| 2 |
|
| # Copyright (C) 2011-2012, 2014 Rocky Bernstein <rocky@cpan.org> |
| 3 |
|
| use warnings; use utf8; |
| 4 |
|
| use rlib '../../../../..'; |
| 5 |
|
| |
| 6 |
|
| package Devel::Trepan::CmdProcessor::Command::Info::Breakpoints; |
| 7 |
|
| use Devel::Trepan::CmdProcessor::Command::Subcmd::Core; |
| 8 |
|
| |
| 9 |
|
| use strict; |
| 10 |
|
| use vars qw(@ISA @SUBCMD_VARS); |
| 11 |
|
| @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd); |
| 12 |
|
| # Values inherited from parent |
| 13 |
|
| use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS; |
| 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 |
|
| no warnings 'redefine'; |
| 62 |
|
| sub complete($$) |
| 63 |
|
| { |
| 64 |
|
| my ($self, $prefix) = @_; |
| 65 |
|
| my @completions = $self->{proc}{brkpts}->ids; |
| 66 |
|
| Devel::Trepan::Complete::complete_token(\@completions, $prefix); |
| 67 |
|
| } |
| 68 |
|
| |
| 69 |
|
| sub bpprint($$;$) |
| 70 |
|
| { |
| 71 |
|
| my ($self, $bp, $verbose) = @_; |
| 72 |
|
| my $proc = $self->{proc}; |
| 73 |
|
| my $disp = ($bp->type eq 'tbreak') ? 'del ' : 'keep '; |
| 74 |
|
| $disp .= $bp->enabled ? 'y ' : 'n '; |
| 75 |
|
| |
| 76 |
|
| my $line_loc = sprintf('%s:%d', $proc->canonic_file($bp->filename), |
| 77 |
|
| $bp->line_num); |
| 78 |
|
| |
| 79 |
|
| my $mess = sprintf('%-4dbreakpoint %s at %s', |
| 80 |
|
| $bp->id, $disp, $line_loc); |
| 81 |
|
| $proc->msg($mess); |
| 82 |
|
| |
| 83 |
|
| if ($bp->condition && $bp->condition ne '1') { |
| 84 |
|
| my $msg = sprintf("\tstop %s %s", |
| 85 |
|
| $bp->negate ? "unless" : "only if", |
| 86 |
|
| $bp->condition); |
| 87 |
|
| $proc->msg($msg); |
| 88 |
|
| } |
| 89 |
|
| if ($bp->hits > 0) { |
| 90 |
|
| my $ss = ($bp->hits > 1) ? 's' : ''; |
| 91 |
|
| my $msg = sprintf("\tbreakpoint already hit %d time%s", |
| 92 |
|
| $bp->hits, $ss); |
| 93 |
|
| $proc->msg($msg); |
| 94 |
|
| } |
| 95 |
|
| } |
| 96 |
|
| |
| 97 |
|
| sub action_print($$;$) |
| 98 |
|
| { |
| 99 |
|
| my ($self, $action, $verbose) = @_; |
| 100 |
|
| my $proc = $self->{proc}; |
| 101 |
|
| my $disp = $action->enabled ? 'y ' : 'n '; |
| 102 |
|
| |
| 103 |
|
| my $line_loc = sprintf('%s:%d', $action->filename, $action->line_num); |
| 104 |
|
| |
| 105 |
|
| my $mess = sprintf('%-4daction %s at %s', |
| 106 |
|
| $action->id, $disp, $line_loc); |
| 107 |
|
| $proc->msg($mess); |
| 108 |
|
| |
| 109 |
|
| if ($action->condition && $action->condition ne '1') { |
| 110 |
|
| my $msg = sprintf("\texpression: %s", $action->condition); |
| 111 |
|
| $proc->msg($msg); |
| 112 |
|
| } |
| 113 |
|
| if ($action->hits > 0) { |
| 114 |
|
| my $ss = ($action->hits > 1) ? 's' : ''; |
| 115 |
|
| my $msg = sprintf("\taction already hit %d time%s", |
| 116 |
|
| $action->hits, $ss); |
| 117 |
|
| $proc->msg($msg); |
| 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 |
|
| my ($self, $args) = @_; |
| 136 |
|
| my $verbose = 0; |
| 137 |
|
| my $proc = $self->{proc}; |
| 138 |
|
| unless (scalar @$args) { |
| 139 |
|
| if ('verbose' eq $args->[-1]) { |
| 140 |
|
| $verbose = 1; |
| 141 |
|
| pop @{$args}; |
| 142 |
|
| } |
| 143 |
|
| } |
| 144 |
|
| |
| 145 |
|
| my $show_all = 1; |
| 146 |
|
| my $show_actions = 1; |
| 147 |
|
| my $show_watch = 1; |
| 148 |
|
| my @args = (); |
| 149 |
|
| if (scalar @{$args} > 2) { |
| 150 |
|
| @args = splice(@{$args}, 2); |
| 151 |
|
| my $max = $proc->{brkpts}->max; |
| 152 |
|
| my $opts = { |
| 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 |
|
| @args = $proc->get_int_list(\@args); |
| 159 |
|
| $show_all = $show_watch = $show_actions = 0; |
| 160 |
|
| } |
| 161 |
|
| |
| 162 |
|
| my $bpmgr = $proc->{brkpts}; |
| 163 |
|
| $bpmgr->compact; |
| 164 |
|
| my @brkpts = @{$bpmgr->{list}}; |
| 165 |
|
| if (0 == scalar @brkpts) { |
| 166 |
|
| $proc->msg('No breakpoints.'); |
| 167 |
|
| } else { |
| 168 |
|
| # There's at least one |
| 169 |
|
| $proc->section("Num Type Disp Enb Where"); |
| 170 |
|
| if ($show_all) { |
| 171 |
|
| for my $bp (@brkpts) { |
| 172 |
|
| $self->bpprint($bp, $verbose); |
| 173 |
|
| } |
| 174 |
|
| } else { |
| 175 |
|
| my @not_found = (); |
| 176 |
|
| for my $bp_num (@args) { |
| 177 |
|
| next unless $bp_num; |
| 178 |
|
| my $bp = $bpmgr->find($bp_num); |
| 179 |
|
| if ($bp) { |
| 180 |
|
| $self->bpprint($bp, $verbose); |
| 181 |
|
| } else { |
| 182 |
|
| push @not_found, $bp_num; |
| 183 |
|
| } |
| 184 |
|
| } |
| 185 |
|
| if (scalar @not_found) { |
| 186 |
|
| my $msg = sprintf("No breakpoint number(s) %s.\n", |
| 187 |
|
| join(', ', @not_found)); |
| 188 |
|
| $proc->errmsg($msg); |
| 189 |
|
| } |
| 190 |
|
| } |
| 191 |
|
| } |
| 192 |
|
| |
| 193 |
|
| if ($show_actions) { |
| 194 |
|
| my $actmgr = $proc->{actions}; |
| 195 |
|
| $actmgr->compact; |
| 196 |
|
| my @actions = @{$actmgr->{list}}; |
| 197 |
|
| if (0 == scalar @actions) { |
| 198 |
|
| $proc->msg('No actions.'); |
| 199 |
|
| } else { |
| 200 |
|
| # There's at least one |
| 201 |
|
| $proc->section("Num Type Enb Where"); |
| 202 |
|
| if ($show_all) { |
| 203 |
|
| for my $action (@actions) { |
| 204 |
|
| $self->action_print($action, $verbose); |
| 205 |
|
| } |
| 206 |
|
| } else { |
| 207 |
|
| my @not_found = (); |
| 208 |
|
| for my $action_num (@args) { |
| 209 |
|
| my $action = $actmgr->find($action_num); |
| 210 |
|
| if ($action) { |
| 211 |
|
| $self->actino_print($action, $verbose); |
| 212 |
|
| } else { |
| 213 |
|
| push @not_found, $action_num; |
| 214 |
|
| } |
| 215 |
|
| } |
| 216 |
|
| unless (scalar @not_found) { |
| 217 |
|
| my $msg = sprintf("No action number(s) %s.\n", |
| 218 |
|
| join(', ', @not_found)); |
| 219 |
|
| $proc->errmsg($msg); |
| 220 |
|
| } |
| 221 |
|
| } |
| 222 |
|
| } |
| 223 |
|
| } |
| 224 |
|
| if ($show_watch) { |
| 225 |
|
| $self->{proc}->run_command('info watch'); |
| 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; |