lib/Devel/Trepan/CmdProcessor.pm

filter: Statementstmt 16.3% 88 / 538 Branchbran 2.5% 6 / 238 Conditioncond 2.2% 2 / 91 MC/DCmcdc 1.7% 1 / 56 Subroutinesub 38.2% 13 / 34 Podpod 0.0% 0 / 18 totaltotal 11.2% 110 / 975 CC 151 SCAR 55.8
CC
151
Cov
11%
process_commands
462.0
process_commands
462.0
run_command
427.5
CRAP 264.7
« blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Files.pm ↑ Summary lib/Devel/Trepan/Core.pm »
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2015 Rocky Bernstein <rocky@cpan.org>
3  
4 # A debugger command processor. This includes the debugger commands
5 # and ties together the debugger core and I/O interface.
6 package Devel::Trepan::CmdProcessor;
7  
8 12 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use warnings; no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 12 ▶use vars qw(@ISA $eval_result);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 12 ▶use rlib '../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # Showing eval results can be done using either data dump package.
16 12 ▶unless (@ISA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ISA) 12 0 12
17 12 require Devel::Trepan::CmdProcessor::Complete;
18 12 require Devel::Trepan::CmdProcessor::Load;
19 12 require Devel::Trepan::BrkptMgr;
20 12 eval {require Devel::Trepan::DB::Display};
21 12 require Devel::Trepan::Interface::User;
22 12 require Devel::Trepan::Processor;
23 12 require Devel::Trepan::CmdProcessor::Alias;
24 12 require Devel::Trepan::CmdProcessor::Default;
25 12 require Devel::Trepan::CmdProcessor::Msg;
26 12 require Devel::Trepan::CmdProcessor::Help;
27 12 require Devel::Trepan::CmdProcessor::Hook;
28 12 require Devel::Trepan::CmdProcessor::Frame;
29 12 require Devel::Trepan::CmdProcessor::Location;
30 12 require Devel::Trepan::CmdProcessor::Eval;
31 12 require Devel::Trepan::CmdProcessor::Validate;
32 }
33 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 12 ▶use Devel::Trepan::Util qw(hash_merge uniq_abbrev parse_eval_sigil);
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 12 @ISA = qw(Devel::Trepan::Processor);
38  
39 12 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
40 12 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 12 @DB::D = (); # Place to save eval results;
42 }
43  
44 13 ▶sub new {
Subroutine new: called CC=5 SCAR=22.5
Pod undocumented
45 0 ▶ my ($class, $interfaces, $dbgr, $settings) = @_;
Subroutine new: not called CC=5 SCAR=22.5
Pod undocumented
46 0 my $intf;
47 0 ▶ if (defined $interfaces) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $interfaces) { } 2 11 13
if (defined $interfaces) { } 0 0 0
48 0 $intf = $interfaces->[0];
49 } else {
50 $intf = Devel::Trepan::Interface::User->new(undef, undef,
51 {readline =>
52 0 $settings->{readline}});
53 0 $interfaces = [$intf];
54 }
55  
56 0 ▶ $settings ||= {};
Condition50%2/4
$settings ||= {}
l!l
121
$settings ||= {}
l!l
00
MC/DC100%1/1
$settings ||= {}
$settings
MC/DC0%0/1
$settings ||= {}
$settings
Truth table100%2/2
A
A= $settings
Aresult
11
00
Truth table0%0/2
A
A= $settings
Aresult
11
00
57 0 my $self = {
58 class => $class,
59 interfaces => $interfaces,
60 settings => $settings,
61 };
62 0 bless ($self, $class);
63  
64 0 $self->{actions} = Devel::Trepan::BrkptMgr->new($dbgr);
65 0 $self->{brkpts} = Devel::Trepan::BrkptMgr->new($dbgr);
66 0 $self->{displays} = Devel::Trepan::DB::DisplayMgr->new($dbgr);
67 0 $self->{completions} = [];
68 0 $self->{dbgr} = $dbgr;
69 0 $self->{event} = undef;
70 0 $self->{cmd_queue} = [];
71 0 $self->{DB_running} = $DB::running;
72 0 $self->{DB_single} = $DB::single;
73 0 $self->{last_command} = undef;
74 0 $self->{leave_cmd_loop} = undef;
75 0 $self->{next_level} = 30000; # Virtually infinite;
76 0 $self->{settings} = hash_merge($settings, DEFAULT_SETTINGS());
77 0 $self->{terminated} = 0;
78  
79 # Initial watch point expr value used when a new watch point is set.
80 # Set in 'watch' command, and reset here after we get the value back.
81 0 $self->{set_wp} = undef;
82  
83 0 $self->{skip_count} = 0;
84 0 $self->load_cmds_initialize;
85 0 $self->running_initialize;
86 0 $self->hook_initialize;
87 $self->{unconditional_prehooks}->insert_if_new(10,
88 $self->{trace_hook}[0],
89 $self->{trace_hook}[1]
90 0 ▶ ) if $self->{settings}{traceprint};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"settings"}{"traceprint"} 0 13 13
if $self->{"settings"}{"traceprint"} 0 0 0
91  
92 0 ▶ if ($intf->has_completion) {
Branch: 2 branches
BranchTrueFalseTotal
if ($intf->has_completion) 13 0 13
if ($intf->has_completion) 0 0 0
93 0 ▶ my $list_completion = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 0 ▶ my($text, $state) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 0 $self->list_complete($text, $state);
96 0 };
97 0 ▶ my $completion = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
98 0 ▶ my ($text, $line, $start, $end) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 0 $self->complete($text, $line, $start, $end);
100 0 };
101 0 $intf->set_completion($completion, $list_completion);
102 }
103 # $B::Data::Dumper::Deparse = 1;
104 0 return $self;
105 }
106  
107 sub set_prompt($)
108 0 ▶{
Subroutine set_prompt: not called CC=1 SCAR=6.9
Pod undocumented
109 0 ▶ my $self = shift;
Subroutine set_prompt: not called CC=1 SCAR=6.9
Pod undocumented
110 0 my $thread_str = '';
111 # if (1 == Thread.list.size) {
112 # $thread_str = '';
113 # } elsif (Thread.current == Thread.main) {
114 # $thread_str = '@main';
115 # } else {
116 # $thread_str = "@#{Thread.current.object_id}";
117 # }
118 0 my $prompt = sprintf("%s$self->{settings}{prompt}%s%s: ",
119 '(' x $DB::level, $thread_str, ')' x $DB::level);
120 0 return $prompt;
121 }
122  
123 sub terminated($)
124 0 ▶{
Subroutine terminated: not called CC=3 SCAR=24.8
Pod undocumented
125 0 ▶ my $self = shift;
Subroutine terminated: not called CC=3 SCAR=24.8
Pod undocumented
126 0 ▶ $self->msg(sprintf("%sThat's all, folks...",
Branch: 2 branches
BranchTrueFalseTotal
defined $Devel::Trepan::PROGRAM ? : 0 0 0
defined $Devel::Trepan::PROGRAM ? : 0 0 0
127 (defined($Devel::Trepan::PROGRAM) ?
128 "${Devel::Trepan::PROGRAM}: " : '')));
129 0 foreach my $interface (@{$self->{interfaces}}) {
130 0 $interface->close();
131 }
132 # breakpoint_finalize
133 }
134  
135 # Check that we meet the criteria that cmd specifies it needs
136 0 ▶sub ok_for_running ($$$$) {
Subroutine ok_for_running: not called CC=10 SCAR=47.0
Pod undocumented
137 0 ▶ my ($self, $cmd, $name, $nargs) = @_;
Subroutine ok_for_running: not called CC=10 SCAR=47.0
Pod undocumented
138 # TODO check execution_set against execution status.
139 # Check we have frame is not null
140 0 ▶ my $min_args = eval { $cmd->MIN_ARGS } || 0;
Condition0%0/4
eval { do { $cmd->MIN_ARGS } } || 0
l!l
00
eval { do { $cmd->MIN_ARGS } } || 0
l!l
00
MC/DC0%0/1
eval { do { $cmd->MIN_ARGS } } || 0
eval { do { $cmd->MIN_ARGS } }
MC/DC0%0/1
eval { do { $cmd->MIN_ARGS } } || 0
eval { do { $cmd->MIN_ARGS } }
Truth table0%0/2
A
A= eval { do { $cmd->MIN_ARGS } }
Aresult
11
00
Truth table0%0/2
A
A= eval { do { $cmd->MIN_ARGS } }
Aresult
11
00
141 0 ▶ if ($nargs < $min_args) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nargs < $min_args) 0 0 0
if ($nargs < $min_args) 0 0 0
142 0 my $msg =
143 sprintf("Command '%s' needs at least %d argument(s); " .
144 "got %d.", $name, $min_args, $nargs);
145 0 $self->errmsg($msg);
146 0 return;
147 }
148 0 ▶ my $max_args = eval { $cmd->MAX_ARGS } || undef;
Condition0%0/4
eval { do { $cmd->MAX_ARGS } } || undef
l!l
00
eval { do { $cmd->MAX_ARGS } } || undef
l!l
00
MC/DC0%0/1
eval { do { $cmd->MAX_ARGS } } || undef
eval { do { $cmd->MAX_ARGS } }
MC/DC0%0/1
eval { do { $cmd->MAX_ARGS } } || undef
eval { do { $cmd->MAX_ARGS } }
Truth table0%0/2
A
A= eval { do { $cmd->MAX_ARGS } }
Aresult
11
00
Truth table0%0/2
A
A= eval { do { $cmd->MAX_ARGS } }
Aresult
11
00
149 0 ▶ if (defined($max_args) && $nargs > $max_args) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $max_args and $nargs > $max_args) 0 0 0
if (defined $max_args and $nargs > $max_args) 0 0 0
Condition0%0/6
defined $max_args and $nargs > $max_args
!ll&&!rl&&r
000
defined $max_args and $nargs > $max_args
!ll&&!rl&&r
000
MC/DC0%0/2
defined $max_args and $nargs > $max_args
defined $max_args $nargs > $max_args
MC/DC0%0/2
defined $max_args and $nargs > $max_args
defined $max_args $nargs > $max_args
Truth table0%0/3
A and B
A= defined $max_argsB= $nargs > $max_args
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $max_argsB= $nargs > $max_args
ABresult
0X0
100
111
150 0 my $mess =
151 sprintf("Command '%s' needs at most %d argument(s); " .
152 "got %d.", $name, $max_args, $nargs);
153 0 $self->errmsg($mess);
154 0 return;
155 }
156  
157 0 ▶ if ($cmd->NEED_STACK && $self->{terminated}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmd->NEED_STACK and $self->{"terminated"}) 0 0 0
if ($cmd->NEED_STACK and $self->{"terminated"}) 0 0 0
Condition0%0/6
$cmd->NEED_STACK and $self->{"terminated"}
!ll&&!rl&&r
000
$cmd->NEED_STACK and $self->{"terminated"}
!ll&&!rl&&r
000
MC/DC0%0/2
$cmd->NEED_STACK and $self->{"terminated"}
$cmd->NEED_STACK $self->{"terminated"}
MC/DC0%0/2
$cmd->NEED_STACK and $self->{"terminated"}
$cmd->NEED_STACK $self->{"terminated"}
Truth table0%0/3
A and B
A= $cmd->NEED_STACKB= $self->{"terminated"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $cmd->NEED_STACKB= $self->{"terminated"}
ABresult
0X0
100
111
158 0 $self->errmsg("Command '$name' requires a running program.");
159 0 return;
160 }
161  
162 0 ▶ if ($cmd->NEED_STACK && !defined $self->{frame}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmd->NEED_STACK and not defined $self->{"frame"}) 0 0 0
if ($cmd->NEED_STACK and not defined $self->{"frame"}) 0 0 0
Condition0%0/6
$cmd->NEED_STACK and not defined $self->{"frame"}
!ll&&!rl&&r
000
$cmd->NEED_STACK and not defined $self->{"frame"}
!ll&&!rl&&r
000
MC/DC0%0/2
$cmd->NEED_STACK and not defined $self->{"frame"}
$cmd->NEED_STACK not defined $self->{"frame"}
MC/DC0%0/2
$cmd->NEED_STACK and not defined $self->{"frame"}
$cmd->NEED_STACK not defined $self->{"frame"}
Truth table0%0/3
A and not(B)
A= $cmd->NEED_STACKB= not defined $self->{"frame"}
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $cmd->NEED_STACKB= not defined $self->{"frame"}
ABresult
0X0
100
111
163 0 $self->errmsg("Command '$name' requires a running stack frame.");
164 0 return;
165 }
166  
167 0 return 1;
168 }
169  
170 # Run one debugger command. 1 is returned if we want to quit.
171 sub process_command_and_quit($)
172 0 ▶{
Subroutine process_command_and_quit: not called CC=16 SCAR=56.1
Pod undocumented
173 0 ▶ my $self = shift;
Subroutine process_command_and_quit: not called CC=16 SCAR=56.1
Pod undocumented
174 0 my $intf_ary = $self->{interfaces};
175 0 my $intf = $intf_ary->[-1];
176 0 my $intf_size = scalar @{$intf_ary};
177 0 ▶ return 1 if !defined $intf || $intf->is_input_eof && $intf_size == 1;
Branch: 2 branches
BranchTrueFalseTotal
if not defined $intf or $intf->is_input_eof and $intf_size == 1 0 0 0
if not defined $intf or $intf->is_input_eof and $intf_size == 1 0 0 0
Condition0%0/12
not defined $intf or $intf->is_input_eof and $intf_size == 1
l!l&&r!l&&!r
000
$intf->is_input_eof and $intf_size == 1
!ll&&!rl&&r
000
not defined $intf or $intf->is_input_eof and $intf_size == 1
l!l&&r!l&&!r
000
$intf->is_input_eof and $intf_size == 1
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $intf or $intf->is_input_eof and $intf_size == 1
not defined $intf $intf->is_input_eof $intf_size == 1
MC/DC0%0/3
not defined $intf or $intf->is_input_eof and $intf_size == 1
not defined $intf $intf->is_input_eof $intf_size == 1
Truth table0%0/4
not(A) or B and C
A= not defined $intfB= $intf->is_input_eofC= $intf_size == 1
ABCresult
1XX1
0111
00X0
0100
Truth table0%0/4
not(A) or B and C
A= not defined $intfB= $intf->is_input_eofC= $intf_size == 1
ABCresult
1XX1
0111
00X0
0100
178 0 ▶ while ($intf_size > 1 || !$intf->is_input_eof) {
Branch: 2 branches
BranchTrueFalseTotal
if ($intf_size > 1 or not $intf->is_input_eof) 0 0 0
if ($intf_size > 1 or not $intf->is_input_eof) 0 0 0
Condition0%0/6
$intf_size > 1 or not $intf->is_input_eof
l!l&&r!l&&!r
000
$intf_size > 1 or not $intf->is_input_eof
l!l&&r!l&&!r
000
MC/DC0%0/2
$intf_size > 1 or not $intf->is_input_eof
$intf_size > 1 not $intf->is_input_eof
MC/DC0%0/2
$intf_size > 1 or not $intf->is_input_eof
$intf_size > 1 not $intf->is_input_eof
Truth table0%0/3
A or not(B)
A= $intf_size > 1B= not $intf->is_input_eof
ABresult
1X1
011
000
Truth table0%0/3
A or not(B)
A= $intf_size > 1B= not $intf->is_input_eof
ABresult
1X1
011
000
179 # begin
180 0 $self->{current_command} = '';
181 0 my @cmd_queue = @{$self->{cmd_queue}};
182 0 ▶ if (scalar(@cmd_queue) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @cmd_queue == 0) { } 0 0 0
if (scalar @cmd_queue == 0) { } 0 0 0
183 # Leave trailing blanks on for the "complete" command
184 0 ▶ $self->{current_command} = $self->read_command() || '';
Condition0%0/4
$self->read_command || ''
l!l
00
$self->read_command || ''
l!l
00
MC/DC0%0/1
$self->read_command || ''
$self->read_command
MC/DC0%0/1
$self->read_command || ''
$self->read_command
Truth table0%0/2
A
A= $self->read_command
Aresult
11
00
Truth table0%0/2
A
A= $self->read_command
Aresult
11
00
185 0 ▶ if ($intf->is_input_eof) {
Branch: 2 branches
BranchTrueFalseTotal
if ($intf->is_input_eof) 0 0 0
if ($intf->is_input_eof) 0 0 0
186 0 ▶ if ($intf_size > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($intf_size > 1) { } 0 0 0
if ($intf_size > 1) { } 0 0 0
187 0 pop @$intf_ary;
188 0 $intf_size = scalar @$intf_ary;
189 0 $intf = $intf_ary->[-1];
190 0 $self->{last_command} = '';
191 # $self->print_location;
192 } else {
193 ## FIXME: think of something better.
194 0 $self->run_command("quit!");
195 0 return 1;
196 }
197 }
198 0 chomp $self->{current_command};
199 } else {
200 0 $self->{current_command} = shift @cmd_queue;
201 0 $self->{cmd_queue} = \@cmd_queue;
202 }
203 0 ▶ if ('' eq $self->{current_command}) {
Branch: 2 branches
BranchTrueFalseTotal
if ("" eq $self->{"current_command"}) 0 0 0
if ("" eq $self->{"current_command"}) 0 0 0
204 0 ▶ next unless $self->{last_command} && $intf->is_interactive;
Branch: 2 branches
BranchTrueFalseTotal
unless $self->{"last_command"} and $intf->is_interactive 0 0 0
unless $self->{"last_command"} and $intf->is_interactive 0 0 0
Condition0%0/6
$self->{"last_command"} and $intf->is_interactive
!ll&&!rl&&r
000
$self->{"last_command"} and $intf->is_interactive
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"last_command"} and $intf->is_interactive
$self->{"last_command"} $intf->is_interactive
MC/DC0%0/2
$self->{"last_command"} and $intf->is_interactive
$self->{"last_command"} $intf->is_interactive
Truth table0%0/3
A and B
A= $self->{"last_command"}B= $intf->is_interactive
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $self->{"last_command"}B= $intf->is_interactive
ABresult
0X0
100
111
205 0 $self->{current_command} = $self->{last_command};
206 }
207 # Skip comment lines
208 0 ▶ next if substr($self->{current_command}, 0, 1) eq '#';
Branch: 2 branches
BranchTrueFalseTotal
if substr($self->{"current_command"}, 0, 1) eq "#" 0 0 0
if substr($self->{"current_command"}, 0, 1) eq "#" 0 0 0
209 0 last;
210 # rescue IOError, Errno::EPIPE => e
211 # }
212 }
213  
214 0 eval {
215 0 $self->run_command($self->{current_command});
216 };
217 0 ▶ if ($EVAL_ERROR) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Devel::Trepan::CmdProcessor::EVAL_ERROR) { } 0 0 0
if ($Devel::Trepan::CmdProcessor::EVAL_ERROR) { } 0 0 0
218 0 $self->errmsg("internal error: $EVAL_ERROR")
219 } else {
220 # Save it to the history.
221 $intf->add_history($self->{last_command}) if
222 0 ▶ $self->{last_command};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"last_command"} 0 0 0
if $self->{"last_command"} 0 0 0
223 }
224 }
225  
226 sub skip_if_next($$)
227 0 ▶{
Subroutine skip_if_next: not called CC=5 SCAR=31.5
Pod undocumented
228 0 ▶ my ($self, $event) = @_;
Subroutine skip_if_next: not called CC=5 SCAR=31.5
Pod undocumented
229 0 ▶ return 0 if ('line' ne $event);
Branch: 2 branches
BranchTrueFalseTotal
if "line" ne $event 0 0 0
if "line" ne $event 0 0 0
230 0 ▶ return 0 if $self->{terminated};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"terminated"} 0 0 0
if $self->{"terminated"} 0 0 0
231 0 ▶ return 0 if eval { no warnings; $DB::tid ne $self->{last_tid} };
Subroutine BEGIN: called CC=1 SCAR=3.3
Branch: 2 branches
BranchTrueFalseTotal
if eval { do { no warnings; $DB::tid ne $self->{"last_tid"} } } 0 0 0
if eval { do { no warnings; $DB::tid ne $self->{"last_tid"} } } 0 0 0
232 # print "+++event $event ", $self->{stack_size}, " ",
233 # $self->{next_level}, "\n";
234 0 ▶ return 1 if $self->{stack_size} > $self->{next_level};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"stack_size"} > $self->{"next_level"} 0 0 0
if $self->{"stack_size"} > $self->{"next_level"} 0 0 0
235 }
236  
237 # This is the main entry point.
238 sub process_commands($$$;$)
239 0 ▶{
Subroutine process_commands: not called CC=21 SCAR=61.4
Pod undocumented
240 0 ▶ my ($self, $frame, $event, $arg) = @_;
Subroutine process_commands: not called CC=21 SCAR=61.4
Pod undocumented
241  
242 0 ▶ if ($event eq 'terminated') {
Branch: 4 branches
BranchTrueFalseTotal
if ($event eq 'terminated') { } 0 0 0
elsif (not defined $event) { } 0 0 0
if ($event eq 'terminated') { } 0 0 0
elsif (not defined $event) { } 0 0 0
243 0 $self->{terminated} = 1;
244 0 $self->section("Debugged program terminated. Use 'q' to quit or 'R' to restart.");
245 } elsif (!defined($event)) {
246 0 $event = 'unknown';
247 }
248  
249 0 my $next_skip = 0;
250 0 ▶ if ($event eq 'after_eval' or $event eq 'after_nest') {
Branch: 2 branches
BranchTrueFalseTotal
if ($event eq 'after_eval' or $event eq 'after_nest') { } 0 0 0
if ($event eq 'after_eval' or $event eq 'after_nest') { } 0 0 0
Condition0%0/6
$event eq "after_eval" or $event eq "after_nest"
l!l&&r!l&&!r
000
$event eq "after_eval" or $event eq "after_nest"
l!l&&r!l&&!r
000
MC/DC0%0/2
$event eq "after_eval" or $event eq "after_nest"
$event eq "after_eval" $event eq "after_nest"
MC/DC0%0/2
$event eq "after_eval" or $event eq "after_nest"
$event eq "after_eval" $event eq "after_nest"
Truth table0%0/3
A or B
A= $event eq "after_eval"B= $event eq "after_nest"
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $event eq "after_eval"B= $event eq "after_nest"
ABresult
1X1
011
000
251 0 $self->handle_eval_result();
252 0 ▶ if ($event eq 'after_nest') {
Branch: 2 branches
BranchTrueFalseTotal
if ($event eq "after_nest") 0 0 0
if ($event eq "after_nest") 0 0 0
253 0 $self->msg("Leaving nested debug level $DB::level");
254 0 $self->{prompt} = set_prompt($self);
255 0 $self->frame_setup();
256 0 $self->print_location;
257 }
258 } else {
259 0 $self->{completions} = [];
260 0 $self->{event} = $event;
261 0 $self->frame_setup();
262  
263 0 ▶ if ($event eq 'watch') {
Branch: 2 branches
BranchTrueFalseTotal
if ($event eq "watch") 0 0 0
if ($event eq "watch") 0 0 0
264 0 my $msg = sprintf("Watchpoint %s: %s changed",
265 $arg->id, $arg->expr);
266 0 $self->section($msg);
267 0 ▶ my $old_value = defined($arg->old_value) ? $arg->old_value
Branch: 2 branches
BranchTrueFalseTotal
defined $arg->old_value ? : 0 0 0
defined $arg->old_value ? : 0 0 0
268 : 'undef';
269 0 $msg = sprintf("old value\t%s", $old_value);
270 0 $self->msg($msg);
271 0 ▶ my $new_value = defined($arg->current_val) ? $arg->current_val
Branch: 2 branches
BranchTrueFalseTotal
defined $arg->current_val ? : 0 0 0
defined $arg->current_val ? : 0 0 0
272 : 'undef';
273 0 $msg = sprintf("new value\t%s", $new_value);
274 0 $self->msg($msg);
275 0 $arg->old_value($arg->current_val);
276 }
277  
278 0 $next_skip = skip_if_next($self, $event);
279 0 ▶ unless ($next_skip) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($next_skip) 0 0 0
unless ($next_skip) 0 0 0
280  
281 # prehooks include traceprint, list, and event saving.
282 0 $self->{unconditional_prehooks}->run;
283  
284 0 ▶ if (index($self->{event}, 'brkpt') < 0 && !$self->{terminated}) {
Branch: 2 branches
BranchTrueFalseTotal
if (index($self->{"event"}, "brkpt") == -1 and not $self->{"terminated"}) 0 0 0
if (index($self->{"event"}, "brkpt") == -1 and not $self->{"terminated"}) 0 0 0
Condition0%0/6
index($self->{"event"}, "brkpt") == -1 and not $self->{"terminated"}
!ll&&!rl&&r
000
index($self->{"event"}, "brkpt") == -1 and not $self->{"terminated"}
!ll&&!rl&&r
000
MC/DC0%0/2
index($self->{"event"}, "brkpt") == -1 and not $self->{"terminated"}
index($self->{"event"}, "brkpt") == -1 not $self->{"terminated"}
MC/DC0%0/2
index($self->{"event"}, "brkpt") == -1 and not $self->{"terminated"}
index($self->{"event"}, "brkpt") == -1 not $self->{"terminated"}
Truth table0%0/3
A and not(B)
A= index($self->{"event"}, "brkpt") == -1B= not $self->{"terminated"}
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= index($self->{"event"}, "brkpt") == -1B= not $self->{"terminated"}
ABresult
0X0
100
111
285 # Not a breakpoint and not terminated.
286  
287 0 ▶ if ($event eq 'line') {
Branch: 2 branches
BranchTrueFalseTotal
if ($event eq "line") 0 0 0
if ($event eq "line") 0 0 0
288  
289 # We may want to not stop because of "step n"; step different, or
290 # "next"
291 # use Enbugger; Enbugger->stop if 2 == $self->{next_level};
292 0 ▶ if ($self->is_stepping_skip()) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->is_stepping_skip) 0 0 0
if ($self->is_stepping_skip) 0 0 0
293 # || $self->{stack_size} <= $self->{hide_level};
294 0 $self->{dbgr}->step;
295 0 return;
296 }
297 # trace print sets stepping even when though otherwise
298 # we may be are continuing, nexting, finishing, or
299 # returning.
300 0 ▶ if ($self->{settings}{traceprint}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{"settings"}{"traceprint"}) 0 0 0
if ($self->{"settings"}{"traceprint"}) 0 0 0
301 0 $self->{dbgr}->step;
302 0 ▶ return unless 0 == $self->{skip_count};
Branch: 2 branches
BranchTrueFalseTotal
unless 0 == $self->{"skip_count"} 0 0 0
unless 0 == $self->{"skip_count"} 0 0 0
303 }
304 }
305 }
306  
307 0 $self->{prompt} = set_prompt($self);
308 $self->print_location unless $self->{settings}{traceprint} ||
309 0 ▶ $self->{terminated};
Branch: 2 branches
BranchTrueFalseTotal
unless $self->{"settings"}{"traceprint"} or $self->{"terminated"} 0 0 0
unless $self->{"settings"}{"traceprint"} or $self->{"terminated"} 0 0 0
Condition0%0/6
$self->{"settings"}{"traceprint"} or $self->{"terminated"}
l!l&&r!l&&!r
000
$self->{"settings"}{"traceprint"} or $self->{"terminated"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"settings"}{"traceprint"} or $self->{"terminated"}
$self->{"settings"}{"traceprint"} $self->{"terminated"}
MC/DC0%0/2
$self->{"settings"}{"traceprint"} or $self->{"terminated"}
$self->{"settings"}{"traceprint"} $self->{"terminated"}
Truth table0%0/3
A or B
A= $self->{"settings"}{"traceprint"}B= $self->{"terminated"}
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $self->{"settings"}{"traceprint"}B= $self->{"terminated"}
ABresult
1X1
011
000
310  
311 ## $self->{eventbuf}->add_mark if $self->{settings}{tracebuffer};
312  
313 0 $self->{cmdloop_prehooks}->run;
314 }
315 }
316 0 ▶ unless ($next_skip) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($next_skip) 0 0 0
unless ($next_skip) 0 0 0
317 # Individual commands force a leave from by the below loop by
318 # setting leave_cmd_loop.
319 0 $self->{leave_cmd_loop} = 0;
320 0 ▶ while (!$self->{leave_cmd_loop}) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($self->{"leave_cmd_loop"}) 0 0 0
unless ($self->{"leave_cmd_loop"}) 0 0 0
321 # begin
322 0 $self->process_command_and_quit;
323 # rescue systemexit
324 # @dbgr.stop
325 # raise
326 #rescue exception => exc
327 # if we are inside the script interface $self->errmsg may fail.
328 # begin
329 # $self->errmsg("internal debugger error: #{exc.inspect}")
330 # rescue ioerror
331 # $stderr.puts "internal debugger error: #{exc.inspect}"
332 # }
333 # exception_dump(exc, @settings[:debugexcept], $!.backtrace)
334 # }
335 }
336 }
337 0 ▶ if ($self->{terminated}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'terminated'}) { } 0 0 0
if ($self->{'terminated'}) { } 0 0 0
338 0 $DB::running = $self->{DB_running};
339 } else {
340 0 $self->{cmdloop_posthooks}->run;
341 0 $self->{last_tid} = $DB::tid;
342 0 $DB::running = $self->{DB_running};
343 0 $DB::single = $self->{DB_single};
344 }
345 }
346  
347 # run current_command, a string. @last_command is set after the
348 # command is run if it is a command.
349 sub run_command($$)
350 0 ▶{
Subroutine run_command: not called CC=21 SCAR=60.6
Pod undocumented
351 0 ▶ my ($self, $current_command) = @_;
Subroutine run_command: not called CC=21 SCAR=60.6
Pod undocumented
352 0 my $eval_command = undef;
353 0 my $cmd_name = undef;
354 0 my @cmd_queue = @{$self->{cmd_queue}};
355 0 ▶ unless ($eval_command) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($eval_command) 0 0 0
unless ($eval_command) 0 0 0
356 0 my @commands = split(';;', $current_command);
357 0 ▶ if (scalar(@commands) > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @commands > 1) 0 0 0
if (scalar @commands > 1) 0 0 0
358 0 $current_command = shift @commands;
359 0 $self->{cmd_queue} = \(@cmd_queue, @commands);
360 }
361  
362 # Split on space trimming leading space. Note ' ' rather than say \s+
363 # which splits on leading spaces among others.
364 0 my @args = split(' ', $current_command);
365  
366 # Expand macros. FIXME: put in a procedure
367 0 while (1) {
368 0 ▶ return if scalar(@args) == 0;
Branch: 2 branches
BranchTrueFalseTotal
if scalar @args == 0 0 0 0
if scalar @args == 0 0 0 0
369 0 my $macro_cmd_name = $args[0];
370 0 ▶ last unless $self->{macros}{$macro_cmd_name};
Branch: 2 branches
BranchTrueFalseTotal
unless $self->{"macros"}{$macro_cmd_name} 0 0 0
unless $self->{"macros"}{$macro_cmd_name} 0 0 0
371 0 my $debugging = $self->{settings}{debugmacro};
372 # if ($debugging) {
373 # require Enbugger; Enbugger->stop();
374 # }
375 0 shift @args;
376 my $macro_expanded =
377 0 $self->{macros}{$macro_cmd_name}[0]->(@args);
378 0 ▶ if (ref $macro_expanded eq 'ARRAY' # &&
Branch: 2 branches
BranchTrueFalseTotal
if (ref $macro_expanded eq 'ARRAY') { } 0 0 0
if (ref $macro_expanded eq 'ARRAY') { } 0 0 0
379 # current_command.all? {|val| val.is_a?(String)}
380 ) {
381 0 my @new_commands = @{$macro_expanded};
382 0 ▶ $self->msg(join(' ', @new_commands)) if $debugging;
Branch: 2 branches
BranchTrueFalseTotal
if $debugging 0 0 0
if $debugging 0 0 0
383 0 ▶ if (scalar @new_commands > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @new_commands > 0) { } 0 0 0
if (scalar @new_commands > 0) { } 0 0 0
384 0 push @cmd_queue, @new_commands;
385 0 $current_command = shift @cmd_queue;
386 0 @args = split(' ', $current_command);
387 } else {
388 0 $current_command = '#';
389 0 @args = ();
390 }
391 } else {
392 0 ▶ $self->msg($macro_expanded) if $debugging;
Branch: 2 branches
BranchTrueFalseTotal
if $debugging 0 0 0
if $debugging 0 0 0
393 0 $current_command = $macro_expanded;
394 0 @args = split(/\s+/, $current_command);
395 # } else {
396 # $self->errmsg("macro ${macro_cmd_name} should return a list " .
397 # "of strings " .
398 # # or a String
399 # ". Got ${current_command.inspect}");
400 # return;
401 }
402 }
403  
404 0 my %commands = %{$self->{commands}};
405 0 $cmd_name = $self->{cmd_name} = $args[0];
406 0 my $run_cmd_name = $cmd_name;
407  
408 0 my %aliases = %{$self->{aliases}};
409 0 ▶ if (exists $aliases{$cmd_name}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $aliases{$cmd_name}) 0 0 0
if (exists $aliases{$cmd_name}) 0 0 0
410 0 my @alias_expand = split(/\s+/, $aliases{$cmd_name});
411 0 $run_cmd_name = shift @alias_expand;
412 0 splice(@args, 1, 0, @alias_expand);
413 }
414  
415 $run_cmd_name = uniq_abbrev([keys %commands], $run_cmd_name) if
416 0 ▶ !$commands{$run_cmd_name} && $self->{settings}{abbrev};
Branch: 2 branches
BranchTrueFalseTotal
if not $commands{$run_cmd_name} and $self->{"settings"}{"abbrev"} 0 0 0
if not $commands{$run_cmd_name} and $self->{"settings"}{"abbrev"} 0 0 0
Condition0%0/6
not $commands{$run_cmd_name} and $self->{"settings"}{"abbrev"}
!ll&&!rl&&r
000
not $commands{$run_cmd_name} and $self->{"settings"}{"abbrev"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $commands{$run_cmd_name} and $self->{"settings"}{"abbrev"}
not $commands{$run_cmd_name} $self->{"settings"}{"abbrev"}
MC/DC0%0/2
not $commands{$run_cmd_name} and $self->{"settings"}{"abbrev"}
not $commands{$run_cmd_name} $self->{"settings"}{"abbrev"}
Truth table0%0/3
not(A) and B
A= not $commands{$run_cmd_name}B= $self->{"settings"}{"abbrev"}
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not $commands{$run_cmd_name}B= $self->{"settings"}{"abbrev"}
ABresult
0X0
100
111
417  
418 0 my $cmd = $commands{$run_cmd_name};
419 0 ▶ if ($cmd) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmd) 0 0 0
if ($cmd) 0 0 0
420 0 ▶ if ($self->ok_for_running($cmd, $run_cmd_name, scalar(@args)-1)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->ok_for_running($cmd, $run_cmd_name, scalar(@args) - 1)) 0 0 0
if ($self->ok_for_running($cmd, $run_cmd_name, scalar(@args) - 1)) 0 0 0
421 # Get part of string after command name
422 0 my $cmd_argstr = substr($current_command, length($cmd_name));
423 0 $self->{cmd_argstr} = $cmd_argstr;
424 0 $cmd->run(\@args);
425 0 $self->{last_command} = $current_command;
426 }
427 0 return;
428 }
429 }
430  
431 # Eval anything that's not a command or has been
432 # requested to be eval'd
433 0 ▶ if ($self->{settings}{autoeval} || $eval_command) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{"settings"}{"autoeval"} or $eval_command) 0 0 0
if ($self->{"settings"}{"autoeval"} or $eval_command) 0 0 0
Condition0%0/6
$self->{"settings"}{"autoeval"} or $eval_command
l!l&&r!l&&!r
000
$self->{"settings"}{"autoeval"} or $eval_command
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"settings"}{"autoeval"} or $eval_command
$self->{"settings"}{"autoeval"} $eval_command
MC/DC0%0/2
$self->{"settings"}{"autoeval"} or $eval_command
$self->{"settings"}{"autoeval"} $eval_command
Truth table0%0/3
A or B
A= $self->{"settings"}{"autoeval"}B= $eval_command
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $self->{"settings"}{"autoeval"}B= $eval_command
ABresult
1X1
011
000
434 0 my $return_type = parse_eval_sigil($current_command);
435 0 ▶ $return_type = '$' unless $return_type;
Branch: 2 branches
BranchTrueFalseTotal
unless $return_type 0 0 0
unless $return_type 0 0 0
436 0 my $opts = {nest => 0,
437 hide_position => 1,
438 fix_file_and_line => 1,
439 return_type => $return_type};
440  
441 # FIXME: 2 below is a magic fixup constant, also found in
442 # DB::finish. Remove it.
443 0 ▶ if (0 == $self->{frame_index}) {
Branch: 2 branches
BranchTrueFalseTotal
if (0 == $self->{'frame_index'}) { } 0 0 0
if (0 == $self->{'frame_index'}) { } 0 0 0
444 0 chomp $current_command;
445 0 $self->eval($current_command, $opts, 2);
446 } else {
447 12 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
448 my $return_type = $DB::eval_opts->{return_type} =
449 0 $opts->{return_type};
450 12 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
451 0 ▶ if ('$' eq $opts->{return_type}) {
Branch: 6 branches
BranchTrueFalseTotal
if ('$' eq $opts->{'return_type'}) { } 0 0 0
elsif ('@' eq $opts->{'return_type'}) { } 0 0 0
elsif ('%' eq $opts->{'return_type'}) { } 0 0 0
if ('$' eq $opts->{'return_type'}) { } 0 0 0
elsif ('@' eq $opts->{'return_type'}) { } 0 0 0
elsif ('%' eq $opts->{'return_type'}) { } 0 0 0
452 0 $DB::eval_result = $self->eval($current_command, $opts, 2);
453 } elsif ('@' eq $opts->{return_type}) {
454 0 @DB::eval_result = $self->eval($current_command, $opts, 2);
455 } elsif ('%' eq $opts->{return_type}) {
456 0 %DB::eval_result = $self->eval($current_command, $opts, 2);
457 } else {
458 0 $DB::eval_result = $self->eval($current_command, $opts, 2);
459 }
460 0 $self->handle_eval_result();
461 }
462 0 return;
463 }
464 0 $self->undefined_command($cmd_name);
465 0 return;
466 }
467  
468 # Error message when a command doesn't exist
469 0 ▶sub undefined_command($$) {
Subroutine undefined_command: not called CC=2 SCAR=17.9
Pod undocumented
470 0 ▶ my ($self, $cmd_name) = @_;
Subroutine undefined_command: not called CC=2 SCAR=17.9
Pod undocumented
471 0 my $msg = sprintf 'Undefined command: "%s". Try "help".', $cmd_name;
472 0 eval { $self->errmsg($msg); };
473 0 ▶ print STDERR $msg if $EVAL_ERROR;
Branch: 2 branches
BranchTrueFalseTotal
if $Devel::Trepan::CmdProcessor::EVAL_ERROR 0 0 0
if $Devel::Trepan::CmdProcessor::EVAL_ERROR 0 0 0
474 }
475  
476 12 ▶unless (caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 12 12
477 0 my $proc = Devel::Trepan::CmdProcessor->new;
478 0 print $proc->{class}, "\n";
479 0 print join(', ', @{$proc->{interfaces}}), "\n";
480 0 $proc->msg("Hi, there!");
481 0 $proc->errmsg(['Two', 'lines']);
482 0 $proc->errmsg("Something wrong?");
483 0 for my $fn (qw(errmsg msg section)) {
484 0 $proc->$fn('testing');
485 }
486 0 $DB::level = 1;
487 0 my $prompt = $proc->{prompt} = set_prompt($proc);
488 0 eval <<'EOE';
489 sub foo() {
490 my @call_values = caller(0);
491 return @call_values;
492 }
493 EOE
494 0 print "prompt setting: $prompt\n";
495 0 $DB::level = 2;
496 0 $prompt = $proc->{prompt} = set_prompt($proc);
497 0 print "prompt setting 2: $prompt\n";
498 0 my @call_values = foo();
499 ## $proc->frame_setup(\@call_values, 0);
500 0 my $sep = '=' x 40 . "\n";
501 0 $proc->undefined_command("foo");
502 0 print $sep;
503 0 $proc->run_command("help *");
504 0 print $sep;
505 0 $proc->run_command("help help;; kill 100");
506 # Note kill 100 is in queue - not run yet.
507 0 ▶ if (scalar(@ARGV) > 0 && $proc->{interfaces}[-1]->is_interactive) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @ARGV > 0 and $proc->{"interfaces"}[-1]->is_interactive) 0 0 0
Condition0%0/3
scalar @ARGV > 0 and $proc->{"interfaces"}[-1]->is_interactive
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @ARGV > 0 and $proc->{"interfaces"}[-1]->is_interactive
scalar @ARGV > 0 $proc->{"interfaces"}[-1]->is_interactive
Truth table0%0/3
A and B
A= scalar @ARGV > 0B= $proc->{"interfaces"}[-1]->is_interactive
ABresult
0X0
100
111
508 0 $proc->process_command_and_quit; # Handle's queued command
509 0 $proc->process_command_and_quit;
510 0 print $sep;
511 0 $proc->process_commands([@call_values], 0, 'debugger-call');
512 }
513 }
514  
515 12 1;
« blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Files.pm ↑ Summary lib/Devel/Trepan/Core.pm »