3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, by Larry Wall and others
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.
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.'"
16 /* This file contains utility routines to dump the contents of SV and OP
17 * structures, as used by command-line options like -Dt and -Dx, and
20 * It also holds the debugging version of the runops function.
24 #define PERL_IN_DUMP_C
30 #define Sequence PL_op_sequence
33 Perl_dump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
37 dump_vindent(level, file, pat, &args);
42 Perl_dump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args)
45 PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), "");
46 PerlIO_vprintf(file, pat, *args);
53 PerlIO_setlinebuf(Perl_debug_log);
55 op_dump(PL_main_root);
56 dump_packsubs(PL_defstash);
60 Perl_dump_packsubs(pTHX_ const HV *stash)
67 for (i = 0; i <= (I32) HvMAX(stash); i++) {
69 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
70 const GV *gv = (GV*)HeVAL(entry);
72 if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
78 if (HeKEY(entry)[HeKLEN(entry)-1] == ':'
79 && (hv = GvHV(gv)) && hv != PL_defstash)
80 dump_packsubs(hv); /* nested package */
86 Perl_dump_sub(pTHX_ const GV *gv)
88 SV * const sv = sv_newmortal();
90 gv_fullname3(sv, gv, NULL);
91 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ", SvPVX_const(sv));
93 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "(xsub 0x%"UVxf" %d)\n",
94 PTR2UV(CvXSUB(GvCV(gv))),
95 (int)CvXSUBANY(GvCV(gv)).any_i32);
96 else if (CvROOT(GvCV(gv)))
97 op_dump(CvROOT(GvCV(gv)));
99 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
103 Perl_dump_form(pTHX_ const GV *gv)
105 SV * const sv = sv_newmortal();
107 gv_fullname3(sv, gv, NULL);
108 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nFORMAT %s = ", SvPVX_const(sv));
109 if (CvROOT(GvFORM(gv)))
110 op_dump(CvROOT(GvFORM(gv)));
112 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
119 op_dump(PL_eval_root);
123 Perl_pv_display(pTHX_ SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
125 const bool nul_terminated = len > cur && pv[cur] == '\0';
128 sv_setpvn(dsv, "\"", 1);
129 for (; cur--; pv++) {
130 if (pvlim && SvCUR(dsv) >= pvlim) {
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;
143 sv_catpvn(dsv, pv, 1);
144 else if (cur && isDIGIT(*(pv+1)))
145 Perl_sv_catpvf(aTHX_ dsv, "\\%03o", (U8)*pv);
147 Perl_sv_catpvf(aTHX_ dsv, "\\%o", (U8)*pv);
150 sv_catpvs(dsv, "\"");
152 sv_catpvs(dsv, "...");
154 sv_catpvs(dsv, "\\0");
160 Perl_sv_peek(pTHX_ SV *sv)
163 SV * const t = sv_newmortal();
172 else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') {
176 else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) {
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)) &&
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|
194 else if (sv == &PL_sv_yes) {
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|
201 SvPVX_const(sv) && *SvPVX_const(sv) == '1' &&
206 sv_catpv(t, "SV_PLACEHOLDER");
207 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
208 SVs_GMG|SVs_SMG|SVs_RMG)) &&
214 else if (SvREFCNT(sv) == 0) {
218 else if (DEBUG_R_TEST_) {
221 /* is this SV on the tmps stack? */
222 for (ix=PL_tmps_ix; ix>=0; ix--) {
223 if (PL_tmps_stack[ix] == sv) {
228 if (SvREFCNT(sv) > 1)
229 Perl_sv_catpvf(aTHX_ t, "<%"UVuf"%s>", (UV)SvREFCNT(sv),
237 if (SvCUR(t) + unref > 10) {
238 SvCUR_set(t, unref + 3);
246 switch (SvTYPE(sv)) {
248 sv_catpv(t, "FREED");
252 sv_catpv(t, "UNDEF");
286 Perl_sv_catpvf(aTHX_ t, "CV(%s)", GvNAME(CvGV(sv)));
305 if (!SvPVX_const(sv))
306 sv_catpv(t, "(null)");
308 SV *tmp = newSVpvs("");
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));
314 Perl_sv_catpvf(aTHX_ t, " [UTF8 \"%s\"]",
315 sv_uni_display(tmp, sv, 8 * sv_len_utf8(sv),
320 else if (SvNOKp(sv)) {
321 STORE_NUMERIC_LOCAL_SET_STANDARD();
322 Perl_sv_catpvf(aTHX_ t, "(%"NVgf")",SvNVX(sv));
323 RESTORE_NUMERIC_LOCAL();
325 else if (SvIOKp(sv)) {
327 Perl_sv_catpvf(aTHX_ t, "(%"UVuf")", (UV)SvUVX(sv));
329 Perl_sv_catpvf(aTHX_ t, "(%"IVdf")", (IV)SvIVX(sv));
339 return SvPV_nolen(t);
343 Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, const PMOP *pm)
348 Perl_dump_indent(aTHX_ level, file, "{}\n");
351 Perl_dump_indent(aTHX_ level, file, "{\n");
353 if (pm->op_pmflags & PMf_ONCE)
358 Perl_dump_indent(aTHX_ level, file, "PMf_PRE %c%s%c%s\n",
359 ch, PM_GETRE(pm)->precomp, ch,
360 (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
362 Perl_dump_indent(aTHX_ level, file, "PMf_PRE (RUNTIME)\n");
363 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
364 Perl_dump_indent(aTHX_ level, file, "PMf_REPL = ");
365 op_dump(pm->op_pmreplroot);
367 if (pm->op_pmflags || (PM_GETRE(pm) && PM_GETRE(pm)->check_substr)) {
368 SV *tmpsv = newSVpvs("");
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");
375 if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr
376 && !(PM_GETRE(pm)->reganch & ROPT_NOSCAN))
377 sv_catpv(tmpsv, ",SCANFIRST");
378 if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr
379 && PM_GETRE(pm)->reganch & ROPT_CHECK_ALL)
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");
395 Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
399 Perl_dump_indent(aTHX_ level-1, file, "}\n");
403 Perl_pmop_dump(pTHX_ PMOP *pm)
405 do_pmop_dump(0, Perl_debug_log, pm);
408 /* An op sequencer. We visit the ops in the order they're to execute. */
411 S_sequence(pTHX_ register const OP *o)
417 const OP *oldop = NULL;
426 for (; o; o = o->op_next) {
427 op = newSVuv(PTR2UV(o));
428 key = SvPV_const(op, len);
429 if (hv_exists(Sequence, key, len))
432 switch (o->op_type) {
434 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
435 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
440 if (oldop && o->op_next)
447 if (oldop && o->op_next)
449 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
462 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
463 for (l = cLOGOPo->op_other; l && l->op_type == OP_NULL; l = l->op_next)
470 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
471 for (l = cLOOPo->op_redoop; l && l->op_type == OP_NULL; l = l->op_next)
474 for (l = cLOOPo->op_nextop; l && l->op_type == OP_NULL; l = l->op_next)
477 for (l = cLOOPo->op_lastop; l && l->op_type == OP_NULL; l = l->op_next)
485 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
486 for (l = cPMOPo->op_pmreplstart; l && l->op_type == OP_NULL; l = l->op_next)
495 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
503 S_sequence_num(pTHX_ const OP *o)
511 op = newSVuv(PTR2UV(o));
512 key = SvPV_const(op, len);
513 seq = hv_fetch(Sequence, key, len, 0);
514 return seq ? SvUV(*seq): 0;
518 Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
523 Perl_dump_indent(aTHX_ level, file, "{\n");
525 seq = sequence_num(o);
527 PerlIO_printf(file, "%-4"UVf, seq);
529 PerlIO_printf(file, " ");
531 "%*sTYPE = %s ===> ",
532 (int)(PL_dumpindent*level-4), "", OP_NAME(o));
534 PerlIO_printf(file, seq ? "%"UVf"\n" : "(%"UVf")\n",
535 sequence_num(o->op_next));
537 PerlIO_printf(file, "DONE\n");
539 if (o->op_type == OP_NULL)
541 Perl_dump_indent(aTHX_ level, file, " (was %s)\n", PL_op_name[o->op_targ]);
542 if (o->op_targ == OP_NEXTSTATE)
545 Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n",
547 if (CopSTASHPV(cCOPo))
548 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
550 if (cCOPo->cop_label)
551 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
556 Perl_dump_indent(aTHX_ level, file, "TARG = %ld\n", (long)o->op_targ);
559 Perl_dump_indent(aTHX_ level, file, "ADDR = 0x%"UVxf" => 0x%"UVxf"\n", (UV)o, (UV)o->op_next);
562 SV *tmpsv = newSVpvs("");
563 switch (o->op_flags & OPf_WANT) {
565 sv_catpv(tmpsv, ",VOID");
567 case OPf_WANT_SCALAR:
568 sv_catpv(tmpsv, ",SCALAR");
571 sv_catpv(tmpsv, ",LIST");
574 sv_catpv(tmpsv, ",UNKNOWN");
577 if (o->op_flags & OPf_KIDS)
578 sv_catpv(tmpsv, ",KIDS");
579 if (o->op_flags & OPf_PARENS)
580 sv_catpv(tmpsv, ",PARENS");
581 if (o->op_flags & OPf_STACKED)
582 sv_catpv(tmpsv, ",STACKED");
583 if (o->op_flags & OPf_REF)
584 sv_catpv(tmpsv, ",REF");
585 if (o->op_flags & OPf_MOD)
586 sv_catpv(tmpsv, ",MOD");
587 if (o->op_flags & OPf_SPECIAL)
588 sv_catpv(tmpsv, ",SPECIAL");
589 Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
593 SV *tmpsv = newSVpvs("");
594 if (PL_opargs[o->op_type] & OA_TARGLEX) {
595 if (o->op_private & OPpTARGET_MY)
596 sv_catpv(tmpsv, ",TARGET_MY");
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");
605 else if (o->op_type == OP_AASSIGN) {
606 if (o->op_private & OPpASSIGN_COMMON)
607 sv_catpv(tmpsv, ",COMMON");
609 else if (o->op_type == OP_SASSIGN) {
610 if (o->op_private & OPpASSIGN_BACKWARDS)
611 sv_catpv(tmpsv, ",BACKWARDS");
613 else if (o->op_type == OP_TRANS) {
614 if (o->op_private & OPpTRANS_SQUASH)
615 sv_catpv(tmpsv, ",SQUASH");
616 if (o->op_private & OPpTRANS_DELETE)
617 sv_catpv(tmpsv, ",DELETE");
618 if (o->op_private & OPpTRANS_COMPLEMENT)
619 sv_catpv(tmpsv, ",COMPLEMENT");
620 if (o->op_private & OPpTRANS_IDENTICAL)
621 sv_catpv(tmpsv, ",IDENTICAL");
622 if (o->op_private & OPpTRANS_GROWS)
623 sv_catpv(tmpsv, ",GROWS");
625 else if (o->op_type == OP_REPEAT) {
626 if (o->op_private & OPpREPEAT_DOLIST)
627 sv_catpv(tmpsv, ",DOLIST");
629 else if (o->op_type == OP_ENTERSUB ||
630 o->op_type == OP_RV2SV ||
631 o->op_type == OP_GVSV ||
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 )
638 if (o->op_type == OP_ENTERSUB) {
639 if (o->op_private & OPpENTERSUB_AMPER)
640 sv_catpv(tmpsv, ",AMPER");
641 if (o->op_private & OPpENTERSUB_DB)
642 sv_catpv(tmpsv, ",DB");
643 if (o->op_private & OPpENTERSUB_HASTARG)
644 sv_catpv(tmpsv, ",HASTARG");
645 if (o->op_private & OPpENTERSUB_NOPAREN)
646 sv_catpv(tmpsv, ",NOPAREN");
647 if (o->op_private & OPpENTERSUB_INARGS)
648 sv_catpv(tmpsv, ",INARGS");
649 if (o->op_private & OPpENTERSUB_NOMOD)
650 sv_catpv(tmpsv, ",NOMOD");
653 switch (o->op_private & OPpDEREF) {
655 sv_catpv(tmpsv, ",SV");
658 sv_catpv(tmpsv, ",AV");
661 sv_catpv(tmpsv, ",HV");
664 if (o->op_private & OPpMAYBE_LVSUB)
665 sv_catpv(tmpsv, ",MAYBE_LVSUB");
667 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
668 if (o->op_private & OPpLVAL_DEFER)
669 sv_catpv(tmpsv, ",LVAL_DEFER");
672 if (o->op_private & HINT_STRICT_REFS)
673 sv_catpv(tmpsv, ",STRICT_REFS");
674 if (o->op_private & OPpOUR_INTRO)
675 sv_catpv(tmpsv, ",OUR_INTRO");
678 else if (o->op_type == OP_CONST) {
679 if (o->op_private & OPpCONST_BARE)
680 sv_catpv(tmpsv, ",BARE");
681 if (o->op_private & OPpCONST_STRICT)
682 sv_catpv(tmpsv, ",STRICT");
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");
690 else if (o->op_type == OP_FLIP) {
691 if (o->op_private & OPpFLIP_LINENUM)
692 sv_catpv(tmpsv, ",LINENUM");
694 else if (o->op_type == OP_FLOP) {
695 if (o->op_private & OPpFLIP_LINENUM)
696 sv_catpv(tmpsv, ",LINENUM");
698 else if (o->op_type == OP_RV2CV) {
699 if (o->op_private & OPpLVAL_INTRO)
700 sv_catpv(tmpsv, ",INTRO");
702 else if (o->op_type == OP_GV) {
703 if (o->op_private & OPpEARLY_CV)
704 sv_catpv(tmpsv, ",EARLY_CV");
706 else if (o->op_type == OP_LIST) {
707 if (o->op_private & OPpLIST_GUESSED)
708 sv_catpv(tmpsv, ",GUESSED");
710 else if (o->op_type == OP_DELETE) {
711 if (o->op_private & OPpSLICE)
712 sv_catpv(tmpsv, ",SLICE");
714 else if (o->op_type == OP_EXISTS) {
715 if (o->op_private & OPpEXISTS_SUB)
716 sv_catpv(tmpsv, ",EXISTS_SUB");
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");
726 else if (o->op_type == OP_THREADSV) {
727 if (o->op_private & OPpDONE_SVREF)
728 sv_catpv(tmpsv, ",SVREF");
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");
740 else if (o->op_type == OP_EXIT) {
741 if (o->op_private & OPpEXIT_VMSISH)
742 sv_catpv(tmpsv, ",EXIT_VMSISH");
743 if (o->op_private & OPpHUSH_VMSISH)
744 sv_catpv(tmpsv, ",HUSH_VMSISH");
746 else if (o->op_type == OP_DIE) {
747 if (o->op_private & OPpHUSH_VMSISH)
748 sv_catpv(tmpsv, ",HUSH_VMSISH");
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");
756 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
757 sv_catpv(tmpsv, ",INTRO");
759 Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX_const(tmpsv) + 1);
763 switch (o->op_type) {
768 Perl_dump_indent(aTHX_ level, file, "PADIX = %" IVdf "\n", (IV)cPADOPo->op_padix);
770 if ( ! PL_op->op_flags & OPf_SPECIAL) { /* not lexical */
772 SV *tmpsv = newSV(0);
775 gv_fullname3(tmpsv, (GV*)cSVOPo->op_sv, NULL);
776 Perl_dump_indent(aTHX_ level, file, "GV = %s\n",
777 SvPV_nolen_const(tmpsv));
781 Perl_dump_indent(aTHX_ level, file, "GV = NULL\n");
786 case OP_METHOD_NAMED:
788 /* with ITHREADS, consts are stored in the pad, and the right pad
789 * may not be active here, so skip */
790 Perl_dump_indent(aTHX_ level, file, "SV = %s\n", SvPEEK(cSVOPo_sv));
797 Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n",
799 if (CopSTASHPV(cCOPo))
800 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
802 if (cCOPo->cop_label)
803 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
807 Perl_dump_indent(aTHX_ level, file, "REDO ===> ");
808 if (cLOOPo->op_redoop)
809 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_redoop));
811 PerlIO_printf(file, "DONE\n");
812 Perl_dump_indent(aTHX_ level, file, "NEXT ===> ");
813 if (cLOOPo->op_nextop)
814 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_nextop));
816 PerlIO_printf(file, "DONE\n");
817 Perl_dump_indent(aTHX_ level, file, "LAST ===> ");
818 if (cLOOPo->op_lastop)
819 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_lastop));
821 PerlIO_printf(file, "DONE\n");
829 Perl_dump_indent(aTHX_ level, file, "OTHER ===> ");
830 if (cLOGOPo->op_other)
831 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOGOPo->op_other));
833 PerlIO_printf(file, "DONE\n");
839 do_pmop_dump(level, file, cPMOPo);
847 if (o->op_private & OPpREFCOUNTED)
848 Perl_dump_indent(aTHX_ level, file, "REFCNT = %"UVuf"\n", (UV)o->op_targ);
853 if (o->op_flags & OPf_KIDS) {
855 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
856 do_op_dump(level, file, kid);
858 Perl_dump_indent(aTHX_ level-1, file, "}\n");
862 Perl_op_dump(pTHX_ const OP *o)
864 do_op_dump(0, Perl_debug_log, o);
868 Perl_gv_dump(pTHX_ GV *gv)
873 PerlIO_printf(Perl_debug_log, "{}\n");
877 PerlIO_printf(Perl_debug_log, "{\n");
878 gv_fullname3(sv, gv, NULL);
879 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s", SvPVX_const(sv));
880 if (gv != GvEGV(gv)) {
881 gv_efullname3(sv, GvEGV(gv), NULL);
882 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s", SvPVX_const(sv));
884 PerlIO_putc(Perl_debug_log, '\n');
885 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "}\n");
889 /* map magic types to the symbolic names
890 * (with the PERL_MAGIC_ prefixed stripped)
893 static const struct { const char type; const char *name; } magic_names[] = {
894 { PERL_MAGIC_sv, "sv(\\0)" },
895 { PERL_MAGIC_arylen, "arylen(#)" },
896 { PERL_MAGIC_rhash, "rhash(%)" },
897 { PERL_MAGIC_glob, "glob(*)" },
898 { PERL_MAGIC_pos, "pos(.)" },
899 { PERL_MAGIC_symtab, "symtab(:)" },
900 { PERL_MAGIC_backref, "backref(<)" },
901 { PERL_MAGIC_arylen_p, "arylen_p(@)" },
902 { PERL_MAGIC_overload, "overload(A)" },
903 { PERL_MAGIC_bm, "bm(B)" },
904 { PERL_MAGIC_regdata, "regdata(D)" },
905 { PERL_MAGIC_env, "env(E)" },
906 { PERL_MAGIC_isa, "isa(I)" },
907 { PERL_MAGIC_dbfile, "dbfile(L)" },
908 { PERL_MAGIC_shared, "shared(N)" },
909 { PERL_MAGIC_tied, "tied(P)" },
910 { PERL_MAGIC_sig, "sig(S)" },
911 { PERL_MAGIC_uvar, "uvar(U)" },
912 { PERL_MAGIC_overload_elem, "overload_elem(a)" },
913 { PERL_MAGIC_overload_table, "overload_table(c)" },
914 { PERL_MAGIC_regdatum, "regdatum(d)" },
915 { PERL_MAGIC_envelem, "envelem(e)" },
916 { PERL_MAGIC_fm, "fm(f)" },
917 { PERL_MAGIC_regex_global, "regex_global(g)" },
918 { PERL_MAGIC_isaelem, "isaelem(i)" },
919 { PERL_MAGIC_nkeys, "nkeys(k)" },
920 { PERL_MAGIC_dbline, "dbline(l)" },
921 { PERL_MAGIC_mutex, "mutex(m)" },
922 { PERL_MAGIC_shared_scalar, "shared_scalar(n)" },
923 { PERL_MAGIC_collxfrm, "collxfrm(o)" },
924 { PERL_MAGIC_tiedelem, "tiedelem(p)" },
925 { PERL_MAGIC_tiedscalar, "tiedscalar(q)" },
926 { PERL_MAGIC_qr, "qr(r)" },
927 { PERL_MAGIC_sigelem, "sigelem(s)" },
928 { PERL_MAGIC_taint, "taint(t)" },
929 { PERL_MAGIC_uvar_elem, "uvar_elem(v)" },
930 { PERL_MAGIC_vec, "vec(v)" },
931 { PERL_MAGIC_vstring, "vstring(V)" },
932 { PERL_MAGIC_utf8, "utf8(w)" },
933 { PERL_MAGIC_substr, "substr(x)" },
934 { PERL_MAGIC_defelem, "defelem(y)" },
935 { PERL_MAGIC_ext, "ext(~)" },
936 /* this null string terminates the list */
941 Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, const MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
943 for (; mg; mg = mg->mg_moremagic) {
944 Perl_dump_indent(aTHX_ level, file,
945 " MAGIC = 0x%"UVxf"\n", PTR2UV(mg));
946 if (mg->mg_virtual) {
947 const MGVTBL * const v = mg->mg_virtual;
948 const char *s = NULL;
949 if (v == &PL_vtbl_sv) s = "sv";
950 else if (v == &PL_vtbl_env) s = "env";
951 else if (v == &PL_vtbl_envelem) s = "envelem";
952 else if (v == &PL_vtbl_sig) s = "sig";
953 else if (v == &PL_vtbl_sigelem) s = "sigelem";
954 else if (v == &PL_vtbl_pack) s = "pack";
955 else if (v == &PL_vtbl_packelem) s = "packelem";
956 else if (v == &PL_vtbl_dbline) s = "dbline";
957 else if (v == &PL_vtbl_isa) s = "isa";
958 else if (v == &PL_vtbl_arylen) s = "arylen";
959 else if (v == &PL_vtbl_glob) s = "glob";
960 else if (v == &PL_vtbl_mglob) s = "mglob";
961 else if (v == &PL_vtbl_nkeys) s = "nkeys";
962 else if (v == &PL_vtbl_taint) s = "taint";
963 else if (v == &PL_vtbl_substr) s = "substr";
964 else if (v == &PL_vtbl_vec) s = "vec";
965 else if (v == &PL_vtbl_pos) s = "pos";
966 else if (v == &PL_vtbl_bm) s = "bm";
967 else if (v == &PL_vtbl_fm) s = "fm";
968 else if (v == &PL_vtbl_uvar) s = "uvar";
969 else if (v == &PL_vtbl_defelem) s = "defelem";
970 #ifdef USE_LOCALE_COLLATE
971 else if (v == &PL_vtbl_collxfrm) s = "collxfrm";
973 else if (v == &PL_vtbl_amagic) s = "amagic";
974 else if (v == &PL_vtbl_amagicelem) s = "amagicelem";
975 else if (v == &PL_vtbl_backref) s = "backref";
976 else if (v == &PL_vtbl_utf8) s = "utf8";
977 else if (v == &PL_vtbl_arylen_p) s = "arylen_p";
979 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", s);
981 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0x%"UVxf"\n", PTR2UV(v));
984 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0\n");
987 Perl_dump_indent(aTHX_ level, file, " MG_PRIVATE = %d\n", mg->mg_private);
991 const char *name = NULL;
992 for (n = 0; magic_names[n].name; n++) {
993 if (mg->mg_type == magic_names[n].type) {
994 name = magic_names[n].name;
999 Perl_dump_indent(aTHX_ level, file,
1000 " MG_TYPE = PERL_MAGIC_%s\n", name);
1002 Perl_dump_indent(aTHX_ level, file,
1003 " MG_TYPE = UNKNOWN(\\%o)\n", mg->mg_type);
1007 Perl_dump_indent(aTHX_ level, file, " MG_FLAGS = 0x%02X\n", mg->mg_flags);
1008 if (mg->mg_type == PERL_MAGIC_envelem &&
1009 mg->mg_flags & MGf_TAINTEDDIR)
1010 Perl_dump_indent(aTHX_ level, file, " TAINTEDDIR\n");
1011 if (mg->mg_flags & MGf_REFCOUNTED)
1012 Perl_dump_indent(aTHX_ level, file, " REFCOUNTED\n");
1013 if (mg->mg_flags & MGf_GSKIP)
1014 Perl_dump_indent(aTHX_ level, file, " GSKIP\n");
1015 if (mg->mg_type == PERL_MAGIC_regex_global &&
1016 mg->mg_flags & MGf_MINMATCH)
1017 Perl_dump_indent(aTHX_ level, file, " MINMATCH\n");
1020 Perl_dump_indent(aTHX_ level, file, " MG_OBJ = 0x%"UVxf"\n", PTR2UV(mg->mg_obj));
1021 if (mg->mg_flags & MGf_REFCOUNTED)
1022 do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
1025 Perl_dump_indent(aTHX_ level, file, " MG_LEN = %ld\n", (long)mg->mg_len);
1027 Perl_dump_indent(aTHX_ level, file, " MG_PTR = 0x%"UVxf, PTR2UV(mg->mg_ptr));
1028 if (mg->mg_len >= 0) {
1029 if (mg->mg_type != PERL_MAGIC_utf8) {
1030 SV *sv = newSVpvs("");
1031 PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim));
1035 else if (mg->mg_len == HEf_SVKEY) {
1036 PerlIO_puts(file, " => HEf_SVKEY\n");
1037 do_sv_dump(level+2, file, (SV*)((mg)->mg_ptr), nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
1041 PerlIO_puts(file, " ???? - please notify IZ");
1042 PerlIO_putc(file, '\n');
1044 if (mg->mg_type == PERL_MAGIC_utf8) {
1045 STRLEN *cache = (STRLEN *) mg->mg_ptr;
1048 for (i = 0; i < PERL_MAGIC_UTF8_CACHESIZE; i++)
1049 Perl_dump_indent(aTHX_ level, file,
1050 " %2"IVdf": %"UVuf" -> %"UVuf"\n",
1053 (UV)cache[i * 2 + 1]);
1060 Perl_magic_dump(pTHX_ const MAGIC *mg)
1062 do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0);
1066 Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, const char *name, HV *sv)
1069 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
1070 if (sv && (hvname = HvNAME_get(sv)))
1071 PerlIO_printf(file, "\t\"%s\"\n", hvname);
1073 PerlIO_putc(file, '\n');
1077 Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
1079 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
1080 if (sv && GvNAME(sv))
1081 PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv));
1083 PerlIO_putc(file, '\n');
1087 Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
1089 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
1090 if (sv && GvNAME(sv)) {
1092 PerlIO_printf(file, "\t\"");
1093 if (GvSTASH(sv) && (hvname = HvNAME_get(GvSTASH(sv))))
1094 PerlIO_printf(file, "%s\" :: \"", hvname);
1095 PerlIO_printf(file, "%s\"\n", GvNAME(sv));
1098 PerlIO_putc(file, '\n');
1102 Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
1111 Perl_dump_indent(aTHX_ level, file, "SV = 0\n");
1115 flags = SvFLAGS(sv);
1118 d = Perl_newSVpvf(aTHX_
1119 "(0x%"UVxf") at 0x%"UVxf"\n%*s REFCNT = %"IVdf"\n%*s FLAGS = (",
1120 PTR2UV(SvANY(sv)), PTR2UV(sv),
1121 (int)(PL_dumpindent*level), "", (IV)SvREFCNT(sv),
1122 (int)(PL_dumpindent*level), "");
1124 if (flags & SVs_PADSTALE) sv_catpv(d, "PADSTALE,");
1125 if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,");
1126 if (flags & SVs_PADMY) sv_catpv(d, "PADMY,");
1127 if (flags & SVs_TEMP) sv_catpv(d, "TEMP,");
1128 if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,");
1129 if (flags & SVs_GMG) sv_catpv(d, "GMG,");
1130 if (flags & SVs_SMG) sv_catpv(d, "SMG,");
1131 if (flags & SVs_RMG) sv_catpv(d, "RMG,");
1133 if (flags & SVf_IOK) sv_catpv(d, "IOK,");
1134 if (flags & SVf_NOK) sv_catpv(d, "NOK,");
1135 if (flags & SVf_POK) sv_catpv(d, "POK,");
1136 if (flags & SVf_ROK) {
1137 sv_catpv(d, "ROK,");
1138 if (SvWEAKREF(sv)) sv_catpv(d, "WEAKREF,");
1140 if (flags & SVf_OOK) sv_catpv(d, "OOK,");
1141 if (flags & SVf_FAKE) sv_catpv(d, "FAKE,");
1142 if (flags & SVf_READONLY) sv_catpv(d, "READONLY,");
1144 if (flags & SVf_AMAGIC && type != SVt_PVHV)
1145 sv_catpv(d, "OVERLOAD,");
1146 if (flags & SVp_IOK) sv_catpv(d, "pIOK,");
1147 if (flags & SVp_NOK) sv_catpv(d, "pNOK,");
1148 if (flags & SVp_POK) sv_catpv(d, "pPOK,");
1149 if (flags & SVp_SCREAM && type != SVt_PVHV)
1150 sv_catpv(d, "SCREAM,");
1155 if (CvANON(sv)) sv_catpv(d, "ANON,");
1156 if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
1157 if (CvCLONE(sv)) sv_catpv(d, "CLONE,");
1158 if (CvCLONED(sv)) sv_catpv(d, "CLONED,");
1159 if (CvCONST(sv)) sv_catpv(d, "CONST,");
1160 if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,");
1161 if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,");
1162 if (CvLVALUE(sv)) sv_catpv(d, "LVALUE,");
1163 if (CvMETHOD(sv)) sv_catpv(d, "METHOD,");
1164 if (CvLOCKED(sv)) sv_catpv(d, "LOCKED,");
1165 if (CvWEAKOUTSIDE(sv)) sv_catpv(d, "WEAKOUTSIDE,");
1166 if (CvASSERTION(sv)) sv_catpv(d, "ASSERTION,");
1169 if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,");
1170 if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,");
1171 if (HvHASKFLAGS(sv)) sv_catpv(d, "HASKFLAGS,");
1172 if (HvREHASH(sv)) sv_catpv(d, "REHASH,");
1173 if (flags & SVphv_CLONEABLE) sv_catpv(d, "CLONEABLE,");
1175 case SVt_PVGV: case SVt_PVLV:
1176 if (GvINTRO(sv)) sv_catpv(d, "INTRO,");
1177 if (GvMULTI(sv)) sv_catpv(d, "MULTI,");
1178 if (GvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
1179 if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,");
1180 if (GvIN_PAD(sv)) sv_catpv(d, "IN_PAD,");
1181 if (flags & SVpad_OUR) sv_catpv(d, "OUR,");
1182 if (GvIMPORTED(sv)) {
1183 sv_catpv(d, "IMPORT");
1184 if (GvIMPORTED(sv) == GVf_IMPORTED)
1185 sv_catpv(d, "ALL,");
1188 if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV");
1189 if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV");
1190 if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV");
1191 if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV");
1197 if (SvEVALED(sv)) sv_catpv(d, "EVALED,");
1198 if (SvIsUV(sv) && !(flags & SVf_ROK)) sv_catpv(d, "IsUV,");
1201 if (SvTAIL(sv)) sv_catpv(d, "TAIL,");
1202 if (SvVALID(sv)) sv_catpv(d, "VALID,");
1205 if (flags & SVpad_TYPED)
1206 sv_catpv(d, "TYPED,");
1211 /* SVphv_SHAREKEYS is also 0x20000000 */
1212 if ((type != SVt_PVHV) && SvUTF8(sv))
1213 sv_catpv(d, "UTF8");
1215 if (*(SvEND(d) - 1) == ',') {
1216 SvCUR_set(d, SvCUR(d) - 1);
1217 SvPVX(d)[SvCUR(d)] = '\0';
1222 #ifdef DEBUG_LEAKING_SCALARS
1223 Perl_dump_indent(aTHX_ level, file, "ALLOCATED at %s:%d %s %s%s\n",
1224 sv->sv_debug_file ? sv->sv_debug_file : "(unknown)",
1226 sv->sv_debug_inpad ? "for" : "by",
1227 sv->sv_debug_optype ? PL_op_name[sv->sv_debug_optype]: "(none)",
1228 sv->sv_debug_cloned ? " (cloned)" : "");
1230 Perl_dump_indent(aTHX_ level, file, "SV = ");
1233 PerlIO_printf(file, "NULL%s\n", s);
1237 PerlIO_printf(file, "IV%s\n", s);
1240 PerlIO_printf(file, "NV%s\n", s);
1243 PerlIO_printf(file, "RV%s\n", s);
1246 PerlIO_printf(file, "PV%s\n", s);
1249 PerlIO_printf(file, "PVIV%s\n", s);
1252 PerlIO_printf(file, "PVNV%s\n", s);
1255 PerlIO_printf(file, "PVBM%s\n", s);
1258 PerlIO_printf(file, "PVMG%s\n", s);
1261 PerlIO_printf(file, "PVLV%s\n", s);
1264 PerlIO_printf(file, "PVAV%s\n", s);
1267 PerlIO_printf(file, "PVHV%s\n", s);
1270 PerlIO_printf(file, "PVCV%s\n", s);
1273 PerlIO_printf(file, "PVGV%s\n", s);
1276 PerlIO_printf(file, "PVFM%s\n", s);
1279 PerlIO_printf(file, "PVIO%s\n", s);
1282 PerlIO_printf(file, "UNKNOWN(0x%"UVxf") %s\n", (UV)type, s);
1286 if ((type >= SVt_PVIV && type != SVt_PVAV && type != SVt_PVHV)
1287 || type == SVt_IV) {
1289 #ifdef PERL_OLD_COPY_ON_WRITE
1293 Perl_dump_indent(aTHX_ level, file, " UV = %"UVuf, (UV)SvUVX(sv));
1295 Perl_dump_indent(aTHX_ level, file, " IV = %"IVdf, (IV)SvIVX(sv));
1297 PerlIO_printf(file, " (OFFSET)");
1298 #ifdef PERL_OLD_COPY_ON_WRITE
1299 if (SvIsCOW_shared_hash(sv))
1300 PerlIO_printf(file, " (HASH)");
1301 else if (SvIsCOW_normal(sv))
1302 PerlIO_printf(file, " (COW from 0x%"UVxf")", (UV)SvUVX(sv));
1304 PerlIO_putc(file, '\n');
1306 if ((type >= SVt_PVNV && type != SVt_PVAV && type != SVt_PVHV)
1307 || type == SVt_NV) {
1308 STORE_NUMERIC_LOCAL_SET_STANDARD();
1309 /* %Vg doesn't work? --jhi */
1310 #ifdef USE_LONG_DOUBLE
1311 Perl_dump_indent(aTHX_ level, file, " NV = %.*" PERL_PRIgldbl "\n", LDBL_DIG, SvNVX(sv));
1313 Perl_dump_indent(aTHX_ level, file, " NV = %.*g\n", DBL_DIG, SvNVX(sv));
1315 RESTORE_NUMERIC_LOCAL();
1318 Perl_dump_indent(aTHX_ level, file, " RV = 0x%"UVxf"\n", PTR2UV(SvRV(sv)));
1320 do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim);
1322 if (type < SVt_PV) {
1326 if (type <= SVt_PVLV && type != SVt_PVGV) {
1327 if (SvPVX_const(sv)) {
1328 Perl_dump_indent(aTHX_ level, file," PV = 0x%"UVxf" ", PTR2UV(SvPVX_const(sv)));
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));
1332 if (SvUTF8(sv)) /* the 8? \x{....} */
1333 PerlIO_printf(file, " [UTF8 \"%s\"]", sv_uni_display(d, sv, 8 * sv_len_utf8(sv), UNI_DISPLAY_QQ));
1334 PerlIO_printf(file, "\n");
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));
1339 Perl_dump_indent(aTHX_ level, file, " PV = 0\n");
1341 if (type >= SVt_PVMG) {
1343 do_magic_dump(level, file, SvMAGIC(sv), nest, maxnest, dumpops, pvlim);
1345 do_hv_dump(level, file, " STASH", SvSTASH(sv));
1349 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(AvARRAY(sv)));
1350 if (AvARRAY(sv) != AvALLOC(sv)) {
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)));
1355 PerlIO_putc(file, '\n');
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));
1358 Perl_dump_indent(aTHX_ level, file, " ARYLEN = 0x%"UVxf"\n", SvMAGIC(sv) ? PTR2UV(AvARYLEN(sv)) : 0);
1359 sv_setpvn(d, "", 0);
1360 if (AvREAL(sv)) sv_catpv(d, ",REAL");
1361 if (AvREIFY(sv)) sv_catpv(d, ",REIFY");
1362 Perl_dump_indent(aTHX_ level, file, " FLAGS = (%s)\n",
1363 SvCUR(d) ? SvPVX_const(d) + 1 : "");
1364 if (nest < maxnest && av_len((AV*)sv) >= 0) {
1366 for (count = 0; count <= av_len((AV*)sv) && count < maxnest; count++) {
1367 SV** elt = av_fetch((AV*)sv,count,0);
1369 Perl_dump_indent(aTHX_ level + 1, file, "Elt No. %"IVdf"\n", (IV)count);
1371 do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim);
1376 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv)));
1377 if (HvARRAY(sv) && HvKEYS(sv)) {
1378 /* Show distribution of HEs in the ARRAY */
1380 #define FREQ_MAX (sizeof freq / sizeof freq[0] - 1)
1383 U32 pow2 = 2, keys = HvKEYS(sv);
1384 NV theoret, sum = 0;
1386 PerlIO_printf(file, " (");
1387 Zero(freq, FREQ_MAX + 1, int);
1388 for (i = 0; (STRLEN)i <= HvMAX(sv); i++) {
1391 for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h))
1393 if (count > FREQ_MAX)
1399 for (i = 0; i <= max; i++) {
1401 PerlIO_printf(file, "%d%s:%d", i,
1402 (i == FREQ_MAX) ? "+" : "",
1405 PerlIO_printf(file, ", ");
1408 PerlIO_putc(file, ')');
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.
1413 The total number of comparisons is equal to the sum of
1414 the squares of the number of entries in each bucket.
1415 For a random hash of n keys into k buckets, the expected
1420 for (i = max; i > 0; i--) { /* Precision: count down. */
1421 sum += freq[i] * i * i;
1423 while ((keys = keys >> 1))
1425 theoret = HvKEYS(sv);
1426 theoret += theoret * (theoret-1)/pow2;
1427 PerlIO_putc(file, '\n');
1428 Perl_dump_indent(aTHX_ level, file, " hash quality = %.1"NVff"%%", theoret/sum*100);
1430 PerlIO_putc(file, '\n');
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));
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)));
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));
1443 const char *hvname = HvNAME_get(sv);
1445 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", hvname);
1448 AV *backrefs = *Perl_hv_backreferences_p(aTHX_ (HV*)sv);
1450 Perl_dump_indent(aTHX_ level, file, " BACKREFS = 0x%"UVxf"\n",
1452 do_sv_dump(level+1, file, (SV*)backrefs, nest+1, maxnest,
1456 if (nest < maxnest && !HvEITER_get(sv)) { /* Try to preserve iterator */
1458 HV * const hv = (HV*)sv;
1459 int count = maxnest - nest;
1462 while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))
1467 const U32 hash = HeHASH(he);
1469 keysv = hv_iterkeysv(he);
1470 keypv = SvPV_const(keysv, len);
1471 elt = hv_iterval(hv, he);
1472 Perl_dump_indent(aTHX_ level+1, file, "Elt %s ", pv_display(d, keypv, len, 0, pvlim));
1474 PerlIO_printf(file, "[UTF8 \"%s\"] ", sv_uni_display(d, keysv, 8 * sv_len_utf8(keysv), UNI_DISPLAY_QQ));
1476 PerlIO_printf(file, "[REHASH] ");
1477 PerlIO_printf(file, "HASH = 0x%"UVxf"\n", (UV)hash);
1478 do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim);
1480 hv_iterinit(hv); /* Return to status quo */
1485 Perl_dump_indent(aTHX_ level, file, " PROTOTYPE = \"%s\"\n", SvPV_nolen_const(sv));
1488 do_hv_dump(level, file, " COMP_STASH", CvSTASH(sv));
1490 Perl_dump_indent(aTHX_ level, file, " START = 0x%"UVxf" ===> %"IVdf"\n", PTR2UV(CvSTART(sv)), (IV)sequence_num(CvSTART(sv)));
1491 Perl_dump_indent(aTHX_ level, file, " ROOT = 0x%"UVxf"\n", PTR2UV(CvROOT(sv)));
1492 if (CvROOT(sv) && dumpops)
1493 do_op_dump(level+1, file, CvROOT(sv));
1494 Perl_dump_indent(aTHX_ level, file, " XSUB = 0x%"UVxf"\n", PTR2UV(CvXSUB(sv)));
1496 SV *constant = cv_const_sv((CV *)sv);
1500 Perl_dump_indent(aTHX_ level, file, " XSUBANY = 0x%"UVxf
1502 PTR2UV(CvXSUBANY(sv).any_ptr));
1503 do_sv_dump(level+1, file, constant, nest+1, maxnest, dumpops,
1506 Perl_dump_indent(aTHX_ level, file, " XSUBANY = %"IVdf"\n",
1507 (IV)CvXSUBANY(sv).any_i32);
1510 do_gvgv_dump(level, file, " GVGV::GV", CvGV(sv));
1511 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", CvFILE(sv));
1512 Perl_dump_indent(aTHX_ level, file, " DEPTH = %"IVdf"\n", (IV)CvDEPTH(sv));
1513 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)CvFLAGS(sv));
1514 Perl_dump_indent(aTHX_ level, file, " OUTSIDE_SEQ = %"UVuf"\n", (UV)CvOUTSIDE_SEQ(sv));
1515 if (type == SVt_PVFM)
1516 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)FmLINES(sv));
1517 Perl_dump_indent(aTHX_ level, file, " PADLIST = 0x%"UVxf"\n", PTR2UV(CvPADLIST(sv)));
1518 if (nest < maxnest) {
1519 do_dump_pad(level+1, file, CvPADLIST(sv), 0);
1522 const CV *outside = CvOUTSIDE(sv);
1523 Perl_dump_indent(aTHX_ level, file, " OUTSIDE = 0x%"UVxf" (%s)\n",
1526 : CvANON(outside) ? "ANON"
1527 : (outside == PL_main_cv) ? "MAIN"
1528 : CvUNIQUE(outside) ? "UNIQUE"
1529 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
1531 if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv)))
1532 do_sv_dump(level+1, file, (SV*)CvOUTSIDE(sv), nest+1, maxnest, dumpops, pvlim);
1534 case SVt_PVGV: case SVt_PVLV:
1535 if (type == SVt_PVLV) {
1536 Perl_dump_indent(aTHX_ level, file, " TYPE = %c\n", LvTYPE(sv));
1537 Perl_dump_indent(aTHX_ level, file, " TARGOFF = %"IVdf"\n", (IV)LvTARGOFF(sv));
1538 Perl_dump_indent(aTHX_ level, file, " TARGLEN = %"IVdf"\n", (IV)LvTARGLEN(sv));
1539 Perl_dump_indent(aTHX_ level, file, " TARG = 0x%"UVxf"\n", PTR2UV(LvTARG(sv)));
1540 if (LvTYPE(sv) != 't' && LvTYPE(sv) != 'T')
1541 do_sv_dump(level+1, file, LvTARG(sv), nest+1, maxnest,
1544 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", GvNAME(sv));
1545 Perl_dump_indent(aTHX_ level, file, " NAMELEN = %"IVdf"\n", (IV)GvNAMELEN(sv));
1546 do_hv_dump (level, file, " GvSTASH", GvSTASH(sv));
1547 Perl_dump_indent(aTHX_ level, file, " GP = 0x%"UVxf"\n", PTR2UV(GvGP(sv)));
1550 Perl_dump_indent(aTHX_ level, file, " SV = 0x%"UVxf"\n", PTR2UV(GvSV(sv)));
1551 Perl_dump_indent(aTHX_ level, file, " REFCNT = %"IVdf"\n", (IV)GvREFCNT(sv));
1552 Perl_dump_indent(aTHX_ level, file, " IO = 0x%"UVxf"\n", PTR2UV(GvIOp(sv)));
1553 Perl_dump_indent(aTHX_ level, file, " FORM = 0x%"UVxf" \n", PTR2UV(GvFORM(sv)));
1554 Perl_dump_indent(aTHX_ level, file, " AV = 0x%"UVxf"\n", PTR2UV(GvAV(sv)));
1555 Perl_dump_indent(aTHX_ level, file, " HV = 0x%"UVxf"\n", PTR2UV(GvHV(sv)));
1556 Perl_dump_indent(aTHX_ level, file, " CV = 0x%"UVxf"\n", PTR2UV(GvCV(sv)));
1557 Perl_dump_indent(aTHX_ level, file, " CVGEN = 0x%"UVxf"\n", (UV)GvCVGEN(sv));
1558 Perl_dump_indent(aTHX_ level, file, " LINE = %"IVdf"\n", (IV)GvLINE(sv));
1559 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", GvFILE(sv));
1560 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)GvFLAGS(sv));
1561 do_gv_dump (level, file, " EGV", GvEGV(sv));
1564 Perl_dump_indent(aTHX_ level, file, " IFP = 0x%"UVxf"\n", PTR2UV(IoIFP(sv)));
1565 Perl_dump_indent(aTHX_ level, file, " OFP = 0x%"UVxf"\n", PTR2UV(IoOFP(sv)));
1566 Perl_dump_indent(aTHX_ level, file, " DIRP = 0x%"UVxf"\n", PTR2UV(IoDIRP(sv)));
1567 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)IoLINES(sv));
1568 Perl_dump_indent(aTHX_ level, file, " PAGE = %"IVdf"\n", (IV)IoPAGE(sv));
1569 Perl_dump_indent(aTHX_ level, file, " PAGE_LEN = %"IVdf"\n", (IV)IoPAGE_LEN(sv));
1570 Perl_dump_indent(aTHX_ level, file, " LINES_LEFT = %"IVdf"\n", (IV)IoLINES_LEFT(sv));
1572 Perl_dump_indent(aTHX_ level, file, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
1573 do_gv_dump (level, file, " TOP_GV", IoTOP_GV(sv));
1575 Perl_dump_indent(aTHX_ level, file, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
1576 do_gv_dump (level, file, " FMT_GV", IoFMT_GV(sv));
1577 if (IoBOTTOM_NAME(sv))
1578 Perl_dump_indent(aTHX_ level, file, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
1579 do_gv_dump (level, file, " BOTTOM_GV", IoBOTTOM_GV(sv));
1580 Perl_dump_indent(aTHX_ level, file, " SUBPROCESS = %"IVdf"\n", (IV)IoSUBPROCESS(sv));
1581 if (isPRINT(IoTYPE(sv)))
1582 Perl_dump_indent(aTHX_ level, file, " TYPE = '%c'\n", IoTYPE(sv));
1584 Perl_dump_indent(aTHX_ level, file, " TYPE = '\\%o'\n", IoTYPE(sv));
1585 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)IoFLAGS(sv));
1592 Perl_sv_dump(pTHX_ SV *sv)
1595 do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0);
1599 Perl_runops_debug(pTHX)
1603 if (ckWARN_d(WARN_DEBUGGING))
1604 Perl_warner(aTHX_ packWARN(WARN_DEBUGGING), "NULL OP IN RUN");
1608 DEBUG_l(Perl_deb(aTHX_ "Entering new RUNOPS level\n"));
1612 if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok)
1613 PerlIO_printf(Perl_debug_log,
1614 "WARNING: %"UVxf" changed from %"UVxf" to %"UVxf"\n",
1615 PTR2UV(PL_watchaddr), PTR2UV(PL_watchok),
1616 PTR2UV(*PL_watchaddr));
1617 if (DEBUG_s_TEST_) {
1618 if (DEBUG_v_TEST_) {
1619 PerlIO_printf(Perl_debug_log, "\n");
1627 if (DEBUG_t_TEST_) debop(PL_op);
1628 if (DEBUG_P_TEST_) debprof(PL_op);
1630 } while ((PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX)));
1631 DEBUG_l(Perl_deb(aTHX_ "leaving RUNOPS level\n"));
1638 Perl_debop(pTHX_ const OP *o)
1641 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
1644 Perl_deb(aTHX_ "%s", OP_NAME(o));
1645 switch (o->op_type) {
1647 PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo_sv));
1653 gv_fullname3(sv, cGVOPo_gv, NULL);
1654 PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv));
1658 PerlIO_printf(Perl_debug_log, "(NULL)");
1664 /* print the lexical's name */
1665 CV *cv = deb_curcv(cxstack_ix);
1668 AV * const padlist = CvPADLIST(cv);
1669 AV * const comppad = (AV*)(*av_fetch(padlist, 0, FALSE));
1670 sv = *av_fetch(comppad, o->op_targ, FALSE);
1674 PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv));
1676 PerlIO_printf(Perl_debug_log, "[%"UVuf"]", (UV)o->op_targ);
1682 PerlIO_printf(Perl_debug_log, "\n");
1687 S_deb_curcv(pTHX_ I32 ix)
1690 const PERL_CONTEXT *cx = &cxstack[ix];
1691 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT)
1692 return cx->blk_sub.cv;
1693 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
1695 else if (ix == 0 && PL_curstackinfo->si_type == PERLSI_MAIN)
1700 return deb_curcv(ix - 1);
1704 Perl_watch(pTHX_ char **addr)
1707 PL_watchaddr = addr;
1709 PerlIO_printf(Perl_debug_log, "WATCHING, %"UVxf" is currently %"UVxf"\n",
1710 PTR2UV(PL_watchaddr), PTR2UV(PL_watchok));
1714 S_debprof(pTHX_ const OP *o)
1717 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
1719 if (!PL_profiledata)
1720 Newxz(PL_profiledata, MAXO, U32);
1721 ++PL_profiledata[o->op_type];
1725 Perl_debprofdump(pTHX)
1729 if (!PL_profiledata)
1731 for (i = 0; i < MAXO; i++) {
1732 if (PL_profiledata[i])
1733 PerlIO_printf(Perl_debug_log,
1734 "%5lu %s\n", (unsigned long)PL_profiledata[i],
1741 * c-indentation-style: bsd
1743 * indent-tabs-mode: t
1746 * ex: set ts=8 sts=4 sw=4 noet: