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