3 * Copyright (c) 1991-1999, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "'You have talked long in your sleep, Frodo,' said Gandalf gently, 'and
12 * it has not been hard for me to read your mind and memory.'"
19 #define DBL_DIG 15 /* A guess that works lots of places */
23 dump_indent(I32 level, PerlIO *file, const char* pat, ...)
29 PerlIO_printf(file, "%*s", level*PL_dumpindent, "");
30 PerlIO_vprintf(file, pat, args);
38 PerlIO_setlinebuf(Perl_debug_log);
40 op_dump(PL_main_root);
41 dump_packsubs(PL_defstash);
45 dump_packsubs(HV *stash)
53 for (i = 0; i <= (I32) HvMAX(stash); i++) {
54 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
55 GV *gv = (GV*)HeVAL(entry);
57 if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
63 if (HeKEY(entry)[HeKLEN(entry)-1] == ':' &&
64 (hv = GvHV(gv)) && HvNAME(hv) && hv != PL_defstash)
65 dump_packsubs(hv); /* nested package */
73 SV *sv = sv_newmortal();
75 gv_fullname3(sv, gv, Nullch);
76 dump_indent(0, Perl_debug_log, "\nSUB %s = ", SvPVX(sv));
78 dump_indent(0, Perl_debug_log, "(xsub 0x%x %d)\n",
79 (long)CvXSUB(GvCV(gv)),
80 CvXSUBANY(GvCV(gv)).any_i32);
81 else if (CvROOT(GvCV(gv)))
82 op_dump(CvROOT(GvCV(gv)));
84 dump_indent(0, Perl_debug_log, "<undef>\n");
90 SV *sv = sv_newmortal();
92 gv_fullname3(sv, gv, Nullch);
93 dump_indent(0, Perl_debug_log, "\nFORMAT %s = ", SvPVX(sv));
94 if (CvROOT(GvFORM(gv)))
95 op_dump(CvROOT(GvFORM(gv)));
97 dump_indent(0, Perl_debug_log, "<undef>\n");
103 op_dump(PL_eval_root);
107 pv_display(SV *sv, char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
110 int nul_terminated = len > cur && pv[cur] == '\0';
112 sv_setpvn(sv, "\"", 1);
113 for (; cur--; pv++) {
114 if (pvlim && SvCUR(sv) >= pvlim) {
120 case '\t': sv_catpvn(sv, "\\t", 2); break;
121 case '\n': sv_catpvn(sv, "\\n", 2); break;
122 case '\r': sv_catpvn(sv, "\\r", 2); break;
123 case '\f': sv_catpvn(sv, "\\f", 2); break;
124 case '"': sv_catpvn(sv, "\\\"", 2); break;
125 case '\\': sv_catpvn(sv, "\\\\", 2); break;
126 default: sv_catpvn(sv, pv, 1); break;
130 if (cur && isDIGIT(*(pv+1)))
131 sv_catpvf(sv, "\\%03o", *pv);
133 sv_catpvf(sv, "\\%o", *pv);
136 sv_catpvn(sv, "\"", 1);
138 sv_catpvn(sv, "...", 3);
140 sv_catpvn(sv, "\\0", 2);
148 SV *t = sv_newmortal();
158 else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') {
162 else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes) {
163 if (sv == &PL_sv_undef) {
164 sv_catpv(t, "SV_UNDEF");
165 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
166 SVs_GMG|SVs_SMG|SVs_RMG)) &&
170 else if (sv == &PL_sv_no) {
171 sv_catpv(t, "SV_NO");
172 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
173 SVs_GMG|SVs_SMG|SVs_RMG)) &&
174 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
181 sv_catpv(t, "SV_YES");
182 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
183 SVs_GMG|SVs_SMG|SVs_RMG)) &&
184 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
187 SvPVX(sv) && *SvPVX(sv) == '1' &&
193 else if (SvREFCNT(sv) == 0) {
199 if (SvCUR(t) + unref > 10) {
200 SvCUR(t) = unref + 3;
208 switch (SvTYPE(sv)) {
210 sv_catpv(t, "FREED");
214 sv_catpv(t, "UNDEF");
248 sv_catpvf(t, "CV(%s)", GvNAME(CvGV(sv)));
268 sv_catpv(t, "(null)");
270 SV *tmp = newSVpvn("", 0);
273 sv_catpvf(t, "[%s]", pv_display(tmp, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, 127));
274 sv_catpvf(t, "%s)", pv_display(tmp, SvPVX(sv), SvCUR(sv), SvLEN(sv), 127));
278 else if (SvNOKp(sv)) {
279 SET_NUMERIC_STANDARD();
280 sv_catpvf(t, "(%g)",SvNVX(sv));
283 sv_catpvf(t, "(%ld)",(long)SvIVX(sv));
296 do_pmop_dump(I32 level, PerlIO *file, PMOP *pm)
301 dump_indent(level, file, "{}\n");
304 dump_indent(level, file, "{\n");
306 if (pm->op_pmflags & PMf_ONCE)
311 dump_indent(level, file, "PMf_PRE %c%s%c%s\n",
312 ch, pm->op_pmregexp->precomp, ch,
313 (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
315 dump_indent(level, file, "PMf_PRE (RUNTIME)\n");
316 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
317 dump_indent(level, file, "PMf_REPL = ");
318 op_dump(pm->op_pmreplroot);
320 if (pm->op_pmflags || (pm->op_pmregexp && pm->op_pmregexp->check_substr)) {
321 SV *tmpsv = newSVpvn("", 0);
322 if (pm->op_pmdynflags & PMdf_USED)
323 sv_catpv(tmpsv, ",USED");
324 if (pm->op_pmdynflags & PMdf_TAINTED)
325 sv_catpv(tmpsv, ",TAINTED");
326 if (pm->op_pmflags & PMf_ONCE)
327 sv_catpv(tmpsv, ",ONCE");
328 if (pm->op_pmregexp && pm->op_pmregexp->check_substr
329 && !(pm->op_pmregexp->reganch & ROPT_NOSCAN))
330 sv_catpv(tmpsv, ",SCANFIRST");
331 if (pm->op_pmregexp && pm->op_pmregexp->check_substr
332 && pm->op_pmregexp->reganch & ROPT_CHECK_ALL)
333 sv_catpv(tmpsv, ",ALL");
334 if (pm->op_pmflags & PMf_SKIPWHITE)
335 sv_catpv(tmpsv, ",SKIPWHITE");
336 if (pm->op_pmflags & PMf_CONST)
337 sv_catpv(tmpsv, ",CONST");
338 if (pm->op_pmflags & PMf_KEEP)
339 sv_catpv(tmpsv, ",KEEP");
340 if (pm->op_pmflags & PMf_GLOBAL)
341 sv_catpv(tmpsv, ",GLOBAL");
342 if (pm->op_pmflags & PMf_CONTINUE)
343 sv_catpv(tmpsv, ",CONTINUE");
344 if (pm->op_pmflags & PMf_RETAINT)
345 sv_catpv(tmpsv, ",RETAINT");
346 if (pm->op_pmflags & PMf_EVAL)
347 sv_catpv(tmpsv, ",EVAL");
348 dump_indent(level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
352 dump_indent(level-1, file, "}\n");
358 do_pmop_dump(0, Perl_debug_log, pm);
362 do_op_dump(I32 level, PerlIO *file, OP *o)
366 dump_indent(level, file, "{\n");
369 PerlIO_printf(file, "%-4d", o->op_seq);
371 PerlIO_printf(file, " ");
372 PerlIO_printf(file, "%*sTYPE = %s ===> ", PL_dumpindent*level-4, "", PL_op_name[o->op_type]);
375 PerlIO_printf(file, "%d\n", o->op_next->op_seq);
377 PerlIO_printf(file, "(%d)\n", o->op_next->op_seq);
380 PerlIO_printf(file, "DONE\n");
382 if (o->op_type == OP_NULL)
383 dump_indent(level, file, " (was %s)\n", PL_op_name[o->op_targ]);
385 dump_indent(level, file, "TARG = %d\n", o->op_targ);
388 dump_indent(level, file, "ADDR = 0x%lx => 0x%lx\n",o, o->op_next);
391 SV *tmpsv = newSVpvn("", 0);
392 switch (o->op_flags & OPf_WANT) {
394 sv_catpv(tmpsv, ",VOID");
396 case OPf_WANT_SCALAR:
397 sv_catpv(tmpsv, ",SCALAR");
400 sv_catpv(tmpsv, ",LIST");
403 sv_catpv(tmpsv, ",UNKNOWN");
406 if (o->op_flags & OPf_KIDS)
407 sv_catpv(tmpsv, ",KIDS");
408 if (o->op_flags & OPf_PARENS)
409 sv_catpv(tmpsv, ",PARENS");
410 if (o->op_flags & OPf_STACKED)
411 sv_catpv(tmpsv, ",STACKED");
412 if (o->op_flags & OPf_REF)
413 sv_catpv(tmpsv, ",REF");
414 if (o->op_flags & OPf_MOD)
415 sv_catpv(tmpsv, ",MOD");
416 if (o->op_flags & OPf_SPECIAL)
417 sv_catpv(tmpsv, ",SPECIAL");
418 dump_indent(level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
422 SV *tmpsv = newSVpvn("", 0);
423 if (o->op_type == OP_AASSIGN) {
424 if (o->op_private & OPpASSIGN_COMMON)
425 sv_catpv(tmpsv, ",COMMON");
427 else if (o->op_type == OP_SASSIGN) {
428 if (o->op_private & OPpASSIGN_BACKWARDS)
429 sv_catpv(tmpsv, ",BACKWARDS");
431 else if (o->op_type == OP_TRANS) {
432 if (o->op_private & OPpTRANS_SQUASH)
433 sv_catpv(tmpsv, ",SQUASH");
434 if (o->op_private & OPpTRANS_DELETE)
435 sv_catpv(tmpsv, ",DELETE");
436 if (o->op_private & OPpTRANS_COMPLEMENT)
437 sv_catpv(tmpsv, ",COMPLEMENT");
439 else if (o->op_type == OP_REPEAT) {
440 if (o->op_private & OPpREPEAT_DOLIST)
441 sv_catpv(tmpsv, ",DOLIST");
443 else if (o->op_type == OP_ENTERSUB ||
444 o->op_type == OP_RV2SV ||
445 o->op_type == OP_RV2AV ||
446 o->op_type == OP_RV2HV ||
447 o->op_type == OP_RV2GV ||
448 o->op_type == OP_AELEM ||
449 o->op_type == OP_HELEM )
451 if (o->op_type == OP_ENTERSUB) {
452 if (o->op_private & OPpENTERSUB_AMPER)
453 sv_catpv(tmpsv, ",AMPER");
454 if (o->op_private & OPpENTERSUB_DB)
455 sv_catpv(tmpsv, ",DB");
457 switch (o->op_private & OPpDEREF) {
459 sv_catpv(tmpsv, ",SV");
462 sv_catpv(tmpsv, ",AV");
465 sv_catpv(tmpsv, ",HV");
468 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
469 if (o->op_private & OPpLVAL_DEFER)
470 sv_catpv(tmpsv, ",LVAL_DEFER");
473 if (o->op_private & HINT_STRICT_REFS)
474 sv_catpv(tmpsv, ",STRICT_REFS");
477 else if (o->op_type == OP_CONST) {
478 if (o->op_private & OPpCONST_BARE)
479 sv_catpv(tmpsv, ",BARE");
481 else if (o->op_type == OP_FLIP) {
482 if (o->op_private & OPpFLIP_LINENUM)
483 sv_catpv(tmpsv, ",LINENUM");
485 else if (o->op_type == OP_FLOP) {
486 if (o->op_private & OPpFLIP_LINENUM)
487 sv_catpv(tmpsv, ",LINENUM");
489 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
490 sv_catpv(tmpsv, ",INTRO");
492 dump_indent(level, file, "PRIVATE = (%s)\n", SvPVX(tmpsv) + 1);
496 switch (o->op_type) {
500 SV *tmpsv = NEWSV(0,0);
503 gv_fullname3(tmpsv, cGVOPo->op_gv, Nullch);
504 dump_indent(level, file, "GV = %s\n", SvPV(tmpsv, n_a));
508 dump_indent(level, file, "GV = NULL\n");
511 dump_indent(level, file, "SV = %s\n", SvPEEK(cSVOPo->op_sv));
516 dump_indent(level, file, "LINE = %d\n",cCOPo->cop_line);
517 if (cCOPo->cop_label)
518 dump_indent(level, file, "LABEL = \"%s\"\n",cCOPo->cop_label);
521 dump_indent(level, file, "REDO ===> ");
522 if (cLOOPo->op_redoop)
523 PerlIO_printf(file, "%d\n", cLOOPo->op_redoop->op_seq);
525 PerlIO_printf(file, "DONE\n");
526 dump_indent(level, file, "NEXT ===> ");
527 if (cLOOPo->op_nextop)
528 PerlIO_printf(file, "%d\n", cLOOPo->op_nextop->op_seq);
530 PerlIO_printf(file, "DONE\n");
531 dump_indent(level, file, "LAST ===> ");
532 if (cLOOPo->op_lastop)
533 PerlIO_printf(file, "%d\n", cLOOPo->op_lastop->op_seq);
535 PerlIO_printf(file, "DONE\n");
538 dump_indent(level, file, "TRUE ===> ");
539 if (cCONDOPo->op_true)
540 PerlIO_printf(file, "%d\n", cCONDOPo->op_true->op_seq);
542 PerlIO_printf(file, "DONE\n");
543 dump_indent(level, file, "FALSE ===> ");
544 if (cCONDOPo->op_false)
545 PerlIO_printf(file, "%d\n", cCONDOPo->op_false->op_seq);
547 PerlIO_printf(file, "DONE\n");
553 dump_indent(level, file, "OTHER ===> ");
554 if (cLOGOPo->op_other)
555 PerlIO_printf(file, "%d\n", cLOGOPo->op_other->op_seq);
557 PerlIO_printf(file, "DONE\n");
563 do_pmop_dump(level, file, cPMOPo);
568 if (o->op_flags & OPf_KIDS) {
570 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
571 do_op_dump(level, file, kid);
573 dump_indent(level-1, file, "}\n");
579 do_op_dump(0, Perl_debug_log, o);
588 PerlIO_printf(Perl_debug_log, "{}\n");
592 PerlIO_printf(Perl_debug_log, "{\n");
593 gv_fullname3(sv, gv, Nullch);
594 dump_indent(1, Perl_debug_log, "GV_NAME = %s", SvPVX(sv));
595 if (gv != GvEGV(gv)) {
596 gv_efullname3(sv, GvEGV(gv), Nullch);
597 dump_indent(1, Perl_debug_log, "-> %s", SvPVX(sv));
599 PerlIO_putc(Perl_debug_log, '\n');
600 dump_indent(0, Perl_debug_log, "}\n");
604 do_magic_dump(I32 level, PerlIO *file, MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
606 for (; mg; mg = mg->mg_moremagic) {
607 dump_indent(level, file, " MAGIC = 0x%lx\n", (long)mg);
608 if (mg->mg_virtual) {
609 MGVTBL *v = mg->mg_virtual;
611 if (v == &PL_vtbl_sv) s = "sv";
612 else if (v == &PL_vtbl_env) s = "env";
613 else if (v == &PL_vtbl_envelem) s = "envelem";
614 else if (v == &PL_vtbl_sig) s = "sig";
615 else if (v == &PL_vtbl_sigelem) s = "sigelem";
616 else if (v == &PL_vtbl_pack) s = "pack";
617 else if (v == &PL_vtbl_packelem) s = "packelem";
618 else if (v == &PL_vtbl_dbline) s = "dbline";
619 else if (v == &PL_vtbl_isa) s = "isa";
620 else if (v == &PL_vtbl_arylen) s = "arylen";
621 else if (v == &PL_vtbl_glob) s = "glob";
622 else if (v == &PL_vtbl_mglob) s = "mglob";
623 else if (v == &PL_vtbl_nkeys) s = "nkeys";
624 else if (v == &PL_vtbl_taint) s = "taint";
625 else if (v == &PL_vtbl_substr) s = "substr";
626 else if (v == &PL_vtbl_vec) s = "vec";
627 else if (v == &PL_vtbl_pos) s = "pos";
628 else if (v == &PL_vtbl_bm) s = "bm";
629 else if (v == &PL_vtbl_fm) s = "fm";
630 else if (v == &PL_vtbl_uvar) s = "uvar";
631 else if (v == &PL_vtbl_defelem) s = "defelem";
632 #ifdef USE_LOCALE_COLLATE
633 else if (v == &PL_vtbl_collxfrm) s = "collxfrm";
635 else if (v == &PL_vtbl_amagic) s = "amagic";
636 else if (v == &PL_vtbl_amagicelem) s = "amagicelem";
638 dump_indent(level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", s);
640 dump_indent(level, file, " MG_VIRTUAL = 0x%lx\n", (long)v);
643 dump_indent(level, file, " MG_VIRTUAL = 0\n");
646 dump_indent(level, file, " MG_PRIVATE = %d\n", mg->mg_private);
648 if (isPRINT(mg->mg_type))
649 dump_indent(level, file, " MG_TYPE = '%c'\n", mg->mg_type);
651 dump_indent(level, file, " MG_TYPE = '\\%o'\n", mg->mg_type);
654 dump_indent(level, file, " MG_FLAGS = 0x%02X\n", mg->mg_flags);
655 if (mg->mg_flags & MGf_TAINTEDDIR)
656 dump_indent(level, file, " TAINTEDDIR\n");
657 if (mg->mg_flags & MGf_REFCOUNTED)
658 dump_indent(level, file, " REFCOUNTED\n");
659 if (mg->mg_flags & MGf_GSKIP)
660 dump_indent(level, file, " GSKIP\n");
661 if (mg->mg_flags & MGf_MINMATCH)
662 dump_indent(level, file, " MINMATCH\n");
665 dump_indent(level, file, " MG_OBJ = 0x%lx\n", (long)mg->mg_obj);
666 if (mg->mg_flags & MGf_REFCOUNTED)
667 do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
670 dump_indent(level, file, " MG_LEN = %d\n", mg->mg_len);
672 dump_indent(level, file, " MG_PTR = 0x%lx", (long)mg->mg_ptr);
673 if (mg->mg_len >= 0) {
674 SV *sv = newSVpvn("", 0);
675 PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim));
678 else if (mg->mg_len == HEf_SVKEY) {
679 PerlIO_puts(file, " => HEf_SVKEY\n");
680 do_sv_dump(level+2, file, (SV*)((mg)->mg_ptr), nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
684 PerlIO_puts(file, " ???? - please notify IZ");
685 PerlIO_putc(file, '\n');
691 magic_dump(MAGIC *mg)
693 do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0);
697 do_hv_dump(I32 level, PerlIO *file, char *name, HV *sv)
699 dump_indent(level, file, "%s = 0x%lx", name, (long)sv);
700 if (sv && HvNAME(sv))
701 PerlIO_printf(file, "\t\"%s\"\n", HvNAME(sv));
703 PerlIO_putc(file, '\n');
707 do_gv_dump(I32 level, PerlIO *file, char *name, GV *sv)
709 dump_indent(level, file, "%s = 0x%lx", name, (long)sv);
710 if (sv && GvNAME(sv))
711 PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv));
713 PerlIO_putc(file, '\n');
717 do_gvgv_dump(I32 level, PerlIO *file, char *name, GV *sv)
719 dump_indent(level, file, "%s = 0x%lx", name, (long)sv);
720 if (sv && GvNAME(sv)) {
721 PerlIO_printf(file, "\t\"");
722 if (GvSTASH(sv) && HvNAME(GvSTASH(sv)))
723 PerlIO_printf(file, "%s\" :: \"", HvNAME(GvSTASH(sv)));
724 PerlIO_printf(file, "%s\"\n", GvNAME(sv));
727 PerlIO_putc(file, '\n');
731 do_sv_dump(I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
734 SV *d = sv_newmortal();
741 dump_indent(level, file, "SV = 0\n");
748 sv_setpvf(d, "(0x%lx) at 0x%lx\n%*s REFCNT = %ld\n%*s FLAGS = (",
749 (unsigned long)SvANY(sv), (unsigned long)sv,
750 PL_dumpindent*level, "", (long)SvREFCNT(sv),
751 PL_dumpindent*level, "");
753 if (flags & SVs_PADBUSY) sv_catpv(d, "PADBUSY,");
754 if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,");
755 if (flags & SVs_PADMY) sv_catpv(d, "PADMY,");
756 if (flags & SVs_TEMP) sv_catpv(d, "TEMP,");
757 if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,");
758 if (flags & SVs_GMG) sv_catpv(d, "GMG,");
759 if (flags & SVs_SMG) sv_catpv(d, "SMG,");
760 if (flags & SVs_RMG) sv_catpv(d, "RMG,");
762 if (flags & SVf_IOK) sv_catpv(d, "IOK,");
763 if (flags & SVf_NOK) sv_catpv(d, "NOK,");
764 if (flags & SVf_POK) sv_catpv(d, "POK,");
765 if (flags & SVf_ROK) sv_catpv(d, "ROK,");
766 if (flags & SVf_OOK) sv_catpv(d, "OOK,");
767 if (flags & SVf_FAKE) sv_catpv(d, "FAKE,");
768 if (flags & SVf_READONLY) sv_catpv(d, "READONLY,");
770 if (flags & SVf_AMAGIC) sv_catpv(d, "OVERLOAD,");
771 if (flags & SVp_IOK) sv_catpv(d, "pIOK,");
772 if (flags & SVp_NOK) sv_catpv(d, "pNOK,");
773 if (flags & SVp_POK) sv_catpv(d, "pPOK,");
774 if (flags & SVp_SCREAM) sv_catpv(d, "SCREAM,");
779 if (CvANON(sv)) sv_catpv(d, "ANON,");
780 if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
781 if (CvCLONE(sv)) sv_catpv(d, "CLONE,");
782 if (CvCLONED(sv)) sv_catpv(d, "CLONED,");
783 if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,");
786 if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,");
787 if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,");
790 if (GvINTRO(sv)) sv_catpv(d, "INTRO,");
791 if (GvMULTI(sv)) sv_catpv(d, "MULTI,");
792 if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,");
793 if (GvIMPORTED(sv)) {
794 sv_catpv(d, "IMPORT");
795 if (GvIMPORTED(sv) == GVf_IMPORTED)
799 if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV");
800 if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV");
801 if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV");
802 if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV");
807 if (SvTAIL(sv)) sv_catpv(d, "TAIL,");
808 if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,");
812 if (*(SvEND(d) - 1) == ',')
813 SvPVX(d)[--SvCUR(d)] = '\0';
817 dump_indent(level, file, "SV = ");
820 PerlIO_printf(file, "NULL%s\n", s);
823 PerlIO_printf(file, "IV%s\n", s);
826 PerlIO_printf(file, "NV%s\n", s);
829 PerlIO_printf(file, "RV%s\n", s);
832 PerlIO_printf(file, "PV%s\n", s);
835 PerlIO_printf(file, "PVIV%s\n", s);
838 PerlIO_printf(file, "PVNV%s\n", s);
841 PerlIO_printf(file, "PVBM%s\n", s);
844 PerlIO_printf(file, "PVMG%s\n", s);
847 PerlIO_printf(file, "PVLV%s\n", s);
850 PerlIO_printf(file, "PVAV%s\n", s);
853 PerlIO_printf(file, "PVHV%s\n", s);
856 PerlIO_printf(file, "PVCV%s\n", s);
859 PerlIO_printf(file, "PVGV%s\n", s);
862 PerlIO_printf(file, "PVFM%s\n", s);
865 PerlIO_printf(file, "PVIO%s\n", s);
868 PerlIO_printf(file, "UNKNOWN(0x%x) %s\n", type, s);
871 if (type >= SVt_PVIV || type == SVt_IV) {
872 dump_indent(level, file, " IV = %ld", (long)SvIVX(sv));
874 PerlIO_printf(file, " (OFFSET)");
875 PerlIO_putc(file, '\n');
877 if (type >= SVt_PVNV || type == SVt_NV) {
878 SET_NUMERIC_STANDARD();
879 dump_indent(level, file, " NV = %.*g\n", DBL_DIG, SvNVX(sv));
882 dump_indent(level, file, " RV = 0x%lx\n", (long)SvRV(sv));
884 do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim);
889 if (type <= SVt_PVLV) {
891 dump_indent(level, file," PV = 0x%lx ", (long)SvPVX(sv));
893 PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim));
894 PerlIO_printf(file, "%s\n", pv_display(d, SvPVX(sv), SvCUR(sv), SvLEN(sv), pvlim));
895 dump_indent(level, file, " CUR = %ld\n", (long)SvCUR(sv));
896 dump_indent(level, file, " LEN = %ld\n", (long)SvLEN(sv));
899 dump_indent(level, file, " PV = 0\n");
901 if (type >= SVt_PVMG) {
903 do_magic_dump(level, file, SvMAGIC(sv), nest, maxnest, dumpops, pvlim);
905 do_hv_dump(level, file, " STASH", SvSTASH(sv));
909 dump_indent(level, file, " TYPE = %c\n", LvTYPE(sv));
910 dump_indent(level, file, " TARGOFF = %ld\n", (long)LvTARGOFF(sv));
911 dump_indent(level, file, " TARGLEN = %ld\n", (long)LvTARGLEN(sv));
912 dump_indent(level, file, " TARG = 0x%lx\n", (long)LvTARG(sv));
913 /* XXX level+1 ??? */
914 do_sv_dump(level, file, LvTARG(sv), nest+1, maxnest, dumpops, pvlim);
917 dump_indent(level, file, " ARRAY = 0x%lx", (long)AvARRAY(sv));
918 if (AvARRAY(sv) != AvALLOC(sv)) {
919 PerlIO_printf(file, " (offset=%d)\n", (AvARRAY(sv) - AvALLOC(sv)));
920 dump_indent(level, file, " ALLOC = 0x%lx\n", (long)AvALLOC(sv));
923 PerlIO_putc(file, '\n');
924 dump_indent(level, file, " FILL = %ld\n", (long)AvFILLp(sv));
925 dump_indent(level, file, " MAX = %ld\n", (long)AvMAX(sv));
926 dump_indent(level, file, " ARYLEN = 0x%lx\n", (long)AvARYLEN(sv));
929 if (flags & AVf_REAL) sv_catpv(d, ",REAL");
930 if (flags & AVf_REIFY) sv_catpv(d, ",REIFY");
931 if (flags & AVf_REUSED) sv_catpv(d, ",REUSED");
932 dump_indent(level, file, " FLAGS = (%s)\n", SvCUR(d) ? SvPVX(d) + 1 : "");
933 if (nest < maxnest && av_len((AV*)sv) >= 0) {
935 for (count = 0; count <= av_len((AV*)sv) && count < maxnest; count++) {
936 SV** elt = av_fetch((AV*)sv,count,0);
938 dump_indent(level + 1, file, "Elt No. %ld\n", (long)count);
940 do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim);
945 dump_indent(level, file, " ARRAY = 0x%lx",(long)HvARRAY(sv));
946 if (HvARRAY(sv) && HvKEYS(sv)) {
947 /* Show distribution of HEs in the ARRAY */
949 #define FREQ_MAX (sizeof freq / sizeof freq[0] - 1)
952 U32 pow2 = 2, keys = HvKEYS(sv);
953 double theoret, sum = 0;
955 PerlIO_printf(file, " (");
956 Zero(freq, FREQ_MAX + 1, int);
957 for (i = 0; i <= HvMAX(sv); i++) {
958 HE* h; int count = 0;
959 for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h))
961 if (count > FREQ_MAX)
967 for (i = 0; i <= max; i++) {
969 PerlIO_printf(file, "%d%s:%d", i,
970 (i == FREQ_MAX) ? "+" : "",
973 PerlIO_printf(file, ", ");
976 PerlIO_putc(file, ')');
977 /* Now calculate quality wrt theoretical value */
978 for (i = max; i > 0; i--) { /* Precision: count down. */
979 sum += freq[i] * i * i;
981 while (keys = keys >> 1)
983 /* Approximate by Poisson distribution */
984 theoret = HvKEYS(sv);
985 theoret += theoret * theoret/pow2;
986 PerlIO_putc(file, '\n');
987 dump_indent(level, file, " hash quality = %.1f%%", theoret/sum*100);
989 PerlIO_putc(file, '\n');
990 dump_indent(level, file, " KEYS = %ld\n", (long)HvKEYS(sv));
991 dump_indent(level, file, " FILL = %ld\n", (long)HvFILL(sv));
992 dump_indent(level, file, " MAX = %ld\n", (long)HvMAX(sv));
993 dump_indent(level, file, " RITER = %ld\n", (long)HvRITER(sv));
994 dump_indent(level, file, " EITER = 0x%lx\n",(long) HvEITER(sv));
996 dump_indent(level, file, " PMROOT = 0x%lx\n",(long)HvPMROOT(sv));
998 dump_indent(level, file, " NAME = \"%s\"\n", HvNAME(sv));
999 if (nest < maxnest && !HvEITER(sv)) { /* Try to preserve iterator */
1002 int count = maxnest - nest;
1005 while ((he = hv_iternext(hv)) && count--) {
1009 U32 hash = HeHASH(he);
1011 key = hv_iterkey(he, &len);
1012 elt = hv_iterval(hv, he);
1013 dump_indent(level+1, file, "Elt %s HASH = 0x%lx\n", pv_display(d, key, len, 0, pvlim), hash);
1014 do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim);
1016 hv_iterinit(hv); /* Return to status quo */
1021 dump_indent(level, file, " PROTOTYPE = \"%s\"\n", SvPV(sv,n_a));
1024 do_hv_dump(level, file, " COMP_STASH", CvSTASH(sv));
1026 dump_indent(level, file, " START = 0x%lx ===> %d\n", (long)CvSTART(sv), CvSTART(sv)->op_seq);
1027 dump_indent(level, file, " ROOT = 0x%lx\n", (long)CvROOT(sv));
1028 if (CvROOT(sv) && dumpops)
1029 do_op_dump(level+1, file, CvROOT(sv));
1030 dump_indent (level, file, " XSUB = 0x%lx\n", (long)CvXSUB(sv));
1031 dump_indent (level, file, " XSUBANY = %ld\n", (long)CvXSUBANY(sv).any_i32);
1032 do_gvgv_dump(level, file, " GVGV::GV", CvGV(sv));
1033 do_gv_dump (level, file, " FILEGV", CvFILEGV(sv));
1034 dump_indent (level, file, " DEPTH = %ld\n", (long)CvDEPTH(sv));
1036 dump_indent (level, file, " MUTEXP = 0x%lx\n", (long)CvMUTEXP(sv));
1037 dump_indent (level, file, " OWNER = 0x%lx\n", (long)CvOWNER(sv));
1038 #endif /* USE_THREADS */
1039 dump_indent (level, file, " FLAGS = 0x%lx\n", (unsigned long)CvFLAGS(sv));
1040 if (type == SVt_PVFM)
1041 dump_indent(level, file, " LINES = %ld\n", (long)FmLINES(sv));
1042 dump_indent(level, file, " PADLIST = 0x%lx\n", (long)CvPADLIST(sv));
1043 if (nest < maxnest && CvPADLIST(sv)) {
1044 AV* padlist = CvPADLIST(sv);
1045 AV* pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
1046 AV* pad = (AV*)*av_fetch(padlist, 1, FALSE);
1047 SV** pname = AvARRAY(pad_name);
1048 SV** ppad = AvARRAY(pad);
1051 for (ix = 1; ix <= AvFILL(pad_name); ix++) {
1052 if (SvPOK(pname[ix]))
1053 dump_indent(level, /* %5d below is enough whitespace. */
1055 "%5d. 0x%lx (%s\"%s\" %ld-%ld)\n",
1057 SvFAKE(pname[ix]) ? "FAKE " : "",
1059 (long)I_32(SvNVX(pname[ix])),
1060 (long)SvIVX(pname[ix]));
1064 CV *outside = CvOUTSIDE(sv);
1065 dump_indent(level, file, " OUTSIDE = 0x%lx (%s)\n",
1068 : CvANON(outside) ? "ANON"
1069 : (outside == PL_main_cv) ? "MAIN"
1070 : CvUNIQUE(outside) ? "UNIQUE"
1071 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
1073 if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv)))
1074 do_sv_dump(level+1, file, (SV*)CvOUTSIDE(sv), nest+1, maxnest, dumpops, pvlim);
1077 dump_indent(level, file, " NAME = \"%s\"\n", GvNAME(sv));
1078 dump_indent(level, file, " NAMELEN = %ld\n", (long)GvNAMELEN(sv));
1079 do_hv_dump (level, file, " GvSTASH", GvSTASH(sv));
1080 dump_indent(level, file, " GP = 0x%lx\n", (long)GvGP(sv));
1081 dump_indent(level, file, " SV = 0x%lx\n", (long)GvSV(sv));
1082 dump_indent(level, file, " REFCNT = %ld\n", (long)GvREFCNT(sv));
1083 dump_indent(level, file, " IO = 0x%lx\n", (long)GvIOp(sv));
1084 dump_indent(level, file, " FORM = 0x%lx\n", (long)GvFORM(sv));
1085 dump_indent(level, file, " AV = 0x%lx\n", (long)GvAV(sv));
1086 dump_indent(level, file, " HV = 0x%lx\n", (long)GvHV(sv));
1087 dump_indent(level, file, " CV = 0x%lx\n", (long)GvCV(sv));
1088 dump_indent(level, file, " CVGEN = 0x%lx\n", (long)GvCVGEN(sv));
1089 dump_indent(level, file, " LASTEXPR = %ld\n", (long)GvLASTEXPR(sv));
1090 dump_indent(level, file, " LINE = %ld\n", (long)GvLINE(sv));
1091 dump_indent(level, file, " FLAGS = 0x%x\n", (int)GvFLAGS(sv));
1092 do_gv_dump (level, file, " FILEGV", GvFILEGV(sv));
1093 do_gv_dump (level, file, " EGV", GvEGV(sv));
1096 dump_indent(level, file, " IFP = 0x%lx\n", (long)IoIFP(sv));
1097 dump_indent(level, file, " OFP = 0x%lx\n", (long)IoOFP(sv));
1098 dump_indent(level, file, " DIRP = 0x%lx\n", (long)IoDIRP(sv));
1099 dump_indent(level, file, " LINES = %ld\n", (long)IoLINES(sv));
1100 dump_indent(level, file, " PAGE = %ld\n", (long)IoPAGE(sv));
1101 dump_indent(level, file, " PAGE_LEN = %ld\n", (long)IoPAGE_LEN(sv));
1102 dump_indent(level, file, " LINES_LEFT = %ld\n", (long)IoLINES_LEFT(sv));
1103 dump_indent(level, file, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
1104 do_gv_dump (level, file, " TOP_GV", IoTOP_GV(sv));
1105 dump_indent(level, file, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
1106 do_gv_dump (level, file, " FMT_GV", IoFMT_GV(sv));
1107 dump_indent(level, file, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
1108 do_gv_dump (level, file, " BOTTOM_GV", IoBOTTOM_GV(sv));
1109 dump_indent(level, file, " SUBPROCESS = %ld\n", (long)IoSUBPROCESS(sv));
1110 dump_indent(level, file, " TYPE = %c\n", IoTYPE(sv));
1111 dump_indent(level, file, " FLAGS = 0x%lx\n", (long)IoFLAGS(sv));
1119 do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0);