3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 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.'"
17 #define PERL_IN_DUMP_C
24 Perl_dump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
28 dump_vindent(level, file, pat, &args);
33 Perl_dump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args)
35 PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), "");
36 PerlIO_vprintf(file, pat, *args);
42 PerlIO_setlinebuf(Perl_debug_log);
44 op_dump(PL_main_root);
45 dump_packsubs(PL_defstash);
49 Perl_dump_packsubs(pTHX_ HV *stash)
56 for (i = 0; i <= (I32) HvMAX(stash); i++) {
57 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
58 GV *gv = (GV*)HeVAL(entry);
60 if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
66 if (HeKEY(entry)[HeKLEN(entry)-1] == ':'
67 && (hv = GvHV(gv)) && hv != PL_defstash)
68 dump_packsubs(hv); /* nested package */
74 Perl_dump_sub(pTHX_ GV *gv)
76 SV *sv = sv_newmortal();
78 gv_fullname3(sv, gv, Nullch);
79 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ", SvPVX(sv));
81 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "(xsub 0x%"UVxf" %d)\n",
82 PTR2UV(CvXSUB(GvCV(gv))),
83 (int)CvXSUBANY(GvCV(gv)).any_i32);
84 else if (CvROOT(GvCV(gv)))
85 op_dump(CvROOT(GvCV(gv)));
87 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
91 Perl_dump_form(pTHX_ GV *gv)
93 SV *sv = sv_newmortal();
95 gv_fullname3(sv, gv, Nullch);
96 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nFORMAT %s = ", SvPVX(sv));
97 if (CvROOT(GvFORM(gv)))
98 op_dump(CvROOT(GvFORM(gv)));
100 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
106 op_dump(PL_eval_root);
110 Perl_pv_display(pTHX_ SV *dsv, char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
113 int nul_terminated = len > cur && pv[cur] == '\0';
115 sv_setpvn(dsv, "\"", 1);
116 for (; cur--; pv++) {
117 if (pvlim && SvCUR(dsv) >= pvlim) {
122 case '\t': sv_catpvn(dsv, "\\t", 2); break;
123 case '\n': sv_catpvn(dsv, "\\n", 2); break;
124 case '\r': sv_catpvn(dsv, "\\r", 2); break;
125 case '\f': sv_catpvn(dsv, "\\f", 2); break;
126 case '"': sv_catpvn(dsv, "\\\"", 2); break;
127 case '\\': sv_catpvn(dsv, "\\\\", 2); break;
130 sv_catpvn(dsv, pv, 1);
131 else if (cur && isDIGIT(*(pv+1)))
132 Perl_sv_catpvf(aTHX_ dsv, "\\%03o", (U8)*pv);
134 Perl_sv_catpvf(aTHX_ dsv, "\\%o", (U8)*pv);
137 sv_catpvn(dsv, "\"", 1);
139 sv_catpvn(dsv, "...", 3);
141 sv_catpvn(dsv, "\\0", 2);
147 Perl_sv_peek(pTHX_ SV *sv)
149 SV *t = sv_newmortal();
159 else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') {
163 else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) {
164 if (sv == &PL_sv_undef) {
165 sv_catpv(t, "SV_UNDEF");
166 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
167 SVs_GMG|SVs_SMG|SVs_RMG)) &&
171 else if (sv == &PL_sv_no) {
172 sv_catpv(t, "SV_NO");
173 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
174 SVs_GMG|SVs_SMG|SVs_RMG)) &&
175 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
181 else if (sv == &PL_sv_yes) {
182 sv_catpv(t, "SV_YES");
183 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
184 SVs_GMG|SVs_SMG|SVs_RMG)) &&
185 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
188 SvPVX(sv) && *SvPVX(sv) == '1' &&
193 sv_catpv(t, "SV_PLACEHOLDER");
194 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
195 SVs_GMG|SVs_SMG|SVs_RMG)) &&
201 else if (SvREFCNT(sv) == 0) {
205 else if (DEBUG_R_TEST_) {
208 /* is this SV on the tmps stack? */
209 for (ix=PL_tmps_ix; ix>=0; ix--) {
210 if (PL_tmps_stack[ix] == sv) {
215 if (SvREFCNT(sv) > 1)
216 Perl_sv_catpvf(aTHX_ t, "<%"UVuf"%s>", (UV)SvREFCNT(sv),
224 if (SvCUR(t) + unref > 10) {
225 SvCUR(t) = unref + 3;
233 switch (SvTYPE(sv)) {
235 sv_catpv(t, "FREED");
239 sv_catpv(t, "UNDEF");
273 Perl_sv_catpvf(aTHX_ t, "CV(%s)", GvNAME(CvGV(sv)));
293 sv_catpv(t, "(null)");
295 SV *tmp = newSVpvn("", 0);
298 Perl_sv_catpvf(aTHX_ t, "[%s]", pv_display(tmp, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, 127));
299 Perl_sv_catpvf(aTHX_ t, "%s)", pv_display(tmp, SvPVX(sv), SvCUR(sv), SvLEN(sv), 127));
301 Perl_sv_catpvf(aTHX_ t, " [UTF8 \"%s\"]",
302 sv_uni_display(tmp, sv, 8 * sv_len_utf8(sv),
307 else if (SvNOKp(sv)) {
308 STORE_NUMERIC_LOCAL_SET_STANDARD();
309 Perl_sv_catpvf(aTHX_ t, "(%"NVgf")",SvNVX(sv));
310 RESTORE_NUMERIC_LOCAL();
312 else if (SvIOKp(sv)) {
314 Perl_sv_catpvf(aTHX_ t, "(%"UVuf")", (UV)SvUVX(sv));
316 Perl_sv_catpvf(aTHX_ t, "(%"IVdf")", (IV)SvIVX(sv));
330 Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, PMOP *pm)
335 Perl_dump_indent(aTHX_ level, file, "{}\n");
338 Perl_dump_indent(aTHX_ level, file, "{\n");
340 if (pm->op_pmflags & PMf_ONCE)
345 Perl_dump_indent(aTHX_ level, file, "PMf_PRE %c%s%c%s\n",
346 ch, PM_GETRE(pm)->precomp, ch,
347 (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
349 Perl_dump_indent(aTHX_ level, file, "PMf_PRE (RUNTIME)\n");
350 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
351 Perl_dump_indent(aTHX_ level, file, "PMf_REPL = ");
352 op_dump(pm->op_pmreplroot);
354 if (pm->op_pmflags || (PM_GETRE(pm) && PM_GETRE(pm)->check_substr)) {
355 SV *tmpsv = newSVpvn("", 0);
356 if (pm->op_pmdynflags & PMdf_USED)
357 sv_catpv(tmpsv, ",USED");
358 if (pm->op_pmdynflags & PMdf_TAINTED)
359 sv_catpv(tmpsv, ",TAINTED");
360 if (pm->op_pmflags & PMf_ONCE)
361 sv_catpv(tmpsv, ",ONCE");
362 if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr
363 && !(PM_GETRE(pm)->reganch & ROPT_NOSCAN))
364 sv_catpv(tmpsv, ",SCANFIRST");
365 if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr
366 && PM_GETRE(pm)->reganch & ROPT_CHECK_ALL)
367 sv_catpv(tmpsv, ",ALL");
368 if (pm->op_pmflags & PMf_SKIPWHITE)
369 sv_catpv(tmpsv, ",SKIPWHITE");
370 if (pm->op_pmflags & PMf_CONST)
371 sv_catpv(tmpsv, ",CONST");
372 if (pm->op_pmflags & PMf_KEEP)
373 sv_catpv(tmpsv, ",KEEP");
374 if (pm->op_pmflags & PMf_GLOBAL)
375 sv_catpv(tmpsv, ",GLOBAL");
376 if (pm->op_pmflags & PMf_CONTINUE)
377 sv_catpv(tmpsv, ",CONTINUE");
378 if (pm->op_pmflags & PMf_RETAINT)
379 sv_catpv(tmpsv, ",RETAINT");
380 if (pm->op_pmflags & PMf_EVAL)
381 sv_catpv(tmpsv, ",EVAL");
382 Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
386 Perl_dump_indent(aTHX_ level-1, file, "}\n");
390 Perl_pmop_dump(pTHX_ PMOP *pm)
392 do_pmop_dump(0, Perl_debug_log, pm);
395 /* An op sequencer. We visit the ops in the order they're to execute. */
398 sequence(pTHX_ register OP *o)
413 op = newSVuv(PTR2UV(o));
415 if (hv_exists(Sequence, key, len))
418 for (; o; o = o->op_next) {
419 op = newSVuv(PTR2UV(o));
421 if (hv_exists(Sequence, key, len))
424 switch (o->op_type) {
426 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
427 hv_store(Sequence, key, len, newSVuv(++seq), 0);
432 if (oldop && o->op_next)
439 if (oldop && o->op_next)
441 hv_store(Sequence, key, len, newSVuv(++seq), 0);
454 hv_store(Sequence, key, len, newSVuv(++seq), 0);
455 for (l = cLOGOPo->op_other; l && l->op_type == OP_NULL; l = l->op_next)
462 hv_store(Sequence, key, len, newSVuv(++seq), 0);
463 for (l = cLOOPo->op_redoop; l && l->op_type == OP_NULL; l = l->op_next)
466 for (l = cLOOPo->op_nextop; l && l->op_type == OP_NULL; l = l->op_next)
469 for (l = cLOOPo->op_lastop; l && l->op_type == OP_NULL; l = l->op_next)
477 hv_store(Sequence, key, len, newSVuv(++seq), 0);
478 for (l = cPMOPo->op_pmreplstart; l && l->op_type == OP_NULL; l = l->op_next)
487 hv_store(Sequence, key, len, newSVuv(++seq), 0);
495 sequence_num(pTHX_ OP *o)
502 op = newSVuv(PTR2UV(o));
504 seq = hv_fetch(Sequence, key, len, 0);
505 return seq ? SvUV(*seq): 0;
509 Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, OP *o)
513 Perl_dump_indent(aTHX_ level, file, "{\n");
515 seq = sequence_num(aTHX_ o);
517 PerlIO_printf(file, "%-4"UVf, seq);
519 PerlIO_printf(file, " ");
521 "%*sTYPE = %s ===> ",
522 (int)(PL_dumpindent*level-4), "", OP_NAME(o));
524 PerlIO_printf(file, seq ? "%"UVf"\n" : "(%"UVf")\n",
525 sequence_num(aTHX_ o->op_next));
527 PerlIO_printf(file, "DONE\n");
529 if (o->op_type == OP_NULL)
531 Perl_dump_indent(aTHX_ level, file, " (was %s)\n", PL_op_name[o->op_targ]);
532 if (o->op_targ == OP_NEXTSTATE)
535 Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n",
537 if (CopSTASHPV(cCOPo))
538 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
540 if (cCOPo->cop_label)
541 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
546 Perl_dump_indent(aTHX_ level, file, "TARG = %ld\n", (long)o->op_targ);
549 Perl_dump_indent(aTHX_ level, file, "ADDR = 0x%"UVxf" => 0x%"UVxf"\n", (UV)o, (UV)o->op_next);
552 SV *tmpsv = newSVpvn("", 0);
553 switch (o->op_flags & OPf_WANT) {
555 sv_catpv(tmpsv, ",VOID");
557 case OPf_WANT_SCALAR:
558 sv_catpv(tmpsv, ",SCALAR");
561 sv_catpv(tmpsv, ",LIST");
564 sv_catpv(tmpsv, ",UNKNOWN");
567 if (o->op_flags & OPf_KIDS)
568 sv_catpv(tmpsv, ",KIDS");
569 if (o->op_flags & OPf_PARENS)
570 sv_catpv(tmpsv, ",PARENS");
571 if (o->op_flags & OPf_STACKED)
572 sv_catpv(tmpsv, ",STACKED");
573 if (o->op_flags & OPf_REF)
574 sv_catpv(tmpsv, ",REF");
575 if (o->op_flags & OPf_MOD)
576 sv_catpv(tmpsv, ",MOD");
577 if (o->op_flags & OPf_SPECIAL)
578 sv_catpv(tmpsv, ",SPECIAL");
579 Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
583 SV *tmpsv = newSVpvn("", 0);
584 if (PL_opargs[o->op_type] & OA_TARGLEX) {
585 if (o->op_private & OPpTARGET_MY)
586 sv_catpv(tmpsv, ",TARGET_MY");
588 else if (o->op_type == OP_LEAVESUB ||
589 o->op_type == OP_LEAVE ||
590 o->op_type == OP_LEAVESUBLV ||
591 o->op_type == OP_LEAVEWRITE) {
592 if (o->op_private & OPpREFCOUNTED)
593 sv_catpv(tmpsv, ",REFCOUNTED");
595 else if (o->op_type == OP_AASSIGN) {
596 if (o->op_private & OPpASSIGN_COMMON)
597 sv_catpv(tmpsv, ",COMMON");
599 else if (o->op_type == OP_SASSIGN) {
600 if (o->op_private & OPpASSIGN_BACKWARDS)
601 sv_catpv(tmpsv, ",BACKWARDS");
603 else if (o->op_type == OP_TRANS) {
604 if (o->op_private & OPpTRANS_SQUASH)
605 sv_catpv(tmpsv, ",SQUASH");
606 if (o->op_private & OPpTRANS_DELETE)
607 sv_catpv(tmpsv, ",DELETE");
608 if (o->op_private & OPpTRANS_COMPLEMENT)
609 sv_catpv(tmpsv, ",COMPLEMENT");
610 if (o->op_private & OPpTRANS_IDENTICAL)
611 sv_catpv(tmpsv, ",IDENTICAL");
612 if (o->op_private & OPpTRANS_GROWS)
613 sv_catpv(tmpsv, ",GROWS");
615 else if (o->op_type == OP_REPEAT) {
616 if (o->op_private & OPpREPEAT_DOLIST)
617 sv_catpv(tmpsv, ",DOLIST");
619 else if (o->op_type == OP_ENTERSUB ||
620 o->op_type == OP_RV2SV ||
621 o->op_type == OP_GVSV ||
622 o->op_type == OP_RV2AV ||
623 o->op_type == OP_RV2HV ||
624 o->op_type == OP_RV2GV ||
625 o->op_type == OP_AELEM ||
626 o->op_type == OP_HELEM )
628 if (o->op_type == OP_ENTERSUB) {
629 if (o->op_private & OPpENTERSUB_AMPER)
630 sv_catpv(tmpsv, ",AMPER");
631 if (o->op_private & OPpENTERSUB_DB)
632 sv_catpv(tmpsv, ",DB");
633 if (o->op_private & OPpENTERSUB_HASTARG)
634 sv_catpv(tmpsv, ",HASTARG");
635 if (o->op_private & OPpENTERSUB_NOPAREN)
636 sv_catpv(tmpsv, ",NOPAREN");
637 if (o->op_private & OPpENTERSUB_INARGS)
638 sv_catpv(tmpsv, ",INARGS");
639 if (o->op_private & OPpENTERSUB_NOMOD)
640 sv_catpv(tmpsv, ",NOMOD");
643 switch (o->op_private & OPpDEREF) {
645 sv_catpv(tmpsv, ",SV");
648 sv_catpv(tmpsv, ",AV");
651 sv_catpv(tmpsv, ",HV");
654 if (o->op_private & OPpMAYBE_LVSUB)
655 sv_catpv(tmpsv, ",MAYBE_LVSUB");
657 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
658 if (o->op_private & OPpLVAL_DEFER)
659 sv_catpv(tmpsv, ",LVAL_DEFER");
662 if (o->op_private & HINT_STRICT_REFS)
663 sv_catpv(tmpsv, ",STRICT_REFS");
664 if (o->op_private & OPpOUR_INTRO)
665 sv_catpv(tmpsv, ",OUR_INTRO");
668 else if (o->op_type == OP_CONST) {
669 if (o->op_private & OPpCONST_BARE)
670 sv_catpv(tmpsv, ",BARE");
671 if (o->op_private & OPpCONST_STRICT)
672 sv_catpv(tmpsv, ",STRICT");
673 if (o->op_private & OPpCONST_ARYBASE)
674 sv_catpv(tmpsv, ",ARYBASE");
675 if (o->op_private & OPpCONST_WARNING)
676 sv_catpv(tmpsv, ",WARNING");
677 if (o->op_private & OPpCONST_ENTERED)
678 sv_catpv(tmpsv, ",ENTERED");
680 else if (o->op_type == OP_FLIP) {
681 if (o->op_private & OPpFLIP_LINENUM)
682 sv_catpv(tmpsv, ",LINENUM");
684 else if (o->op_type == OP_FLOP) {
685 if (o->op_private & OPpFLIP_LINENUM)
686 sv_catpv(tmpsv, ",LINENUM");
688 else if (o->op_type == OP_RV2CV) {
689 if (o->op_private & OPpLVAL_INTRO)
690 sv_catpv(tmpsv, ",INTRO");
692 else if (o->op_type == OP_GV) {
693 if (o->op_private & OPpEARLY_CV)
694 sv_catpv(tmpsv, ",EARLY_CV");
696 else if (o->op_type == OP_LIST) {
697 if (o->op_private & OPpLIST_GUESSED)
698 sv_catpv(tmpsv, ",GUESSED");
700 else if (o->op_type == OP_DELETE) {
701 if (o->op_private & OPpSLICE)
702 sv_catpv(tmpsv, ",SLICE");
704 else if (o->op_type == OP_EXISTS) {
705 if (o->op_private & OPpEXISTS_SUB)
706 sv_catpv(tmpsv, ",EXISTS_SUB");
708 else if (o->op_type == OP_SORT) {
709 if (o->op_private & OPpSORT_NUMERIC)
710 sv_catpv(tmpsv, ",NUMERIC");
711 if (o->op_private & OPpSORT_INTEGER)
712 sv_catpv(tmpsv, ",INTEGER");
713 if (o->op_private & OPpSORT_REVERSE)
714 sv_catpv(tmpsv, ",REVERSE");
716 else if (o->op_type == OP_THREADSV) {
717 if (o->op_private & OPpDONE_SVREF)
718 sv_catpv(tmpsv, ",SVREF");
720 else if (o->op_type == OP_OPEN || o->op_type == OP_BACKTICK) {
721 if (o->op_private & OPpOPEN_IN_RAW)
722 sv_catpv(tmpsv, ",IN_RAW");
723 if (o->op_private & OPpOPEN_IN_CRLF)
724 sv_catpv(tmpsv, ",IN_CRLF");
725 if (o->op_private & OPpOPEN_OUT_RAW)
726 sv_catpv(tmpsv, ",OUT_RAW");
727 if (o->op_private & OPpOPEN_OUT_CRLF)
728 sv_catpv(tmpsv, ",OUT_CRLF");
730 else if (o->op_type == OP_EXIT) {
731 if (o->op_private & OPpEXIT_VMSISH)
732 sv_catpv(tmpsv, ",EXIT_VMSISH");
733 if (o->op_private & OPpHUSH_VMSISH)
734 sv_catpv(tmpsv, ",HUSH_VMSISH");
736 else if (o->op_type == OP_DIE) {
737 if (o->op_private & OPpHUSH_VMSISH)
738 sv_catpv(tmpsv, ",HUSH_VMSISH");
740 else if (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)) {
741 if (OP_IS_FILETEST_ACCESS(o) && o->op_private & OPpFT_ACCESS)
742 sv_catpv(tmpsv, ",FT_ACCESS");
743 if (o->op_private & OPpFT_STACKED)
744 sv_catpv(tmpsv, ",FT_STACKED");
746 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
747 sv_catpv(tmpsv, ",INTRO");
749 Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX(tmpsv) + 1);
753 switch (o->op_type) {
758 Perl_dump_indent(aTHX_ level, file, "PADIX = %" IVdf "\n", (IV)cPADOPo->op_padix);
760 if ( ! PL_op->op_flags & OPf_SPECIAL) { /* not lexical */
762 SV *tmpsv = NEWSV(0,0);
766 gv_fullname3(tmpsv, (GV*)cSVOPo->op_sv, Nullch);
767 Perl_dump_indent(aTHX_ level, file, "GV = %s\n", SvPV(tmpsv, n_a));
771 Perl_dump_indent(aTHX_ level, file, "GV = NULL\n");
776 case OP_METHOD_NAMED:
778 /* with ITHREADS, consts are stored in the pad, and the right pad
779 * may not be active here, so skip */
780 Perl_dump_indent(aTHX_ level, file, "SV = %s\n", SvPEEK(cSVOPo_sv));
787 Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n",
789 if (CopSTASHPV(cCOPo))
790 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
792 if (cCOPo->cop_label)
793 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
797 Perl_dump_indent(aTHX_ level, file, "REDO ===> ");
798 if (cLOOPo->op_redoop)
799 PerlIO_printf(file, "%"UVf"\n", sequence_num(aTHX_ cLOOPo->op_redoop));
801 PerlIO_printf(file, "DONE\n");
802 Perl_dump_indent(aTHX_ level, file, "NEXT ===> ");
803 if (cLOOPo->op_nextop)
804 PerlIO_printf(file, "%"UVf"\n", sequence_num(aTHX_ cLOOPo->op_nextop));
806 PerlIO_printf(file, "DONE\n");
807 Perl_dump_indent(aTHX_ level, file, "LAST ===> ");
808 if (cLOOPo->op_lastop)
809 PerlIO_printf(file, "%"UVf"\n", sequence_num(aTHX_ cLOOPo->op_lastop));
811 PerlIO_printf(file, "DONE\n");
819 Perl_dump_indent(aTHX_ level, file, "OTHER ===> ");
820 if (cLOGOPo->op_other)
821 PerlIO_printf(file, "%"UVf"\n", sequence_num(aTHX_ cLOGOPo->op_other));
823 PerlIO_printf(file, "DONE\n");
829 do_pmop_dump(level, file, cPMOPo);
837 if (o->op_private & OPpREFCOUNTED)
838 Perl_dump_indent(aTHX_ level, file, "REFCNT = %"UVuf"\n", (UV)o->op_targ);
843 if (o->op_flags & OPf_KIDS) {
845 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
846 do_op_dump(level, file, kid);
848 Perl_dump_indent(aTHX_ level-1, file, "}\n");
852 Perl_op_dump(pTHX_ OP *o)
854 do_op_dump(0, Perl_debug_log, o);
858 Perl_gv_dump(pTHX_ GV *gv)
863 PerlIO_printf(Perl_debug_log, "{}\n");
867 PerlIO_printf(Perl_debug_log, "{\n");
868 gv_fullname3(sv, gv, Nullch);
869 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s", SvPVX(sv));
870 if (gv != GvEGV(gv)) {
871 gv_efullname3(sv, GvEGV(gv), Nullch);
872 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s", SvPVX(sv));
874 PerlIO_putc(Perl_debug_log, '\n');
875 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "}\n");
879 /* map magic types to the symbolic names
880 * (with the PERL_MAGIC_ prefixed stripped)
883 static struct { char type; char *name; } magic_names[] = {
884 { PERL_MAGIC_sv, "sv(\\0)" },
885 { PERL_MAGIC_arylen, "arylen(#)" },
886 { PERL_MAGIC_glob, "glob(*)" },
887 { PERL_MAGIC_pos, "pos(.)" },
888 { PERL_MAGIC_backref, "backref(<)" },
889 { PERL_MAGIC_overload, "overload(A)" },
890 { PERL_MAGIC_bm, "bm(B)" },
891 { PERL_MAGIC_regdata, "regdata(D)" },
892 { PERL_MAGIC_env, "env(E)" },
893 { PERL_MAGIC_isa, "isa(I)" },
894 { PERL_MAGIC_dbfile, "dbfile(L)" },
895 { PERL_MAGIC_shared, "shared(N)" },
896 { PERL_MAGIC_tied, "tied(P)" },
897 { PERL_MAGIC_sig, "sig(S)" },
898 { PERL_MAGIC_uvar, "uvar(U)" },
899 { PERL_MAGIC_overload_elem, "overload_elem(a)" },
900 { PERL_MAGIC_overload_table, "overload_table(c)" },
901 { PERL_MAGIC_regdatum, "regdatum(d)" },
902 { PERL_MAGIC_envelem, "envelem(e)" },
903 { PERL_MAGIC_fm, "fm(f)" },
904 { PERL_MAGIC_regex_global, "regex_global(g)" },
905 { PERL_MAGIC_isaelem, "isaelem(i)" },
906 { PERL_MAGIC_nkeys, "nkeys(k)" },
907 { PERL_MAGIC_dbline, "dbline(l)" },
908 { PERL_MAGIC_mutex, "mutex(m)" },
909 { PERL_MAGIC_shared_scalar, "shared_scalar(n)" },
910 { PERL_MAGIC_collxfrm, "collxfrm(o)" },
911 { PERL_MAGIC_tiedelem, "tiedelem(p)" },
912 { PERL_MAGIC_tiedscalar, "tiedscalar(q)" },
913 { PERL_MAGIC_qr, "qr(r)" },
914 { PERL_MAGIC_sigelem, "sigelem(s)" },
915 { PERL_MAGIC_taint, "taint(t)" },
916 { PERL_MAGIC_uvar_elem, "uvar_elem(v)" },
917 { PERL_MAGIC_vec, "vec(v)" },
918 { PERL_MAGIC_vstring, "vstring(V)" },
919 { PERL_MAGIC_utf8, "utf8(w)" },
920 { PERL_MAGIC_substr, "substr(x)" },
921 { PERL_MAGIC_defelem, "defelem(y)" },
922 { PERL_MAGIC_ext, "ext(~)" },
923 /* this null string terminates the list */
928 Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
930 for (; mg; mg = mg->mg_moremagic) {
931 Perl_dump_indent(aTHX_ level, file,
932 " MAGIC = 0x%"UVxf"\n", PTR2UV(mg));
933 if (mg->mg_virtual) {
934 MGVTBL *v = mg->mg_virtual;
936 if (v == &PL_vtbl_sv) s = "sv";
937 else if (v == &PL_vtbl_env) s = "env";
938 else if (v == &PL_vtbl_envelem) s = "envelem";
939 else if (v == &PL_vtbl_sig) s = "sig";
940 else if (v == &PL_vtbl_sigelem) s = "sigelem";
941 else if (v == &PL_vtbl_pack) s = "pack";
942 else if (v == &PL_vtbl_packelem) s = "packelem";
943 else if (v == &PL_vtbl_dbline) s = "dbline";
944 else if (v == &PL_vtbl_isa) s = "isa";
945 else if (v == &PL_vtbl_arylen) s = "arylen";
946 else if (v == &PL_vtbl_glob) s = "glob";
947 else if (v == &PL_vtbl_mglob) s = "mglob";
948 else if (v == &PL_vtbl_nkeys) s = "nkeys";
949 else if (v == &PL_vtbl_taint) s = "taint";
950 else if (v == &PL_vtbl_substr) s = "substr";
951 else if (v == &PL_vtbl_vec) s = "vec";
952 else if (v == &PL_vtbl_pos) s = "pos";
953 else if (v == &PL_vtbl_bm) s = "bm";
954 else if (v == &PL_vtbl_fm) s = "fm";
955 else if (v == &PL_vtbl_uvar) s = "uvar";
956 else if (v == &PL_vtbl_defelem) s = "defelem";
957 #ifdef USE_LOCALE_COLLATE
958 else if (v == &PL_vtbl_collxfrm) s = "collxfrm";
960 else if (v == &PL_vtbl_amagic) s = "amagic";
961 else if (v == &PL_vtbl_amagicelem) s = "amagicelem";
962 else if (v == &PL_vtbl_backref) s = "backref";
963 else if (v == &PL_vtbl_utf8) s = "utf8";
965 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", s);
967 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0x%"UVxf"\n", PTR2UV(v));
970 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0\n");
973 Perl_dump_indent(aTHX_ level, file, " MG_PRIVATE = %d\n", mg->mg_private);
978 for (n=0; magic_names[n].name; n++) {
979 if (mg->mg_type == magic_names[n].type) {
980 name = magic_names[n].name;
985 Perl_dump_indent(aTHX_ level, file,
986 " MG_TYPE = PERL_MAGIC_%s\n", name);
988 Perl_dump_indent(aTHX_ level, file,
989 " MG_TYPE = UNKNOWN(\\%o)\n", mg->mg_type);
993 Perl_dump_indent(aTHX_ level, file, " MG_FLAGS = 0x%02X\n", mg->mg_flags);
994 if (mg->mg_type == PERL_MAGIC_envelem &&
995 mg->mg_flags & MGf_TAINTEDDIR)
996 Perl_dump_indent(aTHX_ level, file, " TAINTEDDIR\n");
997 if (mg->mg_flags & MGf_REFCOUNTED)
998 Perl_dump_indent(aTHX_ level, file, " REFCOUNTED\n");
999 if (mg->mg_flags & MGf_GSKIP)
1000 Perl_dump_indent(aTHX_ level, file, " GSKIP\n");
1001 if (mg->mg_type == PERL_MAGIC_regex_global &&
1002 mg->mg_flags & MGf_MINMATCH)
1003 Perl_dump_indent(aTHX_ level, file, " MINMATCH\n");
1006 Perl_dump_indent(aTHX_ level, file, " MG_OBJ = 0x%"UVxf"\n", PTR2UV(mg->mg_obj));
1007 if (mg->mg_flags & MGf_REFCOUNTED)
1008 do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
1011 Perl_dump_indent(aTHX_ level, file, " MG_LEN = %ld\n", (long)mg->mg_len);
1013 Perl_dump_indent(aTHX_ level, file, " MG_PTR = 0x%"UVxf, PTR2UV(mg->mg_ptr));
1014 if (mg->mg_len >= 0) {
1015 if (mg->mg_type != PERL_MAGIC_utf8) {
1016 SV *sv = newSVpvn("", 0);
1017 PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim));
1021 else if (mg->mg_len == HEf_SVKEY) {
1022 PerlIO_puts(file, " => HEf_SVKEY\n");
1023 do_sv_dump(level+2, file, (SV*)((mg)->mg_ptr), nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
1027 PerlIO_puts(file, " ???? - please notify IZ");
1028 PerlIO_putc(file, '\n');
1030 if (mg->mg_type == PERL_MAGIC_utf8) {
1031 STRLEN *cache = (STRLEN *) mg->mg_ptr;
1034 for (i = 0; i < PERL_MAGIC_UTF8_CACHESIZE; i++)
1035 Perl_dump_indent(aTHX_ level, file,
1036 " %2"IVdf": %"UVuf" -> %"UVuf"\n",
1039 (UV)cache[i * 2 + 1]);
1046 Perl_magic_dump(pTHX_ MAGIC *mg)
1048 do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0);
1052 Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, char *name, HV *sv)
1054 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
1055 if (sv && HvNAME(sv))
1056 PerlIO_printf(file, "\t\"%s\"\n", HvNAME(sv));
1058 PerlIO_putc(file, '\n');
1062 Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv)
1064 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
1065 if (sv && GvNAME(sv))
1066 PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv));
1068 PerlIO_putc(file, '\n');
1072 Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv)
1074 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
1075 if (sv && GvNAME(sv)) {
1076 PerlIO_printf(file, "\t\"");
1077 if (GvSTASH(sv) && HvNAME(GvSTASH(sv)))
1078 PerlIO_printf(file, "%s\" :: \"", HvNAME(GvSTASH(sv)));
1079 PerlIO_printf(file, "%s\"\n", GvNAME(sv));
1082 PerlIO_putc(file, '\n');
1086 Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
1094 Perl_dump_indent(aTHX_ level, file, "SV = 0\n");
1098 flags = SvFLAGS(sv);
1101 d = Perl_newSVpvf(aTHX_
1102 "(0x%"UVxf") at 0x%"UVxf"\n%*s REFCNT = %"IVdf"\n%*s FLAGS = (",
1103 PTR2UV(SvANY(sv)), PTR2UV(sv),
1104 (int)(PL_dumpindent*level), "", (IV)SvREFCNT(sv),
1105 (int)(PL_dumpindent*level), "");
1107 if (flags & SVs_PADSTALE) sv_catpv(d, "PADSTALE,");
1108 if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,");
1109 if (flags & SVs_PADMY) sv_catpv(d, "PADMY,");
1110 if (flags & SVs_TEMP) sv_catpv(d, "TEMP,");
1111 if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,");
1112 if (flags & SVs_GMG) sv_catpv(d, "GMG,");
1113 if (flags & SVs_SMG) sv_catpv(d, "SMG,");
1114 if (flags & SVs_RMG) sv_catpv(d, "RMG,");
1116 if (flags & SVf_IOK) sv_catpv(d, "IOK,");
1117 if (flags & SVf_NOK) sv_catpv(d, "NOK,");
1118 if (flags & SVf_POK) sv_catpv(d, "POK,");
1119 if (flags & SVf_ROK) {
1120 sv_catpv(d, "ROK,");
1121 if (SvWEAKREF(sv)) sv_catpv(d, "WEAKREF,");
1123 if (flags & SVf_OOK) sv_catpv(d, "OOK,");
1124 if (flags & SVf_FAKE) sv_catpv(d, "FAKE,");
1125 if (flags & SVf_READONLY) sv_catpv(d, "READONLY,");
1127 if (flags & SVf_AMAGIC && type != SVt_PVHV)
1128 sv_catpv(d, "OVERLOAD,");
1129 if (flags & SVp_IOK) sv_catpv(d, "pIOK,");
1130 if (flags & SVp_NOK) sv_catpv(d, "pNOK,");
1131 if (flags & SVp_POK) sv_catpv(d, "pPOK,");
1132 if (flags & SVp_SCREAM) sv_catpv(d, "SCREAM,");
1137 if (CvANON(sv)) sv_catpv(d, "ANON,");
1138 if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
1139 if (CvCLONE(sv)) sv_catpv(d, "CLONE,");
1140 if (CvCLONED(sv)) sv_catpv(d, "CLONED,");
1141 if (CvCONST(sv)) sv_catpv(d, "CONST,");
1142 if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,");
1143 if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,");
1144 if (CvLVALUE(sv)) sv_catpv(d, "LVALUE,");
1145 if (CvMETHOD(sv)) sv_catpv(d, "METHOD,");
1146 if (CvLOCKED(sv)) sv_catpv(d, "LOCKED,");
1147 if (CvWEAKOUTSIDE(sv)) sv_catpv(d, "WEAKOUTSIDE,");
1148 if (CvASSERTION(sv)) sv_catpv(d, "ASSERTION,");
1151 if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,");
1152 if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,");
1153 if (HvHASKFLAGS(sv)) sv_catpv(d, "HASKFLAGS,");
1154 if (HvREHASH(sv)) sv_catpv(d, "REHASH,");
1156 case SVt_PVGV: case SVt_PVLV:
1157 if (GvINTRO(sv)) sv_catpv(d, "INTRO,");
1158 if (GvMULTI(sv)) sv_catpv(d, "MULTI,");
1159 if (GvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
1160 if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,");
1161 if (GvIN_PAD(sv)) sv_catpv(d, "IN_PAD,");
1162 if (flags & SVpad_OUR) sv_catpv(d, "OUR,");
1163 if (GvIMPORTED(sv)) {
1164 sv_catpv(d, "IMPORT");
1165 if (GvIMPORTED(sv) == GVf_IMPORTED)
1166 sv_catpv(d, "ALL,");
1169 if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV");
1170 if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV");
1171 if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV");
1172 if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV");
1178 if (SvEVALED(sv)) sv_catpv(d, "EVALED,");
1179 if (SvIsUV(sv)) sv_catpv(d, "IsUV,");
1182 if (SvTAIL(sv)) sv_catpv(d, "TAIL,");
1183 if (SvVALID(sv)) sv_catpv(d, "VALID,");
1186 if (flags & SVpad_TYPED)
1187 sv_catpv(d, "TYPED,");
1190 if ((SvPOK(sv) || SvPOKp(sv)) && SvUTF8(sv))
1191 sv_catpv(d, "UTF8");
1193 if (*(SvEND(d) - 1) == ',')
1194 SvPVX(d)[--SvCUR(d)] = '\0';
1198 Perl_dump_indent(aTHX_ level, file, "SV = ");
1201 PerlIO_printf(file, "NULL%s\n", s);
1205 PerlIO_printf(file, "IV%s\n", s);
1208 PerlIO_printf(file, "NV%s\n", s);
1211 PerlIO_printf(file, "RV%s\n", s);
1214 PerlIO_printf(file, "PV%s\n", s);
1217 PerlIO_printf(file, "PVIV%s\n", s);
1220 PerlIO_printf(file, "PVNV%s\n", s);
1223 PerlIO_printf(file, "PVBM%s\n", s);
1226 PerlIO_printf(file, "PVMG%s\n", s);
1229 PerlIO_printf(file, "PVLV%s\n", s);
1232 PerlIO_printf(file, "PVAV%s\n", s);
1235 PerlIO_printf(file, "PVHV%s\n", s);
1238 PerlIO_printf(file, "PVCV%s\n", s);
1241 PerlIO_printf(file, "PVGV%s\n", s);
1244 PerlIO_printf(file, "PVFM%s\n", s);
1247 PerlIO_printf(file, "PVIO%s\n", s);
1250 PerlIO_printf(file, "UNKNOWN(0x%"UVxf") %s\n", (UV)type, s);
1254 if (type >= SVt_PVIV || type == SVt_IV) {
1256 #ifdef PERL_COPY_ON_WRITE
1260 Perl_dump_indent(aTHX_ level, file, " UV = %"UVuf, (UV)SvUVX(sv));
1262 Perl_dump_indent(aTHX_ level, file, " IV = %"IVdf, (IV)SvIVX(sv));
1264 PerlIO_printf(file, " (OFFSET)");
1265 #ifdef PERL_COPY_ON_WRITE
1266 if (SvIsCOW_shared_hash(sv))
1267 PerlIO_printf(file, " (HASH)");
1268 else if (SvIsCOW_normal(sv))
1269 PerlIO_printf(file, " (COW from 0x%"UVxf")", (UV)SvUVX(sv));
1271 PerlIO_putc(file, '\n');
1273 if (type >= SVt_PVNV || type == SVt_NV) {
1274 STORE_NUMERIC_LOCAL_SET_STANDARD();
1275 /* %Vg doesn't work? --jhi */
1276 #ifdef USE_LONG_DOUBLE
1277 Perl_dump_indent(aTHX_ level, file, " NV = %.*" PERL_PRIgldbl "\n", LDBL_DIG, SvNVX(sv));
1279 Perl_dump_indent(aTHX_ level, file, " NV = %.*g\n", DBL_DIG, SvNVX(sv));
1281 RESTORE_NUMERIC_LOCAL();
1284 Perl_dump_indent(aTHX_ level, file, " RV = 0x%"UVxf"\n", PTR2UV(SvRV(sv)));
1286 do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim);
1288 if (type < SVt_PV) {
1292 if (type <= SVt_PVLV && type != SVt_PVGV) {
1294 Perl_dump_indent(aTHX_ level, file," PV = 0x%"UVxf" ", PTR2UV(SvPVX(sv)));
1296 PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim));
1297 PerlIO_printf(file, "%s", pv_display(d, SvPVX(sv), SvCUR(sv), SvLEN(sv), pvlim));
1298 if (SvUTF8(sv)) /* the 8? \x{....} */
1299 PerlIO_printf(file, " [UTF8 \"%s\"]", sv_uni_display(d, sv, 8 * sv_len_utf8(sv), UNI_DISPLAY_QQ));
1300 PerlIO_printf(file, "\n");
1301 Perl_dump_indent(aTHX_ level, file, " CUR = %"IVdf"\n", (IV)SvCUR(sv));
1302 Perl_dump_indent(aTHX_ level, file, " LEN = %"IVdf"\n", (IV)SvLEN(sv));
1305 Perl_dump_indent(aTHX_ level, file, " PV = 0\n");
1307 if (type >= SVt_PVMG) {
1309 do_magic_dump(level, file, SvMAGIC(sv), nest, maxnest, dumpops, pvlim);
1311 do_hv_dump(level, file, " STASH", SvSTASH(sv));
1315 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(AvARRAY(sv)));
1316 if (AvARRAY(sv) != AvALLOC(sv)) {
1317 PerlIO_printf(file, " (offset=%"IVdf")\n", (IV)(AvARRAY(sv) - AvALLOC(sv)));
1318 Perl_dump_indent(aTHX_ level, file, " ALLOC = 0x%"UVxf"\n", PTR2UV(AvALLOC(sv)));
1321 PerlIO_putc(file, '\n');
1322 Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)AvFILLp(sv));
1323 Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)AvMAX(sv));
1324 Perl_dump_indent(aTHX_ level, file, " ARYLEN = 0x%"UVxf"\n", PTR2UV(AvARYLEN(sv)));
1325 flags = AvFLAGS(sv);
1327 if (flags & AVf_REAL) sv_catpv(d, ",REAL");
1328 if (flags & AVf_REIFY) sv_catpv(d, ",REIFY");
1329 if (flags & AVf_REUSED) sv_catpv(d, ",REUSED");
1330 Perl_dump_indent(aTHX_ level, file, " FLAGS = (%s)\n", SvCUR(d) ? SvPVX(d) + 1 : "");
1331 if (nest < maxnest && av_len((AV*)sv) >= 0) {
1333 for (count = 0; count <= av_len((AV*)sv) && count < maxnest; count++) {
1334 SV** elt = av_fetch((AV*)sv,count,0);
1336 Perl_dump_indent(aTHX_ level + 1, file, "Elt No. %"IVdf"\n", (IV)count);
1338 do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim);
1343 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv)));
1344 if (HvARRAY(sv) && HvKEYS(sv)) {
1345 /* Show distribution of HEs in the ARRAY */
1347 #define FREQ_MAX (sizeof freq / sizeof freq[0] - 1)
1350 U32 pow2 = 2, keys = HvKEYS(sv);
1351 NV theoret, sum = 0;
1353 PerlIO_printf(file, " (");
1354 Zero(freq, FREQ_MAX + 1, int);
1355 for (i = 0; (STRLEN)i <= HvMAX(sv); i++) {
1356 HE* h; int count = 0;
1357 for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h))
1359 if (count > FREQ_MAX)
1365 for (i = 0; i <= max; i++) {
1367 PerlIO_printf(file, "%d%s:%d", i,
1368 (i == FREQ_MAX) ? "+" : "",
1371 PerlIO_printf(file, ", ");
1374 PerlIO_putc(file, ')');
1375 /* The "quality" of a hash is defined as the total number of
1376 comparisons needed to access every element once, relative
1377 to the expected number needed for a random hash.
1379 The total number of comparisons is equal to the sum of
1380 the squares of the number of entries in each bucket.
1381 For a random hash of n keys into k buckets, the expected
1386 for (i = max; i > 0; i--) { /* Precision: count down. */
1387 sum += freq[i] * i * i;
1389 while ((keys = keys >> 1))
1391 theoret = HvKEYS(sv);
1392 theoret += theoret * (theoret-1)/pow2;
1393 PerlIO_putc(file, '\n');
1394 Perl_dump_indent(aTHX_ level, file, " hash quality = %.1"NVff"%%", theoret/sum*100);
1396 PerlIO_putc(file, '\n');
1397 Perl_dump_indent(aTHX_ level, file, " KEYS = %"IVdf"\n", (IV)HvKEYS(sv));
1398 Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)HvFILL(sv));
1399 Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)HvMAX(sv));
1400 Perl_dump_indent(aTHX_ level, file, " RITER = %"IVdf"\n", (IV)HvRITER(sv));
1401 Perl_dump_indent(aTHX_ level, file, " EITER = 0x%"UVxf"\n", PTR2UV(HvEITER(sv)));
1403 Perl_dump_indent(aTHX_ level, file, " PMROOT = 0x%"UVxf"\n", PTR2UV(HvPMROOT(sv)));
1405 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", HvNAME(sv));
1406 if (nest < maxnest && !HvEITER(sv)) { /* Try to preserve iterator */
1409 int count = maxnest - nest;
1412 while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))
1417 U32 hash = HeHASH(he);
1419 keysv = hv_iterkeysv(he);
1420 keypv = SvPV(keysv, len);
1421 elt = hv_iterval(hv, he);
1422 Perl_dump_indent(aTHX_ level+1, file, "Elt %s ", pv_display(d, keypv, len, 0, pvlim));
1424 PerlIO_printf(file, "[UTF8 \"%s\"] ", sv_uni_display(d, keysv, 8 * sv_len_utf8(keysv), UNI_DISPLAY_QQ));
1426 PerlIO_printf(file, "[REHASH] ");
1427 PerlIO_printf(file, "HASH = 0x%"UVxf"\n", (UV)hash);
1428 do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim);
1430 hv_iterinit(hv); /* Return to status quo */
1435 Perl_dump_indent(aTHX_ level, file, " PROTOTYPE = \"%s\"\n", SvPV_nolen(sv));
1438 do_hv_dump(level, file, " COMP_STASH", CvSTASH(sv));
1440 Perl_dump_indent(aTHX_ level, file, " START = 0x%"UVxf" ===> %"IVdf"\n", PTR2UV(CvSTART(sv)), (IV)sequence_num(aTHX_ CvSTART(sv)));
1441 Perl_dump_indent(aTHX_ level, file, " ROOT = 0x%"UVxf"\n", PTR2UV(CvROOT(sv)));
1442 if (CvROOT(sv) && dumpops)
1443 do_op_dump(level+1, file, CvROOT(sv));
1444 Perl_dump_indent(aTHX_ level, file, " XSUB = 0x%"UVxf"\n", PTR2UV(CvXSUB(sv)));
1445 Perl_dump_indent(aTHX_ level, file, " XSUBANY = %"IVdf"\n", (IV)CvXSUBANY(sv).any_i32);
1446 do_gvgv_dump(level, file, " GVGV::GV", CvGV(sv));
1447 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", CvFILE(sv));
1448 Perl_dump_indent(aTHX_ level, file, " DEPTH = %"IVdf"\n", (IV)CvDEPTH(sv));
1449 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)CvFLAGS(sv));
1450 Perl_dump_indent(aTHX_ level, file, " OUTSIDE_SEQ = %"UVuf"\n", (UV)CvOUTSIDE_SEQ(sv));
1451 if (type == SVt_PVFM)
1452 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)FmLINES(sv));
1453 Perl_dump_indent(aTHX_ level, file, " PADLIST = 0x%"UVxf"\n", PTR2UV(CvPADLIST(sv)));
1454 if (nest < maxnest) {
1455 do_dump_pad(level+1, file, CvPADLIST(sv), 0);
1458 CV *outside = CvOUTSIDE(sv);
1459 Perl_dump_indent(aTHX_ level, file, " OUTSIDE = 0x%"UVxf" (%s)\n",
1462 : CvANON(outside) ? "ANON"
1463 : (outside == PL_main_cv) ? "MAIN"
1464 : CvUNIQUE(outside) ? "UNIQUE"
1465 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
1467 if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv)))
1468 do_sv_dump(level+1, file, (SV*)CvOUTSIDE(sv), nest+1, maxnest, dumpops, pvlim);
1470 case SVt_PVGV: case SVt_PVLV:
1471 if (type == SVt_PVLV) {
1472 Perl_dump_indent(aTHX_ level, file, " TYPE = %c\n", LvTYPE(sv));
1473 Perl_dump_indent(aTHX_ level, file, " TARGOFF = %"IVdf"\n", (IV)LvTARGOFF(sv));
1474 Perl_dump_indent(aTHX_ level, file, " TARGLEN = %"IVdf"\n", (IV)LvTARGLEN(sv));
1475 Perl_dump_indent(aTHX_ level, file, " TARG = 0x%"UVxf"\n", PTR2UV(LvTARG(sv)));
1476 if (LvTYPE(sv) != 't' && LvTYPE(sv) != 'T')
1477 do_sv_dump(level+1, file, LvTARG(sv), nest+1, maxnest,
1480 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", GvNAME(sv));
1481 Perl_dump_indent(aTHX_ level, file, " NAMELEN = %"IVdf"\n", (IV)GvNAMELEN(sv));
1482 do_hv_dump (level, file, " GvSTASH", GvSTASH(sv));
1483 Perl_dump_indent(aTHX_ level, file, " GP = 0x%"UVxf"\n", PTR2UV(GvGP(sv)));
1486 Perl_dump_indent(aTHX_ level, file, " SV = 0x%"UVxf"\n", PTR2UV(GvSV(sv)));
1487 Perl_dump_indent(aTHX_ level, file, " REFCNT = %"IVdf"\n", (IV)GvREFCNT(sv));
1488 Perl_dump_indent(aTHX_ level, file, " IO = 0x%"UVxf"\n", PTR2UV(GvIOp(sv)));
1489 Perl_dump_indent(aTHX_ level, file, " FORM = 0x%"UVxf" \n", PTR2UV(GvFORM(sv)));
1490 Perl_dump_indent(aTHX_ level, file, " AV = 0x%"UVxf"\n", PTR2UV(GvAV(sv)));
1491 Perl_dump_indent(aTHX_ level, file, " HV = 0x%"UVxf"\n", PTR2UV(GvHV(sv)));
1492 Perl_dump_indent(aTHX_ level, file, " CV = 0x%"UVxf"\n", PTR2UV(GvCV(sv)));
1493 Perl_dump_indent(aTHX_ level, file, " CVGEN = 0x%"UVxf"\n", (UV)GvCVGEN(sv));
1494 Perl_dump_indent(aTHX_ level, file, " GPFLAGS = 0x%"UVxf"\n", (UV)GvGPFLAGS(sv));
1495 Perl_dump_indent(aTHX_ level, file, " LINE = %"IVdf"\n", (IV)GvLINE(sv));
1496 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", GvFILE(sv));
1497 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)GvFLAGS(sv));
1498 do_gv_dump (level, file, " EGV", GvEGV(sv));
1501 Perl_dump_indent(aTHX_ level, file, " IFP = 0x%"UVxf"\n", PTR2UV(IoIFP(sv)));
1502 Perl_dump_indent(aTHX_ level, file, " OFP = 0x%"UVxf"\n", PTR2UV(IoOFP(sv)));
1503 Perl_dump_indent(aTHX_ level, file, " DIRP = 0x%"UVxf"\n", PTR2UV(IoDIRP(sv)));
1504 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)IoLINES(sv));
1505 Perl_dump_indent(aTHX_ level, file, " PAGE = %"IVdf"\n", (IV)IoPAGE(sv));
1506 Perl_dump_indent(aTHX_ level, file, " PAGE_LEN = %"IVdf"\n", (IV)IoPAGE_LEN(sv));
1507 Perl_dump_indent(aTHX_ level, file, " LINES_LEFT = %"IVdf"\n", (IV)IoLINES_LEFT(sv));
1509 Perl_dump_indent(aTHX_ level, file, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
1510 do_gv_dump (level, file, " TOP_GV", IoTOP_GV(sv));
1512 Perl_dump_indent(aTHX_ level, file, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
1513 do_gv_dump (level, file, " FMT_GV", IoFMT_GV(sv));
1514 if (IoBOTTOM_NAME(sv))
1515 Perl_dump_indent(aTHX_ level, file, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
1516 do_gv_dump (level, file, " BOTTOM_GV", IoBOTTOM_GV(sv));
1517 Perl_dump_indent(aTHX_ level, file, " SUBPROCESS = %"IVdf"\n", (IV)IoSUBPROCESS(sv));
1518 if (isPRINT(IoTYPE(sv)))
1519 Perl_dump_indent(aTHX_ level, file, " TYPE = '%c'\n", IoTYPE(sv));
1521 Perl_dump_indent(aTHX_ level, file, " TYPE = '\\%o'\n", IoTYPE(sv));
1522 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)IoFLAGS(sv));
1529 Perl_sv_dump(pTHX_ SV *sv)
1531 do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0);
1535 Perl_runops_debug(pTHX)
1538 if (ckWARN_d(WARN_DEBUGGING))
1539 Perl_warner(aTHX_ packWARN(WARN_DEBUGGING), "NULL OP IN RUN");
1546 if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok)
1547 PerlIO_printf(Perl_debug_log,
1548 "WARNING: %"UVxf" changed from %"UVxf" to %"UVxf"\n",
1549 PTR2UV(PL_watchaddr), PTR2UV(PL_watchok),
1550 PTR2UV(*PL_watchaddr));
1551 if (DEBUG_s_TEST_) {
1552 if (DEBUG_v_TEST_) {
1553 PerlIO_printf(Perl_debug_log, "\n");
1561 if (DEBUG_t_TEST_) debop(PL_op);
1562 if (DEBUG_P_TEST_) debprof(PL_op);
1564 } while ((PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX)));
1571 Perl_debop(pTHX_ OP *o)
1573 AV *padlist, *comppad;
1577 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
1580 Perl_deb(aTHX_ "%s", OP_NAME(o));
1581 switch (o->op_type) {
1583 PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo_sv));
1589 gv_fullname3(sv, cGVOPo_gv, Nullch);
1590 PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen(sv));
1594 PerlIO_printf(Perl_debug_log, "(NULL)");
1599 /* print the lexical's name */
1600 cv = deb_curcv(cxstack_ix);
1602 padlist = CvPADLIST(cv);
1603 comppad = (AV*)(*av_fetch(padlist, 0, FALSE));
1604 sv = *av_fetch(comppad, o->op_targ, FALSE);
1608 PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen(sv));
1610 PerlIO_printf(Perl_debug_log, "[%"UVuf"]", (UV)o->op_targ);
1615 PerlIO_printf(Perl_debug_log, "\n");
1620 S_deb_curcv(pTHX_ I32 ix)
1622 PERL_CONTEXT *cx = &cxstack[ix];
1623 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT)
1624 return cx->blk_sub.cv;
1625 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
1627 else if (ix == 0 && PL_curstackinfo->si_type == PERLSI_MAIN)
1632 return deb_curcv(ix - 1);
1636 Perl_watch(pTHX_ char **addr)
1638 PL_watchaddr = addr;
1640 PerlIO_printf(Perl_debug_log, "WATCHING, %"UVxf" is currently %"UVxf"\n",
1641 PTR2UV(PL_watchaddr), PTR2UV(PL_watchok));
1645 S_debprof(pTHX_ OP *o)
1647 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
1649 if (!PL_profiledata)
1650 Newz(000, PL_profiledata, MAXO, U32);
1651 ++PL_profiledata[o->op_type];
1655 Perl_debprofdump(pTHX)
1658 if (!PL_profiledata)
1660 for (i = 0; i < MAXO; i++) {
1661 if (PL_profiledata[i])
1662 PerlIO_printf(Perl_debug_log,
1663 "%5lu %s\n", (unsigned long)PL_profiledata[i],