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));
92 if (CvISXSUB(GvCV(gv)))
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 * const tmpsv = pm_description(pm);
369 Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
373 Perl_dump_indent(aTHX_ level-1, file, "}\n");
378 S_pm_description(pTHX_ const PMOP *pm)
380 SV * const desc = newSVpvs("");
381 const REGEXP * regex = PM_GETRE(pm);
382 const U32 pmflags = pm->op_pmflags;
384 if (pm->op_pmdynflags & PMdf_USED)
385 sv_catpv(desc, ",USED");
386 if (pm->op_pmdynflags & PMdf_TAINTED)
387 sv_catpv(desc, ",TAINTED");
389 if (pmflags & PMf_ONCE)
390 sv_catpv(desc, ",ONCE");
391 if (regex && regex->check_substr) {
392 if (!(regex->reganch & ROPT_NOSCAN))
393 sv_catpv(desc, ",SCANFIRST");
394 if (regex->reganch & ROPT_CHECK_ALL)
395 sv_catpv(desc, ",ALL");
397 if (pmflags & PMf_SKIPWHITE)
398 sv_catpv(desc, ",SKIPWHITE");
399 if (pmflags & PMf_CONST)
400 sv_catpv(desc, ",CONST");
401 if (pmflags & PMf_KEEP)
402 sv_catpv(desc, ",KEEP");
403 if (pmflags & PMf_GLOBAL)
404 sv_catpv(desc, ",GLOBAL");
405 if (pmflags & PMf_CONTINUE)
406 sv_catpv(desc, ",CONTINUE");
407 if (pmflags & PMf_RETAINT)
408 sv_catpv(desc, ",RETAINT");
409 if (pmflags & PMf_EVAL)
410 sv_catpv(desc, ",EVAL");
415 Perl_pmop_dump(pTHX_ PMOP *pm)
417 do_pmop_dump(0, Perl_debug_log, pm);
420 /* An op sequencer. We visit the ops in the order they're to execute. */
423 S_sequence(pTHX_ register const OP *o)
426 const OP *oldop = NULL;
439 for (; o; o = o->op_next) {
441 SV * const op = newSVuv(PTR2UV(o));
442 const char * const key = SvPV_const(op, len);
444 if (hv_exists(Sequence, key, len))
447 switch (o->op_type) {
449 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
450 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
459 if (oldop && o->op_next)
466 if (oldop && o->op_next)
468 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
481 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
482 sequence_tail(cLOGOPo->op_other);
487 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
488 sequence_tail(cLOOPo->op_redoop);
489 sequence_tail(cLOOPo->op_nextop);
490 sequence_tail(cLOOPo->op_lastop);
496 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
497 sequence_tail(cPMOPo->op_pmreplstart);
504 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
512 S_sequence_tail(pTHX_ const OP *o)
514 while (o && (o->op_type == OP_NULL))
520 S_sequence_num(pTHX_ const OP *o)
528 op = newSVuv(PTR2UV(o));
529 key = SvPV_const(op, len);
530 seq = hv_fetch(Sequence, key, len, 0);
531 return seq ? SvUV(*seq): 0;
535 Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
539 const OPCODE optype = o->op_type;
542 Perl_dump_indent(aTHX_ level, file, "{\n");
544 seq = sequence_num(o);
546 PerlIO_printf(file, "%-4"UVf, seq);
548 PerlIO_printf(file, " ");
550 "%*sTYPE = %s ===> ",
551 (int)(PL_dumpindent*level-4), "", OP_NAME(o));
553 PerlIO_printf(file, seq ? "%"UVf"\n" : "(%"UVf")\n",
554 sequence_num(o->op_next));
556 PerlIO_printf(file, "DONE\n");
558 if (optype == OP_NULL) {
559 Perl_dump_indent(aTHX_ level, file, " (was %s)\n", PL_op_name[o->op_targ]);
560 if (o->op_targ == OP_NEXTSTATE) {
562 Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n",
564 if (CopSTASHPV(cCOPo))
565 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
567 if (cCOPo->cop_label)
568 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
573 Perl_dump_indent(aTHX_ level, file, "TARG = %ld\n", (long)o->op_targ);
576 Perl_dump_indent(aTHX_ level, file, "ADDR = 0x%"UVxf" => 0x%"UVxf"\n", (UV)o, (UV)o->op_next);
579 SV * const tmpsv = newSVpvs("");
580 switch (o->op_flags & OPf_WANT) {
582 sv_catpv(tmpsv, ",VOID");
584 case OPf_WANT_SCALAR:
585 sv_catpv(tmpsv, ",SCALAR");
588 sv_catpv(tmpsv, ",LIST");
591 sv_catpv(tmpsv, ",UNKNOWN");
594 if (o->op_flags & OPf_KIDS)
595 sv_catpv(tmpsv, ",KIDS");
596 if (o->op_flags & OPf_PARENS)
597 sv_catpv(tmpsv, ",PARENS");
598 if (o->op_flags & OPf_STACKED)
599 sv_catpv(tmpsv, ",STACKED");
600 if (o->op_flags & OPf_REF)
601 sv_catpv(tmpsv, ",REF");
602 if (o->op_flags & OPf_MOD)
603 sv_catpv(tmpsv, ",MOD");
604 if (o->op_flags & OPf_SPECIAL)
605 sv_catpv(tmpsv, ",SPECIAL");
606 Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
610 SV * const tmpsv = newSVpvs("");
611 if (PL_opargs[optype] & OA_TARGLEX) {
612 if (o->op_private & OPpTARGET_MY)
613 sv_catpv(tmpsv, ",TARGET_MY");
615 else if (optype == OP_LEAVESUB ||
616 optype == OP_LEAVE ||
617 optype == OP_LEAVESUBLV ||
618 optype == OP_LEAVEWRITE) {
619 if (o->op_private & OPpREFCOUNTED)
620 sv_catpv(tmpsv, ",REFCOUNTED");
622 else if (optype == OP_AASSIGN) {
623 if (o->op_private & OPpASSIGN_COMMON)
624 sv_catpv(tmpsv, ",COMMON");
626 else if (optype == OP_SASSIGN) {
627 if (o->op_private & OPpASSIGN_BACKWARDS)
628 sv_catpv(tmpsv, ",BACKWARDS");
630 else if (optype == OP_TRANS) {
631 if (o->op_private & OPpTRANS_SQUASH)
632 sv_catpv(tmpsv, ",SQUASH");
633 if (o->op_private & OPpTRANS_DELETE)
634 sv_catpv(tmpsv, ",DELETE");
635 if (o->op_private & OPpTRANS_COMPLEMENT)
636 sv_catpv(tmpsv, ",COMPLEMENT");
637 if (o->op_private & OPpTRANS_IDENTICAL)
638 sv_catpv(tmpsv, ",IDENTICAL");
639 if (o->op_private & OPpTRANS_GROWS)
640 sv_catpv(tmpsv, ",GROWS");
642 else if (optype == OP_REPEAT) {
643 if (o->op_private & OPpREPEAT_DOLIST)
644 sv_catpv(tmpsv, ",DOLIST");
646 else if (optype == OP_ENTERSUB ||
647 optype == OP_RV2SV ||
649 optype == OP_RV2AV ||
650 optype == OP_RV2HV ||
651 optype == OP_RV2GV ||
652 optype == OP_AELEM ||
655 if (optype == OP_ENTERSUB) {
656 if (o->op_private & OPpENTERSUB_AMPER)
657 sv_catpv(tmpsv, ",AMPER");
658 if (o->op_private & OPpENTERSUB_DB)
659 sv_catpv(tmpsv, ",DB");
660 if (o->op_private & OPpENTERSUB_HASTARG)
661 sv_catpv(tmpsv, ",HASTARG");
662 if (o->op_private & OPpENTERSUB_NOPAREN)
663 sv_catpv(tmpsv, ",NOPAREN");
664 if (o->op_private & OPpENTERSUB_INARGS)
665 sv_catpv(tmpsv, ",INARGS");
666 if (o->op_private & OPpENTERSUB_NOMOD)
667 sv_catpv(tmpsv, ",NOMOD");
670 switch (o->op_private & OPpDEREF) {
672 sv_catpv(tmpsv, ",SV");
675 sv_catpv(tmpsv, ",AV");
678 sv_catpv(tmpsv, ",HV");
681 if (o->op_private & OPpMAYBE_LVSUB)
682 sv_catpv(tmpsv, ",MAYBE_LVSUB");
684 if (optype == OP_AELEM || optype == OP_HELEM) {
685 if (o->op_private & OPpLVAL_DEFER)
686 sv_catpv(tmpsv, ",LVAL_DEFER");
689 if (o->op_private & HINT_STRICT_REFS)
690 sv_catpv(tmpsv, ",STRICT_REFS");
691 if (o->op_private & OPpOUR_INTRO)
692 sv_catpv(tmpsv, ",OUR_INTRO");
695 else if (optype == OP_CONST) {
696 if (o->op_private & OPpCONST_BARE)
697 sv_catpv(tmpsv, ",BARE");
698 if (o->op_private & OPpCONST_STRICT)
699 sv_catpv(tmpsv, ",STRICT");
700 if (o->op_private & OPpCONST_ARYBASE)
701 sv_catpv(tmpsv, ",ARYBASE");
702 if (o->op_private & OPpCONST_WARNING)
703 sv_catpv(tmpsv, ",WARNING");
704 if (o->op_private & OPpCONST_ENTERED)
705 sv_catpv(tmpsv, ",ENTERED");
707 else if (optype == OP_FLIP) {
708 if (o->op_private & OPpFLIP_LINENUM)
709 sv_catpv(tmpsv, ",LINENUM");
711 else if (optype == OP_FLOP) {
712 if (o->op_private & OPpFLIP_LINENUM)
713 sv_catpv(tmpsv, ",LINENUM");
715 else if (optype == OP_RV2CV) {
716 if (o->op_private & OPpLVAL_INTRO)
717 sv_catpv(tmpsv, ",INTRO");
719 else if (optype == OP_GV) {
720 if (o->op_private & OPpEARLY_CV)
721 sv_catpv(tmpsv, ",EARLY_CV");
723 else if (optype == OP_LIST) {
724 if (o->op_private & OPpLIST_GUESSED)
725 sv_catpv(tmpsv, ",GUESSED");
727 else if (optype == OP_DELETE) {
728 if (o->op_private & OPpSLICE)
729 sv_catpv(tmpsv, ",SLICE");
731 else if (optype == OP_EXISTS) {
732 if (o->op_private & OPpEXISTS_SUB)
733 sv_catpv(tmpsv, ",EXISTS_SUB");
735 else if (optype == OP_SORT) {
736 if (o->op_private & OPpSORT_NUMERIC)
737 sv_catpv(tmpsv, ",NUMERIC");
738 if (o->op_private & OPpSORT_INTEGER)
739 sv_catpv(tmpsv, ",INTEGER");
740 if (o->op_private & OPpSORT_REVERSE)
741 sv_catpv(tmpsv, ",REVERSE");
743 else if (optype == OP_THREADSV) {
744 if (o->op_private & OPpDONE_SVREF)
745 sv_catpv(tmpsv, ",SVREF");
747 else if (optype == OP_OPEN || optype == OP_BACKTICK) {
748 if (o->op_private & OPpOPEN_IN_RAW)
749 sv_catpv(tmpsv, ",IN_RAW");
750 if (o->op_private & OPpOPEN_IN_CRLF)
751 sv_catpv(tmpsv, ",IN_CRLF");
752 if (o->op_private & OPpOPEN_OUT_RAW)
753 sv_catpv(tmpsv, ",OUT_RAW");
754 if (o->op_private & OPpOPEN_OUT_CRLF)
755 sv_catpv(tmpsv, ",OUT_CRLF");
757 else if (optype == OP_EXIT) {
758 if (o->op_private & OPpEXIT_VMSISH)
759 sv_catpv(tmpsv, ",EXIT_VMSISH");
760 if (o->op_private & OPpHUSH_VMSISH)
761 sv_catpv(tmpsv, ",HUSH_VMSISH");
763 else if (optype == OP_DIE) {
764 if (o->op_private & OPpHUSH_VMSISH)
765 sv_catpv(tmpsv, ",HUSH_VMSISH");
767 else if (PL_check[optype] != MEMBER_TO_FPTR(Perl_ck_ftst)) {
768 if (OP_IS_FILETEST_ACCESS(o) && o->op_private & OPpFT_ACCESS)
769 sv_catpv(tmpsv, ",FT_ACCESS");
770 if (o->op_private & OPpFT_STACKED)
771 sv_catpv(tmpsv, ",FT_STACKED");
773 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
774 sv_catpv(tmpsv, ",INTRO");
776 Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX_const(tmpsv) + 1);
781 if (PL_madskills && o->op_madprop) {
782 SV * const tmpsv = newSVpvn("", 0);
783 MADPROP* mp = o->op_madprop;
784 Perl_dump_indent(aTHX_ level, file, "MADPROPS = {\n");
787 char tmp = mp->mad_key;
788 sv_setpvn(tmpsv,"'",1);
790 sv_catpvn(tmpsv, &tmp, 1);
791 sv_catpv(tmpsv, "'=");
792 switch (mp->mad_type) {
794 sv_catpv(tmpsv, "NULL");
795 Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv));
798 sv_catpv(tmpsv, "<");
799 sv_catpvn(tmpsv, (char*)mp->mad_val, mp->mad_vlen);
800 sv_catpv(tmpsv, ">");
801 Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv));
804 if ((OP*)mp->mad_val) {
805 Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv));
806 do_op_dump(level, file, (OP*)mp->mad_val);
810 sv_catpv(tmpsv, "(UNK)");
811 Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv));
817 Perl_dump_indent(aTHX_ level, file, "}\n");
828 Perl_dump_indent(aTHX_ level, file, "PADIX = %" IVdf "\n", (IV)cPADOPo->op_padix);
830 if ( ! PL_op->op_flags & OPf_SPECIAL) { /* not lexical */
832 SV * const tmpsv = newSV(0);
836 /* FIXME - it this making unwarranted assumptions about the
837 UTF-8 cleanliness of the dump file handle? */
840 gv_fullname3(tmpsv, (GV*)cSVOPo->op_sv, NULL);
841 Perl_dump_indent(aTHX_ level, file, "GV = %s\n",
842 SvPV_nolen_const(tmpsv));
846 Perl_dump_indent(aTHX_ level, file, "GV = NULL\n");
851 case OP_METHOD_NAMED:
853 /* with ITHREADS, consts are stored in the pad, and the right pad
854 * may not be active here, so skip */
855 Perl_dump_indent(aTHX_ level, file, "SV = %s\n", SvPEEK(cSVOPo_sv));
862 Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n",
864 if (CopSTASHPV(cCOPo))
865 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
867 if (cCOPo->cop_label)
868 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
872 Perl_dump_indent(aTHX_ level, file, "REDO ===> ");
873 if (cLOOPo->op_redoop)
874 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_redoop));
876 PerlIO_printf(file, "DONE\n");
877 Perl_dump_indent(aTHX_ level, file, "NEXT ===> ");
878 if (cLOOPo->op_nextop)
879 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_nextop));
881 PerlIO_printf(file, "DONE\n");
882 Perl_dump_indent(aTHX_ level, file, "LAST ===> ");
883 if (cLOOPo->op_lastop)
884 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_lastop));
886 PerlIO_printf(file, "DONE\n");
894 Perl_dump_indent(aTHX_ level, file, "OTHER ===> ");
895 if (cLOGOPo->op_other)
896 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOGOPo->op_other));
898 PerlIO_printf(file, "DONE\n");
904 do_pmop_dump(level, file, cPMOPo);
912 if (o->op_private & OPpREFCOUNTED)
913 Perl_dump_indent(aTHX_ level, file, "REFCNT = %"UVuf"\n", (UV)o->op_targ);
918 if (o->op_flags & OPf_KIDS) {
920 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
921 do_op_dump(level, file, kid);
923 Perl_dump_indent(aTHX_ level-1, file, "}\n");
927 Perl_op_dump(pTHX_ const OP *o)
929 do_op_dump(0, Perl_debug_log, o);
933 Perl_gv_dump(pTHX_ GV *gv)
938 PerlIO_printf(Perl_debug_log, "{}\n");
942 PerlIO_printf(Perl_debug_log, "{\n");
943 gv_fullname3(sv, gv, NULL);
944 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s", SvPVX_const(sv));
945 if (gv != GvEGV(gv)) {
946 gv_efullname3(sv, GvEGV(gv), NULL);
947 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s", SvPVX_const(sv));
949 PerlIO_putc(Perl_debug_log, '\n');
950 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "}\n");
954 /* map magic types to the symbolic names
955 * (with the PERL_MAGIC_ prefixed stripped)
958 static const struct { const char type; const char *name; } magic_names[] = {
959 { PERL_MAGIC_sv, "sv(\\0)" },
960 { PERL_MAGIC_arylen, "arylen(#)" },
961 { PERL_MAGIC_rhash, "rhash(%)" },
962 { PERL_MAGIC_pos, "pos(.)" },
963 { PERL_MAGIC_symtab, "symtab(:)" },
964 { PERL_MAGIC_backref, "backref(<)" },
965 { PERL_MAGIC_arylen_p, "arylen_p(@)" },
966 { PERL_MAGIC_overload, "overload(A)" },
967 { PERL_MAGIC_bm, "bm(B)" },
968 { PERL_MAGIC_regdata, "regdata(D)" },
969 { PERL_MAGIC_env, "env(E)" },
970 { PERL_MAGIC_hints, "hints(H)" },
971 { PERL_MAGIC_isa, "isa(I)" },
972 { PERL_MAGIC_dbfile, "dbfile(L)" },
973 { PERL_MAGIC_shared, "shared(N)" },
974 { PERL_MAGIC_tied, "tied(P)" },
975 { PERL_MAGIC_sig, "sig(S)" },
976 { PERL_MAGIC_uvar, "uvar(U)" },
977 { PERL_MAGIC_overload_elem, "overload_elem(a)" },
978 { PERL_MAGIC_overload_table, "overload_table(c)" },
979 { PERL_MAGIC_regdatum, "regdatum(d)" },
980 { PERL_MAGIC_envelem, "envelem(e)" },
981 { PERL_MAGIC_fm, "fm(f)" },
982 { PERL_MAGIC_regex_global, "regex_global(g)" },
983 { PERL_MAGIC_hintselem, "hintselem(h)" },
984 { PERL_MAGIC_isaelem, "isaelem(i)" },
985 { PERL_MAGIC_nkeys, "nkeys(k)" },
986 { PERL_MAGIC_dbline, "dbline(l)" },
987 { PERL_MAGIC_mutex, "mutex(m)" },
988 { PERL_MAGIC_shared_scalar, "shared_scalar(n)" },
989 { PERL_MAGIC_collxfrm, "collxfrm(o)" },
990 { PERL_MAGIC_tiedelem, "tiedelem(p)" },
991 { PERL_MAGIC_tiedscalar, "tiedscalar(q)" },
992 { PERL_MAGIC_qr, "qr(r)" },
993 { PERL_MAGIC_sigelem, "sigelem(s)" },
994 { PERL_MAGIC_taint, "taint(t)" },
995 { PERL_MAGIC_uvar_elem, "uvar_elem(v)" },
996 { PERL_MAGIC_vec, "vec(v)" },
997 { PERL_MAGIC_vstring, "vstring(V)" },
998 { PERL_MAGIC_utf8, "utf8(w)" },
999 { PERL_MAGIC_substr, "substr(x)" },
1000 { PERL_MAGIC_defelem, "defelem(y)" },
1001 { PERL_MAGIC_ext, "ext(~)" },
1002 /* this null string terminates the list */
1007 Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, const MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
1009 for (; mg; mg = mg->mg_moremagic) {
1010 Perl_dump_indent(aTHX_ level, file,
1011 " MAGIC = 0x%"UVxf"\n", PTR2UV(mg));
1012 if (mg->mg_virtual) {
1013 const MGVTBL * const v = mg->mg_virtual;
1014 const char *s = NULL;
1015 if (v == &PL_vtbl_sv) s = "sv";
1016 else if (v == &PL_vtbl_env) s = "env";
1017 else if (v == &PL_vtbl_envelem) s = "envelem";
1018 else if (v == &PL_vtbl_sig) s = "sig";
1019 else if (v == &PL_vtbl_sigelem) s = "sigelem";
1020 else if (v == &PL_vtbl_pack) s = "pack";
1021 else if (v == &PL_vtbl_packelem) s = "packelem";
1022 else if (v == &PL_vtbl_dbline) s = "dbline";
1023 else if (v == &PL_vtbl_isa) s = "isa";
1024 else if (v == &PL_vtbl_arylen) s = "arylen";
1025 else if (v == &PL_vtbl_mglob) s = "mglob";
1026 else if (v == &PL_vtbl_nkeys) s = "nkeys";
1027 else if (v == &PL_vtbl_taint) s = "taint";
1028 else if (v == &PL_vtbl_substr) s = "substr";
1029 else if (v == &PL_vtbl_vec) s = "vec";
1030 else if (v == &PL_vtbl_pos) s = "pos";
1031 else if (v == &PL_vtbl_bm) s = "bm";
1032 else if (v == &PL_vtbl_fm) s = "fm";
1033 else if (v == &PL_vtbl_uvar) s = "uvar";
1034 else if (v == &PL_vtbl_defelem) s = "defelem";
1035 #ifdef USE_LOCALE_COLLATE
1036 else if (v == &PL_vtbl_collxfrm) s = "collxfrm";
1038 else if (v == &PL_vtbl_amagic) s = "amagic";
1039 else if (v == &PL_vtbl_amagicelem) s = "amagicelem";
1040 else if (v == &PL_vtbl_backref) s = "backref";
1041 else if (v == &PL_vtbl_utf8) s = "utf8";
1042 else if (v == &PL_vtbl_arylen_p) s = "arylen_p";
1043 else if (v == &PL_vtbl_hintselem) s = "hintselem";
1045 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", s);
1047 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0x%"UVxf"\n", PTR2UV(v));
1050 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0\n");
1053 Perl_dump_indent(aTHX_ level, file, " MG_PRIVATE = %d\n", mg->mg_private);
1057 const char *name = NULL;
1058 for (n = 0; magic_names[n].name; n++) {
1059 if (mg->mg_type == magic_names[n].type) {
1060 name = magic_names[n].name;
1065 Perl_dump_indent(aTHX_ level, file,
1066 " MG_TYPE = PERL_MAGIC_%s\n", name);
1068 Perl_dump_indent(aTHX_ level, file,
1069 " MG_TYPE = UNKNOWN(\\%o)\n", mg->mg_type);
1073 Perl_dump_indent(aTHX_ level, file, " MG_FLAGS = 0x%02X\n", mg->mg_flags);
1074 if (mg->mg_type == PERL_MAGIC_envelem &&
1075 mg->mg_flags & MGf_TAINTEDDIR)
1076 Perl_dump_indent(aTHX_ level, file, " TAINTEDDIR\n");
1077 if (mg->mg_flags & MGf_REFCOUNTED)
1078 Perl_dump_indent(aTHX_ level, file, " REFCOUNTED\n");
1079 if (mg->mg_flags & MGf_GSKIP)
1080 Perl_dump_indent(aTHX_ level, file, " GSKIP\n");
1081 if (mg->mg_type == PERL_MAGIC_regex_global &&
1082 mg->mg_flags & MGf_MINMATCH)
1083 Perl_dump_indent(aTHX_ level, file, " MINMATCH\n");
1086 Perl_dump_indent(aTHX_ level, file, " MG_OBJ = 0x%"UVxf"\n", PTR2UV(mg->mg_obj));
1087 if (mg->mg_flags & MGf_REFCOUNTED)
1088 do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
1091 Perl_dump_indent(aTHX_ level, file, " MG_LEN = %ld\n", (long)mg->mg_len);
1093 Perl_dump_indent(aTHX_ level, file, " MG_PTR = 0x%"UVxf, PTR2UV(mg->mg_ptr));
1094 if (mg->mg_len >= 0) {
1095 if (mg->mg_type != PERL_MAGIC_utf8) {
1096 SV *sv = newSVpvs("");
1097 PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim));
1101 else if (mg->mg_len == HEf_SVKEY) {
1102 PerlIO_puts(file, " => HEf_SVKEY\n");
1103 do_sv_dump(level+2, file, (SV*)((mg)->mg_ptr), nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
1107 PerlIO_puts(file, " ???? - please notify IZ");
1108 PerlIO_putc(file, '\n');
1110 if (mg->mg_type == PERL_MAGIC_utf8) {
1111 STRLEN *cache = (STRLEN *) mg->mg_ptr;
1114 for (i = 0; i < PERL_MAGIC_UTF8_CACHESIZE; i++)
1115 Perl_dump_indent(aTHX_ level, file,
1116 " %2"IVdf": %"UVuf" -> %"UVuf"\n",
1119 (UV)cache[i * 2 + 1]);
1126 Perl_magic_dump(pTHX_ const MAGIC *mg)
1128 do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0);
1132 Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, const char *name, HV *sv)
1135 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
1136 if (sv && (hvname = HvNAME_get(sv)))
1137 PerlIO_printf(file, "\t\"%s\"\n", hvname);
1139 PerlIO_putc(file, '\n');
1143 Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
1145 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
1146 if (sv && GvNAME(sv))
1147 PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv));
1149 PerlIO_putc(file, '\n');
1153 Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
1155 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
1156 if (sv && GvNAME(sv)) {
1158 PerlIO_printf(file, "\t\"");
1159 if (GvSTASH(sv) && (hvname = HvNAME_get(GvSTASH(sv))))
1160 PerlIO_printf(file, "%s\" :: \"", hvname);
1161 PerlIO_printf(file, "%s\"\n", GvNAME(sv));
1164 PerlIO_putc(file, '\n');
1168 Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
1177 Perl_dump_indent(aTHX_ level, file, "SV = 0\n");
1181 flags = SvFLAGS(sv);
1184 d = Perl_newSVpvf(aTHX_
1185 "(0x%"UVxf") at 0x%"UVxf"\n%*s REFCNT = %"IVdf"\n%*s FLAGS = (",
1186 PTR2UV(SvANY(sv)), PTR2UV(sv),
1187 (int)(PL_dumpindent*level), "", (IV)SvREFCNT(sv),
1188 (int)(PL_dumpindent*level), "");
1190 if (flags & SVs_PADSTALE) sv_catpv(d, "PADSTALE,");
1191 if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,");
1192 if (flags & SVs_PADMY) sv_catpv(d, "PADMY,");
1193 if (flags & SVs_TEMP) sv_catpv(d, "TEMP,");
1194 if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,");
1195 if (flags & SVs_GMG) sv_catpv(d, "GMG,");
1196 if (flags & SVs_SMG) sv_catpv(d, "SMG,");
1197 if (flags & SVs_RMG) sv_catpv(d, "RMG,");
1199 if (flags & SVf_IOK) sv_catpv(d, "IOK,");
1200 if (flags & SVf_NOK) sv_catpv(d, "NOK,");
1201 if (flags & SVf_POK) sv_catpv(d, "POK,");
1202 if (flags & SVf_ROK) {
1203 sv_catpv(d, "ROK,");
1204 if (SvWEAKREF(sv)) sv_catpv(d, "WEAKREF,");
1206 if (flags & SVf_OOK) sv_catpv(d, "OOK,");
1207 if (flags & SVf_FAKE) sv_catpv(d, "FAKE,");
1208 if (flags & SVf_READONLY) sv_catpv(d, "READONLY,");
1210 if (flags & SVf_AMAGIC) sv_catpv(d, "OVERLOAD,");
1211 if (flags & SVp_IOK) sv_catpv(d, "pIOK,");
1212 if (flags & SVp_NOK) sv_catpv(d, "pNOK,");
1213 if (flags & SVp_POK) sv_catpv(d, "pPOK,");
1214 if (flags & SVp_SCREAM && type != SVt_PVHV)
1215 sv_catpv(d, "SCREAM,");
1220 if (CvANON(sv)) sv_catpv(d, "ANON,");
1221 if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
1222 if (CvCLONE(sv)) sv_catpv(d, "CLONE,");
1223 if (CvCLONED(sv)) sv_catpv(d, "CLONED,");
1224 if (CvCONST(sv)) sv_catpv(d, "CONST,");
1225 if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,");
1226 if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,");
1227 if (CvLVALUE(sv)) sv_catpv(d, "LVALUE,");
1228 if (CvMETHOD(sv)) sv_catpv(d, "METHOD,");
1229 if (CvLOCKED(sv)) sv_catpv(d, "LOCKED,");
1230 if (CvWEAKOUTSIDE(sv)) sv_catpv(d, "WEAKOUTSIDE,");
1231 if (CvASSERTION(sv)) sv_catpv(d, "ASSERTION,");
1234 if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,");
1235 if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,");
1236 if (HvHASKFLAGS(sv)) sv_catpv(d, "HASKFLAGS,");
1237 if (HvREHASH(sv)) sv_catpv(d, "REHASH,");
1238 if (flags & SVphv_CLONEABLE) sv_catpv(d, "CLONEABLE,");
1240 case SVt_PVGV: case SVt_PVLV:
1241 if (GvINTRO(sv)) sv_catpv(d, "INTRO,");
1242 if (GvMULTI(sv)) sv_catpv(d, "MULTI,");
1243 if (GvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
1244 if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,");
1245 if (GvIN_PAD(sv)) sv_catpv(d, "IN_PAD,");
1246 if (SvPAD_OUR(sv)) sv_catpv(d, "OUR,");
1247 if (SvPAD_STATE(sv)) sv_catpv(d, "STATE,");
1248 if (SvPAD_TYPED(sv)) sv_catpv(d, "TYPED,");
1249 if (GvIMPORTED(sv)) {
1250 sv_catpv(d, "IMPORT");
1251 if (GvIMPORTED(sv) == GVf_IMPORTED)
1252 sv_catpv(d, "ALL,");
1255 if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV");
1256 if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV");
1257 if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV");
1258 if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV");
1264 if (SvEVALED(sv)) sv_catpv(d, "EVALED,");
1265 if (SvIsUV(sv) && !(flags & SVf_ROK)) sv_catpv(d, "IsUV,");
1268 if (SvTAIL(sv)) sv_catpv(d, "TAIL,");
1269 if (SvVALID(sv)) sv_catpv(d, "VALID,");
1272 if (SvPAD_TYPED(sv)) sv_catpv(d, "TYPED,");
1277 /* SVphv_SHAREKEYS is also 0x20000000 */
1278 if ((type != SVt_PVHV) && SvUTF8(sv))
1279 sv_catpv(d, "UTF8");
1281 if (*(SvEND(d) - 1) == ',') {
1282 SvCUR_set(d, SvCUR(d) - 1);
1283 SvPVX(d)[SvCUR(d)] = '\0';
1288 #ifdef DEBUG_LEAKING_SCALARS
1289 Perl_dump_indent(aTHX_ level, file, "ALLOCATED at %s:%d %s %s%s\n",
1290 sv->sv_debug_file ? sv->sv_debug_file : "(unknown)",
1292 sv->sv_debug_inpad ? "for" : "by",
1293 sv->sv_debug_optype ? PL_op_name[sv->sv_debug_optype]: "(none)",
1294 sv->sv_debug_cloned ? " (cloned)" : "");
1296 Perl_dump_indent(aTHX_ level, file, "SV = ");
1299 PerlIO_printf(file, "NULL%s\n", s);
1303 PerlIO_printf(file, "IV%s\n", s);
1306 PerlIO_printf(file, "NV%s\n", s);
1309 PerlIO_printf(file, "RV%s\n", s);
1312 PerlIO_printf(file, "PV%s\n", s);
1315 PerlIO_printf(file, "PVIV%s\n", s);
1318 PerlIO_printf(file, "PVNV%s\n", s);
1321 PerlIO_printf(file, "PVBM%s\n", s);
1324 PerlIO_printf(file, "PVMG%s\n", s);
1327 PerlIO_printf(file, "PVLV%s\n", s);
1330 PerlIO_printf(file, "PVAV%s\n", s);
1333 PerlIO_printf(file, "PVHV%s\n", s);
1336 PerlIO_printf(file, "PVCV%s\n", s);
1339 PerlIO_printf(file, "PVGV%s\n", s);
1342 PerlIO_printf(file, "PVFM%s\n", s);
1345 PerlIO_printf(file, "PVIO%s\n", s);
1348 PerlIO_printf(file, "UNKNOWN(0x%"UVxf") %s\n", (UV)type, s);
1352 if ((type >= SVt_PVIV && type != SVt_PVAV && type != SVt_PVHV
1353 && type != SVt_PVCV && !isGV_with_GP(sv))
1354 || type == SVt_IV) {
1356 #ifdef PERL_OLD_COPY_ON_WRITE
1360 Perl_dump_indent(aTHX_ level, file, " UV = %"UVuf, (UV)SvUVX(sv));
1362 Perl_dump_indent(aTHX_ level, file, " IV = %"IVdf, (IV)SvIVX(sv));
1364 PerlIO_printf(file, " (OFFSET)");
1365 #ifdef PERL_OLD_COPY_ON_WRITE
1366 if (SvIsCOW_shared_hash(sv))
1367 PerlIO_printf(file, " (HASH)");
1368 else if (SvIsCOW_normal(sv))
1369 PerlIO_printf(file, " (COW from 0x%"UVxf")", (UV)SvUVX(sv));
1371 PerlIO_putc(file, '\n');
1373 if ((type >= SVt_PVNV && type != SVt_PVAV && type != SVt_PVHV
1374 && type != SVt_PVCV && type != SVt_PVFM && !isGV_with_GP(sv))
1375 || type == SVt_NV) {
1376 STORE_NUMERIC_LOCAL_SET_STANDARD();
1377 /* %Vg doesn't work? --jhi */
1378 #ifdef USE_LONG_DOUBLE
1379 Perl_dump_indent(aTHX_ level, file, " NV = %.*" PERL_PRIgldbl "\n", LDBL_DIG, SvNVX(sv));
1381 Perl_dump_indent(aTHX_ level, file, " NV = %.*g\n", DBL_DIG, SvNVX(sv));
1383 RESTORE_NUMERIC_LOCAL();
1386 Perl_dump_indent(aTHX_ level, file, " RV = 0x%"UVxf"\n", PTR2UV(SvRV(sv)));
1388 do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim);
1390 if (type < SVt_PV) {
1394 if (type <= SVt_PVLV && !isGV_with_GP(sv)) {
1395 if (SvPVX_const(sv)) {
1396 Perl_dump_indent(aTHX_ level, file," PV = 0x%"UVxf" ", PTR2UV(SvPVX_const(sv)));
1398 PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX_const(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim));
1399 PerlIO_printf(file, "%s", pv_display(d, SvPVX_const(sv), SvCUR(sv), SvLEN(sv), pvlim));
1400 if (SvUTF8(sv)) /* the 8? \x{....} */
1401 PerlIO_printf(file, " [UTF8 \"%s\"]", sv_uni_display(d, sv, 8 * sv_len_utf8(sv), UNI_DISPLAY_QQ));
1402 PerlIO_printf(file, "\n");
1403 Perl_dump_indent(aTHX_ level, file, " CUR = %"IVdf"\n", (IV)SvCUR(sv));
1404 Perl_dump_indent(aTHX_ level, file, " LEN = %"IVdf"\n", (IV)SvLEN(sv));
1407 Perl_dump_indent(aTHX_ level, file, " PV = 0\n");
1409 if (type >= SVt_PVMG) {
1411 do_magic_dump(level, file, SvMAGIC(sv), nest, maxnest, dumpops, pvlim);
1413 do_hv_dump(level, file, " STASH", SvSTASH(sv));
1417 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(AvARRAY(sv)));
1418 if (AvARRAY(sv) != AvALLOC(sv)) {
1419 PerlIO_printf(file, " (offset=%"IVdf")\n", (IV)(AvARRAY(sv) - AvALLOC(sv)));
1420 Perl_dump_indent(aTHX_ level, file, " ALLOC = 0x%"UVxf"\n", PTR2UV(AvALLOC(sv)));
1423 PerlIO_putc(file, '\n');
1424 Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)AvFILLp(sv));
1425 Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)AvMAX(sv));
1426 Perl_dump_indent(aTHX_ level, file, " ARYLEN = 0x%"UVxf"\n", SvMAGIC(sv) ? PTR2UV(AvARYLEN(sv)) : 0);
1427 sv_setpvn(d, "", 0);
1428 if (AvREAL(sv)) sv_catpv(d, ",REAL");
1429 if (AvREIFY(sv)) sv_catpv(d, ",REIFY");
1430 Perl_dump_indent(aTHX_ level, file, " FLAGS = (%s)\n",
1431 SvCUR(d) ? SvPVX_const(d) + 1 : "");
1432 if (nest < maxnest && av_len((AV*)sv) >= 0) {
1434 for (count = 0; count <= av_len((AV*)sv) && count < maxnest; count++) {
1435 SV** elt = av_fetch((AV*)sv,count,0);
1437 Perl_dump_indent(aTHX_ level + 1, file, "Elt No. %"IVdf"\n", (IV)count);
1439 do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim);
1444 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv)));
1445 if (HvARRAY(sv) && HvKEYS(sv)) {
1446 /* Show distribution of HEs in the ARRAY */
1448 #define FREQ_MAX ((int)(sizeof freq / sizeof freq[0] - 1))
1451 U32 pow2 = 2, keys = HvKEYS(sv);
1452 NV theoret, sum = 0;
1454 PerlIO_printf(file, " (");
1455 Zero(freq, FREQ_MAX + 1, int);
1456 for (i = 0; (STRLEN)i <= HvMAX(sv); i++) {
1459 for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h))
1461 if (count > FREQ_MAX)
1467 for (i = 0; i <= max; i++) {
1469 PerlIO_printf(file, "%d%s:%d", i,
1470 (i == FREQ_MAX) ? "+" : "",
1473 PerlIO_printf(file, ", ");
1476 PerlIO_putc(file, ')');
1477 /* The "quality" of a hash is defined as the total number of
1478 comparisons needed to access every element once, relative
1479 to the expected number needed for a random hash.
1481 The total number of comparisons is equal to the sum of
1482 the squares of the number of entries in each bucket.
1483 For a random hash of n keys into k buckets, the expected
1488 for (i = max; i > 0; i--) { /* Precision: count down. */
1489 sum += freq[i] * i * i;
1491 while ((keys = keys >> 1))
1493 theoret = HvKEYS(sv);
1494 theoret += theoret * (theoret-1)/pow2;
1495 PerlIO_putc(file, '\n');
1496 Perl_dump_indent(aTHX_ level, file, " hash quality = %.1"NVff"%%", theoret/sum*100);
1498 PerlIO_putc(file, '\n');
1499 Perl_dump_indent(aTHX_ level, file, " KEYS = %"IVdf"\n", (IV)HvKEYS(sv));
1500 Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)HvFILL(sv));
1501 Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)HvMAX(sv));
1502 Perl_dump_indent(aTHX_ level, file, " RITER = %"IVdf"\n", (IV)HvRITER_get(sv));
1503 Perl_dump_indent(aTHX_ level, file, " EITER = 0x%"UVxf"\n", PTR2UV(HvEITER_get(sv)));
1505 MAGIC *mg = mg_find(sv, PERL_MAGIC_symtab);
1506 if (mg && mg->mg_obj) {
1507 Perl_dump_indent(aTHX_ level, file, " PMROOT = 0x%"UVxf"\n", PTR2UV(mg->mg_obj));
1511 const char *hvname = HvNAME_get(sv);
1513 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", hvname);
1516 AV *backrefs = *Perl_hv_backreferences_p(aTHX_ (HV*)sv);
1518 Perl_dump_indent(aTHX_ level, file, " BACKREFS = 0x%"UVxf"\n",
1520 do_sv_dump(level+1, file, (SV*)backrefs, nest+1, maxnest,
1524 if (nest < maxnest && !HvEITER_get(sv)) { /* Try to preserve iterator */
1526 HV * const hv = (HV*)sv;
1527 int count = maxnest - nest;
1530 while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))
1535 const U32 hash = HeHASH(he);
1537 keysv = hv_iterkeysv(he);
1538 keypv = SvPV_const(keysv, len);
1539 elt = hv_iterval(hv, he);
1540 Perl_dump_indent(aTHX_ level+1, file, "Elt %s ", pv_display(d, keypv, len, 0, pvlim));
1542 PerlIO_printf(file, "[UTF8 \"%s\"] ", sv_uni_display(d, keysv, 8 * sv_len_utf8(keysv), UNI_DISPLAY_QQ));
1544 PerlIO_printf(file, "[REHASH] ");
1545 PerlIO_printf(file, "HASH = 0x%"UVxf"\n", (UV)hash);
1546 do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim);
1548 hv_iterinit(hv); /* Return to status quo */
1554 const char *const proto = SvPV_const(sv, len);
1555 Perl_dump_indent(aTHX_ level, file, " PROTOTYPE = \"%.*s\"\n",
1560 do_hv_dump(level, file, " COMP_STASH", CvSTASH(sv));
1561 if (!CvISXSUB(sv)) {
1563 Perl_dump_indent(aTHX_ level, file,
1564 " START = 0x%"UVxf" ===> %"IVdf"\n",
1565 PTR2UV(CvSTART(sv)),
1566 (IV)sequence_num(CvSTART(sv)));
1568 Perl_dump_indent(aTHX_ level, file, " ROOT = 0x%"UVxf"\n",
1569 PTR2UV(CvROOT(sv)));
1570 if (CvROOT(sv) && dumpops) {
1571 do_op_dump(level+1, file, CvROOT(sv));
1574 SV *constant = cv_const_sv((CV *)sv);
1576 Perl_dump_indent(aTHX_ level, file, " XSUB = 0x%"UVxf"\n", PTR2UV(CvXSUB(sv)));
1579 Perl_dump_indent(aTHX_ level, file, " XSUBANY = 0x%"UVxf
1581 PTR2UV(CvXSUBANY(sv).any_ptr));
1582 do_sv_dump(level+1, file, constant, nest+1, maxnest, dumpops,
1585 Perl_dump_indent(aTHX_ level, file, " XSUBANY = %"IVdf"\n",
1586 (IV)CvXSUBANY(sv).any_i32);
1589 do_gvgv_dump(level, file, " GVGV::GV", CvGV(sv));
1590 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", CvFILE(sv));
1591 Perl_dump_indent(aTHX_ level, file, " DEPTH = %"IVdf"\n", (IV)CvDEPTH(sv));
1592 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)CvFLAGS(sv));
1593 Perl_dump_indent(aTHX_ level, file, " OUTSIDE_SEQ = %"UVuf"\n", (UV)CvOUTSIDE_SEQ(sv));
1594 if (type == SVt_PVFM)
1595 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)FmLINES(sv));
1596 Perl_dump_indent(aTHX_ level, file, " PADLIST = 0x%"UVxf"\n", PTR2UV(CvPADLIST(sv)));
1597 if (nest < maxnest) {
1598 do_dump_pad(level+1, file, CvPADLIST(sv), 0);
1601 const CV *outside = CvOUTSIDE(sv);
1602 Perl_dump_indent(aTHX_ level, file, " OUTSIDE = 0x%"UVxf" (%s)\n",
1605 : CvANON(outside) ? "ANON"
1606 : (outside == PL_main_cv) ? "MAIN"
1607 : CvUNIQUE(outside) ? "UNIQUE"
1608 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
1610 if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv)))
1611 do_sv_dump(level+1, file, (SV*)CvOUTSIDE(sv), nest+1, maxnest, dumpops, pvlim);
1613 case SVt_PVGV: case SVt_PVLV:
1614 if (type == SVt_PVLV) {
1615 Perl_dump_indent(aTHX_ level, file, " TYPE = %c\n", LvTYPE(sv));
1616 Perl_dump_indent(aTHX_ level, file, " TARGOFF = %"IVdf"\n", (IV)LvTARGOFF(sv));
1617 Perl_dump_indent(aTHX_ level, file, " TARGLEN = %"IVdf"\n", (IV)LvTARGLEN(sv));
1618 Perl_dump_indent(aTHX_ level, file, " TARG = 0x%"UVxf"\n", PTR2UV(LvTARG(sv)));
1619 if (LvTYPE(sv) != 't' && LvTYPE(sv) != 'T')
1620 do_sv_dump(level+1, file, LvTARG(sv), nest+1, maxnest,
1623 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", GvNAME(sv));
1624 Perl_dump_indent(aTHX_ level, file, " NAMELEN = %"IVdf"\n", (IV)GvNAMELEN(sv));
1625 do_hv_dump (level, file, " GvSTASH", GvSTASH(sv));
1626 if (!isGV_with_GP(sv))
1628 Perl_dump_indent(aTHX_ level, file, " GP = 0x%"UVxf"\n", PTR2UV(GvGP(sv)));
1631 Perl_dump_indent(aTHX_ level, file, " SV = 0x%"UVxf"\n", PTR2UV(GvSV(sv)));
1632 Perl_dump_indent(aTHX_ level, file, " REFCNT = %"IVdf"\n", (IV)GvREFCNT(sv));
1633 Perl_dump_indent(aTHX_ level, file, " IO = 0x%"UVxf"\n", PTR2UV(GvIOp(sv)));
1634 Perl_dump_indent(aTHX_ level, file, " FORM = 0x%"UVxf" \n", PTR2UV(GvFORM(sv)));
1635 Perl_dump_indent(aTHX_ level, file, " AV = 0x%"UVxf"\n", PTR2UV(GvAV(sv)));
1636 Perl_dump_indent(aTHX_ level, file, " HV = 0x%"UVxf"\n", PTR2UV(GvHV(sv)));
1637 Perl_dump_indent(aTHX_ level, file, " CV = 0x%"UVxf"\n", PTR2UV(GvCV(sv)));
1638 Perl_dump_indent(aTHX_ level, file, " CVGEN = 0x%"UVxf"\n", (UV)GvCVGEN(sv));
1639 Perl_dump_indent(aTHX_ level, file, " LINE = %"IVdf"\n", (IV)GvLINE(sv));
1640 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", GvFILE(sv));
1641 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)GvFLAGS(sv));
1642 do_gv_dump (level, file, " EGV", GvEGV(sv));
1645 Perl_dump_indent(aTHX_ level, file, " IFP = 0x%"UVxf"\n", PTR2UV(IoIFP(sv)));
1646 Perl_dump_indent(aTHX_ level, file, " OFP = 0x%"UVxf"\n", PTR2UV(IoOFP(sv)));
1647 Perl_dump_indent(aTHX_ level, file, " DIRP = 0x%"UVxf"\n", PTR2UV(IoDIRP(sv)));
1648 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)IoLINES(sv));
1649 Perl_dump_indent(aTHX_ level, file, " PAGE = %"IVdf"\n", (IV)IoPAGE(sv));
1650 Perl_dump_indent(aTHX_ level, file, " PAGE_LEN = %"IVdf"\n", (IV)IoPAGE_LEN(sv));
1651 Perl_dump_indent(aTHX_ level, file, " LINES_LEFT = %"IVdf"\n", (IV)IoLINES_LEFT(sv));
1653 Perl_dump_indent(aTHX_ level, file, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
1654 if (!IoTOP_GV(sv) || SvTYPE(IoTOP_GV(sv)) == SVt_PVGV)
1655 do_gv_dump (level, file, " TOP_GV", IoTOP_GV(sv));
1657 Perl_dump_indent(aTHX_ level, file, " TOP_GV = 0x%"UVxf"\n",
1658 PTR2UV(IoTOP_GV(sv)));
1659 do_sv_dump (level+1, file, (SV *) IoTOP_GV(sv), nest+1, maxnest,
1662 /* Source filters hide things that are not GVs in these three, so let's
1663 be careful out there. */
1665 Perl_dump_indent(aTHX_ level, file, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
1666 if (!IoFMT_GV(sv) || SvTYPE(IoFMT_GV(sv)) == SVt_PVGV)
1667 do_gv_dump (level, file, " FMT_GV", IoFMT_GV(sv));
1669 Perl_dump_indent(aTHX_ level, file, " FMT_GV = 0x%"UVxf"\n",
1670 PTR2UV(IoFMT_GV(sv)));
1671 do_sv_dump (level+1, file, (SV *) IoFMT_GV(sv), nest+1, maxnest,
1674 if (IoBOTTOM_NAME(sv))
1675 Perl_dump_indent(aTHX_ level, file, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
1676 if (!IoBOTTOM_GV(sv) || SvTYPE(IoBOTTOM_GV(sv)) == SVt_PVGV)
1677 do_gv_dump (level, file, " BOTTOM_GV", IoBOTTOM_GV(sv));
1679 Perl_dump_indent(aTHX_ level, file, " BOTTOM_GV = 0x%"UVxf"\n",
1680 PTR2UV(IoBOTTOM_GV(sv)));
1681 do_sv_dump (level+1, file, (SV *) IoBOTTOM_GV(sv), nest+1, maxnest,
1684 Perl_dump_indent(aTHX_ level, file, " SUBPROCESS = %"IVdf"\n", (IV)IoSUBPROCESS(sv));
1685 if (isPRINT(IoTYPE(sv)))
1686 Perl_dump_indent(aTHX_ level, file, " TYPE = '%c'\n", IoTYPE(sv));
1688 Perl_dump_indent(aTHX_ level, file, " TYPE = '\\%o'\n", IoTYPE(sv));
1689 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)IoFLAGS(sv));
1696 Perl_sv_dump(pTHX_ SV *sv)
1699 do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0);
1703 Perl_runops_debug(pTHX)
1707 if (ckWARN_d(WARN_DEBUGGING))
1708 Perl_warner(aTHX_ packWARN(WARN_DEBUGGING), "NULL OP IN RUN");
1712 DEBUG_l(Perl_deb(aTHX_ "Entering new RUNOPS level\n"));
1716 if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok)
1717 PerlIO_printf(Perl_debug_log,
1718 "WARNING: %"UVxf" changed from %"UVxf" to %"UVxf"\n",
1719 PTR2UV(PL_watchaddr), PTR2UV(PL_watchok),
1720 PTR2UV(*PL_watchaddr));
1721 if (DEBUG_s_TEST_) {
1722 if (DEBUG_v_TEST_) {
1723 PerlIO_printf(Perl_debug_log, "\n");
1731 if (DEBUG_t_TEST_) debop(PL_op);
1732 if (DEBUG_P_TEST_) debprof(PL_op);
1734 } while ((PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX)));
1735 DEBUG_l(Perl_deb(aTHX_ "leaving RUNOPS level\n"));
1742 Perl_debop(pTHX_ const OP *o)
1745 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
1748 Perl_deb(aTHX_ "%s", OP_NAME(o));
1749 switch (o->op_type) {
1751 PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo_sv));
1758 /* FIXME - it this making unwarranted assumptions about the
1759 UTF-8 cleanliness of the dump file handle? */
1762 gv_fullname3(sv, cGVOPo_gv, NULL);
1763 PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv));
1767 PerlIO_printf(Perl_debug_log, "(NULL)");
1773 /* print the lexical's name */
1774 CV *cv = deb_curcv(cxstack_ix);
1777 AV * const padlist = CvPADLIST(cv);
1778 AV * const comppad = (AV*)(*av_fetch(padlist, 0, FALSE));
1779 sv = *av_fetch(comppad, o->op_targ, FALSE);
1783 PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv));
1785 PerlIO_printf(Perl_debug_log, "[%"UVuf"]", (UV)o->op_targ);
1791 PerlIO_printf(Perl_debug_log, "\n");
1796 S_deb_curcv(pTHX_ I32 ix)
1799 const PERL_CONTEXT *cx = &cxstack[ix];
1800 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT)
1801 return cx->blk_sub.cv;
1802 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
1804 else if (ix == 0 && PL_curstackinfo->si_type == PERLSI_MAIN)
1809 return deb_curcv(ix - 1);
1813 Perl_watch(pTHX_ char **addr)
1816 PL_watchaddr = addr;
1818 PerlIO_printf(Perl_debug_log, "WATCHING, %"UVxf" is currently %"UVxf"\n",
1819 PTR2UV(PL_watchaddr), PTR2UV(PL_watchok));
1823 S_debprof(pTHX_ const OP *o)
1826 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
1828 if (!PL_profiledata)
1829 Newxz(PL_profiledata, MAXO, U32);
1830 ++PL_profiledata[o->op_type];
1834 Perl_debprofdump(pTHX)
1838 if (!PL_profiledata)
1840 for (i = 0; i < MAXO; i++) {
1841 if (PL_profiledata[i])
1842 PerlIO_printf(Perl_debug_log,
1843 "%5lu %s\n", (unsigned long)PL_profiledata[i],
1850 * XML variants of most of the above routines
1855 S_xmldump_attr(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
1858 PerlIO_printf(file, "\n ");
1859 va_start(args, pat);
1860 xmldump_vindent(level, file, pat, &args);
1866 Perl_xmldump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
1869 va_start(args, pat);
1870 xmldump_vindent(level, file, pat, &args);
1875 Perl_xmldump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args)
1877 PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), "");
1878 PerlIO_vprintf(file, pat, *args);
1882 Perl_xmldump_all(pTHX)
1884 PerlIO_setlinebuf(PL_xmlfp);
1886 op_xmldump(PL_main_root);
1887 if (PL_xmlfp != (PerlIO*)PerlIO_stdout())
1888 PerlIO_close(PL_xmlfp);
1893 Perl_xmldump_packsubs(pTHX_ const HV *stash)
1898 if (!HvARRAY(stash))
1900 for (i = 0; i <= (I32) HvMAX(stash); i++) {
1901 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
1902 GV *gv = (GV*)HeVAL(entry);
1904 if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
1910 if (HeKEY(entry)[HeKLEN(entry)-1] == ':'
1911 && (hv = GvHV(gv)) && hv != PL_defstash)
1912 xmldump_packsubs(hv); /* nested package */
1918 Perl_xmldump_sub(pTHX_ const GV *gv)
1920 SV *sv = sv_newmortal();
1922 gv_fullname3(sv, gv, Nullch);
1923 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "\nSUB %s = ", SvPVX(sv));
1924 if (CvXSUB(GvCV(gv)))
1925 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "(xsub 0x%"UVxf" %d)\n",
1926 PTR2UV(CvXSUB(GvCV(gv))),
1927 (int)CvXSUBANY(GvCV(gv)).any_i32);
1928 else if (CvROOT(GvCV(gv)))
1929 op_xmldump(CvROOT(GvCV(gv)));
1931 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "<undef>\n");
1935 Perl_xmldump_form(pTHX_ const GV *gv)
1937 SV *sv = sv_newmortal();
1939 gv_fullname3(sv, gv, Nullch);
1940 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "\nFORMAT %s = ", SvPVX(sv));
1941 if (CvROOT(GvFORM(gv)))
1942 op_xmldump(CvROOT(GvFORM(gv)));
1944 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "<undef>\n");
1948 Perl_xmldump_eval(pTHX)
1950 op_xmldump(PL_eval_root);
1954 Perl_sv_catxmlsv(pTHX_ SV *dsv, SV *ssv)
1956 return sv_catxmlpvn(dsv, SvPVX(ssv), SvCUR(ssv), SvUTF8(ssv));
1960 Perl_sv_catxmlpvn(pTHX_ SV *dsv, char* pv, STRLEN len, int utf8)
1968 sv_catpvn(dsv,"",0);
1969 dsvcur = SvCUR(dsv); /* in case we have to restart */
1974 c = utf8_to_uvchr((U8*)pv, &cl);
1976 SvCUR(dsv) = dsvcur;
2041 Perl_sv_catpvf(aTHX_ dsv, "STUPIDXML(#x%X)", c);
2044 Perl_sv_catpvf(aTHX_ dsv, "<");
2047 Perl_sv_catpvf(aTHX_ dsv, ">");
2050 Perl_sv_catpvf(aTHX_ dsv, "&");
2053 Perl_sv_catpvf(aTHX_ dsv, """);
2057 if (c < 32 || c > 127) {
2058 Perl_sv_catpvf(aTHX_ dsv, "&#x%X;", c);
2061 Perl_sv_catpvf(aTHX_ dsv, "%c", c);
2065 if ((c >= 0xD800 && c <= 0xDB7F) ||
2066 (c >= 0xDC00 && c <= 0xDFFF) ||
2067 (c >= 0xFFF0 && c <= 0xFFFF) ||
2069 Perl_sv_catpvf(aTHX_ dsv, "STUPIDXML(#x%X)", c);
2071 Perl_sv_catpvf(aTHX_ dsv, "&#x%X;", c);
2084 Perl_sv_xmlpeek(pTHX_ SV *sv)
2086 SV *t = sv_newmortal();
2091 sv_setpvn(t, "", 0);
2094 sv_catpv(t, "VOID=\"\"");
2097 else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') {
2098 sv_catpv(t, "WILD=\"\"");
2101 else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) {
2102 if (sv == &PL_sv_undef) {
2103 sv_catpv(t, "SV_UNDEF=\"1\"");
2104 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
2105 SVs_GMG|SVs_SMG|SVs_RMG)) &&
2109 else if (sv == &PL_sv_no) {
2110 sv_catpv(t, "SV_NO=\"1\"");
2111 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
2112 SVs_GMG|SVs_SMG|SVs_RMG)) &&
2113 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
2114 SVp_POK|SVp_NOK)) &&
2119 else if (sv == &PL_sv_yes) {
2120 sv_catpv(t, "SV_YES=\"1\"");
2121 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
2122 SVs_GMG|SVs_SMG|SVs_RMG)) &&
2123 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
2124 SVp_POK|SVp_NOK)) &&
2126 SvPVX(sv) && *SvPVX(sv) == '1' &&
2131 sv_catpv(t, "SV_PLACEHOLDER=\"1\"");
2132 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
2133 SVs_GMG|SVs_SMG|SVs_RMG)) &&
2137 sv_catpv(t, " XXX=\"\" ");
2139 else if (SvREFCNT(sv) == 0) {
2140 sv_catpv(t, " refcnt=\"0\"");
2143 else if (DEBUG_R_TEST_) {
2146 /* is this SV on the tmps stack? */
2147 for (ix=PL_tmps_ix; ix>=0; ix--) {
2148 if (PL_tmps_stack[ix] == sv) {
2153 if (SvREFCNT(sv) > 1)
2154 Perl_sv_catpvf(aTHX_ t, " DRT=\"<%"UVuf"%s>\"", (UV)SvREFCNT(sv),
2157 sv_catpv(t, " DRT=\"<T>\"");
2161 sv_catpv(t, " ROK=\"\"");
2163 switch (SvTYPE(sv)) {
2165 sv_catpv(t, " FREED=\"1\"");
2169 sv_catpv(t, " UNDEF=\"1\"");
2172 sv_catpv(t, " IV=\"");
2175 sv_catpv(t, " NV=\"");
2178 sv_catpv(t, " RV=\"");
2181 sv_catpv(t, " PV=\"");
2184 sv_catpv(t, " PVIV=\"");
2187 sv_catpv(t, " PVNV=\"");
2190 sv_catpv(t, " PVMG=\"");
2193 sv_catpv(t, " PVLV=\"");
2196 sv_catpv(t, " AV=\"");
2199 sv_catpv(t, " HV=\"");
2203 Perl_sv_catpvf(aTHX_ t, " CV=\"(%s)\"", GvNAME(CvGV(sv)));
2205 sv_catpv(t, " CV=\"()\"");
2208 sv_catpv(t, " GV=\"");
2211 sv_catpv(t, " BM=\"");
2214 sv_catpv(t, " FM=\"");
2217 sv_catpv(t, " IO=\"");
2226 else if (SvNOKp(sv)) {
2227 STORE_NUMERIC_LOCAL_SET_STANDARD();
2228 Perl_sv_catpvf(aTHX_ t, "%"NVgf"",SvNVX(sv));
2229 RESTORE_NUMERIC_LOCAL();
2231 else if (SvIOKp(sv)) {
2233 Perl_sv_catpvf(aTHX_ t, "%"UVuf"", (UV)SvUVX(sv));
2235 Perl_sv_catpvf(aTHX_ t, "%"IVdf"", (IV)SvIVX(sv));
2246 return SvPV(t, n_a);
2250 Perl_do_pmop_xmldump(pTHX_ I32 level, PerlIO *file, const PMOP *pm)
2253 Perl_xmldump_indent(aTHX_ level, file, "<pmop/>\n");
2256 Perl_xmldump_indent(aTHX_ level, file, "<pmop \n");
2259 char *s = PM_GETRE(pm)->precomp;
2260 SV *tmpsv = newSV(0);
2262 sv_catxmlpvn(tmpsv, s, strlen(s), 1);
2263 Perl_xmldump_indent(aTHX_ level, file, "pre=\"%s\"\n",
2265 SvREFCNT_dec(tmpsv);
2266 Perl_xmldump_indent(aTHX_ level, file, "when=\"%s\"\n",
2267 (pm->op_private & OPpRUNTIME) ? "RUN" : "COMP");
2270 Perl_xmldump_indent(aTHX_ level, file, "pre=\"\" when=\"RUN\"\n");
2271 if (pm->op_pmflags || (PM_GETRE(pm) && PM_GETRE(pm)->check_substr)) {
2272 SV * const tmpsv = pm_description(pm);
2273 Perl_xmldump_indent(aTHX_ level, file, "pmflags=\"%s\"\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
2274 SvREFCNT_dec(tmpsv);
2278 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
2279 Perl_xmldump_indent(aTHX_ level, file, ">\n");
2280 Perl_xmldump_indent(aTHX_ level+1, file, "<pm_repl>\n");
2281 do_op_xmldump(level+2, file, pm->op_pmreplroot);
2282 Perl_xmldump_indent(aTHX_ level+1, file, "</pm_repl>\n");
2283 Perl_xmldump_indent(aTHX_ level, file, "</pmop>\n");
2286 Perl_xmldump_indent(aTHX_ level, file, "/>\n");
2290 Perl_pmop_xmldump(pTHX_ const PMOP *pm)
2292 do_pmop_xmldump(0, PL_xmlfp, pm);
2296 Perl_do_op_xmldump(pTHX_ I32 level, PerlIO *file, const OP *o)
2303 seq = sequence_num(o);
2304 Perl_xmldump_indent(aTHX_ level, file,
2305 "<op_%s seq=\"%"UVuf" -> ",
2310 PerlIO_printf(file, seq ? "%"UVuf"\"" : "(%"UVuf")\"",
2311 sequence_num(o->op_next));
2313 PerlIO_printf(file, "DONE\"");
2316 if (o->op_type == OP_NULL)
2318 PerlIO_printf(file, " was=\"%s\"", PL_op_name[o->op_targ]);
2319 if (o->op_targ == OP_NEXTSTATE)
2322 PerlIO_printf(file, " line=\"%"UVf"\"",
2323 (UV)CopLINE(cCOPo));
2324 if (CopSTASHPV(cCOPo))
2325 PerlIO_printf(file, " package=\"%s\"",
2327 if (cCOPo->cop_label)
2328 PerlIO_printf(file, " label=\"%s\"",
2333 PerlIO_printf(file, " targ=\"%ld\"", (long)o->op_targ);
2336 PerlIO_printf(file, " addr=\"0x%"UVxf" => 0x%"UVxf"\"", (UV)o, (UV)o->op_next);
2339 SV *tmpsv = newSVpvn("", 0);
2340 switch (o->op_flags & OPf_WANT) {
2342 sv_catpv(tmpsv, ",VOID");
2344 case OPf_WANT_SCALAR:
2345 sv_catpv(tmpsv, ",SCALAR");
2348 sv_catpv(tmpsv, ",LIST");
2351 sv_catpv(tmpsv, ",UNKNOWN");
2354 if (o->op_flags & OPf_KIDS)
2355 sv_catpv(tmpsv, ",KIDS");
2356 if (o->op_flags & OPf_PARENS)
2357 sv_catpv(tmpsv, ",PARENS");
2358 if (o->op_flags & OPf_STACKED)
2359 sv_catpv(tmpsv, ",STACKED");
2360 if (o->op_flags & OPf_REF)
2361 sv_catpv(tmpsv, ",REF");
2362 if (o->op_flags & OPf_MOD)
2363 sv_catpv(tmpsv, ",MOD");
2364 if (o->op_flags & OPf_SPECIAL)
2365 sv_catpv(tmpsv, ",SPECIAL");
2366 PerlIO_printf(file, " flags=\"%s\"", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
2367 SvREFCNT_dec(tmpsv);
2369 if (o->op_private) {
2370 SV *tmpsv = newSVpvn("", 0);
2371 if (PL_opargs[o->op_type] & OA_TARGLEX) {
2372 if (o->op_private & OPpTARGET_MY)
2373 sv_catpv(tmpsv, ",TARGET_MY");
2375 else if (o->op_type == OP_LEAVESUB ||
2376 o->op_type == OP_LEAVE ||
2377 o->op_type == OP_LEAVESUBLV ||
2378 o->op_type == OP_LEAVEWRITE) {
2379 if (o->op_private & OPpREFCOUNTED)
2380 sv_catpv(tmpsv, ",REFCOUNTED");
2382 else if (o->op_type == OP_AASSIGN) {
2383 if (o->op_private & OPpASSIGN_COMMON)
2384 sv_catpv(tmpsv, ",COMMON");
2386 else if (o->op_type == OP_SASSIGN) {
2387 if (o->op_private & OPpASSIGN_BACKWARDS)
2388 sv_catpv(tmpsv, ",BACKWARDS");
2390 else if (o->op_type == OP_TRANS) {
2391 if (o->op_private & OPpTRANS_SQUASH)
2392 sv_catpv(tmpsv, ",SQUASH");
2393 if (o->op_private & OPpTRANS_DELETE)
2394 sv_catpv(tmpsv, ",DELETE");
2395 if (o->op_private & OPpTRANS_COMPLEMENT)
2396 sv_catpv(tmpsv, ",COMPLEMENT");
2397 if (o->op_private & OPpTRANS_IDENTICAL)
2398 sv_catpv(tmpsv, ",IDENTICAL");
2399 if (o->op_private & OPpTRANS_GROWS)
2400 sv_catpv(tmpsv, ",GROWS");
2402 else if (o->op_type == OP_REPEAT) {
2403 if (o->op_private & OPpREPEAT_DOLIST)
2404 sv_catpv(tmpsv, ",DOLIST");
2406 else if (o->op_type == OP_ENTERSUB ||
2407 o->op_type == OP_RV2SV ||
2408 o->op_type == OP_GVSV ||
2409 o->op_type == OP_RV2AV ||
2410 o->op_type == OP_RV2HV ||
2411 o->op_type == OP_RV2GV ||
2412 o->op_type == OP_AELEM ||
2413 o->op_type == OP_HELEM )
2415 if (o->op_type == OP_ENTERSUB) {
2416 if (o->op_private & OPpENTERSUB_AMPER)
2417 sv_catpv(tmpsv, ",AMPER");
2418 if (o->op_private & OPpENTERSUB_DB)
2419 sv_catpv(tmpsv, ",DB");
2420 if (o->op_private & OPpENTERSUB_HASTARG)
2421 sv_catpv(tmpsv, ",HASTARG");
2422 if (o->op_private & OPpENTERSUB_NOPAREN)
2423 sv_catpv(tmpsv, ",NOPAREN");
2424 if (o->op_private & OPpENTERSUB_INARGS)
2425 sv_catpv(tmpsv, ",INARGS");
2426 if (o->op_private & OPpENTERSUB_NOMOD)
2427 sv_catpv(tmpsv, ",NOMOD");
2430 switch (o->op_private & OPpDEREF) {
2432 sv_catpv(tmpsv, ",SV");
2435 sv_catpv(tmpsv, ",AV");
2438 sv_catpv(tmpsv, ",HV");
2441 if (o->op_private & OPpMAYBE_LVSUB)
2442 sv_catpv(tmpsv, ",MAYBE_LVSUB");
2444 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
2445 if (o->op_private & OPpLVAL_DEFER)
2446 sv_catpv(tmpsv, ",LVAL_DEFER");
2449 if (o->op_private & HINT_STRICT_REFS)
2450 sv_catpv(tmpsv, ",STRICT_REFS");
2451 if (o->op_private & OPpOUR_INTRO)
2452 sv_catpv(tmpsv, ",OUR_INTRO");
2455 else if (o->op_type == OP_CONST) {
2456 if (o->op_private & OPpCONST_BARE)
2457 sv_catpv(tmpsv, ",BARE");
2458 if (o->op_private & OPpCONST_STRICT)
2459 sv_catpv(tmpsv, ",STRICT");
2460 if (o->op_private & OPpCONST_ARYBASE)
2461 sv_catpv(tmpsv, ",ARYBASE");
2462 if (o->op_private & OPpCONST_WARNING)
2463 sv_catpv(tmpsv, ",WARNING");
2464 if (o->op_private & OPpCONST_ENTERED)
2465 sv_catpv(tmpsv, ",ENTERED");
2467 else if (o->op_type == OP_FLIP) {
2468 if (o->op_private & OPpFLIP_LINENUM)
2469 sv_catpv(tmpsv, ",LINENUM");
2471 else if (o->op_type == OP_FLOP) {
2472 if (o->op_private & OPpFLIP_LINENUM)
2473 sv_catpv(tmpsv, ",LINENUM");
2475 else if (o->op_type == OP_RV2CV) {
2476 if (o->op_private & OPpLVAL_INTRO)
2477 sv_catpv(tmpsv, ",INTRO");
2479 else if (o->op_type == OP_GV) {
2480 if (o->op_private & OPpEARLY_CV)
2481 sv_catpv(tmpsv, ",EARLY_CV");
2483 else if (o->op_type == OP_LIST) {
2484 if (o->op_private & OPpLIST_GUESSED)
2485 sv_catpv(tmpsv, ",GUESSED");
2487 else if (o->op_type == OP_DELETE) {
2488 if (o->op_private & OPpSLICE)
2489 sv_catpv(tmpsv, ",SLICE");
2491 else if (o->op_type == OP_EXISTS) {
2492 if (o->op_private & OPpEXISTS_SUB)
2493 sv_catpv(tmpsv, ",EXISTS_SUB");
2495 else if (o->op_type == OP_SORT) {
2496 if (o->op_private & OPpSORT_NUMERIC)
2497 sv_catpv(tmpsv, ",NUMERIC");
2498 if (o->op_private & OPpSORT_INTEGER)
2499 sv_catpv(tmpsv, ",INTEGER");
2500 if (o->op_private & OPpSORT_REVERSE)
2501 sv_catpv(tmpsv, ",REVERSE");
2503 else if (o->op_type == OP_THREADSV) {
2504 if (o->op_private & OPpDONE_SVREF)
2505 sv_catpv(tmpsv, ",SVREF");
2507 else if (o->op_type == OP_OPEN || o->op_type == OP_BACKTICK) {
2508 if (o->op_private & OPpOPEN_IN_RAW)
2509 sv_catpv(tmpsv, ",IN_RAW");
2510 if (o->op_private & OPpOPEN_IN_CRLF)
2511 sv_catpv(tmpsv, ",IN_CRLF");
2512 if (o->op_private & OPpOPEN_OUT_RAW)
2513 sv_catpv(tmpsv, ",OUT_RAW");
2514 if (o->op_private & OPpOPEN_OUT_CRLF)
2515 sv_catpv(tmpsv, ",OUT_CRLF");
2517 else if (o->op_type == OP_EXIT) {
2518 if (o->op_private & OPpEXIT_VMSISH)
2519 sv_catpv(tmpsv, ",EXIT_VMSISH");
2520 if (o->op_private & OPpHUSH_VMSISH)
2521 sv_catpv(tmpsv, ",HUSH_VMSISH");
2523 else if (o->op_type == OP_DIE) {
2524 if (o->op_private & OPpHUSH_VMSISH)
2525 sv_catpv(tmpsv, ",HUSH_VMSISH");
2527 else if (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)) {
2528 if (OP_IS_FILETEST_ACCESS(o) && o->op_private & OPpFT_ACCESS)
2529 sv_catpv(tmpsv, ",FT_ACCESS");
2530 if (o->op_private & OPpFT_STACKED)
2531 sv_catpv(tmpsv, ",FT_STACKED");
2533 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
2534 sv_catpv(tmpsv, ",INTRO");
2536 S_xmldump_attr(aTHX_ level, file, "private=\"%s\"", SvPVX(tmpsv) + 1);
2537 SvREFCNT_dec(tmpsv);
2540 switch (o->op_type) {
2542 if (o->op_flags & OPf_SPECIAL) {
2548 S_xmldump_attr(aTHX_ level, file, "padix=\"%" IVdf "\"", (IV)cPADOPo->op_padix);
2550 if (cSVOPo->op_sv) {
2551 SV *tmpsv1 = newSV(0);
2552 SV *tmpsv2 = newSV(0);
2560 gv_fullname3(tmpsv1, (GV*)cSVOPo->op_sv, Nullch);
2561 s = SvPV(tmpsv1,len);
2562 sv_catxmlpvn(tmpsv2, s, len, 1);
2563 S_xmldump_attr(aTHX_ level, file, "gv=\"%s\"", SvPV(tmpsv2, len));
2567 S_xmldump_attr(aTHX_ level, file, "gv=\"NULL\"");
2571 case OP_METHOD_NAMED:
2572 #ifndef USE_ITHREADS
2573 /* with ITHREADS, consts are stored in the pad, and the right pad
2574 * may not be active here, so skip */
2575 S_xmldump_attr(aTHX_ level, file, "%s", sv_xmlpeek(cSVOPo_sv));
2581 PerlIO_printf(file, ">\n");
2583 do_op_xmldump(level+1, file, CvROOT(cSVOPo_sv));
2589 S_xmldump_attr(aTHX_ level, file, "line=\"%"UVf"\"",
2590 (UV)CopLINE(cCOPo));
2591 if (CopSTASHPV(cCOPo))
2592 S_xmldump_attr(aTHX_ level, file, "package=\"%s\"",
2594 if (cCOPo->cop_label)
2595 S_xmldump_attr(aTHX_ level, file, "label=\"%s\"",
2599 S_xmldump_attr(aTHX_ level, file, "redo=\"");
2600 if (cLOOPo->op_redoop)
2601 PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOOPo->op_redoop));
2603 PerlIO_printf(file, "DONE\"");
2604 S_xmldump_attr(aTHX_ level, file, "next=\"");
2605 if (cLOOPo->op_nextop)
2606 PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOOPo->op_nextop));
2608 PerlIO_printf(file, "DONE\"");
2609 S_xmldump_attr(aTHX_ level, file, "last=\"");
2610 if (cLOOPo->op_lastop)
2611 PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOOPo->op_lastop));
2613 PerlIO_printf(file, "DONE\"");
2621 S_xmldump_attr(aTHX_ level, file, "other=\"");
2622 if (cLOGOPo->op_other)
2623 PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOGOPo->op_other));
2625 PerlIO_printf(file, "DONE\"");
2633 if (o->op_private & OPpREFCOUNTED)
2634 S_xmldump_attr(aTHX_ level, file, "refcnt=\"%"UVuf"\"", (UV)o->op_targ);
2640 if (PL_madskills && o->op_madprop) {
2641 SV *tmpsv = newSVpvn("", 0);
2642 MADPROP* mp = o->op_madprop;
2643 sv_utf8_upgrade(tmpsv);
2646 PerlIO_printf(file, ">\n");
2648 Perl_xmldump_indent(aTHX_ level, file, "<madprops>\n");
2651 char tmp = mp->mad_key;
2652 sv_setpvn(tmpsv,"\"",1);
2654 sv_catxmlpvn(tmpsv, &tmp, 1, 0);
2655 sv_catpv(tmpsv, "\"");
2656 switch (mp->mad_type) {
2658 sv_catpv(tmpsv, "NULL");
2659 Perl_xmldump_indent(aTHX_ level, file, "<mad_null key=%s/>\n", SvPVX(tmpsv));
2662 sv_catpv(tmpsv, " val=\"");
2663 sv_catxmlpvn(tmpsv, (char*)mp->mad_val, mp->mad_vlen,1);
2664 sv_catpv(tmpsv, "\"");
2665 Perl_xmldump_indent(aTHX_ level, file, "<mad_pv key=%s/>\n", SvPVX(tmpsv));
2668 sv_catpv(tmpsv, " val=\"");
2669 sv_catxmlsv(tmpsv, (SV*)mp->mad_val);
2670 sv_catpv(tmpsv, "\"");
2671 Perl_xmldump_indent(aTHX_ level, file, "<mad_sv key=%s/>\n", SvPVX(tmpsv));
2674 if ((OP*)mp->mad_val) {
2675 Perl_xmldump_indent(aTHX_ level, file, "<mad_op key=%s>\n", SvPVX(tmpsv));
2676 do_op_xmldump(level+1, file, (OP*)mp->mad_val);
2677 Perl_xmldump_indent(aTHX_ level, file, "</mad_op>\n");
2681 Perl_xmldump_indent(aTHX_ level, file, "<mad_unk key=%s/>\n", SvPVX(tmpsv));
2687 Perl_xmldump_indent(aTHX_ level, file, "</madprops>\n");
2689 SvREFCNT_dec(tmpsv);
2692 switch (o->op_type) {
2699 PerlIO_printf(file, ">\n");
2701 do_pmop_xmldump(level, file, cPMOPo);
2707 if (o->op_flags & OPf_KIDS) {
2711 PerlIO_printf(file, ">\n");
2713 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
2714 do_op_xmldump(level, file, kid);
2718 Perl_xmldump_indent(aTHX_ level-1, file, "</op_%s>\n", OP_NAME(o));
2720 PerlIO_printf(file, " />\n");
2724 Perl_op_xmldump(pTHX_ const OP *o)
2726 do_op_xmldump(0, PL_xmlfp, o);
2732 * c-indentation-style: bsd
2734 * indent-tabs-mode: t
2737 * ex: set ts=8 sts=4 sw=4 noet: