« 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
| |||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if (PRINT eq $control_code) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 88 | 0 | my $result = | |||||||||||||||||||||||||||||||||
| 89 | Devel::Trepan::Util::invalid_filename($script_file); | ||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | unless (defined $result) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 122 | } elsif (PROMPT eq $control_code) { | ||||||||||||||||||||||||||||||||||
| 123 | 0 | my $command; | |||||||||||||||||||||||||||||||||
| 124 | 0 | my $leave_loop = 0; | |||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | until ($leave_loop) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if (scalar @{$self->{user_inputs}} == 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 193 | 0 | eval { | |||||||||||||||||||||||||||||||||
| 194 | 0 | ($control_code, $line) = $intf->read_remote; | |||||||||||||||||||||||||||||||||
| 195 | }; | ||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ($EVAL_ERROR) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||