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