YA resync with mainstem, including VMS patches from others
[p5sagit/p5-mst-13.2.git] / ext / B / B / Debug.pm
CommitLineData
a798dbf2 1package B::Debug;
2use strict;
3use B qw(peekop class walkoptree walkoptree_exec
4 main_start main_root cstring sv_undef);
5use B::Asmdata qw(@specialsv_name);
6
7my %done_gv;
8
9sub B::OP::debug {
10 my ($op) = @_;
11 printf <<'EOT', class($op), $$op, ${$op->next}, ${$op->sibling}, $op->ppaddr, $op->targ, $op->type, $op->seq, $op->flags, $op->private;
12%s (0x%lx)
13 op_next 0x%x
14 op_sibling 0x%x
15 op_ppaddr %s
16 op_targ %d
17 op_type %d
18 op_seq %d
19 op_flags %d
20 op_private %d
21EOT
22}
23
24sub B::UNOP::debug {
25 my ($op) = @_;
26 $op->B::OP::debug();
27 printf "\top_first\t0x%x\n", ${$op->first};
28}
29
30sub B::BINOP::debug {
31 my ($op) = @_;
32 $op->B::UNOP::debug();
33 printf "\top_last\t\t0x%x\n", ${$op->last};
34}
35
36sub B::LOGOP::debug {
37 my ($op) = @_;
38 $op->B::UNOP::debug();
39 printf "\top_other\t0x%x\n", ${$op->other};
40}
41
a798dbf2 42sub B::LISTOP::debug {
43 my ($op) = @_;
44 $op->B::BINOP::debug();
45 printf "\top_children\t%d\n", $op->children;
46}
47
48sub B::PMOP::debug {
49 my ($op) = @_;
50 $op->B::LISTOP::debug();
51 printf "\top_pmreplroot\t0x%x\n", ${$op->pmreplroot};
52 printf "\top_pmreplstart\t0x%x\n", ${$op->pmreplstart};
53 printf "\top_pmnext\t0x%x\n", ${$op->pmnext};
54 printf "\top_pmregexp->precomp\t%s\n", cstring($op->precomp);
55 printf "\top_pmflags\t0x%x\n", $op->pmflags;
56 $op->pmshort->debug;
57 $op->pmreplroot->debug;
58}
59
60sub B::COP::debug {
61 my ($op) = @_;
62 $op->B::OP::debug();
146174a9 63 printf <<'EOT', $op->label, $op->stashpv, $op->file, $op->seq, $op->arybase, $op->line, ${$op->warnings};
a798dbf2 64 cop_label %s
146174a9 65 cop_stashpv %s
66 cop_file %s
a798dbf2 67 cop_seq %d
68 cop_arybase %d
69 cop_line %d
b295d113 70 cop_warnings 0x%x
a798dbf2 71EOT
a798dbf2 72}
73
74sub B::SVOP::debug {
75 my ($op) = @_;
76 $op->B::OP::debug();
77 printf "\top_sv\t\t0x%x\n", ${$op->sv};
78 $op->sv->debug;
79}
80
81sub B::PVOP::debug {
82 my ($op) = @_;
83 $op->B::OP::debug();
84 printf "\top_pv\t\t0x%x\n", $op->pv;
85}
86
146174a9 87sub B::PADOP::debug {
a798dbf2 88 my ($op) = @_;
89 $op->B::OP::debug();
146174a9 90 printf "\top_padix\t\t%ld\n", $op->padix;
a798dbf2 91}
92
93sub B::CVOP::debug {
94 my ($op) = @_;
95 $op->B::OP::debug();
96 printf "\top_cv\t\t0x%x\n", ${$op->cv};
97}
98
99sub B::NULL::debug {
100 my ($sv) = @_;
101 if ($$sv == ${sv_undef()}) {
102 print "&sv_undef\n";
103 } else {
104 printf "NULL (0x%x)\n", $$sv;
105 }
106}
107
108sub B::SV::debug {
109 my ($sv) = @_;
110 if (!$$sv) {
111 print class($sv), " = NULL\n";
112 return;
113 }
114 printf <<'EOT', class($sv), $$sv, $sv->REFCNT, $sv->FLAGS;
115%s (0x%x)
116 REFCNT %d
117 FLAGS 0x%x
118EOT
119}
120
121sub B::PV::debug {
122 my ($sv) = @_;
123 $sv->B::SV::debug();
124 my $pv = $sv->PV();
125 printf <<'EOT', cstring($pv), length($pv);
126 xpv_pv %s
127 xpv_cur %d
128EOT
129}
130
131sub B::IV::debug {
132 my ($sv) = @_;
133 $sv->B::SV::debug();
134 printf "\txiv_iv\t\t%d\n", $sv->IV;
135}
136
137sub B::NV::debug {
138 my ($sv) = @_;
139 $sv->B::IV::debug();
140 printf "\txnv_nv\t\t%s\n", $sv->NV;
141}
142
143sub B::PVIV::debug {
144 my ($sv) = @_;
145 $sv->B::PV::debug();
146 printf "\txiv_iv\t\t%d\n", $sv->IV;
147}
148
149sub B::PVNV::debug {
150 my ($sv) = @_;
151 $sv->B::PVIV::debug();
152 printf "\txnv_nv\t\t%s\n", $sv->NV;
153}
154
155sub B::PVLV::debug {
156 my ($sv) = @_;
157 $sv->B::PVNV::debug();
158 printf "\txlv_targoff\t%d\n", $sv->TARGOFF;
159 printf "\txlv_targlen\t%u\n", $sv->TARGLEN;
160 printf "\txlv_type\t%s\n", cstring(chr($sv->TYPE));
161}
162
163sub B::BM::debug {
164 my ($sv) = @_;
165 $sv->B::PVNV::debug();
166 printf "\txbm_useful\t%d\n", $sv->USEFUL;
167 printf "\txbm_previous\t%u\n", $sv->PREVIOUS;
168 printf "\txbm_rare\t%s\n", cstring(chr($sv->RARE));
169}
170
171sub B::CV::debug {
172 my ($sv) = @_;
173 $sv->B::PVNV::debug();
174 my ($stash) = $sv->STASH;
175 my ($start) = $sv->START;
176 my ($root) = $sv->ROOT;
177 my ($padlist) = $sv->PADLIST;
146174a9 178 my ($file) = $sv->FILE;
a798dbf2 179 my ($gv) = $sv->GV;
146174a9 180 printf <<'EOT', $$stash, $$start, $$root, $$gv, $file, $sv->DEPTH, $padlist, ${$sv->OUTSIDE};
a798dbf2 181 STASH 0x%x
182 START 0x%x
183 ROOT 0x%x
184 GV 0x%x
146174a9 185 FILE %s
a798dbf2 186 DEPTH %d
187 PADLIST 0x%x
188 OUTSIDE 0x%x
189EOT
190 $start->debug if $start;
191 $root->debug if $root;
192 $gv->debug if $gv;
a798dbf2 193 $padlist->debug if $padlist;
194}
195
196sub B::AV::debug {
197 my ($av) = @_;
198 $av->B::SV::debug;
199 my(@array) = $av->ARRAY;
200 print "\tARRAY\t\t(", join(", ", map("0x" . $$_, @array)), ")\n";
201 printf <<'EOT', scalar(@array), $av->MAX, $av->OFF, $av->AvFLAGS;
202 FILL %d
203 MAX %d
204 OFF %d
205 AvFLAGS %d
206EOT
207}
208
209sub B::GV::debug {
210 my ($gv) = @_;
211 if ($done_gv{$$gv}++) {
212 printf "GV %s::%s\n", $gv->STASH->NAME, $gv->NAME;
213 return;
214 }
215 my ($sv) = $gv->SV;
216 my ($av) = $gv->AV;
217 my ($cv) = $gv->CV;
218 $gv->B::SV::debug;
146174a9 219 printf <<'EOT', $gv->NAME, $gv->STASH->NAME, $gv->STASH, $$sv, $gv->GvREFCNT, $gv->FORM, $$av, ${$gv->HV}, ${$gv->EGV}, $$cv, $gv->CVGEN, $gv->LINE, $gv->FILE, $gv->GvFLAGS;
a798dbf2 220 NAME %s
221 STASH %s (0x%x)
222 SV 0x%x
223 GvREFCNT %d
224 FORM 0x%x
225 AV 0x%x
226 HV 0x%x
227 EGV 0x%x
228 CV 0x%x
229 CVGEN %d
230 LINE %d
146174a9 231 FILE %s
a798dbf2 232 GvFLAGS 0x%x
233EOT
234 $sv->debug if $sv;
235 $av->debug if $av;
236 $cv->debug if $cv;
237}
238
239sub B::SPECIAL::debug {
240 my $sv = shift;
241 print $specialsv_name[$$sv], "\n";
242}
243
244sub compile {
245 my $order = shift;
c529f79d 246 B::clearsym();
a798dbf2 247 if ($order eq "exec") {
248 return sub { walkoptree_exec(main_start, "debug") }
249 } else {
250 return sub { walkoptree(main_root, "debug") }
251 }
252}
253
2541;
7f20e9dd 255
256__END__
257
258=head1 NAME
259
260B::Debug - Walk Perl syntax tree, printing debug info about ops
261
262=head1 SYNOPSIS
263
264 perl -MO=Debug[,OPTIONS] foo.pl
265
266=head1 DESCRIPTION
267
268See F<ext/B/README>.
269
270=head1 AUTHOR
271
272Malcolm Beattie, C<mbeattie@sable.ox.ac.uk>
273
274=cut