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 | |
3967c732 |
18 | #ifndef DBL_DIG |
19 | #define DBL_DIG 15 /* A guess that works lots of places */ |
20 | #endif |
21 | |
22 | void |
23 | dump_indent(I32 level, PerlIO *file, const char* pat, ...) |
24 | { |
25 | dTHR; |
26 | va_list args; |
27 | |
28 | va_start(args, pat); |
29 | PerlIO_printf(file, "%*s", level*PL_dumpindent, ""); |
30 | PerlIO_vprintf(file, pat, args); |
31 | va_end(args); |
32 | } |
8adcabd8 |
33 | |
34 | void |
8ac85365 |
35 | dump_all(void) |
79072805 |
36 | { |
11343788 |
37 | dTHR; |
760ac839 |
38 | PerlIO_setlinebuf(Perl_debug_log); |
3280af22 |
39 | if (PL_main_root) |
3967c732 |
40 | op_dump(PL_main_root); |
3280af22 |
41 | dump_packsubs(PL_defstash); |
463ee0b2 |
42 | } |
43 | |
44 | void |
8ac85365 |
45 | dump_packsubs(HV *stash) |
463ee0b2 |
46 | { |
11343788 |
47 | dTHR; |
a0d0e21e |
48 | I32 i; |
463ee0b2 |
49 | HE *entry; |
50 | |
8990e307 |
51 | if (!HvARRAY(stash)) |
52 | return; |
a0d0e21e |
53 | for (i = 0; i <= (I32) HvMAX(stash); i++) { |
4db58590 |
54 | for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) { |
55 | GV *gv = (GV*)HeVAL(entry); |
463ee0b2 |
56 | HV *hv; |
e29cdcb3 |
57 | if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv)) |
58 | continue; |
8ebc5c01 |
59 | if (GvCVu(gv)) |
463ee0b2 |
60 | dump_sub(gv); |
85e6fe83 |
61 | if (GvFORM(gv)) |
62 | dump_form(gv); |
4db58590 |
63 | if (HeKEY(entry)[HeKLEN(entry)-1] == ':' && |
3280af22 |
64 | (hv = GvHV(gv)) && HvNAME(hv) && hv != PL_defstash) |
463ee0b2 |
65 | dump_packsubs(hv); /* nested package */ |
66 | } |
79072805 |
67 | } |
68 | } |
69 | |
70 | void |
8ac85365 |
71 | dump_sub(GV *gv) |
a687059c |
72 | { |
8990e307 |
73 | SV *sv = sv_newmortal(); |
85e6fe83 |
74 | |
f6aff53a |
75 | gv_fullname3(sv, gv, Nullch); |
3967c732 |
76 | dump_indent(0, Perl_debug_log, "\nSUB %s = ", SvPVX(sv)); |
a0d0e21e |
77 | if (CvXSUB(GvCV(gv))) |
3967c732 |
78 | dump_indent(0, Perl_debug_log, "(xsub 0x%x %d)\n", |
a0d0e21e |
79 | (long)CvXSUB(GvCV(gv)), |
80 | CvXSUBANY(GvCV(gv)).any_i32); |
85e6fe83 |
81 | else if (CvROOT(GvCV(gv))) |
3967c732 |
82 | op_dump(CvROOT(GvCV(gv))); |
85e6fe83 |
83 | else |
3967c732 |
84 | dump_indent(0, Perl_debug_log, "<undef>\n"); |
85e6fe83 |
85 | } |
86 | |
87 | void |
8ac85365 |
88 | dump_form(GV *gv) |
85e6fe83 |
89 | { |
90 | SV *sv = sv_newmortal(); |
91 | |
f6aff53a |
92 | gv_fullname3(sv, gv, Nullch); |
3967c732 |
93 | dump_indent(0, Perl_debug_log, "\nFORMAT %s = ", SvPVX(sv)); |
85e6fe83 |
94 | if (CvROOT(GvFORM(gv))) |
3967c732 |
95 | op_dump(CvROOT(GvFORM(gv))); |
85e6fe83 |
96 | else |
3967c732 |
97 | dump_indent(0, Perl_debug_log, "<undef>\n"); |
a687059c |
98 | } |
99 | |
8adcabd8 |
100 | void |
8ac85365 |
101 | dump_eval(void) |
8d063cd8 |
102 | { |
3967c732 |
103 | op_dump(PL_eval_root); |
104 | } |
105 | |
106 | char * |
107 | pv_display(SV *sv, char *pv, STRLEN cur, STRLEN len, STRLEN pvlim) |
108 | { |
109 | int truncated = 0; |
110 | int nul_terminated = len > cur && pv[cur] == '\0'; |
111 | |
112 | sv_setpvn(sv, "\"", 1); |
113 | for (; cur--; pv++) { |
114 | if (pvlim && SvCUR(sv) >= pvlim) { |
115 | truncated++; |
116 | break; |
117 | } |
118 | if (isPRINT(*pv)) { |
119 | switch (*pv) { |
120 | case '\t': sv_catpvn(sv, "\\t", 2); break; |
121 | case '\n': sv_catpvn(sv, "\\n", 2); break; |
122 | case '\r': sv_catpvn(sv, "\\r", 2); break; |
123 | case '\f': sv_catpvn(sv, "\\f", 2); break; |
124 | case '"': sv_catpvn(sv, "\\\"", 2); break; |
125 | case '\\': sv_catpvn(sv, "\\\\", 2); break; |
126 | default: sv_catpvn(sv, pv, 1); break; |
127 | } |
128 | } |
129 | else { |
130 | if (cur && isDIGIT(*(pv+1))) |
131 | sv_catpvf(sv, "\\%03o", *pv); |
132 | else |
133 | sv_catpvf(sv, "\\%o", *pv); |
134 | } |
135 | } |
136 | sv_catpvn(sv, "\"", 1); |
137 | if (truncated) |
138 | sv_catpvn(sv, "...", 3); |
139 | if (nul_terminated) |
140 | sv_catpvn(sv, "\\0", 2); |
141 | |
142 | return SvPVX(sv); |
143 | } |
144 | |
145 | char * |
146 | sv_peek(SV *sv) |
147 | { |
148 | SV *t = sv_newmortal(); |
2d8e6c8d |
149 | STRLEN n_a; |
3967c732 |
150 | int unref = 0; |
151 | |
152 | sv_setpvn(t, "", 0); |
153 | retry: |
154 | if (!sv) { |
155 | sv_catpv(t, "VOID"); |
156 | goto finish; |
157 | } |
158 | else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') { |
159 | sv_catpv(t, "WILD"); |
160 | goto finish; |
161 | } |
162 | else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes) { |
163 | if (sv == &PL_sv_undef) { |
164 | sv_catpv(t, "SV_UNDEF"); |
165 | if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT| |
166 | SVs_GMG|SVs_SMG|SVs_RMG)) && |
167 | SvREADONLY(sv)) |
168 | goto finish; |
169 | } |
170 | else if (sv == &PL_sv_no) { |
171 | sv_catpv(t, "SV_NO"); |
172 | if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT| |
173 | SVs_GMG|SVs_SMG|SVs_RMG)) && |
174 | !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY| |
175 | SVp_POK|SVp_NOK)) && |
176 | SvCUR(sv) == 0 && |
177 | SvNVX(sv) == 0.0) |
178 | goto finish; |
179 | } |
180 | else { |
181 | sv_catpv(t, "SV_YES"); |
182 | if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT| |
183 | SVs_GMG|SVs_SMG|SVs_RMG)) && |
184 | !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY| |
185 | SVp_POK|SVp_NOK)) && |
186 | SvCUR(sv) == 1 && |
187 | SvPVX(sv) && *SvPVX(sv) == '1' && |
188 | SvNVX(sv) == 1.0) |
189 | goto finish; |
190 | } |
191 | sv_catpv(t, ":"); |
192 | } |
193 | else if (SvREFCNT(sv) == 0) { |
194 | sv_catpv(t, "("); |
195 | unref++; |
196 | } |
197 | if (SvROK(sv)) { |
198 | sv_catpv(t, "\\"); |
199 | if (SvCUR(t) + unref > 10) { |
200 | SvCUR(t) = unref + 3; |
201 | *SvEND(t) = '\0'; |
202 | sv_catpv(t, "..."); |
203 | goto finish; |
204 | } |
205 | sv = (SV*)SvRV(sv); |
206 | goto retry; |
207 | } |
208 | switch (SvTYPE(sv)) { |
209 | default: |
210 | sv_catpv(t, "FREED"); |
211 | goto finish; |
212 | |
213 | case SVt_NULL: |
214 | sv_catpv(t, "UNDEF"); |
215 | goto finish; |
216 | case SVt_IV: |
217 | sv_catpv(t, "IV"); |
218 | break; |
219 | case SVt_NV: |
220 | sv_catpv(t, "NV"); |
221 | break; |
222 | case SVt_RV: |
223 | sv_catpv(t, "RV"); |
224 | break; |
225 | case SVt_PV: |
226 | sv_catpv(t, "PV"); |
227 | break; |
228 | case SVt_PVIV: |
229 | sv_catpv(t, "PVIV"); |
230 | break; |
231 | case SVt_PVNV: |
232 | sv_catpv(t, "PVNV"); |
233 | break; |
234 | case SVt_PVMG: |
235 | sv_catpv(t, "PVMG"); |
236 | break; |
237 | case SVt_PVLV: |
238 | sv_catpv(t, "PVLV"); |
239 | break; |
240 | case SVt_PVAV: |
241 | sv_catpv(t, "AV"); |
242 | break; |
243 | case SVt_PVHV: |
244 | sv_catpv(t, "HV"); |
245 | break; |
246 | case SVt_PVCV: |
247 | if (CvGV(sv)) |
248 | sv_catpvf(t, "CV(%s)", GvNAME(CvGV(sv))); |
249 | else |
250 | sv_catpv(t, "CV()"); |
251 | goto finish; |
252 | case SVt_PVGV: |
253 | sv_catpv(t, "GV"); |
254 | break; |
255 | case SVt_PVBM: |
256 | sv_catpv(t, "BM"); |
257 | break; |
258 | case SVt_PVFM: |
259 | sv_catpv(t, "FM"); |
260 | break; |
261 | case SVt_PVIO: |
262 | sv_catpv(t, "IO"); |
263 | break; |
264 | } |
265 | |
266 | if (SvPOKp(sv)) { |
267 | if (!SvPVX(sv)) |
268 | sv_catpv(t, "(null)"); |
269 | else { |
270 | SV *tmp = newSVpv("", 0); |
271 | sv_catpv(t, "("); |
272 | if (SvOOK(sv)) |
273 | sv_catpvf(t, "[%s]", pv_display(tmp, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, 127)); |
274 | sv_catpvf(t, "%s)", pv_display(tmp, SvPVX(sv), SvCUR(sv), SvLEN(sv), 127)); |
275 | SvREFCNT_dec(tmp); |
276 | } |
277 | } |
278 | else if (SvNOKp(sv)) { |
279 | SET_NUMERIC_STANDARD(); |
280 | sv_catpvf(t, "(%g)",SvNVX(sv)); |
281 | } |
282 | else if (SvIOKp(sv)) |
283 | sv_catpvf(t, "(%ld)",(long)SvIVX(sv)); |
284 | else |
285 | sv_catpv(t, "()"); |
286 | |
287 | finish: |
288 | if (unref) { |
289 | while (unref--) |
290 | sv_catpv(t, ")"); |
291 | } |
2d8e6c8d |
292 | return SvPV(t, n_a); |
3967c732 |
293 | } |
294 | |
295 | void |
296 | do_pmop_dump(I32 level, PerlIO *file, PMOP *pm) |
297 | { |
298 | char ch; |
299 | |
300 | if (!pm) { |
301 | dump_indent(level, file, "{}\n"); |
302 | return; |
303 | } |
304 | dump_indent(level, file, "{\n"); |
305 | level++; |
306 | if (pm->op_pmflags & PMf_ONCE) |
307 | ch = '?'; |
308 | else |
309 | ch = '/'; |
310 | if (pm->op_pmregexp) |
311 | dump_indent(level, file, "PMf_PRE %c%s%c%s\n", |
312 | ch, pm->op_pmregexp->precomp, ch, |
313 | (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : ""); |
314 | else |
315 | dump_indent(level, file, "PMf_PRE (RUNTIME)\n"); |
316 | if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) { |
317 | dump_indent(level, file, "PMf_REPL = "); |
318 | op_dump(pm->op_pmreplroot); |
319 | } |
320 | if (pm->op_pmflags || (pm->op_pmregexp && pm->op_pmregexp->check_substr)) { |
321 | SV *tmpsv = newSVpv("", 0); |
322 | if (pm->op_pmdynflags & PMdf_USED) |
323 | sv_catpv(tmpsv, ",USED"); |
324 | if (pm->op_pmdynflags & PMdf_TAINTED) |
325 | sv_catpv(tmpsv, ",TAINTED"); |
326 | if (pm->op_pmflags & PMf_ONCE) |
327 | sv_catpv(tmpsv, ",ONCE"); |
328 | if (pm->op_pmregexp && pm->op_pmregexp->check_substr |
329 | && !(pm->op_pmregexp->reganch & ROPT_NOSCAN)) |
330 | sv_catpv(tmpsv, ",SCANFIRST"); |
331 | if (pm->op_pmregexp && pm->op_pmregexp->check_substr |
332 | && pm->op_pmregexp->reganch & ROPT_CHECK_ALL) |
333 | sv_catpv(tmpsv, ",ALL"); |
334 | if (pm->op_pmflags & PMf_SKIPWHITE) |
335 | sv_catpv(tmpsv, ",SKIPWHITE"); |
336 | if (pm->op_pmflags & PMf_CONST) |
337 | sv_catpv(tmpsv, ",CONST"); |
338 | if (pm->op_pmflags & PMf_KEEP) |
339 | sv_catpv(tmpsv, ",KEEP"); |
340 | if (pm->op_pmflags & PMf_GLOBAL) |
341 | sv_catpv(tmpsv, ",GLOBAL"); |
342 | if (pm->op_pmflags & PMf_CONTINUE) |
343 | sv_catpv(tmpsv, ",CONTINUE"); |
344 | if (pm->op_pmflags & PMf_RETAINT) |
345 | sv_catpv(tmpsv, ",RETAINT"); |
346 | if (pm->op_pmflags & PMf_EVAL) |
347 | sv_catpv(tmpsv, ",EVAL"); |
348 | dump_indent(level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); |
349 | SvREFCNT_dec(tmpsv); |
350 | } |
351 | |
352 | dump_indent(level-1, file, "}\n"); |
353 | } |
354 | |
355 | void |
356 | pmop_dump(PMOP *pm) |
357 | { |
358 | do_pmop_dump(0, Perl_debug_log, pm); |
79072805 |
359 | } |
360 | |
361 | void |
3967c732 |
362 | do_op_dump(I32 level, PerlIO *file, OP *o) |
79072805 |
363 | { |
3967c732 |
364 | dTHR; |
2d8e6c8d |
365 | STRLEN n_a; |
3967c732 |
366 | dump_indent(level, file, "{\n"); |
367 | level++; |
11343788 |
368 | if (o->op_seq) |
3967c732 |
369 | PerlIO_printf(file, "%-4d", o->op_seq); |
93a17b20 |
370 | else |
3967c732 |
371 | PerlIO_printf(file, " "); |
372 | PerlIO_printf(file, "%*sTYPE = %s ===> ", PL_dumpindent*level-4, "", PL_op_name[o->op_type]); |
11343788 |
373 | if (o->op_next) { |
374 | if (o->op_seq) |
3967c732 |
375 | PerlIO_printf(file, "%d\n", o->op_next->op_seq); |
93a17b20 |
376 | else |
3967c732 |
377 | PerlIO_printf(file, "(%d)\n", o->op_next->op_seq); |
93a17b20 |
378 | } |
79072805 |
379 | else |
3967c732 |
380 | PerlIO_printf(file, "DONE\n"); |
11343788 |
381 | if (o->op_targ) { |
382 | if (o->op_type == OP_NULL) |
3967c732 |
383 | dump_indent(level, file, " (was %s)\n", PL_op_name[o->op_targ]); |
8990e307 |
384 | else |
3967c732 |
385 | dump_indent(level, file, "TARG = %d\n", o->op_targ); |
8990e307 |
386 | } |
748a9306 |
387 | #ifdef DUMPADDR |
3967c732 |
388 | dump_indent(level, file, "ADDR = 0x%lx => 0x%lx\n",o, o->op_next); |
79072805 |
389 | #endif |
11343788 |
390 | if (o->op_flags) { |
46fc3d4c |
391 | SV *tmpsv = newSVpv("", 0); |
5dc0d613 |
392 | switch (o->op_flags & OPf_WANT) { |
54310121 |
393 | case OPf_WANT_VOID: |
46fc3d4c |
394 | sv_catpv(tmpsv, ",VOID"); |
54310121 |
395 | break; |
396 | case OPf_WANT_SCALAR: |
46fc3d4c |
397 | sv_catpv(tmpsv, ",SCALAR"); |
54310121 |
398 | break; |
399 | case OPf_WANT_LIST: |
46fc3d4c |
400 | sv_catpv(tmpsv, ",LIST"); |
54310121 |
401 | break; |
402 | default: |
46fc3d4c |
403 | sv_catpv(tmpsv, ",UNKNOWN"); |
54310121 |
404 | break; |
405 | } |
11343788 |
406 | if (o->op_flags & OPf_KIDS) |
46fc3d4c |
407 | sv_catpv(tmpsv, ",KIDS"); |
11343788 |
408 | if (o->op_flags & OPf_PARENS) |
46fc3d4c |
409 | sv_catpv(tmpsv, ",PARENS"); |
11343788 |
410 | if (o->op_flags & OPf_STACKED) |
46fc3d4c |
411 | sv_catpv(tmpsv, ",STACKED"); |
11343788 |
412 | if (o->op_flags & OPf_REF) |
46fc3d4c |
413 | sv_catpv(tmpsv, ",REF"); |
11343788 |
414 | if (o->op_flags & OPf_MOD) |
46fc3d4c |
415 | sv_catpv(tmpsv, ",MOD"); |
11343788 |
416 | if (o->op_flags & OPf_SPECIAL) |
46fc3d4c |
417 | sv_catpv(tmpsv, ",SPECIAL"); |
3967c732 |
418 | dump_indent(level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); |
46fc3d4c |
419 | SvREFCNT_dec(tmpsv); |
79072805 |
420 | } |
11343788 |
421 | if (o->op_private) { |
46fc3d4c |
422 | SV *tmpsv = newSVpv("", 0); |
11343788 |
423 | if (o->op_type == OP_AASSIGN) { |
424 | if (o->op_private & OPpASSIGN_COMMON) |
46fc3d4c |
425 | sv_catpv(tmpsv, ",COMMON"); |
8d063cd8 |
426 | } |
11343788 |
427 | else if (o->op_type == OP_SASSIGN) { |
428 | if (o->op_private & OPpASSIGN_BACKWARDS) |
46fc3d4c |
429 | sv_catpv(tmpsv, ",BACKWARDS"); |
a0d0e21e |
430 | } |
11343788 |
431 | else if (o->op_type == OP_TRANS) { |
432 | if (o->op_private & OPpTRANS_SQUASH) |
46fc3d4c |
433 | sv_catpv(tmpsv, ",SQUASH"); |
11343788 |
434 | if (o->op_private & OPpTRANS_DELETE) |
46fc3d4c |
435 | sv_catpv(tmpsv, ",DELETE"); |
11343788 |
436 | if (o->op_private & OPpTRANS_COMPLEMENT) |
46fc3d4c |
437 | sv_catpv(tmpsv, ",COMPLEMENT"); |
8d063cd8 |
438 | } |
11343788 |
439 | else if (o->op_type == OP_REPEAT) { |
440 | if (o->op_private & OPpREPEAT_DOLIST) |
46fc3d4c |
441 | sv_catpv(tmpsv, ",DOLIST"); |
8d063cd8 |
442 | } |
11343788 |
443 | else if (o->op_type == OP_ENTERSUB || |
444 | o->op_type == OP_RV2SV || |
445 | o->op_type == OP_RV2AV || |
446 | o->op_type == OP_RV2HV || |
447 | o->op_type == OP_RV2GV || |
448 | o->op_type == OP_AELEM || |
449 | o->op_type == OP_HELEM ) |
85e6fe83 |
450 | { |
5dc0d613 |
451 | if (o->op_type == OP_ENTERSUB) { |
452 | if (o->op_private & OPpENTERSUB_AMPER) |
46fc3d4c |
453 | sv_catpv(tmpsv, ",AMPER"); |
5dc0d613 |
454 | if (o->op_private & OPpENTERSUB_DB) |
46fc3d4c |
455 | sv_catpv(tmpsv, ",DB"); |
68dc0745 |
456 | } |
5dc0d613 |
457 | switch (o->op_private & OPpDEREF) { |
5f05dabc |
458 | case OPpDEREF_SV: |
46fc3d4c |
459 | sv_catpv(tmpsv, ",SV"); |
5f05dabc |
460 | break; |
461 | case OPpDEREF_AV: |
46fc3d4c |
462 | sv_catpv(tmpsv, ",AV"); |
5f05dabc |
463 | break; |
464 | case OPpDEREF_HV: |
46fc3d4c |
465 | sv_catpv(tmpsv, ",HV"); |
5f05dabc |
466 | break; |
467 | } |
5dc0d613 |
468 | if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) { |
469 | if (o->op_private & OPpLVAL_DEFER) |
46fc3d4c |
470 | sv_catpv(tmpsv, ",LVAL_DEFER"); |
68dc0745 |
471 | } |
472 | else { |
5dc0d613 |
473 | if (o->op_private & HINT_STRICT_REFS) |
46fc3d4c |
474 | sv_catpv(tmpsv, ",STRICT_REFS"); |
68dc0745 |
475 | } |
8d063cd8 |
476 | } |
11343788 |
477 | else if (o->op_type == OP_CONST) { |
478 | if (o->op_private & OPpCONST_BARE) |
46fc3d4c |
479 | sv_catpv(tmpsv, ",BARE"); |
79072805 |
480 | } |
11343788 |
481 | else if (o->op_type == OP_FLIP) { |
482 | if (o->op_private & OPpFLIP_LINENUM) |
46fc3d4c |
483 | sv_catpv(tmpsv, ",LINENUM"); |
79072805 |
484 | } |
11343788 |
485 | else if (o->op_type == OP_FLOP) { |
486 | if (o->op_private & OPpFLIP_LINENUM) |
46fc3d4c |
487 | sv_catpv(tmpsv, ",LINENUM"); |
79072805 |
488 | } |
11343788 |
489 | if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO) |
46fc3d4c |
490 | sv_catpv(tmpsv, ",INTRO"); |
491 | if (SvCUR(tmpsv)) |
3967c732 |
492 | dump_indent(level, file, "PRIVATE = (%s)\n", SvPVX(tmpsv) + 1); |
46fc3d4c |
493 | SvREFCNT_dec(tmpsv); |
8d063cd8 |
494 | } |
8d063cd8 |
495 | |
11343788 |
496 | switch (o->op_type) { |
93a17b20 |
497 | case OP_GVSV: |
79072805 |
498 | case OP_GV: |
11343788 |
499 | if (cGVOPo->op_gv) { |
46fc3d4c |
500 | SV *tmpsv = NEWSV(0,0); |
8990e307 |
501 | ENTER; |
8990e307 |
502 | SAVEFREESV(tmpsv); |
5dc0d613 |
503 | gv_fullname3(tmpsv, cGVOPo->op_gv, Nullch); |
2d8e6c8d |
504 | dump_indent(level, file, "GV = %s\n", SvPV(tmpsv, n_a)); |
8990e307 |
505 | LEAVE; |
378cc40b |
506 | } |
79072805 |
507 | else |
3967c732 |
508 | dump_indent(level, file, "GV = NULL\n"); |
79072805 |
509 | break; |
510 | case OP_CONST: |
3967c732 |
511 | dump_indent(level, file, "SV = %s\n", SvPEEK(cSVOPo->op_sv)); |
79072805 |
512 | break; |
93a17b20 |
513 | case OP_NEXTSTATE: |
514 | case OP_DBSTATE: |
11343788 |
515 | if (cCOPo->cop_line) |
3967c732 |
516 | dump_indent(level, file, "LINE = %d\n",cCOPo->cop_line); |
11343788 |
517 | if (cCOPo->cop_label) |
3967c732 |
518 | dump_indent(level, file, "LABEL = \"%s\"\n",cCOPo->cop_label); |
79072805 |
519 | break; |
520 | case OP_ENTERLOOP: |
3967c732 |
521 | dump_indent(level, file, "REDO ===> "); |
11343788 |
522 | if (cLOOPo->op_redoop) |
3967c732 |
523 | PerlIO_printf(file, "%d\n", cLOOPo->op_redoop->op_seq); |
79072805 |
524 | else |
3967c732 |
525 | PerlIO_printf(file, "DONE\n"); |
526 | dump_indent(level, file, "NEXT ===> "); |
11343788 |
527 | if (cLOOPo->op_nextop) |
3967c732 |
528 | PerlIO_printf(file, "%d\n", cLOOPo->op_nextop->op_seq); |
79072805 |
529 | else |
3967c732 |
530 | PerlIO_printf(file, "DONE\n"); |
531 | dump_indent(level, file, "LAST ===> "); |
11343788 |
532 | if (cLOOPo->op_lastop) |
3967c732 |
533 | PerlIO_printf(file, "%d\n", cLOOPo->op_lastop->op_seq); |
79072805 |
534 | else |
3967c732 |
535 | PerlIO_printf(file, "DONE\n"); |
79072805 |
536 | break; |
537 | case OP_COND_EXPR: |
3967c732 |
538 | dump_indent(level, file, "TRUE ===> "); |
11343788 |
539 | if (cCONDOPo->op_true) |
3967c732 |
540 | PerlIO_printf(file, "%d\n", cCONDOPo->op_true->op_seq); |
79072805 |
541 | else |
3967c732 |
542 | PerlIO_printf(file, "DONE\n"); |
543 | dump_indent(level, file, "FALSE ===> "); |
11343788 |
544 | if (cCONDOPo->op_false) |
3967c732 |
545 | PerlIO_printf(file, "%d\n", cCONDOPo->op_false->op_seq); |
79072805 |
546 | else |
3967c732 |
547 | PerlIO_printf(file, "DONE\n"); |
79072805 |
548 | break; |
a0d0e21e |
549 | case OP_MAPWHILE: |
79072805 |
550 | case OP_GREPWHILE: |
551 | case OP_OR: |
552 | case OP_AND: |
3967c732 |
553 | dump_indent(level, file, "OTHER ===> "); |
11343788 |
554 | if (cLOGOPo->op_other) |
3967c732 |
555 | PerlIO_printf(file, "%d\n", cLOGOPo->op_other->op_seq); |
79072805 |
556 | else |
3967c732 |
557 | PerlIO_printf(file, "DONE\n"); |
79072805 |
558 | break; |
559 | case OP_PUSHRE: |
560 | case OP_MATCH: |
8782bef2 |
561 | case OP_QR: |
79072805 |
562 | case OP_SUBST: |
3967c732 |
563 | do_pmop_dump(level, file, cPMOPo); |
79072805 |
564 | break; |
a0d0e21e |
565 | default: |
566 | break; |
79072805 |
567 | } |
11343788 |
568 | if (o->op_flags & OPf_KIDS) { |
79072805 |
569 | OP *kid; |
11343788 |
570 | for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) |
3967c732 |
571 | do_op_dump(level, file, kid); |
8d063cd8 |
572 | } |
3967c732 |
573 | dump_indent(level-1, file, "}\n"); |
574 | } |
575 | |
576 | void |
577 | op_dump(OP *o) |
578 | { |
579 | do_op_dump(0, Perl_debug_log, o); |
8d063cd8 |
580 | } |
581 | |
8adcabd8 |
582 | void |
3967c732 |
583 | gv_dump(GV *gv) |
378cc40b |
584 | { |
79072805 |
585 | SV *sv; |
378cc40b |
586 | |
79072805 |
587 | if (!gv) { |
760ac839 |
588 | PerlIO_printf(Perl_debug_log, "{}\n"); |
378cc40b |
589 | return; |
590 | } |
8990e307 |
591 | sv = sv_newmortal(); |
760ac839 |
592 | PerlIO_printf(Perl_debug_log, "{\n"); |
f6aff53a |
593 | gv_fullname3(sv, gv, Nullch); |
3967c732 |
594 | dump_indent(1, Perl_debug_log, "GV_NAME = %s", SvPVX(sv)); |
79072805 |
595 | if (gv != GvEGV(gv)) { |
f6aff53a |
596 | gv_efullname3(sv, GvEGV(gv), Nullch); |
3967c732 |
597 | dump_indent(1, Perl_debug_log, "-> %s", SvPVX(sv)); |
8adcabd8 |
598 | } |
3967c732 |
599 | PerlIO_putc(Perl_debug_log, '\n'); |
600 | dump_indent(0, Perl_debug_log, "}\n"); |
8d063cd8 |
601 | } |
602 | |
8adcabd8 |
603 | void |
3967c732 |
604 | do_magic_dump(I32 level, PerlIO *file, MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim) |
8d063cd8 |
605 | { |
3967c732 |
606 | for (; mg; mg = mg->mg_moremagic) { |
607 | dump_indent(level, file, " MAGIC = 0x%lx\n", (long)mg); |
608 | if (mg->mg_virtual) { |
609 | MGVTBL *v = mg->mg_virtual; |
610 | char *s = 0; |
611 | if (v == &PL_vtbl_sv) s = "sv"; |
612 | else if (v == &PL_vtbl_env) s = "env"; |
613 | else if (v == &PL_vtbl_envelem) s = "envelem"; |
614 | else if (v == &PL_vtbl_sig) s = "sig"; |
615 | else if (v == &PL_vtbl_sigelem) s = "sigelem"; |
616 | else if (v == &PL_vtbl_pack) s = "pack"; |
617 | else if (v == &PL_vtbl_packelem) s = "packelem"; |
618 | else if (v == &PL_vtbl_dbline) s = "dbline"; |
619 | else if (v == &PL_vtbl_isa) s = "isa"; |
620 | else if (v == &PL_vtbl_arylen) s = "arylen"; |
621 | else if (v == &PL_vtbl_glob) s = "glob"; |
622 | else if (v == &PL_vtbl_mglob) s = "mglob"; |
623 | else if (v == &PL_vtbl_nkeys) s = "nkeys"; |
624 | else if (v == &PL_vtbl_taint) s = "taint"; |
625 | else if (v == &PL_vtbl_substr) s = "substr"; |
626 | else if (v == &PL_vtbl_vec) s = "vec"; |
627 | else if (v == &PL_vtbl_pos) s = "pos"; |
628 | else if (v == &PL_vtbl_bm) s = "bm"; |
629 | else if (v == &PL_vtbl_fm) s = "fm"; |
630 | else if (v == &PL_vtbl_uvar) s = "uvar"; |
631 | else if (v == &PL_vtbl_defelem) s = "defelem"; |
632 | #ifdef USE_LOCALE_COLLATE |
633 | else if (v == &PL_vtbl_collxfrm) s = "collxfrm"; |
634 | #endif |
635 | #ifdef OVERLOAD |
636 | else if (v == &PL_vtbl_amagic) s = "amagic"; |
637 | else if (v == &PL_vtbl_amagicelem) s = "amagicelem"; |
638 | #endif |
639 | if (s) |
640 | dump_indent(level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", s); |
641 | else |
642 | dump_indent(level, file, " MG_VIRTUAL = 0x%lx\n", (long)v); |
643 | } |
644 | else |
645 | dump_indent(level, file, " MG_VIRTUAL = 0\n"); |
8d063cd8 |
646 | |
3967c732 |
647 | if (mg->mg_private) |
648 | dump_indent(level, file, " MG_PRIVATE = %d\n", mg->mg_private); |
649 | |
650 | if (isPRINT(mg->mg_type)) |
651 | dump_indent(level, file, " MG_TYPE = '%c'\n", mg->mg_type); |
652 | else |
653 | dump_indent(level, file, " MG_TYPE = '\\%o'\n", mg->mg_type); |
654 | |
655 | if (mg->mg_flags) { |
656 | dump_indent(level, file, " MG_FLAGS = 0x%02X\n", mg->mg_flags); |
657 | if (mg->mg_flags & MGf_TAINTEDDIR) |
658 | dump_indent(level, file, " TAINTEDDIR\n"); |
659 | if (mg->mg_flags & MGf_REFCOUNTED) |
660 | dump_indent(level, file, " REFCOUNTED\n"); |
661 | if (mg->mg_flags & MGf_GSKIP) |
662 | dump_indent(level, file, " GSKIP\n"); |
663 | if (mg->mg_flags & MGf_MINMATCH) |
664 | dump_indent(level, file, " MINMATCH\n"); |
665 | } |
666 | if (mg->mg_obj) { |
667 | dump_indent(level, file, " MG_OBJ = 0x%lx\n", (long)mg->mg_obj); |
668 | if (mg->mg_flags & MGf_REFCOUNTED) |
669 | do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */ |
670 | } |
671 | if (mg->mg_len) |
672 | dump_indent(level, file, " MG_LEN = %d\n", mg->mg_len); |
673 | if (mg->mg_ptr) { |
674 | dump_indent(level, file, " MG_PTR = 0x%lx", (long)mg->mg_ptr); |
675 | if (mg->mg_len >= 0) { |
676 | SV *sv = newSVpv("", 0); |
677 | PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim)); |
678 | SvREFCNT_dec(sv); |
679 | } |
680 | else if (mg->mg_len == HEf_SVKEY) { |
681 | PerlIO_puts(file, " => HEf_SVKEY\n"); |
682 | do_sv_dump(level+2, file, (SV*)((mg)->mg_ptr), nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */ |
683 | continue; |
684 | } |
685 | else |
686 | PerlIO_puts(file, " ???? - please notify IZ"); |
687 | PerlIO_putc(file, '\n'); |
688 | } |
378cc40b |
689 | } |
3967c732 |
690 | } |
691 | |
692 | void |
693 | magic_dump(MAGIC *mg) |
694 | { |
695 | do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0); |
696 | } |
697 | |
698 | void |
699 | do_hv_dump(I32 level, PerlIO *file, char *name, HV *sv) |
700 | { |
701 | dump_indent(level, file, "%s = 0x%lx", name, (long)sv); |
702 | if (sv && HvNAME(sv)) |
703 | PerlIO_printf(file, "\t\"%s\"\n", HvNAME(sv)); |
79072805 |
704 | else |
3967c732 |
705 | PerlIO_putc(file, '\n'); |
706 | } |
707 | |
708 | void |
709 | do_gv_dump(I32 level, PerlIO *file, char *name, GV *sv) |
710 | { |
711 | dump_indent(level, file, "%s = 0x%lx", name, (long)sv); |
712 | if (sv && GvNAME(sv)) |
713 | PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv)); |
c90c0ff4 |
714 | else |
3967c732 |
715 | PerlIO_putc(file, '\n'); |
716 | } |
717 | |
718 | void |
719 | do_gvgv_dump(I32 level, PerlIO *file, char *name, GV *sv) |
720 | { |
721 | dump_indent(level, file, "%s = 0x%lx", name, (long)sv); |
722 | if (sv && GvNAME(sv)) { |
723 | PerlIO_printf(file, "\t\""); |
724 | if (GvSTASH(sv) && HvNAME(GvSTASH(sv))) |
725 | PerlIO_printf(file, "%s\" :: \"", HvNAME(GvSTASH(sv))); |
726 | PerlIO_printf(file, "%s\"\n", GvNAME(sv)); |
8d063cd8 |
727 | } |
3967c732 |
728 | else |
729 | PerlIO_putc(file, '\n'); |
730 | } |
731 | |
732 | void |
733 | do_sv_dump(I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim) |
734 | { |
735 | dTHR; |
736 | SV *d = sv_newmortal(); |
737 | char *s; |
738 | U32 flags; |
739 | U32 type; |
2d8e6c8d |
740 | STRLEN n_a; |
3967c732 |
741 | |
742 | if (!sv) { |
743 | dump_indent(level, file, "SV = 0\n"); |
744 | return; |
378cc40b |
745 | } |
3967c732 |
746 | |
747 | flags = SvFLAGS(sv); |
748 | type = SvTYPE(sv); |
79072805 |
749 | |
3967c732 |
750 | sv_setpvf(d, "(0x%lx) at 0x%lx\n%*s REFCNT = %ld\n%*s FLAGS = (", |
751 | (unsigned long)SvANY(sv), (unsigned long)sv, |
752 | PL_dumpindent*level, "", (long)SvREFCNT(sv), |
753 | PL_dumpindent*level, ""); |
8d063cd8 |
754 | |
3967c732 |
755 | if (flags & SVs_PADBUSY) sv_catpv(d, "PADBUSY,"); |
756 | if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,"); |
757 | if (flags & SVs_PADMY) sv_catpv(d, "PADMY,"); |
758 | if (flags & SVs_TEMP) sv_catpv(d, "TEMP,"); |
759 | if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,"); |
760 | if (flags & SVs_GMG) sv_catpv(d, "GMG,"); |
761 | if (flags & SVs_SMG) sv_catpv(d, "SMG,"); |
762 | if (flags & SVs_RMG) sv_catpv(d, "RMG,"); |
4db58590 |
763 | |
3967c732 |
764 | if (flags & SVf_IOK) sv_catpv(d, "IOK,"); |
765 | if (flags & SVf_NOK) sv_catpv(d, "NOK,"); |
766 | if (flags & SVf_POK) sv_catpv(d, "POK,"); |
767 | if (flags & SVf_ROK) sv_catpv(d, "ROK,"); |
768 | if (flags & SVf_OOK) sv_catpv(d, "OOK,"); |
769 | if (flags & SVf_FAKE) sv_catpv(d, "FAKE,"); |
770 | if (flags & SVf_READONLY) sv_catpv(d, "READONLY,"); |
4db58590 |
771 | |
3967c732 |
772 | #ifdef OVERLOAD |
773 | if (flags & SVf_AMAGIC) sv_catpv(d, "OVERLOAD,"); |
774 | #endif /* OVERLOAD */ |
775 | if (flags & SVp_IOK) sv_catpv(d, "pIOK,"); |
776 | if (flags & SVp_NOK) sv_catpv(d, "pNOK,"); |
777 | if (flags & SVp_POK) sv_catpv(d, "pPOK,"); |
778 | if (flags & SVp_SCREAM) sv_catpv(d, "SCREAM,"); |
779 | |
780 | switch (type) { |
781 | case SVt_PVCV: |
782 | case SVt_PVFM: |
783 | if (CvANON(sv)) sv_catpv(d, "ANON,"); |
784 | if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,"); |
785 | if (CvCLONE(sv)) sv_catpv(d, "CLONE,"); |
786 | if (CvCLONED(sv)) sv_catpv(d, "CLONED,"); |
787 | if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,"); |
788 | break; |
789 | case SVt_PVHV: |
790 | if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,"); |
791 | if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,"); |
792 | break; |
793 | case SVt_PVGV: |
794 | if (GvINTRO(sv)) sv_catpv(d, "INTRO,"); |
795 | if (GvMULTI(sv)) sv_catpv(d, "MULTI,"); |
796 | if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,"); |
797 | if (GvIMPORTED(sv)) { |
798 | sv_catpv(d, "IMPORT"); |
799 | if (GvIMPORTED(sv) == GVf_IMPORTED) |
800 | sv_catpv(d, "ALL,"); |
801 | else { |
802 | sv_catpv(d, "("); |
803 | if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV"); |
804 | if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV"); |
805 | if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV"); |
806 | if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV"); |
807 | sv_catpv(d, " ),"); |
808 | } |
809 | } |
810 | case SVt_PVBM: |
811 | if (SvTAIL(sv)) sv_catpv(d, "TAIL,"); |
812 | if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,"); |
813 | break; |
814 | } |
815 | |
816 | if (*(SvEND(d) - 1) == ',') |
817 | SvPVX(d)[--SvCUR(d)] = '\0'; |
818 | sv_catpv(d, ")"); |
819 | s = SvPVX(d); |
820 | |
821 | dump_indent(level, file, "SV = "); |
822 | switch (type) { |
823 | case SVt_NULL: |
824 | PerlIO_printf(file, "NULL%s\n", s); |
825 | return; |
826 | case SVt_IV: |
827 | PerlIO_printf(file, "IV%s\n", s); |
828 | break; |
829 | case SVt_NV: |
830 | PerlIO_printf(file, "NV%s\n", s); |
831 | break; |
832 | case SVt_RV: |
833 | PerlIO_printf(file, "RV%s\n", s); |
834 | break; |
835 | case SVt_PV: |
836 | PerlIO_printf(file, "PV%s\n", s); |
837 | break; |
838 | case SVt_PVIV: |
839 | PerlIO_printf(file, "PVIV%s\n", s); |
840 | break; |
841 | case SVt_PVNV: |
842 | PerlIO_printf(file, "PVNV%s\n", s); |
843 | break; |
844 | case SVt_PVBM: |
845 | PerlIO_printf(file, "PVBM%s\n", s); |
846 | break; |
847 | case SVt_PVMG: |
848 | PerlIO_printf(file, "PVMG%s\n", s); |
849 | break; |
850 | case SVt_PVLV: |
851 | PerlIO_printf(file, "PVLV%s\n", s); |
852 | break; |
853 | case SVt_PVAV: |
854 | PerlIO_printf(file, "PVAV%s\n", s); |
855 | break; |
856 | case SVt_PVHV: |
857 | PerlIO_printf(file, "PVHV%s\n", s); |
858 | break; |
859 | case SVt_PVCV: |
860 | PerlIO_printf(file, "PVCV%s\n", s); |
861 | break; |
862 | case SVt_PVGV: |
863 | PerlIO_printf(file, "PVGV%s\n", s); |
864 | break; |
865 | case SVt_PVFM: |
866 | PerlIO_printf(file, "PVFM%s\n", s); |
867 | break; |
868 | case SVt_PVIO: |
869 | PerlIO_printf(file, "PVIO%s\n", s); |
870 | break; |
871 | default: |
872 | PerlIO_printf(file, "UNKNOWN(0x%x) %s\n", type, s); |
873 | return; |
874 | } |
875 | if (type >= SVt_PVIV || type == SVt_IV) { |
876 | dump_indent(level, file, " IV = %ld", (long)SvIVX(sv)); |
877 | if (SvOOK(sv)) |
878 | PerlIO_printf(file, " (OFFSET)"); |
879 | PerlIO_putc(file, '\n'); |
880 | } |
881 | if (type >= SVt_PVNV || type == SVt_NV) { |
882 | SET_NUMERIC_STANDARD(); |
883 | dump_indent(level, file, " NV = %.*g\n", DBL_DIG, SvNVX(sv)); |
884 | } |
885 | if (SvROK(sv)) { |
886 | dump_indent(level, file, " RV = 0x%lx\n", (long)SvRV(sv)); |
887 | if (nest < maxnest) |
888 | do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim); |
889 | return; |
890 | } |
891 | if (type < SVt_PV) |
892 | return; |
893 | if (type <= SVt_PVLV) { |
894 | if (SvPVX(sv)) { |
895 | dump_indent(level, file," PV = 0x%lx ", (long)SvPVX(sv)); |
896 | if (SvOOK(sv)) |
897 | PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim)); |
898 | PerlIO_printf(file, "%s\n", pv_display(d, SvPVX(sv), SvCUR(sv), SvLEN(sv), pvlim)); |
899 | dump_indent(level, file, " CUR = 0\n", (long)SvCUR(sv)); |
900 | dump_indent(level, file, " LEN = 0\n", (long)SvLEN(sv)); |
901 | } |
902 | else |
903 | dump_indent(level, file, " PV = 0\n"); |
904 | } |
905 | if (type >= SVt_PVMG) { |
906 | if (SvMAGIC(sv)) |
907 | do_magic_dump(level, file, SvMAGIC(sv), nest, maxnest, dumpops, pvlim); |
908 | if (SvSTASH(sv)) |
909 | do_hv_dump(level, file, " STASH", SvSTASH(sv)); |
910 | } |
911 | switch (type) { |
912 | case SVt_PVLV: |
913 | dump_indent(level, file, " TYPE = %c\n", LvTYPE(sv)); |
914 | dump_indent(level, file, " TARGOFF = %ld\n", (long)LvTARGOFF(sv)); |
915 | dump_indent(level, file, " TARGLEN = %ld\n", (long)LvTARGLEN(sv)); |
916 | dump_indent(level, file, " TARG = 0x%lx\n", (long)LvTARG(sv)); |
917 | /* XXX level+1 ??? */ |
918 | do_sv_dump(level, file, LvTARG(sv), nest+1, maxnest, dumpops, pvlim); |
919 | break; |
920 | case SVt_PVAV: |
921 | dump_indent(level, file, " ARRAY = 0x%lx", (long)AvARRAY(sv)); |
922 | if (AvARRAY(sv) != AvALLOC(sv)) { |
923 | PerlIO_printf(file, " (offset=%d)\n", (AvARRAY(sv) - AvALLOC(sv))); |
924 | dump_indent(level, file, " ALLOC = 0x%lx\n", (long)AvALLOC(sv)); |
925 | } |
926 | else |
927 | PerlIO_putc(file, '\n'); |
928 | dump_indent(level, file, " FILL = %ld\n", (long)AvFILLp(sv)); |
929 | dump_indent(level, file, " MAX = %ld\n", (long)AvMAX(sv)); |
930 | dump_indent(level, file, " ARYLEN = 0x%lx\n", (long)AvARYLEN(sv)); |
931 | flags = AvFLAGS(sv); |
932 | sv_setpv(d, ""); |
933 | if (flags & AVf_REAL) sv_catpv(d, ",REAL"); |
934 | if (flags & AVf_REIFY) sv_catpv(d, ",REIFY"); |
935 | if (flags & AVf_REUSED) sv_catpv(d, ",REUSED"); |
936 | dump_indent(level, file, " FLAGS = (%s)\n", SvCUR(d) ? SvPVX(d) + 1 : ""); |
937 | if (nest < maxnest && av_len((AV*)sv) >= 0) { |
938 | int count; |
939 | for (count = 0; count <= av_len((AV*)sv) && count < maxnest; count++) { |
940 | SV** elt = av_fetch((AV*)sv,count,0); |
941 | |
942 | dump_indent(level + 1, file, "Elt No. %ld\n", (long)count); |
943 | if (elt) |
944 | do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim); |
945 | } |
946 | } |
947 | break; |
948 | case SVt_PVHV: |
949 | dump_indent(level, file, " ARRAY = 0x%lx",(long)HvARRAY(sv)); |
950 | if (HvARRAY(sv) && HvKEYS(sv)) { |
951 | /* Show distribution of HEs in the ARRAY */ |
952 | int freq[200]; |
953 | #define FREQ_MAX (sizeof freq / sizeof freq[0] - 1) |
954 | int i; |
955 | int max = 0; |
956 | U32 pow2 = 2, keys = HvKEYS(sv); |
957 | double theoret, sum = 0; |
958 | |
959 | PerlIO_printf(file, " ("); |
960 | Zero(freq, FREQ_MAX + 1, int); |
961 | for (i = 0; i <= HvMAX(sv); i++) { |
962 | HE* h; int count = 0; |
963 | for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h)) |
964 | count++; |
965 | if (count > FREQ_MAX) |
966 | count = FREQ_MAX; |
967 | freq[count]++; |
968 | if (max < count) |
969 | max = count; |
970 | } |
971 | for (i = 0; i <= max; i++) { |
972 | if (freq[i]) { |
973 | PerlIO_printf(file, "%d%s:%d", i, |
974 | (i == FREQ_MAX) ? "+" : "", |
975 | freq[i]); |
976 | if (i != max) |
977 | PerlIO_printf(file, ", "); |
978 | } |
979 | } |
980 | PerlIO_putc(file, ')'); |
981 | /* Now calculate quality wrt theoretical value */ |
982 | for (i = max; i > 0; i--) { /* Precision: count down. */ |
983 | sum += freq[i] * i * i; |
984 | } |
985 | while (keys = keys >> 1) |
986 | pow2 = pow2 << 1; |
987 | /* Approximate by Poisson distribution */ |
988 | theoret = HvKEYS(sv); |
989 | theoret += theoret * theoret/pow2; |
990 | PerlIO_putc(file, '\n'); |
991 | dump_indent(level, file, " hash quality = %.1f%%", theoret/sum*100); |
992 | } |
993 | PerlIO_putc(file, '\n'); |
994 | dump_indent(level, file, " KEYS = %ld\n", (long)HvKEYS(sv)); |
995 | dump_indent(level, file, " FILL = %ld\n", (long)HvFILL(sv)); |
996 | dump_indent(level, file, " MAX = %ld\n", (long)HvMAX(sv)); |
997 | dump_indent(level, file, " RITER = %ld\n", (long)HvRITER(sv)); |
998 | dump_indent(level, file, " EITER = 0x%lx\n",(long) HvEITER(sv)); |
999 | if (HvPMROOT(sv)) |
1000 | dump_indent(level, file, " PMROOT = 0x%lx\n",(long)HvPMROOT(sv)); |
1001 | if (HvNAME(sv)) |
1002 | dump_indent(level, file, " NAME = \"%s\"\n", HvNAME(sv)); |
1003 | if (nest < maxnest && !HvEITER(sv)) { /* Try to preserve iterator */ |
1004 | HE *he; |
1005 | HV *hv = (HV*)sv; |
1006 | int count = maxnest - nest; |
1007 | |
1008 | hv_iterinit(hv); |
1009 | while ((he = hv_iternext(hv)) && count--) { |
1010 | SV *elt; |
1011 | char *key; |
1012 | I32 len; |
1013 | U32 hash = HeHASH(he); |
1014 | |
1015 | key = hv_iterkey(he, &len); |
1016 | elt = hv_iterval(hv, he); |
1017 | dump_indent(level+1, file, "Elt %s HASH = 0x%lx\n", pv_display(d, key, len, 0, pvlim), hash); |
1018 | do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim); |
1019 | } |
1020 | hv_iterinit(hv); /* Return to status quo */ |
1021 | } |
1022 | break; |
1023 | case SVt_PVCV: |
1024 | if (SvPOK(sv)) |
2d8e6c8d |
1025 | dump_indent(level, file, " PROTOTYPE = \"%s\"\n", SvPV(sv,n_a)); |
3967c732 |
1026 | /* FALL THROUGH */ |
1027 | case SVt_PVFM: |
1028 | do_hv_dump(level, file, " COMP_STASH", CvSTASH(sv)); |
1029 | if (CvSTART(sv)) |
1030 | dump_indent(level, file, " START = 0x%lx ===> %d\n", (long)CvSTART(sv), CvSTART(sv)->op_seq); |
1031 | dump_indent(level, file, " ROOT = 0x%lx\n", (long)CvROOT(sv)); |
1032 | if (CvROOT(sv) && dumpops) |
1033 | do_op_dump(level+1, file, CvROOT(sv)); |
1034 | dump_indent (level, file, " XSUB = 0x%lx\n", (long)CvXSUB(sv)); |
1035 | dump_indent (level, file, " XSUBANY = %ld\n", (long)CvXSUBANY(sv).any_i32); |
1036 | do_gvgv_dump(level, file, " GVGV::GV", CvGV(sv)); |
1037 | do_gv_dump (level, file, " FILEGV", CvFILEGV(sv)); |
1038 | dump_indent (level, file, " DEPTH = %ld\n", (long)CvDEPTH(sv)); |
1039 | #ifdef USE_THREADS |
1040 | dump_indent (level, file, " MUTEXP = 0x%lx\n", (long)CvMUTEXP(sv)); |
1041 | dump_indent (level, file, " OWNER = 0x%lx\n", (long)CvOWNER(sv)); |
1042 | #endif /* USE_THREADS */ |
1043 | dump_indent (level, file, " FLAGS = 0x%lx\n", (unsigned long)CvFLAGS(sv)); |
1044 | if (type == SVt_PVFM) |
1045 | dump_indent(level, file, " LINES = %ld\n", (long)FmLINES(sv)); |
1046 | dump_indent(level, file, " PADLIST = 0x%lx\n", (long)CvPADLIST(sv)); |
1047 | if (nest < maxnest && CvPADLIST(sv)) { |
1048 | AV* padlist = CvPADLIST(sv); |
1049 | AV* pad_name = (AV*)*av_fetch(padlist, 0, FALSE); |
1050 | AV* pad = (AV*)*av_fetch(padlist, 1, FALSE); |
1051 | SV** pname = AvARRAY(pad_name); |
1052 | SV** ppad = AvARRAY(pad); |
1053 | I32 ix; |
1054 | |
1055 | for (ix = 1; ix <= AvFILL(pad_name); ix++) { |
1056 | if (SvPOK(pname[ix])) |
1057 | dump_indent(level, /* %5d below is enough whitespace. */ |
1058 | file, |
1059 | "%5d. 0x%lx (%s\"%s\" %ld-%ld)\n", |
1060 | ix, ppad[ix], |
1061 | SvFAKE(pname[ix]) ? "FAKE " : "", |
1062 | SvPVX(pname[ix]), |
1063 | (long)I_32(SvNVX(pname[ix])), |
1064 | (long)SvIVX(pname[ix])); |
1065 | } |
1066 | } |
1067 | { |
1068 | CV *outside = CvOUTSIDE(sv); |
1069 | dump_indent(level, file, " OUTSIDE = 0x%lx (%s)\n", |
1070 | (long)outside, |
1071 | (!outside ? "null" |
1072 | : CvANON(outside) ? "ANON" |
1073 | : (outside == PL_main_cv) ? "MAIN" |
1074 | : CvUNIQUE(outside) ? "UNIQUE" |
1075 | : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED")); |
1076 | } |
1077 | if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv))) |
1078 | do_sv_dump(level+1, file, (SV*)CvOUTSIDE(sv), nest+1, maxnest, dumpops, pvlim); |
1079 | break; |
1080 | case SVt_PVGV: |
1081 | dump_indent(level, file, " NAME = \"%s\"\n", GvNAME(sv)); |
1082 | dump_indent(level, file, " NAMELEN = %ld\n", (long)GvNAMELEN(sv)); |
1083 | do_hv_dump (level, file, " GvSTASH", GvSTASH(sv)); |
1084 | dump_indent(level, file, " GP = 0x%lx\n", (long)GvGP(sv)); |
1085 | dump_indent(level, file, " SV = 0x%lx\n", (long)GvSV(sv)); |
1086 | dump_indent(level, file, " REFCNT = %ld\n", (long)GvREFCNT(sv)); |
1087 | dump_indent(level, file, " IO = 0x%lx\n", (long)GvIOp(sv)); |
1088 | dump_indent(level, file, " FORM = 0x%lx\n", (long)GvFORM(sv)); |
1089 | dump_indent(level, file, " AV = 0x%lx\n", (long)GvAV(sv)); |
1090 | dump_indent(level, file, " HV = 0x%lx\n", (long)GvHV(sv)); |
1091 | dump_indent(level, file, " CV = 0x%lx\n", (long)GvCV(sv)); |
1092 | dump_indent(level, file, " CVGEN = 0x%lx\n", (long)GvCVGEN(sv)); |
1093 | dump_indent(level, file, " LASTEXPR = %ld\n", (long)GvLASTEXPR(sv)); |
1094 | dump_indent(level, file, " LINE = %ld\n", (long)GvLINE(sv)); |
1095 | dump_indent(level, file, " FLAGS = 0x%x\n", (int)GvFLAGS(sv)); |
1096 | do_gv_dump (level, file, " FILEGV", GvFILEGV(sv)); |
1097 | do_gv_dump (level, file, " EGV", GvEGV(sv)); |
1098 | break; |
1099 | case SVt_PVIO: |
1100 | dump_indent(level, file, " IFP = 0x%lx\n", (long)IoIFP(sv)); |
1101 | dump_indent(level, file, " OFP = 0x%lx\n", (long)IoOFP(sv)); |
1102 | dump_indent(level, file, " DIRP = 0x%lx\n", (long)IoDIRP(sv)); |
1103 | dump_indent(level, file, " LINES = %ld\n", (long)IoLINES(sv)); |
1104 | dump_indent(level, file, " PAGE = %ld\n", (long)IoPAGE(sv)); |
1105 | dump_indent(level, file, " PAGE_LEN = %ld\n", (long)IoPAGE_LEN(sv)); |
1106 | dump_indent(level, file, " LINES_LEFT = %ld\n", (long)IoLINES_LEFT(sv)); |
1107 | dump_indent(level, file, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv)); |
1108 | do_gv_dump (level, file, " TOP_GV", IoTOP_GV(sv)); |
1109 | dump_indent(level, file, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv)); |
1110 | do_gv_dump (level, file, " FMT_GV", IoFMT_GV(sv)); |
1111 | dump_indent(level, file, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv)); |
1112 | do_gv_dump (level, file, " BOTTOM_GV", IoBOTTOM_GV(sv)); |
1113 | dump_indent(level, file, " SUBPROCESS = %ld\n", (long)IoSUBPROCESS(sv)); |
1114 | dump_indent(level, file, " TYPE = %c\n", IoTYPE(sv)); |
1115 | dump_indent(level, file, " FLAGS = 0x%lx\n", (long)IoFLAGS(sv)); |
1116 | break; |
1117 | } |
1118 | } |
1119 | |
1120 | void |
1121 | sv_dump(SV *sv) |
1122 | { |
1123 | do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0); |
8d063cd8 |
1124 | } |