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