File Coverage

lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Display.pm
Criterion Covered Total %
statement 48 124 38.7
branch 0 32 0.0
condition n/a
subroutine 16 22 72.7
pod n/a
total 64 178 35.9


line stmt bran cond sub pod time code
1             # -*- coding: utf-8 -*-
2             # Copyright (C) 2015 Rocky Bernstein <rocky@cpan.org>
3 12     12   115 use warnings; use utf8;
  12     12   34  
  12     1   433  
  12     1   73  
  12         33  
  12         83  
  1         10  
  1         6  
  1         36  
  1         9  
  1         4  
  1         7  
4 12     12   329 use rlib '../../../../..';
  12     1   38  
  12         81  
  1         44  
  1         3  
  1         6  
5              
6             package Devel::Trepan::CmdProcessor::Command::Info::Display;
7 12     12   5678 use Devel::Trepan::CmdProcessor::Command::Subcmd::Core;
  12     1   37  
  12         284  
  1         396  
  1         3  
  1         24  
8              
9 12     12   70 use strict;
  12     1   31  
  12         336  
  1         5  
  1         3  
  1         21  
10 12     12   78 use vars qw(@ISA @SUBCMD_VARS);
  12     1   41  
  12         874  
  1         4  
  1         3  
  1         58  
11             @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd);
12             # Values inherited from parent
13 12     12   73 use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS;
  12     1   55  
  12         2023  
  1         6  
  1         4  
  1         137  
14              
15             our $SHORT_HELP = 'List display information';
16              
17             ## FIXME: do automatically.
18             our $CMD = "info display";
19              
20             our $HELP = <<'HELP';
21             =pod
22              
23             B<info display> [I<num1> ...] [B<verbose>]
24              
25             Show status of user-settable display. If no display numbers are
26             given, the show all displays. Otherwise only those displays
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 display
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<display>|Devel::Trepan::CmdProcessor::Command::Display>, and
49             L<C<undisplay>|Devel::Trepan::CmdProcessor::Command::Undisplay>
50              
51             =cut
52             HELP
53              
54             our $MIN_ABBREV = length('di');
55              
56 12     12   84 no warnings 'redefine';
  12     1   35  
  12         6450  
  1         6  
  1         2  
  1         439  
57             sub complete($$)
58             {
59 0     0     my ($self, $prefix) = @_;
  0     0      
60 0           my @displays = @{$self->{proc}{displays}{list}};
  0            
  0            
  0            
61 0           my @completions = map $_->number, @displays;
  0            
62 0           Devel::Trepan::Complete::complete_token(\@completions, $prefix);
  0            
63             }
64              
65             sub display_print($$)
66             {
67 0     0     my ($self, $display) = @_;
  0     0      
68 0           my $proc = $self->{proc};
  0            
69              
70 0 0         my $rt = defined($display->return_type) ? $display->return_type : '?';
  0 0          
71 0 0         my $fmt = defined($display->fmt) ? $display->fmt : '?';
  0 0          
72 0 0         my $enabled .= $display->enabled ? 'y ' : 'n ';
  0 0          
73 0           my $mess = sprintf("%-3d: %s %s %s %s", $display->number,
  0            
74             $rt, $fmt, $enabled, $display->arg);
75 0           $proc->msg($mess);
  0            
76             }
77              
78             # sub save_command($)
79             # {
80             # my $self = shift;
81             # my $proc = $self->{proc};
82             # my $displays = $proc->{displays};
83             # my @res = ();
84             # for my $display ($display->list) {
85             # push @res, "break ${loc}";
86             # }
87             # return @res;
88             # }
89              
90             sub run($$) {
91 0     0     my ($self, $args) = @_;
  0     0      
92 0           my $verbose = 0;
  0            
93 0           my $proc = $self->{proc};
  0            
94 0           my @args = ();
  0            
95 0 0         if (scalar @{$args} > 2) {
  0 0          
  0            
  0            
96 0           @args = splice(@{$args}, 2);
  0            
  0            
  0            
97 0           @args = $proc->get_int_list(\@args);
  0            
98             }
99              
100 0           my @displays = @{$proc->{displays}{list}};
  0            
  0            
  0            
101 0 0         if (0 == scalar @displays) {
  0 0          
102 0           $proc->msg('No Displays.');
  0            
103             } else {
104             # There's at least one
105 0           $proc->section("Num Type Fmt En? Value");
  0            
106 0 0         if (scalar(@args) == 0) {
  0 0          
107 0           for my $display (@displays) {
  0            
108 0           $self->display_print($display);
  0            
109             }
110             } else {
111 0           my @not_found = ();
  0            
112 0           for my $display_num (@args) {
  0            
113 0           my $display = $proc->{displays}->find($display_num);
  0            
114 0 0         if (defined($display)) {
  0 0          
115 0           $self->display_print($display, $verbose);
  0            
116             } else {
117 0           push @not_found, $display_num;
  0            
118             }
119             }
120 0 0         if (scalar @not_found) {
  0 0          
121 0           my $msg = sprintf("No display number(s) %s.\n",
  0            
122             join(', ', @not_found));
123 0           $proc->errmsg($msg);
  0            
124             }
125             }
126             }
127             }
128              
129             if (caller) {
130             # Demo it.
131             # use rlib '../../mock'
132             # name = File.basename(__FILE__, '.rb')
133             # dbgr, cmd = MockDebugger::setup('info')
134             # subcommand = Trepan::Subcommand::InfoBreakpoints.new(cmd)
135              
136             # print '-' * 20
137             # subcommand.run(%w(info break))
138             # print '-' * 20
139             # subcommand.summary_help(name)
140             # print
141             # print '-' * 20
142              
143             # require 'thread_frame'
144             # tf = RubyVM::ThreadFrame.current
145             # pc_offset = tf.pc_offset
146             # sub foo
147             # 5
148             # end
149              
150             # brk_cmd = dbgr.core.processor.commands['break']
151             # brk_cmd.run(['break', "O${pc_offset}"])
152             # cmd.run(%w(info break))
153             # print '-' * 20
154             # brk_cmd.run(['break', 'foo'])
155             # subcommand.run(%w(info break))
156             # print '-' * 20
157             # print subcommand.save_command
158             }
159              
160             1;