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