lib/Devel/Trepan/Client.pm

filter: Statementstmt 17.1% 22 / 128 Branchbran 2.2% 1 / 44 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 41.1% 7 / 17 Podpod 0.0% 0 / 8 totaltotal 15.2% 30 / 197 CC 22 SCAR 44.2
CC
22
Cov
13%
handle_server_reponse
210.0
run_command
20.0
start_client
20.0
CRAP 83.0
« lib/Devel/Trepan/CmdProcessor/Complete.pm ↑ Summary lib/Devel/Trepan/CmdProcessor/Command/Complete.pm »
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2014 Rocky Bernstein <rocky@cpan.org>
3  
4 package Devel::Trepan::Client;
5 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 39 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 39 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 39 my @OLD_INC = @INC;
10 39 ▶ use rlib '../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 39 ▶ use Devel::Trepan::Interface::ComCodes;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 39 ▶ use Devel::Trepan::Interface::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 39 ▶ use Devel::Trepan::Interface::Script;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 39 @INC = @OLD_INC;
15 }
16  
17 sub new
18 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
19 0 my ($class, $settings) = @_;
20 0 my $opts = $settings;
21 0 my $intf = Devel::Trepan::Interface::Client->new(
22 undef, undef, undef, $settings );
23 my $self = {
24 leave_loop => 0,
25 options => $settings,
26 intf => $intf,
27 0 user_inputs => [$intf->{user}],
28 };
29 0 bless $self, $class;
30 }
31  
32 sub handle_server_reponse($$$);
33  
34 sub errmsg($$)
35 0 ▶{
Subroutine errmsg: not called CC=1 SCAR=6.9
Pod undocumented
36 0 my ($self, $msg) = @_;
37 0 $self->{intf}{user}->errmsg($msg);
38 }
39  
40 sub msg($$)
41 0 ▶{
Subroutine msg: not called CC=1 SCAR=6.9
Pod undocumented
42 0 my ($self, $msg) = @_;
43 0 chomp $msg;
44 0 $self->{intf}{user}->msg($msg);
45 }
46  
47 0 ▶sub list_complete {
Subroutine list_complete: not called CC=1 SCAR=6.9
Pod undocumented
48 0 print "List complete called\n", join(", ", @_), "\n";
49 }
50  
51 0 ▶sub complete($$$$$) {
Subroutine complete: not called CC=3 SCAR=24.8
Pod undocumented
52 0 my ($self, $text, $line, $start, $end) = @_;
53 0 my $intf = $self->{intf};
54 # print "complete called: text: $text, line: " .
55 # $line, start: $start, end: $end\n");
56 0 eval {
57 0 $intf->write_remote(COMMAND, "complete " . $line);
58 };
59 0 my ($control_code, $line);
60 0 my @complete;
61 0 eval {
62 0 ($control_code, $line) = $intf->read_remote;
63 0 ▶ while (PROMPT ne $control_code) {
Branch: 1 branch
BranchTrueFalseTotal
if ("p" ne $control_code) 0 0 0
64 0 ▶ if (PRINT eq $control_code) {
Branch: 1 branch
BranchTrueFalseTotal
if ('.' eq $control_code) { } 0 0 0
65 0 chomp $line;
66 0 push @complete, $line;
67 0 ($control_code, $line) = $intf->read_remote;
68 } else {
69 0 $self->errmsg("Was expecting a print response, got $control_code\n+++ $line");
70 0 return $line;
71 }
72 }
73 };
74 0 chomp $line;
75 0 return @complete;
76 }
77  
78 sub run_command($$$$)
79 0 ▶{
Subroutine run_command: not called CC=4 SCAR=30.0
Pod undocumented
80 0 my ($self, $current_command) = @_;
81 0 my $intf = $self->{intf};
82 0 ▶ if (substr($current_command, 0, 1) eq '.') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($current_command, 0, 1) eq ".") 0 0 0
83 0 $current_command = substr($current_command, 1);
84 0 my @args = split(' ', $current_command);
85 0 my $cmd_name = shift @args;
86 0 my $script_file = shift @args;
87 0 ▶ if ('source' eq $cmd_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ('source' eq $cmd_name) { } 0 0 0
88 0 my $result =
89 Devel::Trepan::Util::invalid_filename($script_file);
90 0 ▶ unless (defined $result) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 0 0 0
91 0 $self->errmsg($result);
92 0 return 0;
93 }
94 0 my $script_intf =
95 Devel::Trepan::Interface::Script->new($script_file);
96 0 unshift @{$self->{user_inputs}}, $script_intf->{input};
97 0 $current_command = $script_intf->read_command;
98 } else {
99 0 $self->errmsg(sprintf "Unknown command: '%s'", $cmd_name);
100 0 return 0;
101 };
102 0 } eval {
103 0 $intf->write_remote(COMMAND, $current_command);
104 };
105 0 return 1;
106 }
107  
108 0 ▶sub handle_server_reponse($$$) {
Subroutine handle_server_reponse: not called CC=14 SCAR=53.5
Pod undocumented
109 0 my ($self, $control_code, $line) = @_;
110 0 my $intf = $self->{intf};
111 0 my $options = $self->{options};
112  
113 # p [control_code, line]
114 0 ▶ if (PRINT eq $control_code) {
Branch: 7 branches
BranchTrueFalseTotal
if ('.' eq $control_code) { } 0 0 0
elsif ('Y' eq $control_code) { } 0 0 0
elsif ('N' eq $control_code) { } 0 0 0
elsif ('p' eq $control_code) { } 0 0 0
elsif ('q' eq $control_code) { } 0 0 0
elsif ('r' eq $control_code) { } 0 0 0
elsif ('!' eq $control_code) { } 0 0 0
115 0 $self->msg($line);
116 } elsif (CONFIRM_TRUE eq $control_code) {
117 0 my $response = $intf->confirm($line, 1);
118 0 ▶ $intf->write_remote(CONFIRM_REPLY, $response ? 'Y' : 'N');
Branch: 1 branch
BranchTrueFalseTotal
$response ? : 0 0 0
119 } elsif (CONFIRM_FALSE eq $control_code) {
120 0 my $response = $intf->confirm($line, 1);
121 0 ▶ $intf->write_remote(CONFIRM_REPLY, $response ? 'Y' : 'N');
Branch: 1 branch
BranchTrueFalseTotal
$response ? : 0 0 0
122 } elsif (PROMPT eq $control_code) {
123 0 my $command;
124 0 my $leave_loop = 0;
125 0 ▶ until ($leave_loop) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($leave_loop) 0 0 0
126 0 eval {
127 0 $command = $self->{user_inputs}[0]->read_command($line);
128 };
129 # if ($intf->is_input_eof) {
130 # print "user-side EOF. Quitting...\n";
131 # last;
132 # }
133 0 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::Trepan::Client::EVAL_ERROR) 0 0 0
134 0 ▶ if (scalar @{$self->{user_inputs}} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->{'user_inputs'};} == 0) { } 0 0 0
135 0 $self->msg("user-side EOF. Quitting...");
136 0 $self->{leave_loop} = 1;
137 0 return;
138 } else {
139 0 shift @{$self->{user_inputs}};
140 0 next;
141 }
142 };
143 0 $leave_loop = $self->run_command($command);
144 0 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::Trepan::Client::EVAL_ERROR) 0 0 0
145 0 $self->msg("Remote debugged process died");
146 0 $self->{leave_loop} = 1;
147 0 return;
148 }
149 }
150 } elsif (QUIT eq $control_code) {
151 0 $self->{leave_loop} = 1;
152 0 return;
153 } elsif (RESTART eq $control_code) {
154 0 $intf->close;
155 # Make another connection..
156 $self = Devel::Trepan::Client->new(
157 {client => 1,
158 cmdfiles => [],
159 initial_dir => $options->{chdir},
160 nx => 1,
161 host => $options->{host},
162 port => $options->{port}}
163 0 );
164 0 $intf = $self->{intf};
165 } elsif (SERVERERR eq $control_code) {
166 0 $self->errmsg($line);
167 } else {
168 0 $self->errmsg("Unknown control code: '$control_code'");
169 }
170 }
171  
172 sub start_client($)
173 0 ▶{
Subroutine start_client: not called CC=4 SCAR=30.0
Pod undocumented
174 0 my $options = shift;
175 0 printf "Client option given\n";
176 0 my $client = Devel::Trepan::Client->new($options);
177  
178 0 my $intf = $client->{intf};
179 0 ▶ if ($intf->has_completion) {
Branch: 1 branch
BranchTrueFalseTotal
if ($intf->has_completion) 0 0 0
180 0 ▶ my $list_completion = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
181 0 my($text, $state) = @_;
182 0 list_complete($text, $state);
183 0 };
184 0 ▶ my $completion = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
185 0 my ($text, $line, $start, $end) = @_;
186 0 $client->complete($text, $line, $start, $end);
187 0 };
188 0 $intf->set_completion($completion, $list_completion);
189 }
190  
191 0 my ($control_code, $line);
192 0 ▶ until ($client->{leave_loop}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($client->{"leave_loop"}) 0 0 0
193 0 eval {
194 0 ($control_code, $line) = $intf->read_remote;
195 };
196 0 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Devel::Trepan::Client::EVAL_ERROR) 0 0 0
197 0 $client->msg("$EVAL_ERROR");
198 0 $client->msg("Remote debugged process may have closed connection");
199 0 last;
200 }
201 0 $client->handle_server_reponse($control_code, $line);
202 }
203 }
204  
205 39 ▶unless (caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 39 39
206 # Devel::Trepan::Client::start_client(
207 # {client =>['tcp', '127.0.0.1', port=>1954]});
208 # Devel::Trepan::Client::start_client(
209 # {client =>['tty'], logger => \*STDOUT});
210 0 Devel::Trepan::Client::start_client(
211 {client=>['tty', '/dev/pts/4', '/dev/pts/2'],
212 logger => \*STDOUT});
213 }
214 39 1;
« lib/Devel/Trepan/CmdProcessor/Complete.pm ↑ Summary lib/Devel/Trepan/CmdProcessor/Command/Complete.pm »