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