blib/lib/Devel/ebug/Console.pm

filter: Statementstmt 57.3% 74 / 129 Branchbran 54.6% 47 / 86 Conditioncond 18.1% 2 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 2 totaltotal 54.0% 133 / 246 CC 55 SCAR 50.3
CC
55
Cov
54%
run
212.9
show_codelines
56.0
__ANON__
30.0
CRAP 153.5
↑ Summary blib/lib/Devel/ebug/Backend.pm »
1 package Devel::ebug::Console;
2  
3 5 our $VERSION = '0.69'; # VERSION
4  
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Class::Accessor::Chained::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Devel::ebug;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Term::ReadLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use base qw(Class::Accessor::Chained::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 ▶sub run {
Subroutine run: called CC=45 SCAR=53.6
Pod undocumented
15 5 my $self = shift;
16 5 my $backend = shift;
17  
18 1 ▶ $SIG{INT} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
19 1 die "INT";
20 5 };
21  
22 5 my $ebug = Devel::ebug->new;
23  
24 # "ebug add.pl 3 4" passes each argument through untouched, while a
25 # single "ebug 'add.pl 3 4'" is still handed to the shell as before
26 5 my ($filename, @args) = @ARGV;
27 5 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 1 4 5
28 1 $ebug->args(\@args);
29 }
30  
31 5 ▶ unless (defined $filename && length $filename) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $filename and length $filename) 0 5 5
Condition33%1/3
defined $filename and length $filename
!ll&&!rl&&r
005
MC/DC0%0/2
defined $filename and length $filename
defined $filename length $filename
Truth table33%1/3
A and B
A= defined $filenameB= length $filename
ABresult
0X0
100
111
32 0 $filename = '-e "Interactive ebugging shell"';
33 }
34  
35 5 $ebug->program($filename);
36 5 $ebug->backend($backend);
37 5 $ebug->load;
38  
39 5 my $codelines = {};
40  
41 5 print "* Welcome to Devel::ebug $Devel::ebug::VERSION\n";
42  
43 5 my $term = Term::ReadLine->new('ebug');
44 5 my $attribs = $term->Attribs;
45 0 ▶ $attribs->{completion_function} = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
46 0 my ($text, $line, $start) = @_;
47 0 ▶ my $pad = $ebug->pad || {};
Condition0%0/2
$ebug->pad || {}
l!l
00
MC/DC0%0/1
$ebug->pad || {}
$ebug->pad
Truth table0%0/2
A
A= $ebug->pad
Aresult
11
00
48 0 ▶ return unless $line =~ s/^x //;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ s/^x // 0 0 0
49 0 my @result = grep { /^\Q$line/ } keys %$pad;
50 0 ▶ if ($line =~ /^[\$\@]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^[\$\@]/) 0 0 0
51 0 s/^[\$\@]// for @result;
52 }
53 0 return @result;
54 5 };
55 5 my $last_command = "s";
56 5 my $list_always = 0;
57 5 my $list_lines_count = 9;
58  
59 5 while (1) {
60 21 ▶ if ($ebug->finished) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ebug->finished) { } 2 19 21
61 2 print "ebug: Program finished. Enter 'restart' or 'q'\n";
62 } else {
63 19 ▶ if ($list_always) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list_always) { } 0 19 19
64 0 ▶ show_codelines($codelines, $ebug, $list_lines_count) if($list_always);
Branch: 1 branch
BranchTrueFalseTotal
if $list_always 0 0 0
65 } else {
66 19 print $ebug->subroutine
67 . "(" . $ebug->filename . "#" . $ebug->line . "):\n"
68 . $ebug->codeline, "\n";
69 }
70 }
71  
72 21 my $command = $term->readline("ebug: ");
73 21 ▶ $command = "q" if not defined $command;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $command 0 21 21
74 21 ▶ $command = $last_command if ($command eq "");
Branch: 1 branch
BranchTrueFalseTotal
if $command eq "" 1 20 21
75  
76 21 ▶ if ($command =~ /^\s*[?h](elp)?\s*$/) {
Branch: 26 branches
BranchTrueFalseTotal
if ($command =~ /^\s*[?h](elp)?\s*$/) { } 1 20 21
elsif ($command eq 'l') { } 0 20 20
elsif ($command =~ /^ l \s+ (\d+) $/x) { } 0 20 20
elsif ($command eq 'L') { } 0 20 20
elsif ($command eq 'p') { } 1 19 20
elsif ($command eq 's') { } 3 16 19
elsif ($command eq 'n') { } 1 15 16
elsif ($command eq 'o') { } 0 15 15
elsif ($command eq 'r') { } 5 10 15
elsif ($command eq 'restart') { } 0 10 10
elsif ($command =~ /^ret ?(.*)/) { } 0 10 10
elsif ($command eq 'T') { } 0 10 10
elsif ($command eq 'f') { } 0 10 10
elsif (() = $command =~ /^b (\d+) ?(.*)/) { } 1 9 10
elsif (() = $command =~ /^b ((?:\w+::)+\w+)(?: (.+))?$/) { } 1 8 9
elsif ($command =~ /^b (.+?) (\d+) ?(.*)/) { } 0 8 8
elsif ($command =~ /^b (.+)/) { } 0 8 8
elsif ($command =~ /^bf (.+)/) { } 0 8 8
elsif ($command =~ /^d (.+?) (\d+)/) { } 0 8 8
elsif ($command =~ /^d (\d+)/) { } 0 8 8
elsif ($command =~ /^w (.+)/) { } 0 8 8
elsif ($command =~ /^u ?(.*)/) { } 0 8 8
elsif ($command eq 'q') { } 4 4 8
elsif ($command =~ /^x (.+)/) { } 0 4 4
elsif ($command =~ /^e (.+)/) { } 4 0 4
elsif ($command) { } 0 0 0
77 1 print 'Commands:
78  
79 b Set break point at a line number (eg: b 6, b code.pl 6, b code.pl 6 $x > 7,
80 b Calc::fib, b Calc::fib $_[1] > 5)
81 bf break on file loading (eg: bf Calc.pm)
82 d Delete a break point (d 6, d code.pl 6)
83 e Eval Perl code and print the result (eg: e $x+$y)
84 f Show all the filenames loaded
85 l List codelines or set number of codelines to list (eg: l, l 20)
86 L List codelines always (toggle)
87 n Next (steps over subroutine calls)
88 o Output (show STDOUT, STDERR)
89 p Show pad
90 r Run until next break point or watch point
91 ret Return from subroutine (eg: ret, ret 3.141)
92 restart Restart the program
93 s Step (steps into subroutine calls)
94 T Show a stack trace
95 u Undo (eg: u, u 4)
96 w Set a watchpoint (eg: w $t > 10)
97 x Dump a variable using YAML (eg: x $object)
98 q Quit
99 ';
100 } elsif ($command eq 'l') {
101 0 show_codelines($codelines, $ebug, $list_lines_count);
102 } elsif ($command =~ /^ l \s+ (\d+) $/x) {
103 0 ▶ $list_lines_count = $1 if $1 > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $1 > 0 0 0 0
104 0 show_codelines($codelines, $ebug, $list_lines_count);
105 } elsif ($command eq 'L') {
106 0 $list_always = !$list_always;
107 } elsif ($command eq 'p') {
108 1 my $pad = $ebug->pad_human;
109 1 foreach my $k (sort keys %$pad) {
110 1 my $v = $pad->{$k};
111 1 print " $k = $v;\n";
112 }
113 } elsif ($command eq 's') {
114 3 $ebug->step;
115 } elsif ($command eq 'n') {
116 1 $ebug->next;
117 } elsif ($command eq 'o') {
118 0 my($stdout, $stderr) = $ebug->output;
119 0 print "STDOUT:\n$stdout\n";
120 0 print "STDERR:\n$stderr\n";
121 } elsif ($command eq 'r') {
122 5 eval { $ebug->run };
123 5 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 2 3 5
124 2 ▶ die $@ unless $@ =~ /^INT/;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ =~ /^INT/ 1 1 2
125 # SIGINT while the program was running: the backend already
126 # dropped into the debugger, so pick up where it stopped
127 # instead of dying back out to the shell.
128 1 $ebug->wait_for_stop;
129 }
130 } elsif ($command eq 'restart') {
131 0 $ebug->load;
132 } elsif ($command =~ /^ret ?(.*)/) {
133 0 $ebug->return($1);
134 } elsif ($command eq 'T') {
135 0 my @trace = $ebug->stack_trace_human;
136 0 foreach my $frame (@trace) {
137 0 print "$frame\n";
138 }
139 } elsif ($command eq 'f') {
140 0 print "$_\n" foreach $ebug->filenames;
141 } elsif (my($line, $condition) = $command =~ /^b (\d+) ?(.*)/) {
142 1 ▶ undef $condition unless $condition;
Branch: 1 branch
BranchTrueFalseTotal
unless $condition 1 0 1
143 1 $ebug->break_point($line, $condition);
144 } elsif (my($sub, $sub_condition) = $command =~ /^b ((?:\w+::)+\w+)(?: (.+))?$/) {
145 # a fully qualified subroutine name, optionally with a condition;
146 # checked before "b FILE LINE", which would otherwise take a
147 # condition ending in a number as the line
148 1 $ebug->break_point_subroutine($sub, $sub_condition);
149 } elsif ($command =~ /^b (.+?) (\d+) ?(.*)/) {
150 0 $ebug->break_point($1, $2, $3);
151 } elsif ($command =~ /^b (.+)/) {
152 0 $ebug->break_point_subroutine($1);
153 } elsif ($command =~ /^bf (.+)/) {
154 0 $ebug->break_on_load($1);
155 } elsif ($command =~ /^d (.+?) (\d+)/) {
156 0 $ebug->break_point_delete($1, $2);
157 } elsif ($command =~ /^d (\d+)/) {
158 0 $ebug->break_point_delete($1);
159 } elsif ($command =~ /^w (.+)/) {
160 0 my($watch_point) = $command =~ /^w (.+)/;
161 0 $ebug->watch_point($watch_point);
162 } elsif ($command =~ /^u ?(.*)/) {
163 0 $ebug->undo($1);
164 } elsif ($command eq 'q') {
165 4 exit;
166 } elsif ($command =~ /^x (.+)/) {
167 0 ▶ my $v = $ebug->eval("use YAML; Dump($1)") || "";
Condition0%0/2
$ebug->eval("use YAML; Dump($1)") || ''
l!l
00
MC/DC0%0/1
$ebug->eval("use YAML; Dump($1)") || ''
$ebug->eval("use YAML; Dump($1)")
Truth table0%0/2
A
A= $ebug->eval("use YAML; Dump($1)")
Aresult
11
00
168 0 print "$v\n";
169 } elsif ($command =~ /^e (.+)/) {
170 4 ▶ my $v = $ebug->eval($1) || "";
Condition50%1/2
$ebug->eval($1) || ''
l!l
40
MC/DC0%0/1
$ebug->eval($1) || ''
$ebug->eval($1)
Truth table50%1/2
A
A= $ebug->eval($1)
Aresult
11
00
171 4 print "$v\n";
172 } elsif ($command) {
173 0 ▶ my $v = $ebug->eval($command) || "";
Condition0%0/2
$ebug->eval($command) || ''
l!l
00
MC/DC0%0/1
$ebug->eval($command) || ''
$ebug->eval($command)
Truth table0%0/2
A
A= $ebug->eval($command)
Aresult
11
00
174 0 print "$v\n";
175  
176 }
177 16 $last_command = $command;
178 }
179 }
180  
181 0 ▶sub show_codelines {
Subroutine show_codelines: not called CC=7 SCAR=40.3
Pod undocumented
182 0 my ($codelines, $ebug, $list_lines_count) = @_;
183  
184 0 my $line_count = int($list_lines_count / 2);
185  
186 0 ▶ if (not exists $codelines->{$ebug->filename}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$codelines{$ebug->filename}) 0 0 0
187 0 $codelines->{$ebug->filename} = [$ebug->codelines];
188 }
189  
190 0 my @span = ($ebug->line-$line_count .. $ebug->line+$line_count);
191 0 @span = grep { $_ > 0 } @span;
192 0 my @codelines = @{$codelines->{$ebug->filename}};
193 0 my @break_points = $ebug->break_points();
194 0 my %break_points;
195 0 $break_points{$_}++ foreach @break_points;
196 0 foreach my $s (@span) {
197 0 my $codeline = $codelines[$s -1 ];
198 0 ▶ next unless defined $codeline;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $codeline 0 0 0
199 0 ▶ if ($s == $ebug->line) {
Branch: 2 branches
BranchTrueFalseTotal
if ($s == $ebug->line) { } 0 0 0
elsif ($break_points{$s}) { } 0 0 0
200 0 print "*";
201 } elsif ($break_points{$s}) {
202 0 print "b";
203 } else {
204 0 print " ";
205 }
206 0 print "$s:$codeline\n";
207 }
208 }
209  
210 5 1;
211  
212 __END__
↑ Summary blib/lib/Devel/ebug/Backend.pm »