File Coverage

blib/lib/B/Debug.pm
Criterion Covered Total %
statement 0 205 0.0
branch 0 104 0.0
condition 0 15 0.0
subroutine 0 33 0.0
pod 0 1 0.0
total 0 358 0.0


line stmt bran cond sub pod time code
1             package B::Debug;
2              
3             our $VERSION = '1.26';
4             BEGIN { if ($] >= 5.027001) { require deprecate; import deprecate; } }
5              
6             use strict;
7             require 5.006;
8             use B qw(peekop walkoptree walkoptree_exec
9             main_start main_root cstring sv_undef SVf_NOK SVf_IOK);
10             use Config;
11             my (@optype, @specialsv_name);
12             require B;
13             if ($] < 5.009) {
14             require B::Asmdata;
15             B::Asmdata->import (qw(@optype @specialsv_name));
16             } else {
17             B->import (qw(@optype @specialsv_name));
18             }
19              
20             if ($] < 5.006002) {
21             eval q|sub B::GV::SAFENAME {
22             my $name = (shift())->NAME;
23             # The regex below corresponds to the isCONTROLVAR macro from toke.c
24             $name =~ s/^([\cA-\cZ\c\\c[\c]\c?\c_\c^])/"^".chr(64 ^ ord($1))/e;
25             return $name;
26             }|;
27             }
28              
29             my ($have_B_Flags, $have_B_Flags_extra);
30             if (!$ENV{PERL_CORE}){ # avoid CORE test crashes
31             eval { require B::Flags and $have_B_Flags++ };
32             $have_B_Flags_extra++ if $have_B_Flags and $B::Flags::VERSION gt '0.03';
33             }
34             my %done_gv;
35              
36             sub _printop {
37 0     0     my $op = shift;
38 0 0         my $addr = ${$op} ? $op->ppaddr : '';
  0            
39 0 0         $addr =~ s/^PL_ppaddr// if $addr;
40 0 0         if (${$op}) {
  0            
41 0           return sprintf "0x%08x %6s %s", ${$op}, B::class($op), $addr;
  0            
42             } else {
43 0           return sprintf "0x%x %6s %s", ${$op}, '', $addr;
  0            
44             }
45             }
46              
47             sub B::OP::debug {
48 0     0     my ($op) = @_;
49 0           printf <<'EOT', B::class($op), $$op, _printop($op), _printop($op->next), _printop($op->sibling), $op->targ, $op->type, $op->name;
50             %s (0x%lx)
51             op_ppaddr %s
52             op_next %s
53             op_sibling %s
54             op_targ %d
55             op_type %d %s
56             EOT
57 0 0         if ($] > 5.009) {
58 0           printf <<'EOT', $op->opt;
59             op_opt %d
60             EOT
61             } else {
62 0           printf <<'EOT', $op->seq;
63             op_seq %d
64             EOT
65             }
66 0 0         if ($have_B_Flags) {
67 0           printf <<'EOT', $op->flags, $op->flagspv, $op->private, $op->privatepv;
68             op_flags %u %s
69             op_private %u %s
70             EOT
71             } else {
72 0           printf <<'EOT', $op->flags, $op->private;
73             op_flags %u
74             op_private %u
75             EOT
76             }
77 0 0         if ($op->can('rettype')) {
78 0           printf <<'EOT', $op->rettype;
79             op_rettype %u
80             EOT
81             }
82             }
83              
84             sub B::UNOP::debug {
85 0     0     my ($op) = @_;
86 0           $op->B::OP::debug();
87 0           printf "\top_first\t%s\n", _printop($op->first);
88             }
89              
90             sub B::BINOP::debug {
91 0     0     my ($op) = @_;
92 0           $op->B::UNOP::debug();
93 0           printf "\top_last \t%s\n", _printop($op->last);
94             }
95              
96             sub B::LOOP::debug {
97 0     0     my ($op) = @_;
98 0           $op->B::BINOP::debug();
99 0           printf <<'EOT', _printop($op->redoop), _printop($op->nextop), _printop($op->lastop);
100             op_redoop %s
101             op_nextop %s
102             op_lastop %s
103             EOT
104             }
105              
106             sub B::LOGOP::debug {
107 0     0     my ($op) = @_;
108 0           $op->B::UNOP::debug();
109 0           printf "\top_other\t%s\n", _printop($op->other);
110             }
111              
112             sub B::LISTOP::debug {
113 0     0     my ($op) = @_;
114 0           $op->B::BINOP::debug();
115 0           printf "\top_children\t%d\n", $op->children;
116             }
117              
118             sub B::PMOP::debug {
119 0     0     my ($op) = @_;
120 0           $op->B::LISTOP::debug();
121 0 0         printf "\top_pmreplroot\t0x%x\n", $] < 5.008 ? ${$op->pmreplroot} : $op->pmreplroot;
  0            
122 0           printf "\top_pmreplstart\t0x%x\n", ${$op->pmreplstart};
  0            
123 0 0         printf "\top_pmnext\t0x%x\n", ${$op->pmnext} if $] < 5.009005;
  0            
124 0 0         if ($Config{'useithreads'}) {
125 0           printf "\top_pmstashpv\t%s\n", cstring($op->pmstashpv);
126 0           printf "\top_pmoffset\t%d\n", $op->pmoffset;
127             } else {
128 0           printf "\top_pmstash\t%s\n", cstring($op->pmstash);
129             }
130 0           printf "\top_precomp\t%s\n", cstring($op->precomp);
131 0           printf "\top_pmflags\t0x%x\n", $op->pmflags;
132 0 0         printf "\top_reflags\t0x%x\n", $op->reflags if $] >= 5.009;
133 0 0         printf "\top_pmpermflags\t0x%x\n", $op->pmpermflags if $] < 5.009;
134 0 0         printf "\top_pmdynflags\t0x%x\n", $op->pmdynflags if $] < 5.009;
135 0 0         $op->pmreplroot->debug if $] < 5.008;
136             }
137              
138             sub B::COP::debug {
139 0     0     my ($op) = @_;
140 0           $op->B::OP::debug();
141 0 0         my $warnings = ref $op->warnings ? ${$op->warnings} : 0;
  0            
142 0           printf <<'EOT', $op->label, $op->stashpv, $op->file, $op->cop_seq, $op->arybase, $op->line, $warnings;
143             cop_label "%s"
144             cop_stashpv "%s"
145             cop_file "%s"
146             cop_seq %d
147             cop_arybase %d
148             cop_line %d
149             cop_warnings 0x%x
150             EOT
151 0 0 0       if ($] > 5.008 and $] < 5.011) {
152 0 0         my $cop_io = B::class($op->io) eq 'SPECIAL' ? '' : $op->io->as_string;
153 0           printf(" cop_io %s\n", cstring($cop_io));
154             }
155             }
156              
157             sub B::SVOP::debug {
158 0     0     my ($op) = @_;
159 0           $op->B::OP::debug();
160 0           printf "\top_sv\t\t0x%x\n", ${$op->sv};
  0            
161 0           $op->sv->debug;
162             }
163              
164             sub B::METHOP::debug {
165 0     0     my ($op) = @_;
166 0           $op->B::OP::debug();
167 0 0         if (${$op->first}) {
  0            
168 0           printf "\top_first\t0x%x\n", ${$op->first};
  0            
169 0           $op->first->debug;
170             } else {
171 0           printf "\top_meth_sv\t0x%x\n", ${$op->meth_sv};
  0            
172 0           $op->meth_sv->debug;
173             }
174             }
175              
176             sub B::UNOP_AUX::debug {
177 0     0     my ($op) = @_;
178 0           $op->B::OP::debug();
179             # string and perl5 aux_list needs the cv
180             # cperl has aux, Concise,-debug leaves it empty
181 0 0         if ($op->can('aux')) {
182 0           printf "\top_aux\t%s\n", cstring($op->aux);
183             }
184             }
185              
186             sub B::PVOP::debug {
187 0     0     my ($op) = @_;
188 0           $op->B::OP::debug();
189 0           printf "\top_pv\t\t%s\n", cstring($op->pv);
190             }
191              
192             sub B::PADOP::debug {
193 0     0     my ($op) = @_;
194 0           $op->B::OP::debug();
195 0           printf "\top_padix\t%ld\n", $op->padix;
196             }
197              
198             sub B::NULL::debug {
199 0     0     my ($sv) = @_;
200 0 0         if ($$sv == ${sv_undef()}) {
  0            
201 0           print "&sv_undef\n";
202             } else {
203 0           printf "NULL (0x%x)\n", $$sv;
204             }
205             }
206              
207             sub B::SV::debug {
208 0     0     my ($sv) = @_;
209 0 0         if (!$$sv) {
210 0           print B::class($sv), " = NULL\n";
211 0           return;
212             }
213 0           printf <<'EOT', B::class($sv), $$sv, $sv->REFCNT;
214             %s (0x%x)
215             REFCNT %d
216             EOT
217 0           printf "\tFLAGS\t\t0x%x", $sv->FLAGS;
218 0 0         if ($have_B_Flags) {
219 0 0         printf "\t%s", $have_B_Flags_extra ? $sv->flagspv(0) : $sv->flagspv;
220             }
221 0           print "\n";
222             }
223              
224             sub B::RV::debug {
225 0     0     my ($rv) = @_;
226 0           B::SV::debug($rv);
227 0           printf <<'EOT', ${$rv->RV};
  0            
228             RV 0x%x
229             EOT
230 0           $rv->RV->debug;
231             }
232              
233             sub B::PV::debug {
234 0     0     my ($sv) = @_;
235 0           $sv->B::SV::debug();
236 0           my $pv = $sv->PV();
237 0           printf <<'EOT', cstring($pv), $sv->CUR, $sv->LEN;
238             xpv_pv %s
239             xpv_cur %d
240             xpv_len %d
241             EOT
242             }
243              
244             sub B::IV::debug {
245 0     0     my ($sv) = @_;
246 0           $sv->B::SV::debug();
247 0 0         printf "\txiv_iv\t\t%d\n", $sv->IV if $sv->FLAGS & SVf_IOK;
248             }
249              
250             sub B::NV::debug {
251 0     0     my ($sv) = @_;
252 0           $sv->B::IV::debug();
253 0 0         printf "\txnv_nv\t\t%s\n", $sv->NV if $sv->FLAGS & SVf_NOK;
254             }
255              
256             sub B::PVIV::debug {
257 0     0     my ($sv) = @_;
258 0           $sv->B::PV::debug();
259 0 0         printf "\txiv_iv\t\t%d\n", $sv->IV if $sv->FLAGS & SVf_IOK;
260             }
261              
262             sub B::PVNV::debug {
263 0     0     my ($sv) = @_;
264 0           $sv->B::PVIV::debug();
265 0 0         printf "\txnv_nv\t\t%s\n", $sv->NV if $sv->FLAGS & SVf_NOK;
266             }
267              
268             sub B::PVLV::debug {
269 0     0     my ($sv) = @_;
270 0           $sv->B::PVNV::debug();
271 0           printf "\txlv_targoff\t%d\n", $sv->TARGOFF;
272 0           printf "\txlv_targlen\t%u\n", $sv->TARGLEN;
273 0           printf "\txlv_type\t%s\n", cstring(chr($sv->TYPE));
274             }
275              
276             sub B::BM::debug {
277 0     0     my ($sv) = @_;
278 0           $sv->B::PVNV::debug();
279 0           printf "\txbm_useful\t%d\n", $sv->USEFUL;
280 0           printf "\txbm_previous\t%u\n", $sv->PREVIOUS;
281 0           printf "\txbm_rare\t%s\n", cstring(chr($sv->RARE));
282             }
283              
284             sub B::CV::debug {
285 0     0     my ($cv) = @_;
286 0           $cv->B::PVNV::debug();
287 0           my $stash = $cv->STASH;
288 0           my $start = $cv->START;
289 0           my $root = $cv->ROOT;
290 0           my $padlist = $cv->PADLIST;
291 0           my $file = $cv->FILE;
292 0           my $gv;
293 0           printf <<'EOT', $$stash, $$start, $$root;
294             STASH 0x%x
295             START 0x%x
296             ROOT 0x%x
297             EOT
298 0 0 0       if ($cv->can('NAME_HEK') && $cv->NAME_HEK) {
    0 0        
299 0           printf("\tNAME\t%%s\n", $cv->NAME_HEK);
300             }
301             elsif ( $]>5.017 && ($cv->FLAGS & 0x40000)) { #lexsub
302 0           printf("\tNAME\t%%s\n", $cv->NAME_HEK);
303             } else {
304 0           $gv = $cv->GV;
305 0           printf("\tGV\t%0x%x\t%s\n", $$gv, $gv->SAFENAME);
306             }
307 0           printf <<'EOT', $file, $cv->DEPTH, $padlist, ${$cv->OUTSIDE};
  0            
