Commit | Line | Data |
a0d0e21e |
1 | /* dump.c |
a687059c |
2 | * |
be3c0a43 |
3 | * Copyright (c) 1991-2002, 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" |
864dbfa3 |
16 | #define PERL_IN_DUMP_C |
8d063cd8 |
17 | #include "perl.h" |
f722798b |
18 | #include "regcomp.h" |
8d063cd8 |
19 | |
3967c732 |
20 | void |
864dbfa3 |
21 | Perl_dump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...) |
3967c732 |
22 | { |
3967c732 |
23 | va_list args; |
3967c732 |
24 | va_start(args, pat); |
c5be433b |
25 | dump_vindent(level, file, pat, &args); |
3967c732 |
26 | va_end(args); |
27 | } |
8adcabd8 |
28 | |
29 | void |
c5be433b |
30 | Perl_dump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args) |
31 | { |
c8db6e60 |
32 | PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), ""); |
c5be433b |
33 | PerlIO_vprintf(file, pat, *args); |
34 | } |
35 | |
36 | void |
864dbfa3 |
37 | Perl_dump_all(pTHX) |
79072805 |
38 | { |
760ac839 |
39 | PerlIO_setlinebuf(Perl_debug_log); |
3280af22 |
40 | if (PL_main_root) |
3967c732 |
41 | op_dump(PL_main_root); |
3280af22 |
42 | dump_packsubs(PL_defstash); |
463ee0b2 |
43 | } |
44 | |
45 | void |
864dbfa3 |
46 | Perl_dump_packsubs(pTHX_ HV *stash) |
463ee0b2 |
47 | { |
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); |
6676db26 |
63 | if (HeKEY(entry)[HeKLEN(entry)-1] == ':' |
64 | && (hv = GvHV(gv)) && hv != PL_defstash) |
463ee0b2 |
65 | dump_packsubs(hv); /* nested package */ |
66 | } |
79072805 |
67 | } |
68 | } |
69 | |
70 | void |
864dbfa3 |
71 | Perl_dump_sub(pTHX_ GV *gv) |
a687059c |
72 | { |
8990e307 |
73 | SV *sv = sv_newmortal(); |
85e6fe83 |
74 | |
f6aff53a |
75 | gv_fullname3(sv, gv, Nullch); |
35c1215d |
76 | Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %"SVf" = ", sv); |
a0d0e21e |
77 | if (CvXSUB(GvCV(gv))) |
91f3b821 |
78 | Perl_dump_indent(aTHX_ 0, Perl_debug_log, "(xsub 0x%"UVxf" %d)\n", |
79 | PTR2UV(CvXSUB(GvCV(gv))), |
894356b3 |
80 | (int)CvXSUBANY(GvCV(gv)).any_i32); |
85e6fe83 |
81 | else if (CvROOT(GvCV(gv))) |
3967c732 |
82 | op_dump(CvROOT(GvCV(gv))); |
85e6fe83 |
83 | else |
cea2e8a9 |
84 | Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n"); |
85e6fe83 |
85 | } |
86 | |
87 | void |
864dbfa3 |
88 | Perl_dump_form(pTHX_ GV *gv) |
85e6fe83 |
89 | { |
90 | SV *sv = sv_newmortal(); |
91 | |
f6aff53a |
92 | gv_fullname3(sv, gv, Nullch); |
35c1215d |
93 | Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nFORMAT %"SVf" = ", sv); |
85e6fe83 |
94 | if (CvROOT(GvFORM(gv))) |
3967c732 |
95 | op_dump(CvROOT(GvFORM(gv))); |
85e6fe83 |
96 | else |
cea2e8a9 |
97 | Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n"); |
a687059c |
98 | } |
99 | |
8adcabd8 |
100 | void |
864dbfa3 |
101 | Perl_dump_eval(pTHX) |
8d063cd8 |
102 | { |
3967c732 |
103 | op_dump(PL_eval_root); |
104 | } |
105 | |
106 | char * |
e6abe6d8 |
107 | Perl_pv_display(pTHX_ SV *dsv, char *pv, STRLEN cur, STRLEN len, STRLEN pvlim) |
3967c732 |
108 | { |
109 | int truncated = 0; |
110 | int nul_terminated = len > cur && pv[cur] == '\0'; |
111 | |
e6abe6d8 |
112 | sv_setpvn(dsv, "\"", 1); |
3967c732 |
113 | for (; cur--; pv++) { |
e6abe6d8 |
114 | if (pvlim && SvCUR(dsv) >= pvlim) { |
3967c732 |
115 | truncated++; |
116 | break; |
117 | } |
118 | if (isPRINT(*pv)) { |
119 | switch (*pv) { |
e6abe6d8 |
120 | case '\t': sv_catpvn(dsv, "\\t", 2); break; |
121 | case '\n': sv_catpvn(dsv, "\\n", 2); break; |
122 | case '\r': sv_catpvn(dsv, "\\r", 2); break; |
123 | case '\f': sv_catpvn(dsv, "\\f", 2); break; |
124 | case '"': sv_catpvn(dsv, "\\\"", 2); break; |
125 | case '\\': sv_catpvn(dsv, "\\\\", 2); break; |
126 | default: sv_catpvn(dsv, pv, 1); break; |
3967c732 |
127 | } |
128 | } |
129 | else { |
130 | if (cur && isDIGIT(*(pv+1))) |
e6abe6d8 |
131 | Perl_sv_catpvf(aTHX_ dsv, "\\%03o", (U8)*pv); |
3967c732 |
132 | else |
e6abe6d8 |
133 | Perl_sv_catpvf(aTHX_ dsv, "\\%o", (U8)*pv); |
3967c732 |
134 | } |
135 | } |
e6abe6d8 |
136 | sv_catpvn(dsv, "\"", 1); |
3967c732 |
137 | if (truncated) |
e6abe6d8 |
138 | sv_catpvn(dsv, "...", 3); |
3967c732 |
139 | if (nul_terminated) |
e6abe6d8 |
140 | sv_catpvn(dsv, "\\0", 2); |
3967c732 |
141 | |
e6abe6d8 |
142 | return SvPVX(dsv); |
143 | } |
144 | |
145 | char * |
864dbfa3 |
146 | Perl_sv_peek(pTHX_ SV *sv) |
3967c732 |
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 | } |
a3b4c9c6 |
197 | else if (DEBUG_R_TEST_) { |
198 | int is_tmp = 0; |
199 | I32 ix; |
200 | /* is this SV on the tmps stack? */ |
201 | for (ix=PL_tmps_ix; ix>=0; ix--) { |
202 | if (PL_tmps_stack[ix] == sv) { |
203 | is_tmp = 1; |
204 | break; |
205 | } |
206 | } |
207 | if (SvREFCNT(sv) > 1) |
208 | Perl_sv_catpvf(aTHX_ t, "<%"UVuf"%s>", (UV)SvREFCNT(sv), |
209 | is_tmp ? "T" : ""); |
210 | else if (is_tmp) |
211 | sv_catpv(t, "<T>"); |
04932ac8 |
212 | } |
213 | |
3967c732 |
214 | if (SvROK(sv)) { |
215 | sv_catpv(t, "\\"); |
216 | if (SvCUR(t) + unref > 10) { |
217 | SvCUR(t) = unref + 3; |
218 | *SvEND(t) = '\0'; |
219 | sv_catpv(t, "..."); |
220 | goto finish; |
221 | } |
222 | sv = (SV*)SvRV(sv); |
223 | goto retry; |
224 | } |
225 | switch (SvTYPE(sv)) { |
226 | default: |
227 | sv_catpv(t, "FREED"); |
228 | goto finish; |
229 | |
230 | case SVt_NULL: |
231 | sv_catpv(t, "UNDEF"); |
232 | goto finish; |
233 | case SVt_IV: |
234 | sv_catpv(t, "IV"); |
235 | break; |
236 | case SVt_NV: |
237 | sv_catpv(t, "NV"); |
238 | break; |
239 | case SVt_RV: |
240 | sv_catpv(t, "RV"); |
241 | break; |
242 | case SVt_PV: |
243 | sv_catpv(t, "PV"); |
244 | break; |
245 | case SVt_PVIV: |
246 | sv_catpv(t, "PVIV"); |
247 | break; |
248 | case SVt_PVNV: |
249 | sv_catpv(t, "PVNV"); |
250 | break; |
251 | case SVt_PVMG: |
252 | sv_catpv(t, "PVMG"); |
253 | break; |
254 | case SVt_PVLV: |
255 | sv_catpv(t, "PVLV"); |
256 | break; |
257 | case SVt_PVAV: |
258 | sv_catpv(t, "AV"); |
259 | break; |
260 | case SVt_PVHV: |
261 | sv_catpv(t, "HV"); |
262 | break; |
263 | case SVt_PVCV: |
264 | if (CvGV(sv)) |
cea2e8a9 |
265 | Perl_sv_catpvf(aTHX_ t, "CV(%s)", GvNAME(CvGV(sv))); |
3967c732 |
266 | else |
267 | sv_catpv(t, "CV()"); |
268 | goto finish; |
269 | case SVt_PVGV: |
270 | sv_catpv(t, "GV"); |
271 | break; |
272 | case SVt_PVBM: |
273 | sv_catpv(t, "BM"); |
274 | break; |
275 | case SVt_PVFM: |
276 | sv_catpv(t, "FM"); |
277 | break; |
278 | case SVt_PVIO: |
279 | sv_catpv(t, "IO"); |
280 | break; |
281 | } |
282 | |
283 | if (SvPOKp(sv)) { |
284 | if (!SvPVX(sv)) |
285 | sv_catpv(t, "(null)"); |
286 | else { |
79cb57f6 |
287 | SV *tmp = newSVpvn("", 0); |
3967c732 |
288 | sv_catpv(t, "("); |
289 | if (SvOOK(sv)) |
cea2e8a9 |
290 | Perl_sv_catpvf(aTHX_ t, "[%s]", pv_display(tmp, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, 127)); |
291 | Perl_sv_catpvf(aTHX_ t, "%s)", pv_display(tmp, SvPVX(sv), SvCUR(sv), SvLEN(sv), 127)); |
32639b87 |
292 | if (SvUTF8(sv)) |
b2ff9928 |
293 | Perl_sv_catpvf(aTHX_ t, " [UTF8 \"%s\"]", |
c728cb41 |
294 | sv_uni_display(tmp, sv, 8 * sv_len_utf8(sv), |
295 | UNI_DISPLAY_QQ)); |
3967c732 |
296 | SvREFCNT_dec(tmp); |
297 | } |
298 | } |
299 | else if (SvNOKp(sv)) { |
e54dc35b |
300 | STORE_NUMERIC_LOCAL_SET_STANDARD(); |
1779d84d |
301 | Perl_sv_catpvf(aTHX_ t, "(%"NVgf")",SvNVX(sv)); |
e54dc35b |
302 | RESTORE_NUMERIC_LOCAL(); |
3967c732 |
303 | } |
57def98f |
304 | else if (SvIOKp(sv)) { |
cf2093f6 |
305 | if (SvIsUV(sv)) |
57def98f |
306 | Perl_sv_catpvf(aTHX_ t, "(%"UVuf")", (UV)SvUVX(sv)); |
cf2093f6 |
307 | else |
57def98f |
308 | Perl_sv_catpvf(aTHX_ t, "(%"IVdf")", (IV)SvIVX(sv)); |
25da4f38 |
309 | } |
3967c732 |
310 | else |
311 | sv_catpv(t, "()"); |
2ef28da1 |
312 | |
3967c732 |
313 | finish: |
314 | if (unref) { |
315 | while (unref--) |
316 | sv_catpv(t, ")"); |
317 | } |
2d8e6c8d |
318 | return SvPV(t, n_a); |
3967c732 |
319 | } |
320 | |
321 | void |
864dbfa3 |
322 | Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, PMOP *pm) |
3967c732 |
323 | { |
324 | char ch; |
325 | |
326 | if (!pm) { |
cea2e8a9 |
327 | Perl_dump_indent(aTHX_ level, file, "{}\n"); |
3967c732 |
328 | return; |
329 | } |
cea2e8a9 |
330 | Perl_dump_indent(aTHX_ level, file, "{\n"); |
3967c732 |
331 | level++; |
332 | if (pm->op_pmflags & PMf_ONCE) |
333 | ch = '?'; |
334 | else |
335 | ch = '/'; |
aaa362c4 |
336 | if (PM_GETRE(pm)) |
cea2e8a9 |
337 | Perl_dump_indent(aTHX_ level, file, "PMf_PRE %c%s%c%s\n", |
aaa362c4 |
338 | ch, PM_GETRE(pm)->precomp, ch, |
3967c732 |
339 | (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : ""); |
340 | else |
cea2e8a9 |
341 | Perl_dump_indent(aTHX_ level, file, "PMf_PRE (RUNTIME)\n"); |
3967c732 |
342 | if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) { |
cea2e8a9 |
343 | Perl_dump_indent(aTHX_ level, file, "PMf_REPL = "); |
3967c732 |
344 | op_dump(pm->op_pmreplroot); |
345 | } |
aaa362c4 |
346 | if (pm->op_pmflags || (PM_GETRE(pm) && PM_GETRE(pm)->check_substr)) { |
79cb57f6 |
347 | SV *tmpsv = newSVpvn("", 0); |
3967c732 |
348 | if (pm->op_pmdynflags & PMdf_USED) |
349 | sv_catpv(tmpsv, ",USED"); |
350 | if (pm->op_pmdynflags & PMdf_TAINTED) |
351 | sv_catpv(tmpsv, ",TAINTED"); |
352 | if (pm->op_pmflags & PMf_ONCE) |
353 | sv_catpv(tmpsv, ",ONCE"); |
aaa362c4 |
354 | if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr |
355 | && !(PM_GETRE(pm)->reganch & ROPT_NOSCAN)) |
3967c732 |
356 | sv_catpv(tmpsv, ",SCANFIRST"); |
aaa362c4 |
357 | if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr |
358 | && PM_GETRE(pm)->reganch & ROPT_CHECK_ALL) |
3967c732 |
359 | sv_catpv(tmpsv, ",ALL"); |
360 | if (pm->op_pmflags & PMf_SKIPWHITE) |
361 | sv_catpv(tmpsv, ",SKIPWHITE"); |
362 | if (pm->op_pmflags & PMf_CONST) |
363 | sv_catpv(tmpsv, ",CONST"); |
364 | if (pm->op_pmflags & PMf_KEEP) |
365 | sv_catpv(tmpsv, ",KEEP"); |
366 | if (pm->op_pmflags & PMf_GLOBAL) |
367 | sv_catpv(tmpsv, ",GLOBAL"); |
368 | if (pm->op_pmflags & PMf_CONTINUE) |
369 | sv_catpv(tmpsv, ",CONTINUE"); |
370 | if (pm->op_pmflags & PMf_RETAINT) |
371 | sv_catpv(tmpsv, ",RETAINT"); |
372 | if (pm->op_pmflags & PMf_EVAL) |
373 | sv_catpv(tmpsv, ",EVAL"); |
cea2e8a9 |
374 | Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); |
3967c732 |
375 | SvREFCNT_dec(tmpsv); |
376 | } |
377 | |
cea2e8a9 |
378 | Perl_dump_indent(aTHX_ level-1, file, "}\n"); |
3967c732 |
379 | } |
380 | |
381 | void |
864dbfa3 |
382 | Perl_pmop_dump(pTHX_ PMOP *pm) |
3967c732 |
383 | { |
384 | do_pmop_dump(0, Perl_debug_log, pm); |
79072805 |
385 | } |
386 | |
387 | void |
864dbfa3 |
388 | Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, OP *o) |
79072805 |
389 | { |
cea2e8a9 |
390 | Perl_dump_indent(aTHX_ level, file, "{\n"); |
3967c732 |
391 | level++; |
11343788 |
392 | if (o->op_seq) |
3967c732 |
393 | PerlIO_printf(file, "%-4d", o->op_seq); |
93a17b20 |
394 | else |
3967c732 |
395 | PerlIO_printf(file, " "); |
c8db6e60 |
396 | PerlIO_printf(file, |
397 | "%*sTYPE = %s ===> ", |
53e06cf0 |
398 | (int)(PL_dumpindent*level-4), "", OP_NAME(o)); |
11343788 |
399 | if (o->op_next) { |
400 | if (o->op_seq) |
3967c732 |
401 | PerlIO_printf(file, "%d\n", o->op_next->op_seq); |
93a17b20 |
402 | else |
3967c732 |
403 | PerlIO_printf(file, "(%d)\n", o->op_next->op_seq); |
93a17b20 |
404 | } |
79072805 |
405 | else |
3967c732 |
406 | PerlIO_printf(file, "DONE\n"); |
11343788 |
407 | if (o->op_targ) { |
acb36ea4 |
408 | if (o->op_type == OP_NULL) |
ae7d165c |
409 | { |
cea2e8a9 |
410 | Perl_dump_indent(aTHX_ level, file, " (was %s)\n", PL_op_name[o->op_targ]); |
ae7d165c |
411 | if (o->op_targ == OP_NEXTSTATE) |
412 | { |
413 | if (CopLINE(cCOPo)) |
414 | Perl_dump_indent(aTHX_ level, file, "LINE = %d\n",CopLINE(cCOPo)); |
415 | if (CopSTASHPV(cCOPo)) |
416 | Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n", |
417 | CopSTASHPV(cCOPo)); |
418 | if (cCOPo->cop_label) |
419 | Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n", |
420 | cCOPo->cop_label); |
421 | } |
422 | } |
8990e307 |
423 | else |
894356b3 |
424 | Perl_dump_indent(aTHX_ level, file, "TARG = %ld\n", (long)o->op_targ); |
8990e307 |
425 | } |
748a9306 |
426 | #ifdef DUMPADDR |
57def98f |
427 | Perl_dump_indent(aTHX_ level, file, "ADDR = 0x%"UVxf" => 0x%"UVxf"\n", (UV)o, (UV)o->op_next); |
79072805 |
428 | #endif |
11343788 |
429 | if (o->op_flags) { |
79cb57f6 |
430 | SV *tmpsv = newSVpvn("", 0); |
5dc0d613 |
431 | switch (o->op_flags & OPf_WANT) { |
54310121 |
432 | case OPf_WANT_VOID: |
46fc3d4c |
433 | sv_catpv(tmpsv, ",VOID"); |
54310121 |
434 | break; |
435 | case OPf_WANT_SCALAR: |
46fc3d4c |
436 | sv_catpv(tmpsv, ",SCALAR"); |
54310121 |
437 | break; |
438 | case OPf_WANT_LIST: |
46fc3d4c |
439 | sv_catpv(tmpsv, ",LIST"); |
54310121 |
440 | break; |
441 | default: |
46fc3d4c |
442 | sv_catpv(tmpsv, ",UNKNOWN"); |
54310121 |
443 | break; |
444 | } |
11343788 |
445 | if (o->op_flags & OPf_KIDS) |
46fc3d4c |
446 | sv_catpv(tmpsv, ",KIDS"); |
11343788 |
447 | if (o->op_flags & OPf_PARENS) |
46fc3d4c |
448 | sv_catpv(tmpsv, ",PARENS"); |
11343788 |
449 | if (o->op_flags & OPf_STACKED) |
46fc3d4c |
450 | sv_catpv(tmpsv, ",STACKED"); |
11343788 |
451 | if (o->op_flags & OPf_REF) |
46fc3d4c |
452 | sv_catpv(tmpsv, ",REF"); |
11343788 |
453 | if (o->op_flags & OPf_MOD) |
46fc3d4c |
454 | sv_catpv(tmpsv, ",MOD"); |
11343788 |
455 | if (o->op_flags & OPf_SPECIAL) |
46fc3d4c |
456 | sv_catpv(tmpsv, ",SPECIAL"); |
cea2e8a9 |
457 | Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); |
46fc3d4c |
458 | SvREFCNT_dec(tmpsv); |
79072805 |
459 | } |
11343788 |
460 | if (o->op_private) { |
79cb57f6 |
461 | SV *tmpsv = newSVpvn("", 0); |
07447971 |
462 | if (PL_opargs[o->op_type] & OA_TARGLEX) { |
463 | if (o->op_private & OPpTARGET_MY) |
464 | sv_catpv(tmpsv, ",TARGET_MY"); |
465 | } |
bf91b999 |
466 | else if (o->op_type == OP_LEAVESUB || |
467 | o->op_type == OP_LEAVE || |
468 | o->op_type == OP_LEAVESUBLV || |
469 | o->op_type == OP_LEAVEWRITE) { |
470 | if (o->op_private & OPpREFCOUNTED) |
471 | sv_catpv(tmpsv, ",REFCOUNTED"); |
472 | } |
473 | else if (o->op_type == OP_AASSIGN) { |
11343788 |
474 | if (o->op_private & OPpASSIGN_COMMON) |
46fc3d4c |
475 | sv_catpv(tmpsv, ",COMMON"); |
8d063cd8 |
476 | } |
11343788 |
477 | else if (o->op_type == OP_SASSIGN) { |
478 | if (o->op_private & OPpASSIGN_BACKWARDS) |
46fc3d4c |
479 | sv_catpv(tmpsv, ",BACKWARDS"); |
a0d0e21e |
480 | } |
11343788 |
481 | else if (o->op_type == OP_TRANS) { |
482 | if (o->op_private & OPpTRANS_SQUASH) |
46fc3d4c |
483 | sv_catpv(tmpsv, ",SQUASH"); |
11343788 |
484 | if (o->op_private & OPpTRANS_DELETE) |
46fc3d4c |
485 | sv_catpv(tmpsv, ",DELETE"); |
11343788 |
486 | if (o->op_private & OPpTRANS_COMPLEMENT) |
46fc3d4c |
487 | sv_catpv(tmpsv, ",COMPLEMENT"); |
bf91b999 |
488 | if (o->op_private & OPpTRANS_IDENTICAL) |
489 | sv_catpv(tmpsv, ",IDENTICAL"); |
490 | if (o->op_private & OPpTRANS_GROWS) |
491 | sv_catpv(tmpsv, ",GROWS"); |
8d063cd8 |
492 | } |
11343788 |
493 | else if (o->op_type == OP_REPEAT) { |
494 | if (o->op_private & OPpREPEAT_DOLIST) |
46fc3d4c |
495 | sv_catpv(tmpsv, ",DOLIST"); |
8d063cd8 |
496 | } |
11343788 |
497 | else if (o->op_type == OP_ENTERSUB || |
498 | o->op_type == OP_RV2SV || |
23f1ca44 |
499 | o->op_type == OP_GVSV || |
11343788 |
500 | o->op_type == OP_RV2AV || |
501 | o->op_type == OP_RV2HV || |
502 | o->op_type == OP_RV2GV || |
503 | o->op_type == OP_AELEM || |
504 | o->op_type == OP_HELEM ) |
85e6fe83 |
505 | { |
5dc0d613 |
506 | if (o->op_type == OP_ENTERSUB) { |
507 | if (o->op_private & OPpENTERSUB_AMPER) |
46fc3d4c |
508 | sv_catpv(tmpsv, ",AMPER"); |
5dc0d613 |
509 | if (o->op_private & OPpENTERSUB_DB) |
46fc3d4c |
510 | sv_catpv(tmpsv, ",DB"); |
d3011074 |
511 | if (o->op_private & OPpENTERSUB_HASTARG) |
512 | sv_catpv(tmpsv, ",HASTARG"); |
bf91b999 |
513 | if (o->op_private & OPpENTERSUB_NOPAREN) |
514 | sv_catpv(tmpsv, ",NOPAREN"); |
515 | if (o->op_private & OPpENTERSUB_INARGS) |
516 | sv_catpv(tmpsv, ",INARGS"); |
95f0a2f1 |
517 | if (o->op_private & OPpENTERSUB_NOMOD) |
518 | sv_catpv(tmpsv, ",NOMOD"); |
68dc0745 |
519 | } |
bf91b999 |
520 | else { |
d3011074 |
521 | switch (o->op_private & OPpDEREF) { |
5f05dabc |
522 | case OPpDEREF_SV: |
46fc3d4c |
523 | sv_catpv(tmpsv, ",SV"); |
5f05dabc |
524 | break; |
525 | case OPpDEREF_AV: |
46fc3d4c |
526 | sv_catpv(tmpsv, ",AV"); |
5f05dabc |
527 | break; |
528 | case OPpDEREF_HV: |
46fc3d4c |
529 | sv_catpv(tmpsv, ",HV"); |
5f05dabc |
530 | break; |
531 | } |
bf91b999 |
532 | if (o->op_private & OPpMAYBE_LVSUB) |
533 | sv_catpv(tmpsv, ",MAYBE_LVSUB"); |
534 | } |
5dc0d613 |
535 | if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) { |
536 | if (o->op_private & OPpLVAL_DEFER) |
46fc3d4c |
537 | sv_catpv(tmpsv, ",LVAL_DEFER"); |
68dc0745 |
538 | } |
539 | else { |
5dc0d613 |
540 | if (o->op_private & HINT_STRICT_REFS) |
46fc3d4c |
541 | sv_catpv(tmpsv, ",STRICT_REFS"); |
192587c2 |
542 | if (o->op_private & OPpOUR_INTRO) |
543 | sv_catpv(tmpsv, ",OUR_INTRO"); |
68dc0745 |
544 | } |
8d063cd8 |
545 | } |
11343788 |
546 | else if (o->op_type == OP_CONST) { |
547 | if (o->op_private & OPpCONST_BARE) |
46fc3d4c |
548 | sv_catpv(tmpsv, ",BARE"); |
7a52d87a |
549 | if (o->op_private & OPpCONST_STRICT) |
550 | sv_catpv(tmpsv, ",STRICT"); |
bf91b999 |
551 | if (o->op_private & OPpCONST_ARYBASE) |
552 | sv_catpv(tmpsv, ",ARYBASE"); |
553 | if (o->op_private & OPpCONST_WARNING) |
554 | sv_catpv(tmpsv, ",WARNING"); |
555 | if (o->op_private & OPpCONST_ENTERED) |
556 | sv_catpv(tmpsv, ",ENTERED"); |
79072805 |
557 | } |
11343788 |
558 | else if (o->op_type == OP_FLIP) { |
559 | if (o->op_private & OPpFLIP_LINENUM) |
46fc3d4c |
560 | sv_catpv(tmpsv, ",LINENUM"); |
79072805 |
561 | } |
11343788 |
562 | else if (o->op_type == OP_FLOP) { |
563 | if (o->op_private & OPpFLIP_LINENUM) |
46fc3d4c |
564 | sv_catpv(tmpsv, ",LINENUM"); |
95f0a2f1 |
565 | } |
566 | else if (o->op_type == OP_RV2CV) { |
cd06dffe |
567 | if (o->op_private & OPpLVAL_INTRO) |
568 | sv_catpv(tmpsv, ",INTRO"); |
79072805 |
569 | } |
bf91b999 |
570 | else if (o->op_type == OP_GV) { |
571 | if (o->op_private & OPpEARLY_CV) |
572 | sv_catpv(tmpsv, ",EARLY_CV"); |
573 | } |
574 | else if (o->op_type == OP_LIST) { |
575 | if (o->op_private & OPpLIST_GUESSED) |
576 | sv_catpv(tmpsv, ",GUESSED"); |
577 | } |
578 | else if (o->op_type == OP_DELETE) { |
579 | if (o->op_private & OPpSLICE) |
580 | sv_catpv(tmpsv, ",SLICE"); |
581 | } |
582 | else if (o->op_type == OP_EXISTS) { |
583 | if (o->op_private & OPpEXISTS_SUB) |
584 | sv_catpv(tmpsv, ",EXISTS_SUB"); |
585 | } |
586 | else if (o->op_type == OP_SORT) { |
587 | if (o->op_private & OPpSORT_NUMERIC) |
588 | sv_catpv(tmpsv, ",NUMERIC"); |
589 | if (o->op_private & OPpSORT_INTEGER) |
590 | sv_catpv(tmpsv, ",INTEGER"); |
591 | if (o->op_private & OPpSORT_REVERSE) |
592 | sv_catpv(tmpsv, ",REVERSE"); |
593 | } |
594 | else if (o->op_type == OP_THREADSV) { |
595 | if (o->op_private & OPpDONE_SVREF) |
596 | sv_catpv(tmpsv, ",SVREF"); |
597 | } |
598 | else if (o->op_type == OP_OPEN || o->op_type == OP_BACKTICK) { |
599 | if (o->op_private & OPpOPEN_IN_RAW) |
600 | sv_catpv(tmpsv, ",IN_RAW"); |
601 | if (o->op_private & OPpOPEN_IN_CRLF) |
602 | sv_catpv(tmpsv, ",IN_CRLF"); |
603 | if (o->op_private & OPpOPEN_OUT_RAW) |
604 | sv_catpv(tmpsv, ",OUT_RAW"); |
605 | if (o->op_private & OPpOPEN_OUT_CRLF) |
606 | sv_catpv(tmpsv, ",OUT_CRLF"); |
607 | } |
608 | else if (o->op_type == OP_EXIT) { |
609 | if (o->op_private & OPpEXIT_VMSISH) |
96e176bf |
610 | sv_catpv(tmpsv, ",EXIT_VMSISH"); |
611 | if (o->op_private & OPpHUSH_VMSISH) |
612 | sv_catpv(tmpsv, ",HUSH_VMSISH"); |
613 | } |
614 | else if (o->op_type == OP_DIE) { |
615 | if (o->op_private & OPpHUSH_VMSISH) |
616 | sv_catpv(tmpsv, ",HUSH_VMSISH"); |
bf91b999 |
617 | } |
11343788 |
618 | if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO) |
46fc3d4c |
619 | sv_catpv(tmpsv, ",INTRO"); |
620 | if (SvCUR(tmpsv)) |
cea2e8a9 |
621 | Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX(tmpsv) + 1); |
46fc3d4c |
622 | SvREFCNT_dec(tmpsv); |
8d063cd8 |
623 | } |
8d063cd8 |
624 | |
11343788 |
625 | switch (o->op_type) { |
971a9dd3 |
626 | case OP_AELEMFAST: |
93a17b20 |
627 | case OP_GVSV: |
79072805 |
628 | case OP_GV: |
971a9dd3 |
629 | #ifdef USE_ITHREADS |
c803eecc |
630 | Perl_dump_indent(aTHX_ level, file, "PADIX = %" IVdf "\n", (IV)cPADOPo->op_padix); |
971a9dd3 |
631 | #else |
632 | if (cSVOPo->op_sv) { |
46fc3d4c |
633 | SV *tmpsv = NEWSV(0,0); |
8990e307 |
634 | ENTER; |
8990e307 |
635 | SAVEFREESV(tmpsv); |
971a9dd3 |
636 | gv_fullname3(tmpsv, (GV*)cSVOPo->op_sv, Nullch); |
35c1215d |
637 | Perl_dump_indent(aTHX_ level, file, "GV = %"SVf"\n", tmpsv); |
8990e307 |
638 | LEAVE; |
378cc40b |
639 | } |
79072805 |
640 | else |
cea2e8a9 |
641 | Perl_dump_indent(aTHX_ level, file, "GV = NULL\n"); |
971a9dd3 |
642 | #endif |
79072805 |
643 | break; |
644 | case OP_CONST: |
f5d5a27c |
645 | case OP_METHOD_NAMED: |
cea2e8a9 |
646 | Perl_dump_indent(aTHX_ level, file, "SV = %s\n", SvPEEK(cSVOPo->op_sv)); |
79072805 |
647 | break; |
7399586d |
648 | case OP_SETSTATE: |
93a17b20 |
649 | case OP_NEXTSTATE: |
650 | case OP_DBSTATE: |
57843af0 |
651 | if (CopLINE(cCOPo)) |
652 | Perl_dump_indent(aTHX_ level, file, "LINE = %d\n",CopLINE(cCOPo)); |
ed094faf |
653 | if (CopSTASHPV(cCOPo)) |
654 | Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n", |
655 | CopSTASHPV(cCOPo)); |
11343788 |
656 | if (cCOPo->cop_label) |
ed094faf |
657 | Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n", |
658 | cCOPo->cop_label); |
79072805 |
659 | break; |
660 | case OP_ENTERLOOP: |
cea2e8a9 |
661 | Perl_dump_indent(aTHX_ level, file, "REDO ===> "); |
11343788 |
662 | if (cLOOPo->op_redoop) |
3967c732 |
663 | PerlIO_printf(file, "%d\n", cLOOPo->op_redoop->op_seq); |
79072805 |
664 | else |
3967c732 |
665 | PerlIO_printf(file, "DONE\n"); |
cea2e8a9 |
666 | Perl_dump_indent(aTHX_ level, file, "NEXT ===> "); |
11343788 |
667 | if (cLOOPo->op_nextop) |
3967c732 |
668 | PerlIO_printf(file, "%d\n", cLOOPo->op_nextop->op_seq); |
79072805 |
669 | else |
3967c732 |
670 | PerlIO_printf(file, "DONE\n"); |
cea2e8a9 |
671 | Perl_dump_indent(aTHX_ level, file, "LAST ===> "); |
11343788 |
672 | if (cLOOPo->op_lastop) |
3967c732 |
673 | PerlIO_printf(file, "%d\n", cLOOPo->op_lastop->op_seq); |
79072805 |
674 | else |
3967c732 |
675 | PerlIO_printf(file, "DONE\n"); |
79072805 |
676 | break; |
677 | case OP_COND_EXPR: |
1a67a97c |
678 | case OP_RANGE: |
a0d0e21e |
679 | case OP_MAPWHILE: |
79072805 |
680 | case OP_GREPWHILE: |
681 | case OP_OR: |
682 | case OP_AND: |
cea2e8a9 |
683 | Perl_dump_indent(aTHX_ level, file, "OTHER ===> "); |
11343788 |
684 | if (cLOGOPo->op_other) |
3967c732 |
685 | PerlIO_printf(file, "%d\n", cLOGOPo->op_other->op_seq); |
79072805 |
686 | else |
3967c732 |
687 | PerlIO_printf(file, "DONE\n"); |
79072805 |
688 | break; |
689 | case OP_PUSHRE: |
690 | case OP_MATCH: |
8782bef2 |
691 | case OP_QR: |
79072805 |
692 | case OP_SUBST: |
3967c732 |
693 | do_pmop_dump(level, file, cPMOPo); |
79072805 |
694 | break; |
7934575e |
695 | case OP_LEAVE: |
696 | case OP_LEAVEEVAL: |
697 | case OP_LEAVESUB: |
698 | case OP_LEAVESUBLV: |
699 | case OP_LEAVEWRITE: |
700 | case OP_SCOPE: |
701 | if (o->op_private & OPpREFCOUNTED) |
702 | Perl_dump_indent(aTHX_ level, file, "REFCNT = %"UVuf"\n", (UV)o->op_targ); |
703 | break; |
a0d0e21e |
704 | default: |
705 | break; |
79072805 |
706 | } |
11343788 |
707 | if (o->op_flags & OPf_KIDS) { |
79072805 |
708 | OP *kid; |
11343788 |
709 | for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) |
3967c732 |
710 | do_op_dump(level, file, kid); |
8d063cd8 |
711 | } |
cea2e8a9 |
712 | Perl_dump_indent(aTHX_ level-1, file, "}\n"); |
3967c732 |
713 | } |
714 | |
715 | void |
864dbfa3 |
716 | Perl_op_dump(pTHX_ OP *o) |
3967c732 |
717 | { |
718 | do_op_dump(0, Perl_debug_log, o); |
8d063cd8 |
719 | } |
720 | |
8adcabd8 |
721 | void |
864dbfa3 |
722 | Perl_gv_dump(pTHX_ GV *gv) |
378cc40b |
723 | { |
79072805 |
724 | SV *sv; |
378cc40b |
725 | |
79072805 |
726 | if (!gv) { |
760ac839 |
727 | PerlIO_printf(Perl_debug_log, "{}\n"); |
378cc40b |
728 | return; |
729 | } |
8990e307 |
730 | sv = sv_newmortal(); |
760ac839 |
731 | PerlIO_printf(Perl_debug_log, "{\n"); |
f6aff53a |
732 | gv_fullname3(sv, gv, Nullch); |
35c1215d |
733 | Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %"SVf"", sv); |
79072805 |
734 | if (gv != GvEGV(gv)) { |
f6aff53a |
735 | gv_efullname3(sv, GvEGV(gv), Nullch); |
35c1215d |
736 | Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %"SVf"", sv); |
8adcabd8 |
737 | } |
3967c732 |
738 | PerlIO_putc(Perl_debug_log, '\n'); |
cea2e8a9 |
739 | Perl_dump_indent(aTHX_ 0, Perl_debug_log, "}\n"); |
8d063cd8 |
740 | } |
741 | |
14befaf4 |
742 | |
afe38520 |
743 | /* map magic types to the symbolic names |
14befaf4 |
744 | * (with the PERL_MAGIC_ prefixed stripped) |
745 | */ |
746 | |
747 | static struct { char type; char *name; } magic_names[] = { |
516a5887 |
748 | { PERL_MAGIC_sv, "sv(\\0)" }, |
749 | { PERL_MAGIC_arylen, "arylen(#)" }, |
750 | { PERL_MAGIC_glob, "glob(*)" }, |
751 | { PERL_MAGIC_pos, "pos(.)" }, |
752 | { PERL_MAGIC_backref, "backref(<)" }, |
753 | { PERL_MAGIC_overload, "overload(A)" }, |
754 | { PERL_MAGIC_bm, "bm(B)" }, |
755 | { PERL_MAGIC_regdata, "regdata(D)" }, |
756 | { PERL_MAGIC_env, "env(E)" }, |
757 | { PERL_MAGIC_isa, "isa(I)" }, |
758 | { PERL_MAGIC_dbfile, "dbfile(L)" }, |
afe38520 |
759 | { PERL_MAGIC_shared, "shared(N)" }, |
516a5887 |
760 | { PERL_MAGIC_tied, "tied(P)" }, |
761 | { PERL_MAGIC_sig, "sig(S)" }, |
762 | { PERL_MAGIC_uvar, "uvar(U)" }, |
763 | { PERL_MAGIC_overload_elem, "overload_elem(a)" }, |
764 | { PERL_MAGIC_overload_table, "overload_table(c)" }, |
765 | { PERL_MAGIC_regdatum, "regdatum(d)" }, |
766 | { PERL_MAGIC_envelem, "envelem(e)" }, |
767 | { PERL_MAGIC_fm, "fm(f)" }, |
768 | { PERL_MAGIC_regex_global, "regex_global(g)" }, |
769 | { PERL_MAGIC_isaelem, "isaelem(i)" }, |
770 | { PERL_MAGIC_nkeys, "nkeys(k)" }, |
771 | { PERL_MAGIC_dbline, "dbline(l)" }, |
772 | { PERL_MAGIC_mutex, "mutex(m)" }, |
afe38520 |
773 | { PERL_MAGIC_shared_scalar, "shared_scalar(n)" }, |
516a5887 |
774 | { PERL_MAGIC_collxfrm, "collxfrm(o)" }, |
775 | { PERL_MAGIC_tiedelem, "tiedelem(p)" }, |
776 | { PERL_MAGIC_tiedscalar, "tiedscalar(q)" }, |
777 | { PERL_MAGIC_qr, "qr(r)" }, |
778 | { PERL_MAGIC_sigelem, "sigelem(s)" }, |
779 | { PERL_MAGIC_taint, "taint(t)" }, |
afe38520 |
780 | { PERL_MAGIC_uvar_elem, "uvar_elem(v)" }, |
516a5887 |
781 | { PERL_MAGIC_vec, "vec(v)" }, |
cb50f42d |
782 | { PERL_MAGIC_vstring, "vstring(V)" }, |
7e8c5dac |
783 | { PERL_MAGIC_utf8, "utf8(w)" }, |
516a5887 |
784 | { PERL_MAGIC_substr, "substr(x)" }, |
785 | { PERL_MAGIC_defelem, "defelem(y)" }, |
786 | { PERL_MAGIC_ext, "ext(~)" }, |
787 | /* this null string terminates the list */ |
788 | { 0, 0 }, |
14befaf4 |
789 | }; |
790 | |
8adcabd8 |
791 | void |
864dbfa3 |
792 | Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim) |
8d063cd8 |
793 | { |
3967c732 |
794 | for (; mg; mg = mg->mg_moremagic) { |
b900a521 |
795 | Perl_dump_indent(aTHX_ level, file, |
796 | " MAGIC = 0x%"UVxf"\n", PTR2UV(mg)); |
3967c732 |
797 | if (mg->mg_virtual) { |
798 | MGVTBL *v = mg->mg_virtual; |
799 | char *s = 0; |
800 | if (v == &PL_vtbl_sv) s = "sv"; |
801 | else if (v == &PL_vtbl_env) s = "env"; |
802 | else if (v == &PL_vtbl_envelem) s = "envelem"; |
803 | else if (v == &PL_vtbl_sig) s = "sig"; |
804 | else if (v == &PL_vtbl_sigelem) s = "sigelem"; |
805 | else if (v == &PL_vtbl_pack) s = "pack"; |
806 | else if (v == &PL_vtbl_packelem) s = "packelem"; |
807 | else if (v == &PL_vtbl_dbline) s = "dbline"; |
808 | else if (v == &PL_vtbl_isa) s = "isa"; |
809 | else if (v == &PL_vtbl_arylen) s = "arylen"; |
810 | else if (v == &PL_vtbl_glob) s = "glob"; |
811 | else if (v == &PL_vtbl_mglob) s = "mglob"; |
812 | else if (v == &PL_vtbl_nkeys) s = "nkeys"; |
813 | else if (v == &PL_vtbl_taint) s = "taint"; |
814 | else if (v == &PL_vtbl_substr) s = "substr"; |
815 | else if (v == &PL_vtbl_vec) s = "vec"; |
816 | else if (v == &PL_vtbl_pos) s = "pos"; |
817 | else if (v == &PL_vtbl_bm) s = "bm"; |
818 | else if (v == &PL_vtbl_fm) s = "fm"; |
819 | else if (v == &PL_vtbl_uvar) s = "uvar"; |
820 | else if (v == &PL_vtbl_defelem) s = "defelem"; |
821 | #ifdef USE_LOCALE_COLLATE |
822 | else if (v == &PL_vtbl_collxfrm) s = "collxfrm"; |
823 | #endif |
3967c732 |
824 | else if (v == &PL_vtbl_amagic) s = "amagic"; |
825 | else if (v == &PL_vtbl_amagicelem) s = "amagicelem"; |
810b8aa5 |
826 | else if (v == &PL_vtbl_backref) s = "backref"; |
7e8c5dac |
827 | else if (v == &PL_vtbl_utf8) s = "utf8"; |
3967c732 |
828 | if (s) |
cea2e8a9 |
829 | Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", s); |
3967c732 |
830 | else |
b900a521 |
831 | Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0x%"UVxf"\n", PTR2UV(v)); |
3967c732 |
832 | } |
833 | else |
cea2e8a9 |
834 | Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0\n"); |
8d063cd8 |
835 | |
3967c732 |
836 | if (mg->mg_private) |
cea2e8a9 |
837 | Perl_dump_indent(aTHX_ level, file, " MG_PRIVATE = %d\n", mg->mg_private); |
3967c732 |
838 | |
14befaf4 |
839 | { |
840 | int n; |
841 | char *name = 0; |
842 | for (n=0; magic_names[n].name; n++) { |
843 | if (mg->mg_type == magic_names[n].type) { |
844 | name = magic_names[n].name; |
845 | break; |
846 | } |
847 | } |
848 | if (name) |
849 | Perl_dump_indent(aTHX_ level, file, |
850 | " MG_TYPE = PERL_MAGIC_%s\n", name); |
851 | else |
852 | Perl_dump_indent(aTHX_ level, file, |
853 | " MG_TYPE = UNKNOWN(\\%o)\n", mg->mg_type); |
854 | } |
3967c732 |
855 | |
856 | if (mg->mg_flags) { |
cea2e8a9 |
857 | Perl_dump_indent(aTHX_ level, file, " MG_FLAGS = 0x%02X\n", mg->mg_flags); |
cb50f42d |
858 | if (mg->mg_type == PERL_MAGIC_envelem && |
859 | mg->mg_flags & MGf_TAINTEDDIR) |
cea2e8a9 |
860 | Perl_dump_indent(aTHX_ level, file, " TAINTEDDIR\n"); |
3967c732 |
861 | if (mg->mg_flags & MGf_REFCOUNTED) |
cea2e8a9 |
862 | Perl_dump_indent(aTHX_ level, file, " REFCOUNTED\n"); |
3967c732 |
863 | if (mg->mg_flags & MGf_GSKIP) |
cea2e8a9 |
864 | Perl_dump_indent(aTHX_ level, file, " GSKIP\n"); |
cb50f42d |
865 | if (mg->mg_type == PERL_MAGIC_regex_global && |
866 | mg->mg_flags & MGf_MINMATCH) |
cea2e8a9 |
867 | Perl_dump_indent(aTHX_ level, file, " MINMATCH\n"); |
3967c732 |
868 | } |
869 | if (mg->mg_obj) { |
b900a521 |
870 | Perl_dump_indent(aTHX_ level, file, " MG_OBJ = 0x%"UVxf"\n", PTR2UV(mg->mg_obj)); |
3967c732 |
871 | if (mg->mg_flags & MGf_REFCOUNTED) |
872 | do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */ |
873 | } |
874 | if (mg->mg_len) |
894356b3 |
875 | Perl_dump_indent(aTHX_ level, file, " MG_LEN = %ld\n", (long)mg->mg_len); |
3967c732 |
876 | if (mg->mg_ptr) { |
b900a521 |
877 | Perl_dump_indent(aTHX_ level, file, " MG_PTR = 0x%"UVxf, PTR2UV(mg->mg_ptr)); |
3967c732 |
878 | if (mg->mg_len >= 0) { |
7e8c5dac |
879 | if (mg->mg_type != PERL_MAGIC_utf8) { |
880 | SV *sv = newSVpvn("", 0); |
881 | PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim)); |
882 | SvREFCNT_dec(sv); |
883 | } |
3967c732 |
884 | } |
885 | else if (mg->mg_len == HEf_SVKEY) { |
886 | PerlIO_puts(file, " => HEf_SVKEY\n"); |
887 | do_sv_dump(level+2, file, (SV*)((mg)->mg_ptr), nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */ |
888 | continue; |
889 | } |
890 | else |
891 | PerlIO_puts(file, " ???? - please notify IZ"); |
892 | PerlIO_putc(file, '\n'); |
893 | } |
7e8c5dac |
894 | if (mg->mg_type == PERL_MAGIC_utf8) { |
895 | STRLEN *cache = (STRLEN *) mg->mg_ptr; |
896 | if (cache) { |
897 | IV i; |
898 | for (i = 0; i < PERL_MAGIC_UTF8_CACHESIZE; i++) |
899 | Perl_dump_indent(aTHX_ level, file, |
900 | " %2"IVdf": %"UVuf" -> %"UVuf"\n", |
901 | i, |
902 | (UV)cache[i * 2], |
903 | (UV)cache[i * 2 + 1]); |
904 | } |
905 | } |
378cc40b |
906 | } |
3967c732 |
907 | } |
908 | |
909 | void |
864dbfa3 |
910 | Perl_magic_dump(pTHX_ MAGIC *mg) |
3967c732 |
911 | { |
912 | do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0); |
913 | } |
914 | |
915 | void |
864dbfa3 |
916 | Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, char *name, HV *sv) |
3967c732 |
917 | { |
b900a521 |
918 | Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv)); |
3967c732 |
919 | if (sv && HvNAME(sv)) |
920 | PerlIO_printf(file, "\t\"%s\"\n", HvNAME(sv)); |
79072805 |
921 | else |
3967c732 |
922 | PerlIO_putc(file, '\n'); |
923 | } |
924 | |
925 | void |
864dbfa3 |
926 | Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv) |
3967c732 |
927 | { |
b900a521 |
928 | Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv)); |
3967c732 |
929 | if (sv && GvNAME(sv)) |
930 | PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv)); |
c90c0ff4 |
931 | else |
3967c732 |
932 | PerlIO_putc(file, '\n'); |
933 | } |
934 | |
935 | void |
864dbfa3 |
936 | Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv) |
3967c732 |
937 | { |
b900a521 |
938 | Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv)); |
3967c732 |
939 | if (sv && GvNAME(sv)) { |
940 | PerlIO_printf(file, "\t\""); |
6676db26 |
941 | if (GvSTASH(sv)) |
3967c732 |
942 | PerlIO_printf(file, "%s\" :: \"", HvNAME(GvSTASH(sv))); |
943 | PerlIO_printf(file, "%s\"\n", GvNAME(sv)); |
8d063cd8 |
944 | } |
3967c732 |
945 | else |
946 | PerlIO_putc(file, '\n'); |
947 | } |
948 | |
949 | void |
864dbfa3 |
950 | Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim) |
3967c732 |
951 | { |
cea89e20 |
952 | SV *d; |
3967c732 |
953 | char *s; |
954 | U32 flags; |
955 | U32 type; |
956 | |
957 | if (!sv) { |
cea2e8a9 |
958 | Perl_dump_indent(aTHX_ level, file, "SV = 0\n"); |
3967c732 |
959 | return; |
378cc40b |
960 | } |
2ef28da1 |
961 | |
3967c732 |
962 | flags = SvFLAGS(sv); |
963 | type = SvTYPE(sv); |
79072805 |
964 | |
cea89e20 |
965 | d = Perl_newSVpvf(aTHX_ |
57def98f |
966 | "(0x%"UVxf") at 0x%"UVxf"\n%*s REFCNT = %"IVdf"\n%*s FLAGS = (", |
56431972 |
967 | PTR2UV(SvANY(sv)), PTR2UV(sv), |
894356b3 |
968 | (int)(PL_dumpindent*level), "", (IV)SvREFCNT(sv), |
969 | (int)(PL_dumpindent*level), ""); |
8d063cd8 |
970 | |
d9d18af6 |
971 | if (flags & SVs_PADSTALE) sv_catpv(d, "PADSTALE,"); |
3967c732 |
972 | if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,"); |
973 | if (flags & SVs_PADMY) sv_catpv(d, "PADMY,"); |
974 | if (flags & SVs_TEMP) sv_catpv(d, "TEMP,"); |
975 | if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,"); |
976 | if (flags & SVs_GMG) sv_catpv(d, "GMG,"); |
977 | if (flags & SVs_SMG) sv_catpv(d, "SMG,"); |
978 | if (flags & SVs_RMG) sv_catpv(d, "RMG,"); |
4db58590 |
979 | |
3967c732 |
980 | if (flags & SVf_IOK) sv_catpv(d, "IOK,"); |
981 | if (flags & SVf_NOK) sv_catpv(d, "NOK,"); |
982 | if (flags & SVf_POK) sv_catpv(d, "POK,"); |
810b8aa5 |
983 | if (flags & SVf_ROK) { |
984 | sv_catpv(d, "ROK,"); |
985 | if (SvWEAKREF(sv)) sv_catpv(d, "WEAKREF,"); |
986 | } |
3967c732 |
987 | if (flags & SVf_OOK) sv_catpv(d, "OOK,"); |
988 | if (flags & SVf_FAKE) sv_catpv(d, "FAKE,"); |
989 | if (flags & SVf_READONLY) sv_catpv(d, "READONLY,"); |
4db58590 |
990 | |
3967c732 |
991 | if (flags & SVf_AMAGIC) sv_catpv(d, "OVERLOAD,"); |
3967c732 |
992 | if (flags & SVp_IOK) sv_catpv(d, "pIOK,"); |
993 | if (flags & SVp_NOK) sv_catpv(d, "pNOK,"); |
994 | if (flags & SVp_POK) sv_catpv(d, "pPOK,"); |
995 | if (flags & SVp_SCREAM) sv_catpv(d, "SCREAM,"); |
996 | |
997 | switch (type) { |
998 | case SVt_PVCV: |
999 | case SVt_PVFM: |
1000 | if (CvANON(sv)) sv_catpv(d, "ANON,"); |
1001 | if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,"); |
1002 | if (CvCLONE(sv)) sv_catpv(d, "CLONE,"); |
1003 | if (CvCLONED(sv)) sv_catpv(d, "CLONED,"); |
de3f1649 |
1004 | if (CvCONST(sv)) sv_catpv(d, "CONST,"); |
3967c732 |
1005 | if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,"); |
25da4f38 |
1006 | if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,"); |
18f7acf9 |
1007 | if (CvLVALUE(sv)) sv_catpv(d, "LVALUE,"); |
1008 | if (CvMETHOD(sv)) sv_catpv(d, "METHOD,"); |
662a8415 |
1009 | if (CvLOCKED(sv)) sv_catpv(d, "LOCKED,"); |
7dafbf52 |
1010 | if (CvWEAKOUTSIDE(sv)) sv_catpv(d, "WEAKOUTSIDE,"); |
3967c732 |
1011 | break; |
1012 | case SVt_PVHV: |
1013 | if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,"); |
1014 | if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,"); |
19692e8d |
1015 | if (HvHASKFLAGS(sv)) sv_catpv(d, "HASKFLAGS,"); |
3967c732 |
1016 | break; |
1017 | case SVt_PVGV: |
1018 | if (GvINTRO(sv)) sv_catpv(d, "INTRO,"); |
1019 | if (GvMULTI(sv)) sv_catpv(d, "MULTI,"); |
7fb37951 |
1020 | if (GvUNIQUE(sv)) sv_catpv(d, "UNIQUE,"); |
3967c732 |
1021 | if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,"); |
12c18039 |
1022 | if (GvIN_PAD(sv)) sv_catpv(d, "IN_PAD,"); |
addd1794 |
1023 | if (flags & SVpad_OUR) sv_catpv(d, "OUR,"); |
3967c732 |
1024 | if (GvIMPORTED(sv)) { |
1025 | sv_catpv(d, "IMPORT"); |
1026 | if (GvIMPORTED(sv) == GVf_IMPORTED) |
1027 | sv_catpv(d, "ALL,"); |
1028 | else { |
1029 | sv_catpv(d, "("); |
1030 | if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV"); |
1031 | if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV"); |
1032 | if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV"); |
1033 | if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV"); |
1034 | sv_catpv(d, " ),"); |
1035 | } |
1036 | } |
addd1794 |
1037 | /* FALL THROUGH */ |
25da4f38 |
1038 | default: |
1039 | if (SvEVALED(sv)) sv_catpv(d, "EVALED,"); |
1040 | if (SvIsUV(sv)) sv_catpv(d, "IsUV,"); |
1041 | break; |
3967c732 |
1042 | case SVt_PVBM: |
1043 | if (SvTAIL(sv)) sv_catpv(d, "TAIL,"); |
25da4f38 |
1044 | if (SvVALID(sv)) sv_catpv(d, "VALID,"); |
3967c732 |
1045 | break; |
addd1794 |
1046 | case SVt_PVMG: |
1047 | if (flags & SVpad_TYPED) |
1048 | sv_catpv(d, "TYPED,"); |
1049 | break; |
3967c732 |
1050 | } |
34aa1585 |
1051 | if ((SvPOK(sv) || SvPOKp(sv)) && SvUTF8(sv)) |
9fe74ede |
1052 | sv_catpv(d, "UTF8"); |
3967c732 |
1053 | |
1054 | if (*(SvEND(d) - 1) == ',') |
1055 | SvPVX(d)[--SvCUR(d)] = '\0'; |
1056 | sv_catpv(d, ")"); |
1057 | s = SvPVX(d); |
1058 | |
cea2e8a9 |
1059 | Perl_dump_indent(aTHX_ level, file, "SV = "); |
3967c732 |
1060 | switch (type) { |
1061 | case SVt_NULL: |
1062 | PerlIO_printf(file, "NULL%s\n", s); |
cea89e20 |
1063 | SvREFCNT_dec(d); |
3967c732 |
1064 | return; |
1065 | case SVt_IV: |
1066 | PerlIO_printf(file, "IV%s\n", s); |
1067 | break; |
1068 | case SVt_NV: |
1069 | PerlIO_printf(file, "NV%s\n", s); |
1070 | break; |
1071 | case SVt_RV: |
1072 | PerlIO_printf(file, "RV%s\n", s); |
1073 | break; |
1074 | case SVt_PV: |
1075 | PerlIO_printf(file, "PV%s\n", s); |
1076 | break; |
1077 | case SVt_PVIV: |
1078 | PerlIO_printf(file, "PVIV%s\n", s); |
1079 | break; |
1080 | case SVt_PVNV: |
1081 | PerlIO_printf(file, "PVNV%s\n", s); |
1082 | break; |
1083 | case SVt_PVBM: |
1084 | PerlIO_printf(file, "PVBM%s\n", s); |
1085 | break; |
1086 | case SVt_PVMG: |
1087 | PerlIO_printf(file, "PVMG%s\n", s); |
1088 | break; |
1089 | case SVt_PVLV: |
1090 | PerlIO_printf(file, "PVLV%s\n", s); |
1091 | break; |
1092 | case SVt_PVAV: |
1093 | PerlIO_printf(file, "PVAV%s\n", s); |
1094 | break; |
1095 | case SVt_PVHV: |
1096 | PerlIO_printf(file, "PVHV%s\n", s); |
1097 | break; |
1098 | case SVt_PVCV: |
1099 | PerlIO_printf(file, "PVCV%s\n", s); |
1100 | break; |
1101 | case SVt_PVGV: |
1102 | PerlIO_printf(file, "PVGV%s\n", s); |
1103 | break; |
1104 | case SVt_PVFM: |
1105 | PerlIO_printf(file, "PVFM%s\n", s); |
1106 | break; |
1107 | case SVt_PVIO: |
1108 | PerlIO_printf(file, "PVIO%s\n", s); |
1109 | break; |
1110 | default: |
faccc32b |
1111 | PerlIO_printf(file, "UNKNOWN(0x%"UVxf") %s\n", (UV)type, s); |
cea89e20 |
1112 | SvREFCNT_dec(d); |
3967c732 |
1113 | return; |
1114 | } |
1115 | if (type >= SVt_PVIV || type == SVt_IV) { |
765f542d |
1116 | if (SvIsUV(sv) |
1117 | #ifdef PERL_COPY_ON_WRITE |
1118 | || SvIsCOW(sv) |
1119 | #endif |
1120 | ) |
57def98f |
1121 | Perl_dump_indent(aTHX_ level, file, " UV = %"UVuf, (UV)SvUVX(sv)); |
cf2093f6 |
1122 | else |
57def98f |
1123 | Perl_dump_indent(aTHX_ level, file, " IV = %"IVdf, (IV)SvIVX(sv)); |
3967c732 |
1124 | if (SvOOK(sv)) |
1125 | PerlIO_printf(file, " (OFFSET)"); |
765f542d |
1126 | #ifdef PERL_COPY_ON_WRITE |
1127 | if (SvIsCOW_shared_hash(sv)) |
1128 | PerlIO_printf(file, " (HASH)"); |
1129 | else if (SvIsCOW_normal(sv)) |
1130 | PerlIO_printf(file, " (COW from 0x%"UVxf")", (UV)SvUVX(sv)); |
1131 | #endif |
3967c732 |
1132 | PerlIO_putc(file, '\n'); |
1133 | } |
1134 | if (type >= SVt_PVNV || type == SVt_NV) { |
e54dc35b |
1135 | STORE_NUMERIC_LOCAL_SET_STANDARD(); |
57def98f |
1136 | /* %Vg doesn't work? --jhi */ |
cf2093f6 |
1137 | #ifdef USE_LONG_DOUBLE |
2d4389e4 |
1138 | Perl_dump_indent(aTHX_ level, file, " NV = %.*" PERL_PRIgldbl "\n", LDBL_DIG, SvNVX(sv)); |
cf2093f6 |
1139 | #else |
cea2e8a9 |
1140 | Perl_dump_indent(aTHX_ level, file, " NV = %.*g\n", DBL_DIG, SvNVX(sv)); |
cf2093f6 |
1141 | #endif |
e54dc35b |
1142 | RESTORE_NUMERIC_LOCAL(); |
3967c732 |
1143 | } |
1144 | if (SvROK(sv)) { |
57def98f |
1145 | Perl_dump_indent(aTHX_ level, file, " RV = 0x%"UVxf"\n", PTR2UV(SvRV(sv))); |
3967c732 |
1146 | if (nest < maxnest) |
1147 | do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim); |
3967c732 |
1148 | } |
cea89e20 |
1149 | if (type < SVt_PV) { |
1150 | SvREFCNT_dec(d); |
3967c732 |
1151 | return; |
cea89e20 |
1152 | } |
3967c732 |
1153 | if (type <= SVt_PVLV) { |
1154 | if (SvPVX(sv)) { |
57def98f |
1155 | Perl_dump_indent(aTHX_ level, file," PV = 0x%"UVxf" ", PTR2UV(SvPVX(sv))); |
3967c732 |
1156 | if (SvOOK(sv)) |
1157 | PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim)); |
e6abe6d8 |
1158 | PerlIO_printf(file, "%s", pv_display(d, SvPVX(sv), SvCUR(sv), SvLEN(sv), pvlim)); |
1159 | if (SvUTF8(sv)) /* the 8? \x{....} */ |
c728cb41 |
1160 | PerlIO_printf(file, " [UTF8 \"%s\"]", sv_uni_display(d, sv, 8 * sv_len_utf8(sv), UNI_DISPLAY_QQ)); |
e6abe6d8 |
1161 | PerlIO_printf(file, "\n"); |
57def98f |
1162 | Perl_dump_indent(aTHX_ level, file, " CUR = %"IVdf"\n", (IV)SvCUR(sv)); |
1163 | Perl_dump_indent(aTHX_ level, file, " LEN = %"IVdf"\n", (IV)SvLEN(sv)); |
3967c732 |
1164 | } |
1165 | else |
cea2e8a9 |
1166 | Perl_dump_indent(aTHX_ level, file, " PV = 0\n"); |
3967c732 |
1167 | } |
1168 | if (type >= SVt_PVMG) { |
1169 | if (SvMAGIC(sv)) |
1170 | do_magic_dump(level, file, SvMAGIC(sv), nest, maxnest, dumpops, pvlim); |
1171 | if (SvSTASH(sv)) |
1172 | do_hv_dump(level, file, " STASH", SvSTASH(sv)); |
1173 | } |
1174 | switch (type) { |
1175 | case SVt_PVLV: |
cea2e8a9 |
1176 | Perl_dump_indent(aTHX_ level, file, " TYPE = %c\n", LvTYPE(sv)); |
57def98f |
1177 | Perl_dump_indent(aTHX_ level, file, " TARGOFF = %"IVdf"\n", (IV)LvTARGOFF(sv)); |
1178 | Perl_dump_indent(aTHX_ level, file, " TARGLEN = %"IVdf"\n", (IV)LvTARGLEN(sv)); |
1179 | Perl_dump_indent(aTHX_ level, file, " TARG = 0x%"UVxf"\n", PTR2UV(LvTARG(sv))); |
3967c732 |
1180 | /* XXX level+1 ??? */ |
1181 | do_sv_dump(level, file, LvTARG(sv), nest+1, maxnest, dumpops, pvlim); |
1182 | break; |
1183 | case SVt_PVAV: |
57def98f |
1184 | Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(AvARRAY(sv))); |
3967c732 |
1185 | if (AvARRAY(sv) != AvALLOC(sv)) { |
57def98f |
1186 | PerlIO_printf(file, " (offset=%"IVdf")\n", (IV)(AvARRAY(sv) - AvALLOC(sv))); |
1187 | Perl_dump_indent(aTHX_ level, file, " ALLOC = 0x%"UVxf"\n", PTR2UV(AvALLOC(sv))); |
3967c732 |
1188 | } |
1189 | else |
1190 | PerlIO_putc(file, '\n'); |
57def98f |
1191 | Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)AvFILLp(sv)); |
1192 | Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)AvMAX(sv)); |
1193 | Perl_dump_indent(aTHX_ level, file, " ARYLEN = 0x%"UVxf"\n", PTR2UV(AvARYLEN(sv))); |
3967c732 |
1194 | flags = AvFLAGS(sv); |
1195 | sv_setpv(d, ""); |
1196 | if (flags & AVf_REAL) sv_catpv(d, ",REAL"); |
1197 | if (flags & AVf_REIFY) sv_catpv(d, ",REIFY"); |
1198 | if (flags & AVf_REUSED) sv_catpv(d, ",REUSED"); |
cea2e8a9 |
1199 | Perl_dump_indent(aTHX_ level, file, " FLAGS = (%s)\n", SvCUR(d) ? SvPVX(d) + 1 : ""); |
3967c732 |
1200 | if (nest < maxnest && av_len((AV*)sv) >= 0) { |
1201 | int count; |
1202 | for (count = 0; count <= av_len((AV*)sv) && count < maxnest; count++) { |
1203 | SV** elt = av_fetch((AV*)sv,count,0); |
1204 | |
57def98f |
1205 | Perl_dump_indent(aTHX_ level + 1, file, "Elt No. %"IVdf"\n", (IV)count); |
2ef28da1 |
1206 | if (elt) |
3967c732 |
1207 | do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim); |
1208 | } |
1209 | } |
1210 | break; |
1211 | case SVt_PVHV: |
57def98f |
1212 | Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv))); |
3967c732 |
1213 | if (HvARRAY(sv) && HvKEYS(sv)) { |
1214 | /* Show distribution of HEs in the ARRAY */ |
1215 | int freq[200]; |
1216 | #define FREQ_MAX (sizeof freq / sizeof freq[0] - 1) |
1217 | int i; |
1218 | int max = 0; |
1219 | U32 pow2 = 2, keys = HvKEYS(sv); |
65202027 |
1220 | NV theoret, sum = 0; |
3967c732 |
1221 | |
1222 | PerlIO_printf(file, " ("); |
1223 | Zero(freq, FREQ_MAX + 1, int); |
eb160463 |
1224 | for (i = 0; (STRLEN)i <= HvMAX(sv); i++) { |
3967c732 |
1225 | HE* h; int count = 0; |
1226 | for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h)) |
1227 | count++; |
1228 | if (count > FREQ_MAX) |
1229 | count = FREQ_MAX; |
1230 | freq[count]++; |
1231 | if (max < count) |
1232 | max = count; |
1233 | } |
1234 | for (i = 0; i <= max; i++) { |
1235 | if (freq[i]) { |
1236 | PerlIO_printf(file, "%d%s:%d", i, |
1237 | (i == FREQ_MAX) ? "+" : "", |
1238 | freq[i]); |
1239 | if (i != max) |
1240 | PerlIO_printf(file, ", "); |
1241 | } |
1242 | } |
1243 | PerlIO_putc(file, ')'); |
b8fa94d8 |
1244 | /* The "quality" of a hash is defined as the total number of |
1245 | comparisons needed to access every element once, relative |
1246 | to the expected number needed for a random hash. |
1247 | |
1248 | The total number of comparisons is equal to the sum of |
e76cd0fa |
1249 | the squares of the number of entries in each bucket. |
1250 | For a random hash of n keys into k buckets, the expected |
b8fa94d8 |
1251 | value is |
1252 | n + n(n-1)/2k |
1253 | */ |
1254 | |
3967c732 |
1255 | for (i = max; i > 0; i--) { /* Precision: count down. */ |
1256 | sum += freq[i] * i * i; |
1257 | } |
155aba94 |
1258 | while ((keys = keys >> 1)) |
3967c732 |
1259 | pow2 = pow2 << 1; |
3967c732 |
1260 | theoret = HvKEYS(sv); |
b8fa94d8 |
1261 | theoret += theoret * (theoret-1)/pow2; |
3967c732 |
1262 | PerlIO_putc(file, '\n'); |
6b4667fc |
1263 | Perl_dump_indent(aTHX_ level, file, " hash quality = %.1"NVff"%%", theoret/sum*100); |
3967c732 |
1264 | } |
1265 | PerlIO_putc(file, '\n'); |
57def98f |
1266 | Perl_dump_indent(aTHX_ level, file, " KEYS = %"IVdf"\n", (IV)HvKEYS(sv)); |
1267 | Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)HvFILL(sv)); |
1268 | Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)HvMAX(sv)); |
1269 | Perl_dump_indent(aTHX_ level, file, " RITER = %"IVdf"\n", (IV)HvRITER(sv)); |
1270 | Perl_dump_indent(aTHX_ level, file, " EITER = 0x%"UVxf"\n", PTR2UV(HvEITER(sv))); |
3967c732 |
1271 | if (HvPMROOT(sv)) |
57def98f |
1272 | Perl_dump_indent(aTHX_ level, file, " PMROOT = 0x%"UVxf"\n", PTR2UV(HvPMROOT(sv))); |
3967c732 |
1273 | if (HvNAME(sv)) |
cea2e8a9 |
1274 | Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", HvNAME(sv)); |
3967c732 |
1275 | if (nest < maxnest && !HvEITER(sv)) { /* Try to preserve iterator */ |
1276 | HE *he; |
1277 | HV *hv = (HV*)sv; |
1278 | int count = maxnest - nest; |
1279 | |
1280 | hv_iterinit(hv); |
e16e2ff8 |
1281 | while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) |
1282 | && count--) { |
98c991d1 |
1283 | SV *elt, *keysv; |
1284 | char *keypv; |
1285 | STRLEN len; |
3967c732 |
1286 | U32 hash = HeHASH(he); |
1287 | |
98c991d1 |
1288 | keysv = hv_iterkeysv(he); |
1289 | keypv = SvPV(keysv, len); |
3967c732 |
1290 | elt = hv_iterval(hv, he); |
98c991d1 |
1291 | Perl_dump_indent(aTHX_ level+1, file, "Elt %s ", pv_display(d, keypv, len, 0, pvlim)); |
1292 | if (SvUTF8(keysv)) |
c728cb41 |
1293 | PerlIO_printf(file, "[UTF8 \"%s\"] ", sv_uni_display(d, keysv, 8 * sv_len_utf8(keysv), UNI_DISPLAY_QQ)); |
98c991d1 |
1294 | PerlIO_printf(file, "HASH = 0x%"UVxf"\n", (UV)hash); |
3967c732 |
1295 | do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim); |
1296 | } |
1297 | hv_iterinit(hv); /* Return to status quo */ |
1298 | } |
1299 | break; |
1300 | case SVt_PVCV: |
1301 | if (SvPOK(sv)) |
7f848b6b |
1302 | Perl_dump_indent(aTHX_ level, file, " PROTOTYPE = \"%s\"\n", SvPV_nolen(sv)); |
3967c732 |
1303 | /* FALL THROUGH */ |
1304 | case SVt_PVFM: |
1305 | do_hv_dump(level, file, " COMP_STASH", CvSTASH(sv)); |
1306 | if (CvSTART(sv)) |
57def98f |
1307 | Perl_dump_indent(aTHX_ level, file, " START = 0x%"UVxf" ===> %"IVdf"\n", PTR2UV(CvSTART(sv)), (IV)CvSTART(sv)->op_seq); |
1308 | Perl_dump_indent(aTHX_ level, file, " ROOT = 0x%"UVxf"\n", PTR2UV(CvROOT(sv))); |
3967c732 |
1309 | if (CvROOT(sv) && dumpops) |
1310 | do_op_dump(level+1, file, CvROOT(sv)); |
57def98f |
1311 | Perl_dump_indent(aTHX_ level, file, " XSUB = 0x%"UVxf"\n", PTR2UV(CvXSUB(sv))); |
1312 | Perl_dump_indent(aTHX_ level, file, " XSUBANY = %"IVdf"\n", (IV)CvXSUBANY(sv).any_i32); |
3967c732 |
1313 | do_gvgv_dump(level, file, " GVGV::GV", CvGV(sv)); |
57843af0 |
1314 | Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", CvFILE(sv)); |
57def98f |
1315 | Perl_dump_indent(aTHX_ level, file, " DEPTH = %"IVdf"\n", (IV)CvDEPTH(sv)); |
894356b3 |
1316 | Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)CvFLAGS(sv)); |
a3985cdc |
1317 | Perl_dump_indent(aTHX_ level, file, " OUTSIDE_SEQ = %"UVuf"\n", (UV)CvOUTSIDE_SEQ(sv)); |
3967c732 |
1318 | if (type == SVt_PVFM) |
57def98f |
1319 | Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)FmLINES(sv)); |
1320 | Perl_dump_indent(aTHX_ level, file, " PADLIST = 0x%"UVxf"\n", PTR2UV(CvPADLIST(sv))); |
dd2155a4 |
1321 | if (nest < maxnest) { |
1322 | do_dump_pad(level+1, file, CvPADLIST(sv), 0); |
3967c732 |
1323 | } |
1324 | { |
1325 | CV *outside = CvOUTSIDE(sv); |
2ef28da1 |
1326 | Perl_dump_indent(aTHX_ level, file, " OUTSIDE = 0x%"UVxf" (%s)\n", |
57def98f |
1327 | PTR2UV(outside), |
cf2093f6 |
1328 | (!outside ? "null" |
1329 | : CvANON(outside) ? "ANON" |
1330 | : (outside == PL_main_cv) ? "MAIN" |
1331 | : CvUNIQUE(outside) ? "UNIQUE" |
1332 | : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED")); |
3967c732 |
1333 | } |
1334 | if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv))) |
1335 | do_sv_dump(level+1, file, (SV*)CvOUTSIDE(sv), nest+1, maxnest, dumpops, pvlim); |
1336 | break; |
1337 | case SVt_PVGV: |
cea2e8a9 |
1338 | Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", GvNAME(sv)); |
57def98f |
1339 | Perl_dump_indent(aTHX_ level, file, " NAMELEN = %"IVdf"\n", (IV)GvNAMELEN(sv)); |
3967c732 |
1340 | do_hv_dump (level, file, " GvSTASH", GvSTASH(sv)); |
57def98f |
1341 | Perl_dump_indent(aTHX_ level, file, " GP = 0x%"UVxf"\n", PTR2UV(GvGP(sv))); |
f472eb5c |
1342 | if (!GvGP(sv)) |
1343 | break; |
57def98f |
1344 | Perl_dump_indent(aTHX_ level, file, " SV = 0x%"UVxf"\n", PTR2UV(GvSV(sv))); |
1345 | Perl_dump_indent(aTHX_ level, file, " REFCNT = %"IVdf"\n", (IV)GvREFCNT(sv)); |
1346 | Perl_dump_indent(aTHX_ level, file, " IO = 0x%"UVxf"\n", PTR2UV(GvIOp(sv))); |
1347 | Perl_dump_indent(aTHX_ level, file, " FORM = 0x%"UVxf" \n", PTR2UV(GvFORM(sv))); |
1348 | Perl_dump_indent(aTHX_ level, file, " AV = 0x%"UVxf"\n", PTR2UV(GvAV(sv))); |
1349 | Perl_dump_indent(aTHX_ level, file, " HV = 0x%"UVxf"\n", PTR2UV(GvHV(sv))); |
1350 | Perl_dump_indent(aTHX_ level, file, " CV = 0x%"UVxf"\n", PTR2UV(GvCV(sv))); |
1351 | Perl_dump_indent(aTHX_ level, file, " CVGEN = 0x%"UVxf"\n", (UV)GvCVGEN(sv)); |
f4c556ac |
1352 | Perl_dump_indent(aTHX_ level, file, " GPFLAGS = 0x%"UVxf"\n", (UV)GvGPFLAGS(sv)); |
57def98f |
1353 | Perl_dump_indent(aTHX_ level, file, " LINE = %"IVdf"\n", (IV)GvLINE(sv)); |
b195d487 |
1354 | Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", GvFILE(sv)); |
e39917cc |
1355 | Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)GvFLAGS(sv)); |
3967c732 |
1356 | do_gv_dump (level, file, " EGV", GvEGV(sv)); |
1357 | break; |
1358 | case SVt_PVIO: |
57def98f |
1359 | Perl_dump_indent(aTHX_ level, file, " IFP = 0x%"UVxf"\n", PTR2UV(IoIFP(sv))); |
1360 | Perl_dump_indent(aTHX_ level, file, " OFP = 0x%"UVxf"\n", PTR2UV(IoOFP(sv))); |
1361 | Perl_dump_indent(aTHX_ level, file, " DIRP = 0x%"UVxf"\n", PTR2UV(IoDIRP(sv))); |
1362 | Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)IoLINES(sv)); |
1363 | Perl_dump_indent(aTHX_ level, file, " PAGE = %"IVdf"\n", (IV)IoPAGE(sv)); |
1364 | Perl_dump_indent(aTHX_ level, file, " PAGE_LEN = %"IVdf"\n", (IV)IoPAGE_LEN(sv)); |
1365 | Perl_dump_indent(aTHX_ level, file, " LINES_LEFT = %"IVdf"\n", (IV)IoLINES_LEFT(sv)); |
27533608 |
1366 | if (IoTOP_NAME(sv)) |
cea2e8a9 |
1367 | Perl_dump_indent(aTHX_ level, file, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv)); |
3967c732 |
1368 | do_gv_dump (level, file, " TOP_GV", IoTOP_GV(sv)); |
27533608 |
1369 | if (IoFMT_NAME(sv)) |
cea2e8a9 |
1370 | Perl_dump_indent(aTHX_ level, file, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv)); |
3967c732 |
1371 | do_gv_dump (level, file, " FMT_GV", IoFMT_GV(sv)); |
27533608 |
1372 | if (IoBOTTOM_NAME(sv)) |
cea2e8a9 |
1373 | Perl_dump_indent(aTHX_ level, file, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv)); |
3967c732 |
1374 | do_gv_dump (level, file, " BOTTOM_GV", IoBOTTOM_GV(sv)); |
57def98f |
1375 | Perl_dump_indent(aTHX_ level, file, " SUBPROCESS = %"IVdf"\n", (IV)IoSUBPROCESS(sv)); |
27533608 |
1376 | if (isPRINT(IoTYPE(sv))) |
cea2e8a9 |
1377 | Perl_dump_indent(aTHX_ level, file, " TYPE = '%c'\n", IoTYPE(sv)); |
27533608 |
1378 | else |
cea2e8a9 |
1379 | Perl_dump_indent(aTHX_ level, file, " TYPE = '\\%o'\n", IoTYPE(sv)); |
57def98f |
1380 | Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)IoFLAGS(sv)); |
3967c732 |
1381 | break; |
1382 | } |
cea89e20 |
1383 | SvREFCNT_dec(d); |
3967c732 |
1384 | } |
1385 | |
1386 | void |
864dbfa3 |
1387 | Perl_sv_dump(pTHX_ SV *sv) |
3967c732 |
1388 | { |
1389 | do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0); |
8d063cd8 |
1390 | } |
bd16a5f0 |
1391 | |
1392 | int |
1393 | Perl_runops_debug(pTHX) |
1394 | { |
1395 | if (!PL_op) { |
1396 | if (ckWARN_d(WARN_DEBUGGING)) |
9014280d |
1397 | Perl_warner(aTHX_ packWARN(WARN_DEBUGGING), "NULL OP IN RUN"); |
bd16a5f0 |
1398 | return 0; |
1399 | } |
1400 | |
1401 | do { |
1402 | PERL_ASYNC_CHECK(); |
1403 | if (PL_debug) { |
1404 | if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok) |
1405 | PerlIO_printf(Perl_debug_log, |
1406 | "WARNING: %"UVxf" changed from %"UVxf" to %"UVxf"\n", |
1407 | PTR2UV(PL_watchaddr), PTR2UV(PL_watchok), |
1408 | PTR2UV(*PL_watchaddr)); |
d6721266 |
1409 | if (DEBUG_s_TEST_) { |
1410 | if (DEBUG_v_TEST_) { |
1411 | PerlIO_printf(Perl_debug_log, "\n"); |
1412 | deb_stack_all(); |
1413 | } |
1414 | else |
1415 | debstack(); |
1416 | } |
1417 | |
1418 | |
bd16a5f0 |
1419 | if (DEBUG_t_TEST_) debop(PL_op); |
1420 | if (DEBUG_P_TEST_) debprof(PL_op); |
1421 | } |
1422 | } while ((PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX))); |
1423 | |
1424 | TAINT_NOT; |
1425 | return 0; |
1426 | } |
1427 | |
1428 | I32 |
1429 | Perl_debop(pTHX_ OP *o) |
1430 | { |
1431 | AV *padlist, *comppad; |
1432 | CV *cv; |
1433 | SV *sv; |
1045810a |
1434 | |
1435 | if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_) |
1436 | return 0; |
1437 | |
bd16a5f0 |
1438 | Perl_deb(aTHX_ "%s", OP_NAME(o)); |
1439 | switch (o->op_type) { |
1440 | case OP_CONST: |
1441 | PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo_sv)); |
1442 | break; |
1443 | case OP_GVSV: |
1444 | case OP_GV: |
1445 | if (cGVOPo_gv) { |
1446 | sv = NEWSV(0,0); |
1447 | gv_fullname3(sv, cGVOPo_gv, Nullch); |
35c1215d |
1448 | PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen(sv)); |
bd16a5f0 |
1449 | SvREFCNT_dec(sv); |
1450 | } |
1451 | else |
1452 | PerlIO_printf(Perl_debug_log, "(NULL)"); |
1453 | break; |
1454 | case OP_PADSV: |
1455 | case OP_PADAV: |
1456 | case OP_PADHV: |
1457 | /* print the lexical's name */ |
1458 | cv = deb_curcv(cxstack_ix); |
1459 | if (cv) { |
1460 | padlist = CvPADLIST(cv); |
1461 | comppad = (AV*)(*av_fetch(padlist, 0, FALSE)); |
1462 | sv = *av_fetch(comppad, o->op_targ, FALSE); |
1463 | } else |
1464 | sv = Nullsv; |
1465 | if (sv) |
1466 | PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen(sv)); |
1467 | else |
1468 | PerlIO_printf(Perl_debug_log, "[%"UVuf"]", (UV)o->op_targ); |
1469 | break; |
1470 | default: |
091ab601 |
1471 | break; |
bd16a5f0 |
1472 | } |
1473 | PerlIO_printf(Perl_debug_log, "\n"); |
1474 | return 0; |
1475 | } |
1476 | |
1477 | STATIC CV* |
1478 | S_deb_curcv(pTHX_ I32 ix) |
1479 | { |
1480 | PERL_CONTEXT *cx = &cxstack[ix]; |
1481 | if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) |
1482 | return cx->blk_sub.cv; |
1483 | else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx)) |
1484 | return PL_compcv; |
1485 | else if (ix == 0 && PL_curstackinfo->si_type == PERLSI_MAIN) |
1486 | return PL_main_cv; |
1487 | else if (ix <= 0) |
1488 | return Nullcv; |
1489 | else |
1490 | return deb_curcv(ix - 1); |
1491 | } |
1492 | |
1493 | void |
1494 | Perl_watch(pTHX_ char **addr) |
1495 | { |
1496 | PL_watchaddr = addr; |
1497 | PL_watchok = *addr; |
1498 | PerlIO_printf(Perl_debug_log, "WATCHING, %"UVxf" is currently %"UVxf"\n", |
1499 | PTR2UV(PL_watchaddr), PTR2UV(PL_watchok)); |
1500 | } |
1501 | |
1502 | STATIC void |
1503 | S_debprof(pTHX_ OP *o) |
1504 | { |
1045810a |
1505 | if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_) |
1506 | return; |
bd16a5f0 |
1507 | if (!PL_profiledata) |
1508 | Newz(000, PL_profiledata, MAXO, U32); |
1509 | ++PL_profiledata[o->op_type]; |
1510 | } |
1511 | |
1512 | void |
1513 | Perl_debprofdump(pTHX) |
1514 | { |
1515 | unsigned i; |
1516 | if (!PL_profiledata) |
1517 | return; |
1518 | for (i = 0; i < MAXO; i++) { |
1519 | if (PL_profiledata[i]) |
1520 | PerlIO_printf(Perl_debug_log, |
1521 | "%5lu %s\n", (unsigned long)PL_profiledata[i], |
1522 | PL_op_name[i]); |
1523 | } |
1524 | } |