Commit | Line | Data |
a0d0e21e |
1 | /* dump.c |
a687059c |
2 | * |
9607fc9c |
3 | * Copyright (c) 1991-1997, Larry Wall |
a687059c |
4 | * |
6e21c824 |
5 | * You may distribute under the terms of either the GNU General Public |
6 | * License or the Artistic License, as specified in the README file. |
8d063cd8 |
7 | * |
a0d0e21e |
8 | */ |
9 | |
10 | /* |
11 | * "'You have talked long in your sleep, Frodo,' said Gandalf gently, 'and |
12 | * it has not been hard for me to read your mind and memory.'" |
8d063cd8 |
13 | */ |
14 | |
8d063cd8 |
15 | #include "EXTERN.h" |
8d063cd8 |
16 | #include "perl.h" |
17 | |
76e3520e |
18 | #ifndef PERL_OBJECT |
4db58590 |
19 | static void dump(char *pat, ...); |
76e3520e |
20 | #endif /* PERL_OBJECT */ |
8adcabd8 |
21 | |
22 | void |
8ac85365 |
23 | dump_all(void) |
79072805 |
24 | { |
35ff7856 |
25 | #ifdef DEBUGGING |
11343788 |
26 | dTHR; |
760ac839 |
27 | PerlIO_setlinebuf(Perl_debug_log); |
93a17b20 |
28 | if (main_root) |
29 | dump_op(main_root); |
463ee0b2 |
30 | dump_packsubs(defstash); |
17c3b450 |
31 | #endif /* DEBUGGING */ |
463ee0b2 |
32 | } |
33 | |
34 | void |
8ac85365 |
35 | dump_packsubs(HV *stash) |
463ee0b2 |
36 | { |
35ff7856 |
37 | #ifdef DEBUGGING |
11343788 |
38 | dTHR; |
a0d0e21e |
39 | I32 i; |
463ee0b2 |
40 | HE *entry; |
41 | |
8990e307 |
42 | if (!HvARRAY(stash)) |
43 | return; |
a0d0e21e |
44 | for (i = 0; i <= (I32) HvMAX(stash); i++) { |
4db58590 |
45 | for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) { |
46 | GV *gv = (GV*)HeVAL(entry); |
463ee0b2 |
47 | HV *hv; |
8ebc5c01 |
48 | if (GvCVu(gv)) |
463ee0b2 |
49 | dump_sub(gv); |
85e6fe83 |
50 | if (GvFORM(gv)) |
51 | dump_form(gv); |
4db58590 |
52 | if (HeKEY(entry)[HeKLEN(entry)-1] == ':' && |
a0d0e21e |
53 | (hv = GvHV(gv)) && HvNAME(hv) && hv != defstash) |
463ee0b2 |
54 | dump_packsubs(hv); /* nested package */ |
55 | } |
79072805 |
56 | } |
17c3b450 |
57 | #endif /* DEBUGGING */ |
79072805 |
58 | } |
59 | |
60 | void |
8ac85365 |
61 | dump_sub(GV *gv) |
a687059c |
62 | { |
35ff7856 |
63 | #ifdef DEBUGGING |
8990e307 |
64 | SV *sv = sv_newmortal(); |
85e6fe83 |
65 | |
f6aff53a |
66 | gv_fullname3(sv, gv, Nullch); |
85e6fe83 |
67 | dump("\nSUB %s = ", SvPVX(sv)); |
a0d0e21e |
68 | if (CvXSUB(GvCV(gv))) |
85e6fe83 |
69 | dump("(xsub 0x%x %d)\n", |
a0d0e21e |
70 | (long)CvXSUB(GvCV(gv)), |
71 | CvXSUBANY(GvCV(gv)).any_i32); |
85e6fe83 |
72 | else if (CvROOT(GvCV(gv))) |
73 | dump_op(CvROOT(GvCV(gv))); |
74 | else |
75 | dump("<undef>\n"); |
17c3b450 |
76 | #endif /* DEBUGGING */ |
85e6fe83 |
77 | } |
78 | |
79 | void |
8ac85365 |
80 | dump_form(GV *gv) |
85e6fe83 |
81 | { |
35ff7856 |
82 | #ifdef DEBUGGING |
85e6fe83 |
83 | SV *sv = sv_newmortal(); |
84 | |
f6aff53a |
85 | gv_fullname3(sv, gv, Nullch); |
85e6fe83 |
86 | dump("\nFORMAT %s = ", SvPVX(sv)); |
87 | if (CvROOT(GvFORM(gv))) |
88 | dump_op(CvROOT(GvFORM(gv))); |
89 | else |
90 | dump("<undef>\n"); |
17c3b450 |
91 | #endif /* DEBUGGING */ |
a687059c |
92 | } |
93 | |
8adcabd8 |
94 | void |
8ac85365 |
95 | dump_eval(void) |
8d063cd8 |
96 | { |
35ff7856 |
97 | #ifdef DEBUGGING |
79072805 |
98 | dump_op(eval_root); |
17c3b450 |
99 | #endif /* DEBUGGING */ |
79072805 |
100 | } |
101 | |
102 | void |
8ac85365 |
103 | dump_op(OP *o) |
79072805 |
104 | { |
35ff7856 |
105 | #ifdef DEBUGGING |
79072805 |
106 | dump("{\n"); |
11343788 |
107 | if (o->op_seq) |
5dc0d613 |
108 | PerlIO_printf(Perl_debug_log, "%-4d", o->op_seq); |
93a17b20 |
109 | else |
760ac839 |
110 | PerlIO_printf(Perl_debug_log, " "); |
11343788 |
111 | dump("TYPE = %s ===> ", op_name[o->op_type]); |
112 | if (o->op_next) { |
113 | if (o->op_seq) |
5dc0d613 |
114 | PerlIO_printf(Perl_debug_log, "%d\n", o->op_next->op_seq); |
93a17b20 |
115 | else |
5dc0d613 |
116 | PerlIO_printf(Perl_debug_log, "(%d)\n", o->op_next->op_seq); |
93a17b20 |
117 | } |
79072805 |
118 | else |
760ac839 |
119 | PerlIO_printf(Perl_debug_log, "DONE\n"); |
79072805 |
120 | dumplvl++; |
11343788 |
121 | if (o->op_targ) { |
122 | if (o->op_type == OP_NULL) |
123 | dump(" (was %s)\n", op_name[o->op_targ]); |
8990e307 |
124 | else |
11343788 |
125 | dump("TARG = %d\n", o->op_targ); |
8990e307 |
126 | } |
748a9306 |
127 | #ifdef DUMPADDR |
11343788 |
128 | dump("ADDR = 0x%lx => 0x%lx\n",o, o->op_next); |
79072805 |
129 | #endif |
11343788 |
130 | if (o->op_flags) { |
46fc3d4c |
131 | SV *tmpsv = newSVpv("", 0); |
5dc0d613 |
132 | switch (o->op_flags & OPf_WANT) { |
54310121 |
133 | case OPf_WANT_VOID: |
46fc3d4c |
134 | sv_catpv(tmpsv, ",VOID"); |
54310121 |
135 | break; |
136 | case OPf_WANT_SCALAR: |
46fc3d4c |
137 | sv_catpv(tmpsv, ",SCALAR"); |
54310121 |
138 | break; |
139 | case OPf_WANT_LIST: |
46fc3d4c |
140 | sv_catpv(tmpsv, ",LIST"); |
54310121 |
141 | break; |
142 | default: |
46fc3d4c |
143 | sv_catpv(tmpsv, ",UNKNOWN"); |
54310121 |
144 | break; |
145 | } |
11343788 |
146 | if (o->op_flags & OPf_KIDS) |
46fc3d4c |
147 | sv_catpv(tmpsv, ",KIDS"); |
11343788 |
148 | if (o->op_flags & OPf_PARENS) |
46fc3d4c |
149 | sv_catpv(tmpsv, ",PARENS"); |
11343788 |
150 | if (o->op_flags & OPf_STACKED) |
46fc3d4c |
151 | sv_catpv(tmpsv, ",STACKED"); |
11343788 |
152 | if (o->op_flags & OPf_REF) |
46fc3d4c |
153 | sv_catpv(tmpsv, ",REF"); |
11343788 |
154 | if (o->op_flags & OPf_MOD) |
46fc3d4c |
155 | sv_catpv(tmpsv, ",MOD"); |
11343788 |
156 | if (o->op_flags & OPf_SPECIAL) |
46fc3d4c |
157 | sv_catpv(tmpsv, ",SPECIAL"); |
158 | dump("FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); |
159 | SvREFCNT_dec(tmpsv); |
79072805 |
160 | } |
11343788 |
161 | if (o->op_private) { |
46fc3d4c |
162 | SV *tmpsv = newSVpv("", 0); |
11343788 |
163 | if (o->op_type == OP_AASSIGN) { |
164 | if (o->op_private & OPpASSIGN_COMMON) |
46fc3d4c |
165 | sv_catpv(tmpsv, ",COMMON"); |
8d063cd8 |
166 | } |
11343788 |
167 | else if (o->op_type == OP_SASSIGN) { |
168 | if (o->op_private & OPpASSIGN_BACKWARDS) |
46fc3d4c |
169 | sv_catpv(tmpsv, ",BACKWARDS"); |
a0d0e21e |
170 | } |
11343788 |
171 | else if (o->op_type == OP_TRANS) { |
172 | if (o->op_private & OPpTRANS_SQUASH) |
46fc3d4c |
173 | sv_catpv(tmpsv, ",SQUASH"); |
11343788 |
174 | if (o->op_private & OPpTRANS_DELETE) |
46fc3d4c |
175 | sv_catpv(tmpsv, ",DELETE"); |
11343788 |
176 | if (o->op_private & OPpTRANS_COMPLEMENT) |
46fc3d4c |
177 | sv_catpv(tmpsv, ",COMPLEMENT"); |
8d063cd8 |
178 | } |
11343788 |
179 | else if (o->op_type == OP_REPEAT) { |
180 | if (o->op_private & OPpREPEAT_DOLIST) |
46fc3d4c |
181 | sv_catpv(tmpsv, ",DOLIST"); |
8d063cd8 |
182 | } |
11343788 |
183 | else if (o->op_type == OP_ENTERSUB || |
184 | o->op_type == OP_RV2SV || |
185 | o->op_type == OP_RV2AV || |
186 | o->op_type == OP_RV2HV || |
187 | o->op_type == OP_RV2GV || |
188 | o->op_type == OP_AELEM || |
189 | o->op_type == OP_HELEM ) |
85e6fe83 |
190 | { |
5dc0d613 |
191 | if (o->op_type == OP_ENTERSUB) { |
192 | if (o->op_private & OPpENTERSUB_AMPER) |
46fc3d4c |
193 | sv_catpv(tmpsv, ",AMPER"); |
5dc0d613 |
194 | if (o->op_private & OPpENTERSUB_DB) |
46fc3d4c |
195 | sv_catpv(tmpsv, ",DB"); |
68dc0745 |
196 | } |
5dc0d613 |
197 | switch (o->op_private & OPpDEREF) { |
5f05dabc |
198 | case OPpDEREF_SV: |
46fc3d4c |
199 | sv_catpv(tmpsv, ",SV"); |
5f05dabc |
200 | break; |
201 | case OPpDEREF_AV: |
46fc3d4c |
202 | sv_catpv(tmpsv, ",AV"); |
5f05dabc |
203 | break; |
204 | case OPpDEREF_HV: |
46fc3d4c |
205 | sv_catpv(tmpsv, ",HV"); |
5f05dabc |
206 | break; |
207 | } |
5dc0d613 |
208 | if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) { |
209 | if (o->op_private & OPpLVAL_DEFER) |
46fc3d4c |
210 | sv_catpv(tmpsv, ",LVAL_DEFER"); |
68dc0745 |
211 | } |
212 | else { |
5dc0d613 |
213 | if (o->op_private & HINT_STRICT_REFS) |
46fc3d4c |
214 | sv_catpv(tmpsv, ",STRICT_REFS"); |
68dc0745 |
215 | } |
8d063cd8 |
216 | } |
11343788 |
217 | else if (o->op_type == OP_CONST) { |
218 | if (o->op_private & OPpCONST_BARE) |
46fc3d4c |
219 | sv_catpv(tmpsv, ",BARE"); |
79072805 |
220 | } |
11343788 |
221 | else if (o->op_type == OP_FLIP) { |
222 | if (o->op_private & OPpFLIP_LINENUM) |
46fc3d4c |
223 | sv_catpv(tmpsv, ",LINENUM"); |
79072805 |
224 | } |
11343788 |
225 | else if (o->op_type == OP_FLOP) { |
226 | if (o->op_private & OPpFLIP_LINENUM) |
46fc3d4c |
227 | sv_catpv(tmpsv, ",LINENUM"); |
79072805 |
228 | } |
11343788 |
229 | if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO) |
46fc3d4c |
230 | sv_catpv(tmpsv, ",INTRO"); |
231 | if (SvCUR(tmpsv)) |
232 | dump("PRIVATE = (%s)\n", SvPVX(tmpsv) + 1); |
233 | SvREFCNT_dec(tmpsv); |
8d063cd8 |
234 | } |
8d063cd8 |
235 | |
11343788 |
236 | switch (o->op_type) { |
93a17b20 |
237 | case OP_GVSV: |
79072805 |
238 | case OP_GV: |
11343788 |
239 | if (cGVOPo->op_gv) { |
46fc3d4c |
240 | SV *tmpsv = NEWSV(0,0); |
8990e307 |
241 | ENTER; |
8990e307 |
242 | SAVEFREESV(tmpsv); |
5dc0d613 |
243 | gv_fullname3(tmpsv, cGVOPo->op_gv, Nullch); |
463ee0b2 |
244 | dump("GV = %s\n", SvPV(tmpsv, na)); |
8990e307 |
245 | LEAVE; |
378cc40b |
246 | } |
79072805 |
247 | else |
248 | dump("GV = NULL\n"); |
249 | break; |
250 | case OP_CONST: |
11343788 |
251 | dump("SV = %s\n", SvPEEK(cSVOPo->op_sv)); |
79072805 |
252 | break; |
93a17b20 |
253 | case OP_NEXTSTATE: |
254 | case OP_DBSTATE: |
11343788 |
255 | if (cCOPo->cop_line) |
256 | dump("LINE = %d\n",cCOPo->cop_line); |
257 | if (cCOPo->cop_label) |
258 | dump("LABEL = \"%s\"\n",cCOPo->cop_label); |
79072805 |
259 | break; |
260 | case OP_ENTERLOOP: |
261 | dump("REDO ===> "); |
11343788 |
262 | if (cLOOPo->op_redoop) |
5dc0d613 |
263 | PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_redoop->op_seq); |
79072805 |
264 | else |
760ac839 |
265 | PerlIO_printf(Perl_debug_log, "DONE\n"); |
79072805 |
266 | dump("NEXT ===> "); |
11343788 |
267 | if (cLOOPo->op_nextop) |
5dc0d613 |
268 | PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_nextop->op_seq); |
79072805 |
269 | else |
760ac839 |
270 | PerlIO_printf(Perl_debug_log, "DONE\n"); |
79072805 |
271 | dump("LAST ===> "); |
11343788 |
272 | if (cLOOPo->op_lastop) |
5dc0d613 |
273 | PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_lastop->op_seq); |
79072805 |
274 | else |
760ac839 |
275 | PerlIO_printf(Perl_debug_log, "DONE\n"); |
79072805 |
276 | break; |
277 | case OP_COND_EXPR: |
278 | dump("TRUE ===> "); |
11343788 |
279 | if (cCONDOPo->op_true) |
5dc0d613 |
280 | PerlIO_printf(Perl_debug_log, "%d\n", cCONDOPo->op_true->op_seq); |
79072805 |
281 | else |
760ac839 |
282 | PerlIO_printf(Perl_debug_log, "DONE\n"); |
79072805 |
283 | dump("FALSE ===> "); |
11343788 |
284 | if (cCONDOPo->op_false) |
5dc0d613 |
285 | PerlIO_printf(Perl_debug_log, "%d\n", cCONDOPo->op_false->op_seq); |
79072805 |
286 | else |
760ac839 |
287 | PerlIO_printf(Perl_debug_log, "DONE\n"); |
79072805 |
288 | break; |
a0d0e21e |
289 | case OP_MAPWHILE: |
79072805 |
290 | case OP_GREPWHILE: |
291 | case OP_OR: |
292 | case OP_AND: |
79072805 |
293 | dump("OTHER ===> "); |
11343788 |
294 | if (cLOGOPo->op_other) |
5dc0d613 |
295 | PerlIO_printf(Perl_debug_log, "%d\n", cLOGOPo->op_other->op_seq); |
79072805 |
296 | else |
760ac839 |
297 | PerlIO_printf(Perl_debug_log, "DONE\n"); |
79072805 |
298 | break; |
299 | case OP_PUSHRE: |
300 | case OP_MATCH: |
301 | case OP_SUBST: |
11343788 |
302 | dump_pm(cPMOPo); |
79072805 |
303 | break; |
a0d0e21e |
304 | default: |
305 | break; |
79072805 |
306 | } |
11343788 |
307 | if (o->op_flags & OPf_KIDS) { |
79072805 |
308 | OP *kid; |
11343788 |
309 | for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) |
79072805 |
310 | dump_op(kid); |
8d063cd8 |
311 | } |
312 | dumplvl--; |
313 | dump("}\n"); |
17c3b450 |
314 | #endif /* DEBUGGING */ |
8d063cd8 |
315 | } |
316 | |
8adcabd8 |
317 | void |
8ac85365 |
318 | dump_gv(GV *gv) |
378cc40b |
319 | { |
35ff7856 |
320 | #ifdef DEBUGGING |
79072805 |
321 | SV *sv; |
378cc40b |
322 | |
79072805 |
323 | if (!gv) { |
760ac839 |
324 | PerlIO_printf(Perl_debug_log, "{}\n"); |
378cc40b |
325 | return; |
326 | } |
8990e307 |
327 | sv = sv_newmortal(); |
8d063cd8 |
328 | dumplvl++; |
760ac839 |
329 | PerlIO_printf(Perl_debug_log, "{\n"); |
f6aff53a |
330 | gv_fullname3(sv, gv, Nullch); |
463ee0b2 |
331 | dump("GV_NAME = %s", SvPVX(sv)); |
79072805 |
332 | if (gv != GvEGV(gv)) { |
f6aff53a |
333 | gv_efullname3(sv, GvEGV(gv), Nullch); |
463ee0b2 |
334 | dump("-> %s", SvPVX(sv)); |
8adcabd8 |
335 | } |
336 | dump("\n"); |
8d063cd8 |
337 | dumplvl--; |
338 | dump("}\n"); |
17c3b450 |
339 | #endif /* DEBUGGING */ |
8d063cd8 |
340 | } |
341 | |
8adcabd8 |
342 | void |
8ac85365 |
343 | dump_pm(PMOP *pm) |
8d063cd8 |
344 | { |
35ff7856 |
345 | #ifdef DEBUGGING |
8d063cd8 |
346 | char ch; |
347 | |
79072805 |
348 | if (!pm) { |
349 | dump("{}\n"); |
378cc40b |
350 | return; |
351 | } |
79072805 |
352 | dump("{\n"); |
8d063cd8 |
353 | dumplvl++; |
79072805 |
354 | if (pm->op_pmflags & PMf_ONCE) |
355 | ch = '?'; |
356 | else |
357 | ch = '/'; |
358 | if (pm->op_pmregexp) |
c90c0ff4 |
359 | dump("PMf_PRE %c%s%c%s\n", |
360 | ch, pm->op_pmregexp->precomp, ch, |
361 | (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : ""); |
362 | else |
363 | dump("PMf_PRE (RUNTIME)\n"); |
79072805 |
364 | if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) { |
365 | dump("PMf_REPL = "); |
366 | dump_op(pm->op_pmreplroot); |
8d063cd8 |
367 | } |
c277df42 |
368 | if (pm->op_pmflags || (pm->op_pmregexp && pm->op_pmregexp->check_substr)) { |
46fc3d4c |
369 | SV *tmpsv = newSVpv("", 0); |
48c036b1 |
370 | if (pm->op_pmdynflags & PMdf_USED) |
46fc3d4c |
371 | sv_catpv(tmpsv, ",USED"); |
79072805 |
372 | if (pm->op_pmflags & PMf_ONCE) |
46fc3d4c |
373 | sv_catpv(tmpsv, ",ONCE"); |
c277df42 |
374 | if (pm->op_pmregexp && pm->op_pmregexp->check_substr |
375 | && !(pm->op_pmregexp->reganch & ROPT_NOSCAN)) |
46fc3d4c |
376 | sv_catpv(tmpsv, ",SCANFIRST"); |
c277df42 |
377 | if (pm->op_pmregexp && pm->op_pmregexp->check_substr |
378 | && pm->op_pmregexp->reganch & ROPT_CHECK_ALL) |
46fc3d4c |
379 | sv_catpv(tmpsv, ",ALL"); |
79072805 |
380 | if (pm->op_pmflags & PMf_SKIPWHITE) |
46fc3d4c |
381 | sv_catpv(tmpsv, ",SKIPWHITE"); |
79072805 |
382 | if (pm->op_pmflags & PMf_CONST) |
46fc3d4c |
383 | sv_catpv(tmpsv, ",CONST"); |
79072805 |
384 | if (pm->op_pmflags & PMf_KEEP) |
46fc3d4c |
385 | sv_catpv(tmpsv, ",KEEP"); |
79072805 |
386 | if (pm->op_pmflags & PMf_GLOBAL) |
46fc3d4c |
387 | sv_catpv(tmpsv, ",GLOBAL"); |
c90c0ff4 |
388 | if (pm->op_pmflags & PMf_CONTINUE) |
389 | sv_catpv(tmpsv, ",CONTINUE"); |
48c036b1 |
390 | if (pm->op_pmflags & PMf_TAINTMEM) |
391 | sv_catpv(tmpsv, ",TAINTMEM"); |
79072805 |
392 | if (pm->op_pmflags & PMf_EVAL) |
46fc3d4c |
393 | sv_catpv(tmpsv, ",EVAL"); |
394 | dump("PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); |
395 | SvREFCNT_dec(tmpsv); |
378cc40b |
396 | } |
79072805 |
397 | |
8d063cd8 |
398 | dumplvl--; |
399 | dump("}\n"); |
17c3b450 |
400 | #endif /* DEBUGGING */ |
8d063cd8 |
401 | } |
402 | |
4db58590 |
403 | |
76e3520e |
404 | STATIC void |
4db58590 |
405 | dump(char *pat,...) |
4db58590 |
406 | { |
35ff7856 |
407 | #ifdef DEBUGGING |
4db58590 |
408 | I32 i; |
409 | va_list args; |
4db58590 |
410 | |
4db58590 |
411 | va_start(args, pat); |
4db58590 |
412 | for (i = dumplvl*4; i; i--) |
760ac839 |
413 | (void)PerlIO_putc(Perl_debug_log,' '); |
414 | PerlIO_vprintf(Perl_debug_log,pat,args); |
4db58590 |
415 | va_end(args); |
17c3b450 |
416 | #endif /* DEBUGGING */ |
8d063cd8 |
417 | } |