blib/lib/B/Disassembler.pm

filter: Statementstmt 64.5% 166 / 257 Branchbran 26.4% 46 / 174 Conditioncond 25.0% 9 / 36 MC/DCmcdc 13.0% 3 / 23 Subroutinesub 80.0% 32 / 40 Podpod 0.0% 0 / 5 totaltotal 47.8% 256 / 535 CC 93 SCAR 61.5
CC
93
Cov
47%
print_insn
1560.0
disassemble_fh
22.5
GET_double
20.0
CRAP 466.4
« script/cc_harness ↑ Summary blib/lib/B/Bytecode.pm »
1 # Disassembler.pm
2 #
3 # Copyright (c) 1996 Malcolm Beattie
4 # Copyright (c) 2008,2009,2010,2011,2012 Reini Urban
5 #
6 # You may distribute under the terms of either the GNU General Public
7 # License or the Artistic License, as specified in the README file.
8  
9 1 $B::Disassembler::VERSION = '1.13';
10  
11 package B::Disassembler::BytecodeStream;
12  
13 1 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Config qw(%Config);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use B qw(cstring cast_I32);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 @ISA = qw(FileHandle);
18  
19 134 ▶sub readn {
Subroutine readn: called CC=2 SCAR=7.0
20 134 my ( $fh, $len ) = @_;
21 134 my $data;
22 134 read( $fh, $data, $len );
23 134 ▶ croak "reached EOF while reading $len bytes" unless length($data) == $len;
Branch: 1 branch
BranchTrueFalseTotal
unless length $data == $len 0 134 134
24 134 return $data;
25 }
26  
27 27 ▶sub GET_U8 {
Subroutine GET_U8: called CC=2 SCAR=7.0
28 27 my $fh = shift;
29 27 my $c = $fh->getc;
30 27 ▶ croak "reached EOF while reading U8" unless defined($c);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 27 27
31 27 return ord($c);
32 }
33  
34 6 ▶sub GET_U16 {
Subroutine GET_U16: called CC=2 SCAR=7.0
35 6 my $fh = shift;
36 6 my $str = $fh->readn(2);
37 6 ▶ croak "reached EOF while reading U16" unless length($str) == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless length $str == 2 0 6 6
38  
39 # Todo: check byteorder
40 6 return unpack( "S", $str );
41 }
42  
43 2 ▶sub GET_NV {
Subroutine GET_NV: called CC=4 SCAR=14.0
44 2 my $fh = shift;
45 2 my ( $str, $c );
46 2 ▶ while ( defined( $c = $fh->getc ) && $c ne "\0" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($c = $fh->getc) and $c ne "\0") 20 2 22
Condition66%2/3
defined($c = $fh->getc) and $c ne "\0"
!ll&&!rl&&r
0220
MC/DC50%1/2
defined($c = $fh->getc) and $c ne "\0"
defined($c = $fh->getc) $c ne "\0"
Truth table66%2/3
A and B
A= defined($c = $fh->getc)B= $c ne "\0"
ABresult
0X0
100
111
47 20 $str .= $c;
48 }
49 2 ▶ croak "reached EOF while reading double" unless defined($c);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 2 2
50 2 return $str;
51 }
52  
53 33 ▶sub GET_U32 {
Subroutine GET_U32: called CC=2 SCAR=7.0
54 33 my $fh = shift;
55 33 my $str = $fh->readn(4);
56 33 ▶ croak "reached EOF while reading U32" unless length($str) == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless length $str == 4 0 33 33
57  
58 # Todo: check byteorder
59 33 return unpack( "L", $str );
60 }
61  
62 5 ▶sub GET_I32 {
Subroutine GET_I32: called CC=2 SCAR=7.0
63 5 my $fh = shift;
64 5 my $str = $fh->readn(4);
65 5 ▶ croak "reached EOF while reading I32" unless length($str) == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless length $str == 4 0 5 5
66  
67 # Todo: check byteorder
68 5 return unpack( "l", $str );
69 }
70  
71 0 ▶sub GET_objindex {
Subroutine GET_objindex: not called CC=2 SCAR=17.9
72 0 my $fh = shift;
73 0 my $str = $fh->readn(4);
74 0 ▶ croak "reached EOF while reading objindex" unless length($str) == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless length $str == 4 0 0 0
75  
76 # Todo: check byteorder
77 0 return unpack( "L", $str );
78 }
79  
80 17 ▶sub GET_opindex {
Subroutine GET_opindex: called CC=2 SCAR=7.0
81 17 my $fh = shift;
82 17 my $str = $fh->readn(4);
83 17 ▶ croak "reached EOF while reading opindex" unless length($str) == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless length $str == 4 0 17 17
84  
85 # Todo: check byteorder
86 17 return unpack( "L", $str );
87 }
88  
89 48 ▶sub GET_svindex {
Subroutine GET_svindex: called CC=2 SCAR=7.0
90 48 my $fh = shift;
91 48 my $str = $fh->readn(4);
92 48 ▶ croak "reached EOF while reading svindex" unless length($str) == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless length $str == 4 0 48 48
93  
94 # Todo: check byteorder
95 48 return unpack( "L", $str );
96 }
97  
98 10 ▶sub GET_pvindex {
Subroutine GET_pvindex: called CC=2 SCAR=7.0
99 10 my $fh = shift;
100 10 my $str = $fh->readn(4);
101 10 ▶ croak "reached EOF while reading pvindex" unless length($str) == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless length $str == 4 0 10 10
102  
103 # Todo: check byteorder
104 10 return unpack( "L", $str );
105 }
106  
107 0 ▶sub GET_hekindex {
Subroutine GET_hekindex: not called CC=2 SCAR=17.9
108 0 my $fh = shift;
109 0 my $str = $fh->readn(4);
110 0 ▶ croak "reached EOF while reading hekindex" unless length($str) == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless length $str == 4 0 0 0
111  
112 # Todo: check byteorder
113 0 return unpack( "L", $str );
114 }
115  
116 15 ▶sub GET_strconst {
Subroutine GET_strconst: called CC=4 SCAR=14.0
117 15 my $fh = shift;
118 15 my ( $str, $c );
119 15 $str = '';
120 15 ▶ while ( defined( $c = $fh->getc ) && $c ne "\0" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($c = $fh->getc) and $c ne "\0") 48 15 63
Condition66%2/3
defined($c = $fh->getc) and $c ne "\0"
!ll&&!rl&&r
01548
MC/DC50%1/2
defined($c = $fh->getc) and $c ne "\0"
defined($c = $fh->getc) $c ne "\0"
Truth table66%2/3
A and B
A= defined($c = $fh->getc)B= $c ne "\0"
ABresult
0X0
100
111
121 48 $str .= $c;
122 }
123 15 ▶ croak "reached EOF while reading strconst" unless defined($c);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 15 15
124 15 return cstring($str);
125 }
126  
127 4 ▶sub GET_pvcontents { }
Subroutine GET_pvcontents: called CC=1 SCAR=0.0
128  
129 3 ▶sub GET_PV {
Subroutine GET_PV: called CC=3 SCAR=11.0
130 3 my $fh = shift;
131 3 my $str;
132 3 my $len = $fh->GET_U32;
133 3 ▶ if ($len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len) { } 1 2 3
134 1 read( $fh, $str, $len );
135 1 ▶ croak "reached EOF while reading PV" unless length($str) == $len;
Branch: 1 branch
BranchTrueFalseTotal
unless length $str == $len 0 1 1
136 1 return cstring($str);
137 }
138 else {
139 2 return '""';
140 }
141 }
142  
143 2 ▶sub GET_comment_t {
Subroutine GET_comment_t: called CC=4 SCAR=14.0
144 2 my $fh = shift;
145 2 my ( $str, $c );
146 2 ▶ while ( defined( $c = $fh->getc ) && $c ne "\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($c = $fh->getc) and $c ne "\n") 18 2 20
Condition66%2/3
defined($c = $fh->getc) and $c ne "\n"
!ll&&!rl&&r
0218
MC/DC50%1/2
defined($c = $fh->getc) and $c ne "\n"
defined($c = $fh->getc) $c ne "\n"
Truth table66%2/3
A and B
A= defined($c = $fh->getc)B= $c ne "\n"
ABresult
0X0
100
111
147 18 $str .= $c;
148 }
149 2 ▶ croak "reached EOF while reading comment" unless defined($c);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 2 2
150 2 return cstring($str);
151 }
152  
153 0 ▶sub GET_double {
Subroutine GET_double: not called CC=4 SCAR=30.0
154 0 my $fh = shift;
155 0 my ( $str, $c );
156 0 ▶ while ( defined( $c = $fh->getc ) && $c ne "\0" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($c = $fh->getc) and $c ne "\0") 0 0 0
Condition0%0/3
defined($c = $fh->getc) and $c ne "\0"
!ll&&!rl&&r
000
MC/DC0%0/2
defined($c = $fh->getc) and $c ne "\0"
defined($c = $fh->getc) $c ne "\0"
Truth table0%0/3
A and B
A= defined($c = $fh->getc)B= $c ne "\0"
ABresult
0X0
100
111
157 0 $str .= $c;
158 }
159 0 ▶ croak "reached EOF while reading double" unless defined($c);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 0 0
160 0 return $str;
161 }
162  
163 6 ▶sub GET_none { }
Subroutine GET_none: called CC=1 SCAR=0.0
164  
165 2 ▶sub GET_op_tr_array {
Subroutine GET_op_tr_array: called CC=1 SCAR=0.0
166 2 my $fh = shift;
167 2 my $len = unpack "S", $fh->readn(2);
168 2 my @ary = unpack "S*", $fh->readn( $len * 2 );
169 2 return join( ",", $len, @ary );
170 }
171  
172 9 ▶sub GET_IV64 {
Subroutine GET_IV64: called CC=3 SCAR=11.0
173 9 my $fh = shift;
174 9 my $str = $fh->readn(8);
175 9 ▶ croak "reached EOF while reading I32" unless length($str) == 8;
Branch: 1 branch
BranchTrueFalseTotal
unless length $str == 8 0 9 9
176  
177 # Todo: check byteorder
178 9 my $i = unpack( "q", $str );
179 9 ▶ return $i > 8 ? sprintf "0x%09llx", $i : $i;
Branch: 1 branch
BranchTrueFalseTotal
$i > 8 ? : 1 8 9
180 }
181  
182 9 ▶sub GET_IV {
Subroutine GET_IV: called CC=2 SCAR=7.6
183 # Check the header settings, not the current settings.
184 9 ▶ $B::Disassembler::ivsize == 4 ? &GET_I32 : &GET_IV64;
Branch: 1 branch
BranchTrueFalseTotal
$B::Disassembler::ivsize == 4 ? : 0 9 9
185 # $Config{ivsize} == 4 ? &GET_I32 : &GET_IV64;
186 }
187  
188 0 ▶sub GET_PADOFFSET {
Subroutine GET_PADOFFSET: not called CC=2 SCAR=17.9
189 # Check the header settings, not the current settings.
190 0 ▶ $B::Disassembler::ptrsize == 8 ? &GET_IV64 : &GET_U32;
Branch: 1 branch
BranchTrueFalseTotal
$B::Disassembler::ptrsize == 8 ? : 0 0 0
191 # $Config{ptrsize} == 8 ? &GET_IV64 : &GET_U32;
192 }
193  
194 0 ▶sub GET_long {
Subroutine GET_long: not called CC=4 SCAR=30.0
195 # Check the header settings, not the current settings.
196 # B::Disassembler::ivsize or longsize if ge xxx?
197 0 ▶ if ($B::Disassembler::longsize) {
Branch: 1 branch
BranchTrueFalseTotal
if ($B::Disassembler::longsize) { } 0 0 0
198 0 ▶ return $B::Disassembler::longsize == 8 ? &GET_IV64 : &GET_U32;
Branch: 1 branch
BranchTrueFalseTotal
$B::Disassembler::longsize == 8 ? : 0 0 0
199 } else {
200 # return $Config{longsize} == 8 ? &GET_IV64 : &GET_U32;
201 0 ▶ return $B::Disassembler::ivsize == 8 ? &GET_IV64 : &GET_U32;
Branch: 1 branch
BranchTrueFalseTotal
$B::Disassembler::ivsize == 8 ? : 0 0 0
202 }
203 }
204  
205 3 ▶sub GET_pmflags {
Subroutine GET_pmflags: called CC=3 SCAR=11.8
206 3 my $fh = shift;
207 3 my $size = 2;
208 3 ▶ if ($B::Disassembler::blversion ge '"0.07"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($B::Disassembler::blversion ge "\"0.07\"") 3 0 3
209 3 ▶ if ($B::Disassembler::perlversion ge '"5.013"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($B::Disassembler::perlversion ge "\"5.013\"") 3 0 3
210 3 return $fh->GET_U32;
211 }
212 }
213 0 return $fh->GET_U16;
214 }
215  
216 package B::Disassembler;
217 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
218 1 @ISA = qw(Exporter);
219 1 our @EXPORT_OK = qw(disassemble_fh get_header print_insn print_insn_bare @opname);
220 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
221 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
222 1 ▶use B::Asmdata qw(%insn_data @insn_name);
Subroutine BEGIN: called CC=1 SCAR=0.0
223 1 ▶use Opcode qw(opset_to_ops full_opset);
Subroutine BEGIN: called CC=1 SCAR=0.0
224 1 ▶use Config qw(%Config);
Subroutine BEGIN: called CC=1 SCAR=0.0
225 1 ▶use B::Concise;
Subroutine BEGIN: called CC=1 SCAR=0.0
226  
227 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=8.1
228 1 ▶ if ( $] < 5.009 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < 5.009) { } 0 1 1
229 0 B::Asmdata->import(qw(@specialsv_name));
230 }
231 else {
232 1 B->import(qw(@specialsv_name));
233 }
234 }
235  
236 1 my $ix;
237 my $opname;
238 1 our @opname = opset_to_ops(full_opset);
239 our (
240 1 $magic, $archname, $blversion, $ivsize,
241 $ptrsize, $longsize, $byteorder, $archflag, $perlversion
242 );
243 # >=5.12
244 1 our @svnames = ("NULL"); # 0
245 1 ▶push @svnames, "BIND" if $] >= 5.009 and $] < 5.019002; # 1
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.009" and $] < "5.019002" 0 1 1
Condition33%1/3
$] >= "5.009" and $] < "5.019002"
!ll&&!rl&&r
010
MC/DC0%0/2
$] >= "5.009" and $] < "5.019002"
$] >= "5.009" $] < "5.019002"
Truth table33%1/3
A and B
A= $] >= "5.009"B= $] < "5.019002"
ABresult
0X0
100
111
246 1 push @svnames, ("IV", "NV"); # 2,3
247 1 ▶push @svnames, "RV" if $] < 5.011; #
Branch: 1 branch
BranchTrueFalseTotal
if $] < "5.011" 0 1 1
248 1 push @svnames, "PV";
249 1 ▶push @svnames, "INVLIST" if $] >= 5.019002; # 4
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.019002" 1 0 1
250 1 push @svnames, ("PVIV", "PVNV", "PVMG"); # 4-7
251 1 ▶push @svnames, "BM" if $] < 5.009;
Branch: 1 branch
BranchTrueFalseTotal
if $] < "5.009" 0 1 1
252 1 ▶push @svnames, "REGEXP" if $] >= 5.011; # 8
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.011" 1 0 1
253 1 ▶push @svnames, "GV" if $] >= 5.009; # 9
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.009" 1 0 1
254 1 push @svnames, ("PVLV", "AV", "HV", "CV"); # 10-13
255 1 ▶push @svnames, "GV" if $] < 5.009;
Branch: 1 branch
BranchTrueFalseTotal
if $] < "5.009" 0 1 1
256 1 push @svnames, ("FM", "IO"); # 14,15
257  
258 1 ▶sub dis_header($) {
Subroutine dis_header: called CC=8 SCAR=22.9
Pod undocumented
259 1 my ($fh) = @_;
260 1 my $str = $fh->readn(3);
261 1 ▶ if ($str eq '#! ') {
Branch: 1 branch
BranchTrueFalseTotal
if ($str eq '#! ') { } 0 1 1
262 0 $str .= $fh->GET_comment_t;
263 0 $str .= $fh->GET_comment_t;
264 0 $magic = $fh->GET_U32;
265 } else {
266 1 $str .= $fh->readn(1);
267 1 $magic = unpack( "L", $str );
268 }
269 1 ▶ warn("bad magic") if $magic != 0x43424c50;
Branch: 1 branch
BranchTrueFalseTotal
if $B::Disassembler::magic != 1128418384 0 1 1
270 1 $archname = $fh->GET_strconst();
271 1 $blversion = $fh->GET_strconst();
272 1 $ivsize = $fh->GET_U32();
273 1 $ptrsize = $fh->GET_U32();
274 1 ▶ if ( $blversion ge '"0.06_03"' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($B::Disassembler::blversion ge "\"0.06_03\"") 1 0 1
275 1 $longsize = $fh->GET_U32();
276 }
277 1 ▶ if ( $blversion gt '"0.06"' or $blversion eq '"0.04"' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($B::Disassembler::blversion gt "\"0.06\"" or $B::Disassembler::blversion eq "\"0.04\"") 1 0 1
Condition33%1/3
$B::Disassembler::blversion gt "\"0.06\"" or $B::Disassembler::blversion eq "\"0.04\""
l!l&&r!l&&!r
100
MC/DC0%0/2
$B::Disassembler::blversion gt "\"0.06\"" or $B::Disassembler::blversion eq "\"0.04\""
$B::Disassembler::blversion gt "\"0.06\"" $B::Disassembler::blversion eq "\"0.04\""
Truth table33%1/3
A or B
A= $B::Disassembler::blversion gt "\"0.06\""B= $B::Disassembler::blversion eq "\"0.04\""
ABresult
1X1
011
000
278 1 $byteorder = $fh->GET_strconst();
279 }
280 1 ▶ if ( $blversion ge '"0.06_05"' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($B::Disassembler::blversion ge "\"0.06_05\"") 1 0 1
281 1 $archflag = $fh->GET_U16();
282 }
283 1 ▶ if ( $blversion ge '"0.06_06"' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($B::Disassembler::blversion ge "\"0.06_06\"") 1 0 1
284 1 $perlversion = $fh->GET_strconst();
285 }
286 }
287  
288 0 ▶sub get_header() {
Subroutine get_header: not called CC=4 SCAR=30.0
Pod undocumented
289 0 my @result = (
290 $magic, $archname, $blversion, $ivsize,
291 $ptrsize, $byteorder, $longsize, $archflag,
292 $perlversion
293 );
294 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
295 0 return @result;
296 }
297 else {
298 0 my $hash = {
299 magic => $magic,
300 archname => $archname,
301 blversion => $blversion,
302 ivsize => $ivsize,
303 ptrsize => $ptrsize,
304 };
305 0 for (qw(magic archname blversion ivsize ptrsize byteorder
306 longsize archflag perlversion))
307 {
308 0 ▶ $hash->{$_} = $$_ if defined $$_;
Branch: 1 branch
BranchTrueFalseTotal
if defined $$_ 0 0 0
309 }
310 0 return $hash;
311 }
312 }
313  
314 0 ▶sub print_insn {
Subroutine print_insn: not called CC=39 SCAR=73.5
Pod undocumented
315 0 my ( $insn, $arg, $comment ) = @_;
316 0 ▶ undef $comment unless $comment;
Branch: 1 branch
BranchTrueFalseTotal
unless $comment 0 0 0
317 0 ▶ if ( defined($arg) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) { } 0 0 0
318 # threaded or unthreaded
319 0 ▶ if ( $insn eq 'newopx' or $insn eq 'ldop' and $] > 5.007) {
Branch: 16 branches
BranchTrueFalseTotal
if ($insn eq 'newopx' or $insn eq 'ldop' and $] > 5.007) { } 0 0 0
elsif (not $comment) { } 0 0 0
elsif ($insn eq 'comment') { } 0 0 0
elsif ($insn eq 'stpv') { } 0 0 0
elsif ($insn eq 'newsvx') { } 0 0 0
elsif ($insn eq 'newpadlx') { } 0 0 0
elsif ($insn eq 'newpadnlx') { } 0 0 0
elsif ($insn eq 'newpadnx') { } 0 0 0
elsif ($insn eq 'gv_stashpvx') { } 0 0 0
elsif ($insn eq 'ldspecsvx') { } 0 0 0
elsif ($insn eq 'ldsv') { } 0 0 0
elsif ($insn eq 'gv_fetchpvx') { } 0 0 0
elsif ($insn eq 'sv_magic') { } 0 0 0
elsif ($insn =~ /_flags/) { } 0 0 0
elsif ($comment and $insn eq 'op_private') { } 0 0 0
elsif ($insn eq 'op_type' and $] < 5.007) { } 0 0 0
Condition0%0/6
$insn eq "newopx" or $insn eq "ldop" and $] > "5.007"
l!l&&r!l&&!r
000
$insn eq "ldop" and $] > "5.007"
!ll&&!rl&&r
000
MC/DC0%0/3
$insn eq "newopx" or $insn eq "ldop" and $] > "5.007"
$insn eq "newopx" $insn eq "ldop" $] > "5.007"
Truth table0%0/4
A or B and C
A= $insn eq "newopx"B= $insn eq "ldop"C= $] > "5.007"
ABCresult
1XX1
0111
00X0
0100
320 0 my $type = $arg >> 7;
321 0 my $size = $arg - ( $type << 7 );
322 0 ▶ $arg .= sprintf( " \t# size:%d, type:%d %s", $size, $type) if $comment;
Branch: 1 branch
BranchTrueFalseTotal
if $comment 0 0 0
323 0 $opname = $opname[$type];
324 0 printf "\n# [%s %d]\n", $opname, $ix++;
325 }
326 elsif ( !$comment ) {
327 ;
328 }
329 elsif ( $insn eq 'comment' ) {
330 0 $arg .= "comment $arg";
331 0 ▶ $arg .= " \t#" . $comment if $comment ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne 1 0 0 0
332 }
333 elsif ( $insn eq 'stpv' ) {
334 0 ▶ $arg .= "\t# " . $comment if $comment ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne 1 0 0 0
335 0 printf "# -%s- %d\n", 'PV', $ix++;
336 }
337 elsif ( $insn eq 'newsvx' ) {
338 0 my $type = $arg & 0xff; # SVTYPEMASK
339 0 $arg .= sprintf("\t# type=%d,flags=0x%x", $type, $arg);
340 0 ▶ $arg .= $comment if $comment ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne 1 0 0 0
341 0 printf "\n# [%s %d]\n", $svnames[$type], $ix++;
342 }
343 elsif ( $insn eq 'newpadlx' ) {
344 0 ▶ $arg .= "\t# " . $comment if $comment ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne 1 0 0 0
345 0 printf "\n# [%s %d]\n", "PADLIST", $ix++;
346 }
347 elsif ( $insn eq 'newpadnlx' ) {
348 0 ▶ $arg .= "\t# " . $comment if $comment ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne 1 0 0 0
349 0 printf "\n# [%s %d]\n", "PADNAMELIST", $ix++;
350 }
351 elsif ( $insn eq 'newpadnx' ) {
352 0 ▶ $arg .= "\t# " . $comment if $comment ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne 1 0 0 0
353 0 printf "\n# [%s %d]\n", "PADNAME", $ix++;
354 }
355 elsif ( $insn eq 'gv_stashpvx' ) {
356 0 ▶ $arg .= "\t# " . $comment if $comment ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne 1 0 0 0
357 0 printf "\n# [%s %d]\n", "STASH", $ix++;
358 }
359 elsif ( $insn eq 'ldspecsvx' ) {
360 0 $arg .= "\t# $specialsv_name[$arg]";
361 0 ▶ $arg .= $comment if $comment ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne 1 0 0 0
362 0 printf "\n# [%s %d]\n", "SPECIAL", $ix++;
363 }
364 elsif ( $insn eq 'ldsv' ) {
365 0 ▶ $arg .= "\t# " . $comment if $comment ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne 1 0 0 0
366 0 printf "# -%s-\n", 'GP/AV/HV/NULL/MG';
367 }
368 elsif ( $insn eq 'gv_fetchpvx' ) {
369 0 ▶ $arg .= "\t# " . $comment if $comment ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne 1 0 0 0
370 0 printf "\n# [%s %d]\n", 'GV', $ix++;
371 }
372 elsif ( $insn eq 'sv_magic' ) {
373 0 $arg .= sprintf( "\t# '%s'", chr($arg) );
374 }
375 elsif ( $insn =~ /_flags/ ) {
376 0 my $f = $arg;
377 0 ▶ $arg .= sprintf( "\t# 0x%x", $f ) if $comment;
Branch: 1 branch
BranchTrueFalseTotal
if $comment 0 0 0
378 0 ▶ $arg .= " ".B::Concise::op_flags($f) if $insn eq 'op_flags' and $comment;
Branch: 1 branch
BranchTrueFalseTotal
if $insn eq "op_flags" and $comment 0 0 0
Condition0%0/3
$insn eq "op_flags" and $comment
!ll&&!rl&&r
000
MC/DC0%0/2
$insn eq "op_flags" and $comment
$insn eq "op_flags" $comment
Truth table0%0/3
A and B
A= $insn eq "op_flags"B= $comment
ABresult
0X0
100
111
379 }
380 ▶ elsif ( $comment and $insn eq 'op_private' ) {
Condition0%0/3
$comment and $insn eq "op_private"
!ll&&!rl&&r
000
MC/DC0%0/2
$comment and $insn eq "op_private"
$comment $insn eq "op_private"
Truth table0%0/3
A and B
A= $commentB= $insn eq "op_private"
ABresult
0X0
100
111
381 0 my $f = $arg;
382 0 $arg .= sprintf( "\t# 0x%x", $f );
383 0 $arg .= " ".B::Concise::private_flags($opname, $f);
384 }
385 ▶ elsif ( $insn eq 'op_type' and $] < 5.007 ) {
Condition0%0/3
$insn eq "op_type" and $] < "5.007"
!ll&&!rl&&r
000
MC/DC0%0/2
$insn eq "op_type" and $] < "5.007"
$insn eq "op_type" $] < "5.007"
Truth table0%0/3
A and B
A= $insn eq "op_type"B= $] < "5.007"
ABresult
0X0
100
111
386 0 my $type = $arg;
387 0 $arg .= sprintf( "\t# [ %s ]", $opname[$type] );
388 }
389 else {
390 0 ▶ $arg .= "\t# " . $comment if $comment ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne 1 0 0 0
391 }
392 0 printf "%s %s\n", $insn, $arg;
393 }
394 else {
395 0 ▶ $insn .= "\t# " . $comment if $comment ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $comment ne 1 0 0 0
396 0 print $insn, "\n";
397 }
398 }
399  
400 0 ▶sub print_insn_bare {
Subroutine print_insn_bare: not called CC=2 SCAR=17.9
Pod undocumented
401 0 my ( $insn, $arg ) = @_;
402 0 ▶ if ( defined($arg) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) { } 0 0 0
403 0 printf "%s %s\n", $insn, $arg;
404 }
405 else {
406 0 print $insn, "\n";
407 }
408 }
409  
410 1 ▶sub disassemble_fh {
Subroutine disassemble_fh: called CC=10 SCAR=31.1
Pod undocumented
411 1 my $fh = shift;
412 1 my $out = shift;
413 1 my $verbose = shift;
414 1 my ( $c, $getmeth, $insn, $arg );
415 1 $ix = 1;
416 1 bless $fh, "B::Disassembler::BytecodeStream";
417 1 dis_header($fh);
418 1 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 1 1
419 0 printf "#magic 0x%x\n", $magic; #0x43424c50
420 0 printf "#archname %s\n", $archname;
421 0 printf "#blversion %s\n", $blversion;
422 0 printf "#ivsize %d\n", $ivsize;
423 0 printf "#ptrsize %d\n", $ptrsize;
424 0 ▶ printf "#byteorder %s\n", $byteorder if $byteorder;
Branch: 1 branch
BranchTrueFalseTotal
if $B::Disassembler::byteorder 0 0 0
425 0 ▶ printf "#longsize %d\n", $longsize if $longsize;
Branch: 1 branch
BranchTrueFalseTotal
if $B::Disassembler::longsize 0 0 0
426 0 ▶ printf "#archflag %d\n", $archflag if defined $archflag;
Branch: 1 branch
BranchTrueFalseTotal
if defined $B::Disassembler::archflag 0 0 0
427 0 ▶ printf "#perlversion %s\n", $perlversion if $perlversion;
Branch: 1 branch
BranchTrueFalseTotal
if $B::Disassembler::perlversion 0 0 0
428 0 print "\n";
429 }
430 1 ▶ while ( defined( $c = $fh->getc ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($c = $fh->getc)) 178 1 179
431 178 $c = ord($c);
432 178 $insn = $insn_name[$c];
433 178 ▶ if ( !defined($insn) || $insn eq "unused" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $insn or $insn eq "unused") 0 178 178
Condition33%1/3
not defined $insn or $insn eq "unused"
l!l&&r!l&&!r
00178
MC/DC0%0/2
not defined $insn or $insn eq "unused"
not defined $insn $insn eq "unused"
Truth table33%1/3
not(A) or B
A= not defined $insnB= $insn eq "unused"
ABresult
1X1
011
000
434 0 my $pos = $fh->tell - 1;
435 0 warn "Illegal instruction code $c at stream offset $pos.\n";
436 }
437 178 $getmeth = $insn_data{$insn}->[2];
438 #warn "EOF at $insn $getmeth" if $fh->eof();
439 178 $arg = $fh->$getmeth();
440 178 ▶ if ( defined($arg) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) { } 168 10 178
441 168 &$out( $insn, $arg, $verbose );
442 }
443 else {
444 10 &$out( $insn, undef, $verbose );
445 }
446 }
447 }
448  
449 1 1;
450  
451 __END__
« script/cc_harness ↑ Summary blib/lib/B/Bytecode.pm »