line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
15
|
|
|
15
|
|
73255
|
use strict; |
|
15
|
|
|
|
|
62
|
|
|
15
|
|
|
|
|
721
|
|
14
|
15
|
|
|
15
|
|
152
|
use Exporter; |
|
15
|
|
|
|
|
50
|
|
|
15
|
|
|
|
|
879
|
|
15
|
15
|
|
|
15
|
|
170
|
use warnings; |
|
15
|
|
|
|
|
64
|
|
|
15
|
|
|
|
|
579
|
|
16
|
|
|
|
|
|
|
|
17
|
15
|
|
|
15
|
|
103
|
use rlib '../../..'; |
|
15
|
|
|
|
|
42
|
|
|
15
|
|
|
|
|
113
|
|
18
|
15
|
|
|
15
|
|
6043
|
use IO::Handle; |
|
15
|
|
|
|
|
6326
|
|
|
15
|
|
|
|
|
1236
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# This is an abstract class that specifies debugger output. |
21
|
|
|
|
|
|
|
package Devel::Trepan::IO::Output; |
22
|
|
|
|
|
|
|
# use Devel::Trepan::Util qw(hash_merge); |
23
|
|
|
|
|
|
|
|
24
|
15
|
|
|
15
|
|
128
|
use vars qw(@EXPORT @EXPORT_OK); |
|
15
|
|
|
|
|
40
|
|
|
15
|
|
|
|
|
9184
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new($;$$) { |
27
|
14
|
|
|
14
|
0
|
642
|
my($class, $output, $opts) = @_; |
28
|
14
|
|
50
|
|
|
136
|
$opts ||= {}; |
29
|
14
|
50
|
|
|
|
55
|
unless ($output) { |
30
|
14
|
|
|
|
|
371
|
open STDOUT_DUP, ">&", STDOUT; |
31
|
14
|
|
|
|
|
88
|
$output = *STDOUT_DUP; |
32
|
|
|
|
|
|
|
}; |
33
|
14
|
|
|
|
|
154
|
my $self = { |
34
|
|
|
|
|
|
|
flush_after_write => 0, |
35
|
|
|
|
|
|
|
output => $output, |
36
|
|
|
|
|
|
|
eof => 0 |
37
|
|
|
|
|
|
|
}; |
38
|
14
|
|
|
|
|
43
|
bless $self, $class; |
39
|
14
|
|
|
|
|
162
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub is_closed($) { |
43
|
1
|
|
|
1
|
0
|
2
|
my($self) = @_; |
44
|
1
|
50
|
|
|
|
13
|
! $self->{output} || $self->is_eof; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
sub close($) { |
47
|
0
|
|
|
0
|
0
|
0
|
my($self) = @_; |
48
|
0
|
0
|
|
|
|
0
|
close $self->{output} unless $self->is_closed; |
49
|
0
|
|
|
|
|
0
|
$self->{eof} = 1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub is_eof($) { |
53
|
1
|
|
|
1
|
0
|
2
|
my($self) = @_; |
54
|
1
|
|
|
|
|
6
|
return $self->{eof}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub flush($) { |
58
|
0
|
|
|
0
|
0
|
0
|
my($self) = @_; |
59
|
0
|
|
|
|
|
0
|
$self->{output}->autoflush(1); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Use this to set where to write to. output can be a |
63
|
|
|
|
|
|
|
# file object or a string. This code raises IOError on error. |
64
|
|
|
|
|
|
|
sub write($$) { |
65
|
0
|
|
|
0
|
0
|
0
|
my ($self, $msg) = @_; |
66
|
0
|
|
|
|
|
0
|
print {$self->{output}} $msg; |
|
0
|
|
|
|
|
0
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# used to write to a debugger that is connected to this |
70
|
|
|
|
|
|
|
# `str' written will have a newline added to it |
71
|
|
|
|
|
|
|
# |
72
|
|
|
|
|
|
|
sub writeline($$) { |
73
|
1
|
|
|
1
|
0
|
16
|
my ($self, $msg) = @_; |
74
|
1
|
50
|
|
|
|
5
|
print {$self->{output}} $msg . "\n" unless $self->is_closed(); |
|
1
|
|
|
|
|
40
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
if (__FILE__ eq $0) { |
78
|
|
|
|
|
|
|
my $out = Devel::Trepan::IO::Output->new(); |
79
|
|
|
|
|
|
|
CORE::close(STDOUT); |
80
|
|
|
|
|
|
|
$out->writeline("Now is the time!"); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |