3 our $VERSION = '1.05_02';
6 use B qw(peekop class walkoptree walkoptree_exec
7 main_start main_root cstring sv_undef @specialsv_name);
8 # <=5.008 had @specialsv_name exported from B::Asmdata
11 my $ithreads = $Config{'useithreads'} eq 'define';
13 sub ITHREADS() { $ithreads }
22 my $addr = ${$op} ? $op->ppaddr : '';
23 $addr =~ s/^PL_ppaddr// if $addr;
24 return sprintf "0x%x %s %s", ${$op}, ${$op} ? class($op) : '', $addr;
29 printf <<'EOT', class($op), $$op, $op->ppaddr, _printop($op->next), _printop($op->sibling), $op->targ, $op->type;
38 printf <<'EOT', $op->opt;
42 printf <<'EOT', $op->seq;
46 printf <<'EOT', $op->flags, $op->private;
55 printf "\top_first\t%s\n", _printop($op->first);
60 $op->B::UNOP::debug();
61 printf "\top_last \t%s\n", _printop($op->last);
66 $op->B::BINOP::debug();
67 printf <<'EOT', _printop($op->redoop), _printop($op->nextop), _printop($op->lastop);
76 $op->B::UNOP::debug();
77 printf "\top_other\t%s\n", _printop($op->other);
80 sub B::LISTOP::debug {
82 $op->B::BINOP::debug();
83 printf "\top_children\t%d\n", $op->children;
88 $op->B::LISTOP::debug();
89 printf "\top_pmreplroot\t0x%x\n", ${$op->pmreplroot};
90 printf "\top_pmreplstart\t0x%x\n", ${$op->pmreplstart};
91 printf "\top_pmnext\t0x%x\n", ${$op->pmnext} if $] < 5.009005;
93 printf "\top_pmstashpv\t%s\n", cstring($op->pmstashpv);
94 printf "\top_pmoffset\t%d\n", $op->pmoffset;
96 printf "\top_pmstash\t%s\n", cstring($op->pmstash);
98 printf "\top_precomp->precomp\t%s\n", cstring($op->precomp);
99 printf "\top_pmflags\t0x%x\n", $op->pmflags;
100 printf "\top_reflags\t0x%x\n", $op->reflags if $] >= 5.009;
101 printf "\top_pmpermflags\t0x%x\n", $op->pmpermflags if $] < 5.009;
102 printf "\top_pmdynflags\t0x%x\n", $op->pmdynflags if $] < 5.009;
103 $op->pmreplroot->debug;
109 my $cop_io = class($op->io) eq 'SPECIAL' ? '' : $op->io->as_string;
110 printf <<'EOT', $op->label, $op->stashpv, $op->file, $op->cop_seq, $op->arybase, $op->line, ${$op->warnings}, cstring($cop_io);
125 printf "\top_sv\t\t0x%x\n", ${$op->sv};
132 printf "\top_pv\t\t%s\n", cstring($op->pv);
135 sub B::PADOP::debug {
138 printf "\top_padix\t%ld\n", $op->padix;
143 if ($$sv == ${sv_undef()}) {
146 printf "NULL (0x%x)\n", $$sv;
153 print class($sv), " = NULL\n";
156 printf <<'EOT', class($sv), $$sv, $sv->REFCNT, $sv->FLAGS;
166 printf <<'EOT', ${$rv->RV};
176 printf <<'EOT', cstring($pv), length($pv);
185 printf "\txiv_iv\t\t%d\n", $sv->IV;
191 printf "\txnv_nv\t\t%s\n", $sv->NV;
197 printf "\txiv_iv\t\t%d\n", $sv->IV;
202 $sv->B::PVIV::debug();
203 printf "\txnv_nv\t\t%s\n", $sv->NV;
208 $sv->B::PVNV::debug();
209 printf "\txlv_targoff\t%d\n", $sv->TARGOFF;
210 printf "\txlv_targlen\t%u\n", $sv->TARGLEN;
211 printf "\txlv_type\t%s\n", cstring(chr($sv->TYPE));
216 $sv->B::PVNV::debug();
217 printf "\txbm_useful\t%d\n", $sv->USEFUL;
218 printf "\txbm_previous\t%u\n", $sv->PREVIOUS;
219 printf "\txbm_rare\t%s\n", cstring(chr($sv->RARE));
224 $sv->B::PVNV::debug();
225 my ($stash) = $sv->STASH;
226 my ($start) = $sv->START;
227 my ($root) = $sv->ROOT;
228 my ($padlist) = $sv->PADLIST;
229 my ($file) = $sv->FILE;
231 printf <<'EOT', $$stash, $$start, $$root, $$gv, $file, $sv->DEPTH, $padlist, ${$sv->OUTSIDE}, $sv->OUTSIDE_SEQ;
242 $start->debug if $start;
243 $root->debug if $root;
245 $padlist->debug if $padlist;
251 my(@array) = $av->ARRAY;
252 print "\tARRAY\t\t(", join(", ", map("0x" . $$_, @array)), ")\n";
253 printf <<'EOT', scalar(@array), $av->MAX, $av->OFF;
258 printf <<'EOT', $av->AvFLAGS if $] < 5.009;
265 if ($done_gv{$$gv}++) {
266 printf "GV %s::%s\n", $gv->STASH->NAME, $gv->SAFENAME;
273 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;
293 sub B::SPECIAL::debug {
295 print $specialsv_name[$$sv], "\n";
301 if ($order && $order eq "exec") {
302 return sub { walkoptree_exec(main_start, "debug") }
304 return sub { walkoptree(main_root, "debug") }
314 B::Debug - Walk Perl syntax tree, printing debug info about ops
318 perl -MO=Debug[,OPTIONS] foo.pl
322 See F<ext/B/README> and the newer L<B::Concise>, L<B::Terse>.
326 With option -exec, walks tree in execute order,
327 otherwise in basic order.
331 Malcolm Beattie, C<mbeattie@sable.ox.ac.uk>