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