| 1 | # Copyright (C) 2011, 2012 Rocky Bernstein <rocky@cpan.org> | ||||||||||||||||||||||
| 2 | # classes to support communication to and from the debugger. This | ||||||||||||||||||||||
| 3 | # communcation might be to/from another process or another computer. | ||||||||||||||||||||||
| 4 | # And reading may be from a debugger command script. | ||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||
| 6 | # For example, we'd like to support Sockets, and serial lines and file | ||||||||||||||||||||||
| 7 | # reading, as well a readline-type input. Encryption and Authentication | ||||||||||||||||||||||
| 8 | # methods might decorate some of the communication channels. | ||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||
| 10 | # Some ideas originiated as part of Matt Fleming's 2006 Google Summer of | ||||||||||||||||||||||
| 11 | # Code project. | ||||||||||||||||||||||
| 12 | |||||||||||||||||||||||
| 13 | 55 | ▶ | use strict; use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | 55 | ▶ | use Exporter; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 15 | 55 | ▶ | use rlib '../..'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | package Devel::Trepan::IO::InputBase; | ||||||||||||||||||||||
| 18 | 55 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | 55 | ▶ | use Devel::Trepan::Util qw(hash_merge); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 21 | # our @EXPORT; | ||||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | 55 | my $DEFAULT_OPTS = {line_edit => 0}; | |||||||||||||||||||||
| 24 | # @EXPORT = qw(DEFAULT_OPTS); | ||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | 28 | ▶ | sub new($$;$) { | ||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=9.2
| |||||||||||||||||||||||
| 27 | 0 | ▶ | my($class, $input, $opts) = @_; | ||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=9.2
| |||||||||||||||||||||||
| 28 | 0 | ▶ | $opts ||= {}; | ||||||||||||||||||||
|
Condition50%2/4
$opts ||= {}
$opts ||= {}
MC/DC100%1/1
$opts ||= {}
$opts
MC/DC0%0/1
$opts ||= {}
$opts
Truth table100%2/2
A
A= $opts
Truth table0%0/2
A
A= $opts
| |||||||||||||||||||||||
| 29 | 0 | hash_merge($opts, $DEFAULT_OPTS); | |||||||||||||||||||||
| 30 | 0 | my $line_edit = $opts->{line_edit}; | |||||||||||||||||||||
| 31 | 0 | my $self = { | |||||||||||||||||||||
| 32 | input => $input, | ||||||||||||||||||||||
| 33 | eof => 0, | ||||||||||||||||||||||
| 34 | line_edit => $line_edit | ||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||
| 36 | 0 | bless $self, $class; | |||||||||||||||||||||
| 37 | 0 | return $self; | |||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||
| 39 | |||||||||||||||||||||||
| 40 | 0 | ▶ | sub is_closed($) { | ||||||||||||||||||||
|
Subroutine
is_closed: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 41 | 0 | ▶ | my($self) = shift; | ||||||||||||||||||||
|
Subroutine
is_closed: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 42 | 0 | ▶ | ! $self->{input} || $self->is_eof; | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||
| 44 | |||||||||||||||||||||||
| 45 | 0 | ▶ | sub close($) { | ||||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 46 | 0 | ▶ | my($self) = shift; | ||||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 47 | 0 | ▶ | CORE::close $self->{input} unless $self->is_closed; | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 48 | 0 | $self->{eof} = 1; | |||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||
| 50 | |||||||||||||||||||||||
| 51 | sub want_term_readline() { | ||||||||||||||||||||||
| 52 | 0; | ||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | 10 | ▶ | sub is_eof($) { | ||||||||||||||||||||
|
Subroutine
is_eof: called CC=1 SCAR=1.2
| |||||||||||||||||||||||
| 56 | 0 | ▶ | my($self) = shift; | ||||||||||||||||||||
|
Subroutine
is_eof: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||
| 57 | 0 | return $self->{eof}; | |||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | sub is_interactive() { | ||||||||||||||||||||||
| 61 | 0; | ||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | # This is an abstract class that specifies debugger output. | ||||||||||||||||||||||
| 65 | package Devel::Trepan::IO::OutputBase; | ||||||||||||||||||||||
| 66 | |||||||||||||||||||||||
| 67 | # attr_accessor :flush_after_write | ||||||||||||||||||||||
| 68 | # attr_reader :output | ||||||||||||||||||||||
| 69 | |||||||||||||||||||||||
| 70 | sub new($$;$) | ||||||||||||||||||||||
| 71 | 3 | ▶ | { | ||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=10.1
| |||||||||||||||||||||||
| 72 | 0 | ▶ | my ($class, $out, $opts) = @_; | ||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=10.1
| |||||||||||||||||||||||
| 73 | 0 | ▶ | $opts = {} unless defined $opts; | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | 0 | my $self = { | |||||||||||||||||||||
| 76 | output => $out, | ||||||||||||||||||||||
| 77 | flush_after_write => 0, | ||||||||||||||||||||||
| 78 | eof => 0 | ||||||||||||||||||||||
| 79 | }; | ||||||||||||||||||||||
| 80 | 0 | bless $self, $class; | |||||||||||||||||||||
| 81 | 0 | $self | |||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | sub close($) | ||||||||||||||||||||||
| 85 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 86 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
close: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 87 | 0 | ▶ | $self->{output}->close if $self->{output}; | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 88 | 0 | $self->{eof} = 1; | |||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | 0 | ▶ | sub is_eof($) { $_->[0]->{eof} || $_->[0]->eof } | ||||||||||||||||||||
|
Subroutine
is_eof: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||
| 92 | |||||||||||||||||||||||
| 93 | ## sub flush($) { $_->[0]->{output}->flush } | ||||||||||||||||||||||
| 94 | ## FIXME: this isn't quite right. | ||||||||||||||||||||||
| 95 | 0 | ▶ | sub flush($) {$_->[0]->{output}->autoflush = 1 } | ||||||||||||||||||||
|
Subroutine
flush: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 96 | |||||||||||||||||||||||
| 97 | # Use this to set where to write to. output can be a | ||||||||||||||||||||||
| 98 | # file object or a string. This code raises IOError on error. | ||||||||||||||||||||||
| 99 | sub write | ||||||||||||||||||||||
| 100 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
write: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 101 | 0 | my $self = shift; | |||||||||||||||||||||
| 102 | 0 | $self->{output}->print(@_); | |||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||
| 104 | |||||||||||||||||||||||
| 105 | # used to write to a debugger that is connected to this | ||||||||||||||||||||||
| 106 | # `str' written will have a newline added to it | ||||||||||||||||||||||
| 107 | # | ||||||||||||||||||||||
| 108 | sub writeline($$) | ||||||||||||||||||||||
| 109 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
writeline: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 110 | 0 | my ($self, $msg) = @_; | |||||||||||||||||||||
| 111 | 0 | $self->{output}->write("${msg}\n") | |||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||
| 113 | |||||||||||||||||||||||
| 114 | 55 | ▶ | unless (caller) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 115 | 0 | my $in = Devel::Trepan::IO::InputBase->new(*main::STDIN); | |||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||
| 117 | |||||||||||||||||||||||
| 118 | 55 | 1; | |||||||||||||||||||||