308             FILE %s
309             DEPTH %d
310             PADLIST 0x%x
311             OUTSIDE 0x%x
312             EOT
313 0 0         printf("\tOUTSIDE_SEQ\t%d\n", $cv->OUTSIDE_SEQ) if $] > 5.007;
314 0 0         if ($have_B_Flags) {
315 0 0         my $SVt_PVCV = $] < 5.010 ? 12 : 13;
316 0 0         printf("\tCvFLAGS\t0x%x\t%s\n", $cv->CvFLAGS,
317             $have_B_Flags_extra ? $cv->flagspv($SVt_PVCV) : $cv->flagspv);
318             } else {
319 0           printf("\tCvFLAGS\t0x%x\n", $cv->CvFLAGS);
320             }
321 0 0         printf("\tSIGOP\t0x%x\n", $cv->SIGOP) if $cv->can('SIGOP');
322 0 0         $start->debug if $start;
323 0 0         $root->debug if $root;
324 0 0         $gv->debug if $gv;
325 0 0         $padlist->debug if $padlist;
326             }
327              
328             sub B::AV::debug {
329 0     0     my ($av) = @_;
330 0           $av->B::SV::debug;
331 0           _array_debug($av);
332             }
333              
334             sub _array_debug {
335 0     0     my ($av) = @_;
336             # tied arrays may leave out FETCHSIZE
337 0           my (@array) = eval { $av->ARRAY; };
  0            
338 0           print "\tARRAY\t\t(", join(", ", map("0x" . $$_, @array)), ")\n";
339 0           my $fill = eval { scalar(@array) };
  0            
340 0 0 0       if ($Config{'useithreads'} && B::class($av) ne 'PADLIST') {
341 0           printf <<'EOT', $fill, $av->MAX, $av->OFF;
342             FILL %d
343             MAX %d
344             OFF %d
345             EOT
346             } else {
347 0           printf <<'EOT', $fill, $av->MAX;
348             FILL %d
349             MAX %d
350             EOT
351             }
352 0 0         if ($] < 5.009) {
353 0 0         if ($have_B_Flags) {
354 0 0         printf("\tAvFLAGS\t0x%x\t%s\n", $av->AvFLAGS,
355             $have_B_Flags_extra ? $av->flagspv(10) : $av->flagspv);
356             } else {
357 0           printf("\tAvFLAGS\t0x%x\n", $av->AvFLAGS);
358             }
359             }
360             }
361              
362             sub B::GV::debug {
363 0     0     my ($gv) = @_;
364 0 0         if ($done_gv{$$gv}++) {
365 0           printf "GV %s::%s\n", $gv->STASH->NAME, $gv->SAFENAME;
366 0           return;
367             }
368 0           my $sv = $gv->SV;
369 0           my $av = $gv->AV;
370 0           my $cv = $gv->CV;
371 0           $gv->B::SV::debug;
372 0           printf <<'EOT', $gv->SAFENAME, $gv->STASH->NAME, $gv->STASH, $$sv, $gv->GvREFCNT, $gv->FORM, $$av, ${$gv->HV}, ${$gv->EGV}, $$cv, $gv->CVGEN, $gv->LINE, $gv->FILE, $gv->GvFLAGS;
  0            
  0            
373             NAME %s
374             STASH %s (0x%x)
375             SV 0x%x
376             GvREFCNT %d
377             FORM 0x%x
378             AV 0x%x
379             HV 0x%x
380             EGV 0x%x
381             CV 0x%x
382             CVGEN %d
383             LINE %d
384             FILE %s
385             EOT
386 0 0         if ($have_B_Flags) {
387 0 0         my $SVt_PVGV = $] < 5.010 ? 13 : 9;
388 0 0         printf("\tGvFLAGS\t0x%x\t%s\n", $gv->GvFLAGS,
389             $have_B_Flags_extra ? $gv->flagspv($SVt_PVGV) : $gv->flagspv);
390             } else {
391 0           printf("\tGvFLAGS\t0x%x\n", $gv->GvFLAGS);
392             }
393 0 0         $sv->debug if $sv;
394 0 0         $av->debug if $av;
395 0 0         $cv->debug if $cv;
396             }
397              
398             sub B::SPECIAL::debug {
399 0     0     my $sv = shift;
400 0 0         my $i = ref $sv ? $$sv : 0;
401 0 0         print defined $specialsv_name[$i] ? $specialsv_name[$i] : "", "\n";
402             }
403              
404             sub B::PADLIST::debug {
405 0     0     my ($padlist) = @_;
406 0           printf <<'EOT', B::class($padlist), $$padlist, $padlist->REFCNT;
407             %s (0x%x)
408             REFCNT %d
409             EOT
410 0           _array_debug($padlist);
411             }
412              
413             sub compile {
414 0     0 0   my $order = shift;
415 0           B::clearsym();
416 0 0         $DB::single = 1 if defined &DB::DB;
417 0 0 0       if ($order && $order eq "exec") {
418 0     0     return sub { walkoptree_exec(main_start, "debug") }
419 0           } else {
420 0     0     return sub { walkoptree(main_root, "debug") }
421 0           }
422             }
423              
424             1;
425              
426             __END__