4 BEGIN { if ($] >= 5.027001) { require deprecate; import deprecate; } }
8 use B qw(peekop walkoptree walkoptree_exec
9 main_start main_root cstring sv_undef SVf_NOK SVf_IOK);
11 my (@optype, @specialsv_name);
15 B::Asmdata->import (qw(@optype @specialsv_name));
17 B->import (qw(@optype @specialsv_name));
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;
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';
38 my $addr = ${$op} ? $op->ppaddr : '';
39 $addr =~ s/^PL_ppaddr// if $addr;
41 return sprintf "0x%08x %6s %s", ${$op}, B::class($op), $addr;
43 return sprintf "0x%x %6s %s", ${$op}, '', $addr;
49 printf <<'EOT', B::class($op), $$op, _printop($op), _printop($op->next), _printop($op->sibling), $op->targ, $op->type, $op->name;
58 printf <<'EOT', $op->opt;
62 printf <<'EOT', $op->seq;
67 printf <<'EOT', $op->flags, $op->flagspv, $op->private, $op->privatepv;
72 printf <<'EOT', $op->flags, $op->private;
77 if ($op->can('rettype')) {
78 printf <<'EOT', $op->rettype;
87 printf "\top_first\t%s\n", _printop($op->first);
92 $op->B::UNOP::debug();
93 printf "\top_last \t%s\n", _printop($op->last);
98 $op->B::BINOP::debug();
99 printf <<'EOT', _printop($op->redoop), _printop($op->nextop), _printop($op->lastop);
106 sub B::LOGOP::debug {
108 $op->B::UNOP::debug();
109 printf "\top_other\t%s\n", _printop($op->other);
112 sub B::LISTOP::debug {
114 $op->B::BINOP::debug();
115 printf "\top_children\t%d\n", $op->children;
120 $op->B::LISTOP::debug();
121 printf "\top_pmreplroot\t0x%x\n", $] < 5.008 ? ${$op->pmreplroot} : $op->pmreplroot;
122 printf "\top_pmreplstart\t0x%x\n", ${$op->pmreplstart};
123 printf "\top_pmnext\t0x%x\n", ${$op->pmnext} if $] < 5.009005;
124 if ($Config{'useithreads'}) {
125 printf "\top_pmstashpv\t%s\n", cstring($op->pmstashpv);
126 printf "\top_pmoffset\t%d\n", $op->pmoffset;
128 printf "\top_pmstash\t%s\n", cstring($op->pmstash);
130 printf "\top_precomp\t%s\n", cstring($op->precomp);
131 printf "\top_pmflags\t0x%x\n", $op->pmflags;
132 printf "\top_reflags\t0x%x\n", $op->reflags if $] >= 5.009;
133 printf "\top_pmpermflags\t0x%x\n", $op->pmpermflags if $] < 5.009;
134 printf "\top_pmdynflags\t0x%x\n", $op->pmdynflags if $] < 5.009;
135 $op->pmreplroot->debug if $] < 5.008;
141 my $warnings = ref $op->warnings ? ${$op->warnings} : 0;
142 printf <<'EOT', $op->label, $op->stashpv, $op->file, $op->cop_seq, $op->arybase, $op->line, $warnings;
151 if ($] > 5.008 and $] < 5.011) {
152 my $cop_io = B::class($op->io) eq 'SPECIAL' ? '' : $op->io->as_string;
153 printf(" cop_io %s\n", cstring($cop_io));
160 printf "\top_sv\t\t0x%x\n", ${$op->sv};
164 sub B::METHOP::debug {
168 printf "\top_first\t0x%x\n", ${$op->first};
171 printf "\top_meth_sv\t0x%x\n", ${$op->meth_sv};
176 sub B::UNOP_AUX::debug {
179 # string and perl5 aux_list needs the cv
180 # cperl has aux, Concise,-debug leaves it empty
181 if ($op->can('aux')) {
182 printf "\top_aux\t%s\n", cstring($op->aux);
189 printf "\top_pv\t\t%s\n", cstring($op->pv);
192 sub B::PADOP::debug {
195 printf "\top_padix\t%ld\n", $op->padix;
200 if ($$sv == ${sv_undef()}) {
203 printf "NULL (0x%x)\n", $$sv;
210 print B::class($sv), " = NULL\n";
213 printf <<'EOT', B::class($sv), $$sv, $sv->REFCNT;
217 printf "\tFLAGS\t\t0x%x", $sv->FLAGS;
219 printf "\t%s", $have_B_Flags_extra ? $sv->flagspv(0) : $sv->flagspv;
227 printf <<'EOT', ${$rv->RV};
237 printf <<'EOT', cstring($pv), $sv->CUR, $sv->LEN;
247 printf "\txiv_iv\t\t%d\n", $sv->IV if $sv->FLAGS & SVf_IOK;
253 printf "\txnv_nv\t\t%s\n", $sv->NV if $sv->FLAGS & SVf_NOK;
259 printf "\txiv_iv\t\t%d\n", $sv->IV if $sv->FLAGS & SVf_IOK;
264 $sv->B::PVIV::debug();
265 printf "\txnv_nv\t\t%s\n", $sv->NV if $sv->FLAGS & SVf_NOK;
270 $sv->B::PVNV::debug();
271 printf "\txlv_targoff\t%d\n", $sv->TARGOFF;
272 printf "\txlv_targlen\t%u\n", $sv->TARGLEN;
273 printf "\txlv_type\t%s\n", cstring(chr($sv->TYPE));
278 $sv->B::PVNV::debug();
279 printf "\txbm_useful\t%d\n", $sv->USEFUL;
280 printf "\txbm_previous\t%u\n", $sv->PREVIOUS;
281 printf "\txbm_rare\t%s\n", cstring(chr($sv->RARE));
286 $cv->B::PVNV::debug();
287 my $stash = $cv->STASH;
288 my $start = $cv->START;
289 my $root = $cv->ROOT;
290 my $padlist = $cv->PADLIST;
291 my $file = $cv->FILE;
293 printf <<'EOT', $$stash, $$start, $$root;
298 if ($cv->can('NAME_HEK') && $cv->NAME_HEK) {
299 printf("\tNAME\t%%s\n", $cv->NAME_HEK);
301 elsif ( $]>5.017 && ($cv->FLAGS & 0x40000)) { #lexsub
302 printf("\tNAME\t%%s\n", $cv->NAME_HEK);
305 printf("\tGV\t%0x%x\t%s\n", $$gv, $gv->SAFENAME);
307 printf <<'EOT', $file, $cv->DEPTH, $padlist, ${$cv->OUTSIDE};
313 printf("\tOUTSIDE_SEQ\t%d\n", $cv->OUTSIDE_SEQ) if $] > 5.007;
315 my $SVt_PVCV = $] < 5.010 ? 12 : 13;
316 printf("\tCvFLAGS\t0x%x\t%s\n", $cv->CvFLAGS,
317 $have_B_Flags_extra ? $cv->flagspv($SVt_PVCV) : $cv->flagspv);
319 printf("\tCvFLAGS\t0x%x\n", $cv->CvFLAGS);
321 printf("\tSIGOP\t0x%x\n", $cv->SIGOP) if $cv->can('SIGOP');
322 $start->debug if $start;
323 $root->debug if $root;
325 $padlist->debug if $padlist;
336 # tied arrays may leave out FETCHSIZE
337 my (@array) = eval { $av->ARRAY; };
338 print "\tARRAY\t\t(", join(", ", map("0x" . $$_, @array)), ")\n";
339 my $fill = eval { scalar(@array) };
340 if ($Config{'useithreads'} && B::class($av) ne 'PADLIST') {
341 printf <<'EOT', $fill, $av->MAX, $av->OFF;
347 printf <<'EOT', $fill, $av->MAX;
354 printf("\tAvFLAGS\t0x%x\t%s\n", $av->AvFLAGS,
355 $have_B_Flags_extra ? $av->flagspv(10) : $av->flagspv);
357 printf("\tAvFLAGS\t0x%x\n", $av->AvFLAGS);
364 if ($done_gv{$$gv}++) {
365 printf "GV %s::%s\n", $gv->STASH->NAME, $gv->SAFENAME;
372 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;
387 my $SVt_PVGV = $] < 5.010 ? 13 : 9;
388 printf("\tGvFLAGS\t0x%x\t%s\n", $gv->GvFLAGS,
389 $have_B_Flags_extra ? $gv->flagspv($SVt_PVGV) : $gv->flagspv);
391 printf("\tGvFLAGS\t0x%x\n", $gv->GvFLAGS);
398 sub B::SPECIAL::debug {
400 my $i = ref $sv ? $$sv : 0;
401 print defined $specialsv_name[$i] ? $specialsv_name[$i] : "", "\n";
404 sub B::PADLIST::debug {
406 printf <<'EOT', B::class($padlist), $$padlist, $padlist->REFCNT;
410 _array_debug($padlist);
416 $DB::single = 1 if defined &DB::DB;
417 if ($order && $order eq "exec") {
418 return sub { walkoptree_exec(main_start, "debug") }
420 return sub { walkoptree(main_root, "debug") }
430 B::Debug - Walk Perl syntax tree, printing debug info about ops
434 perl -MO=Debug foo.pl
435 perl -MO=Debug,-exec foo.pl
439 See F<ext/B/README> and the newer L<B::Concise>.
443 With option -exec, walks tree in execute order,
444 otherwise in basic order.
448 Malcolm Beattie, C<retired>
449 Reini Urban C<rurban@cpan.org>
453 Copyright (c) 1996, 1997 Malcolm Beattie
454 Copyright (c) 2008, 2010, 2013, 2014 Reini Urban
456 This program is free software; you can redistribute it and/or modify
457 it under the terms of either:
459 a) the GNU General Public License as published by the Free
460 Software Foundation; either version 1, or (at your option) any
463 b) the "Artistic License" which comes with this kit.
465 This program is distributed in the hope that it will be useful,
466 but WITHOUT ANY WARRANTY; without even the implied warranty of
467 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either
468 the GNU General Public License or the Artistic License for more details.
470 You should have received a copy of the Artistic License with this kit,
471 in the file named "Artistic". If not, you can get one from the Perl
472 distribution. You should also have received a copy of the GNU General
473 Public License, in the file named "Copying". If not, you can get one
474 from the Perl distribution or else write to the Free Software Foundation,
475 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.