3 * Copyright (c) 1991-2001, 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.'"
16 #define PERL_IN_DUMP_C
21 Perl_dump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
25 dump_vindent(level, file, pat, &args);
30 Perl_dump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args)
32 PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), "");
33 PerlIO_vprintf(file, pat, *args);
39 PerlIO_setlinebuf(Perl_debug_log);
41 op_dump(PL_main_root);
42 dump_packsubs(PL_defstash);
46 Perl_dump_packsubs(pTHX_ 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 */
71 Perl_dump_sub(pTHX_ GV *gv)
73 SV *sv = sv_newmortal();
75 gv_fullname3(sv, gv, Nullch);
76 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ", SvPVX(sv));
78 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "(xsub 0x%lx %d)\n",
79 (long)CvXSUB(GvCV(gv)),
80 (int)CvXSUBANY(GvCV(gv)).any_i32);
81 else if (CvROOT(GvCV(gv)))
82 op_dump(CvROOT(GvCV(gv)));
84 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
88 Perl_dump_form(pTHX_ GV *gv)
90 SV *sv = sv_newmortal();
92 gv_fullname3(sv, gv, Nullch);
93 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nFORMAT %s = ", SvPVX(sv));
94 if (CvROOT(GvFORM(gv)))
95 op_dump(CvROOT(GvFORM(gv)));
97 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
103 op_dump(PL_eval_root);
107 Perl_pv_display(pTHX_ 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 Perl_sv_catpvf(aTHX_ sv, "\\%03o", (U8)*pv);
133 Perl_sv_catpvf(aTHX_ sv, "\\%o", (U8)*pv);
136 sv_catpvn(sv, "\"", 1);
138 sv_catpvn(sv, "...", 3);
140 sv_catpvn(sv, "\\0", 2);
146 Perl_sv_peek(pTHX_ SV *sv)
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 Perl_sv_catpvf(aTHX_ t, "CV(%s)", GvNAME(CvGV(sv)));
268 sv_catpv(t, "(null)");
270 SV *tmp = newSVpvn("", 0);
273 Perl_sv_catpvf(aTHX_ t, "[%s]", pv_display(tmp, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, 127));
274 Perl_sv_catpvf(aTHX_ t, "%s)", pv_display(tmp, SvPVX(sv), SvCUR(sv), SvLEN(sv), 127));
276 Perl_sv_catpvf(aTHX_ t, " [UTF8]");
280 else if (SvNOKp(sv)) {
281 STORE_NUMERIC_LOCAL_SET_STANDARD();
282 Perl_sv_catpvf(aTHX_ t, "(%g)",SvNVX(sv));
283 RESTORE_NUMERIC_LOCAL();
285 else if (SvIOKp(sv)) {
287 Perl_sv_catpvf(aTHX_ t, "(%"UVuf")", (UV)SvUVX(sv));
289 Perl_sv_catpvf(aTHX_ t, "(%"IVdf")", (IV)SvIVX(sv));
303 Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, PMOP *pm)
308 Perl_dump_indent(aTHX_ level, file, "{}\n");
311 Perl_dump_indent(aTHX_ level, file, "{\n");
313 if (pm->op_pmflags & PMf_ONCE)
318 Perl_dump_indent(aTHX_ level, file, "PMf_PRE %c%s%c%s\n",
319 ch, pm->op_pmregexp->precomp, ch,
320 (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
322 Perl_dump_indent(aTHX_ level, file, "PMf_PRE (RUNTIME)\n");
323 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
324 Perl_dump_indent(aTHX_ level, file, "PMf_REPL = ");
325 op_dump(pm->op_pmreplroot);
327 if (pm->op_pmflags || (pm->op_pmregexp && pm->op_pmregexp->check_substr)) {
328 SV *tmpsv = newSVpvn("", 0);
329 if (pm->op_pmdynflags & PMdf_USED)
330 sv_catpv(tmpsv, ",USED");
331 if (pm->op_pmdynflags & PMdf_TAINTED)
332 sv_catpv(tmpsv, ",TAINTED");
333 if (pm->op_pmflags & PMf_ONCE)
334 sv_catpv(tmpsv, ",ONCE");
335 if (pm->op_pmregexp && pm->op_pmregexp->check_substr
336 && !(pm->op_pmregexp->reganch & ROPT_NOSCAN))
337 sv_catpv(tmpsv, ",SCANFIRST");
338 if (pm->op_pmregexp && pm->op_pmregexp->check_substr
339 && pm->op_pmregexp->reganch & ROPT_CHECK_ALL)
340 sv_catpv(tmpsv, ",ALL");
341 if (pm->op_pmflags & PMf_SKIPWHITE)
342 sv_catpv(tmpsv, ",SKIPWHITE");
343 if (pm->op_pmflags & PMf_CONST)
344 sv_catpv(tmpsv, ",CONST");
345 if (pm->op_pmflags & PMf_KEEP)
346 sv_catpv(tmpsv, ",KEEP");
347 if (pm->op_pmflags & PMf_GLOBAL)
348 sv_catpv(tmpsv, ",GLOBAL");
349 if (pm->op_pmflags & PMf_CONTINUE)
350 sv_catpv(tmpsv, ",CONTINUE");
351 if (pm->op_pmflags & PMf_RETAINT)
352 sv_catpv(tmpsv, ",RETAINT");
353 if (pm->op_pmflags & PMf_EVAL)
354 sv_catpv(tmpsv, ",EVAL");
355 Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
359 Perl_dump_indent(aTHX_ level-1, file, "}\n");
363 Perl_pmop_dump(pTHX_ PMOP *pm)
365 do_pmop_dump(0, Perl_debug_log, pm);
369 Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, OP *o)
371 Perl_dump_indent(aTHX_ level, file, "{\n");
374 PerlIO_printf(file, "%-4d", o->op_seq);
376 PerlIO_printf(file, " ");
378 "%*sTYPE = %s ===> ",
379 (int)(PL_dumpindent*level-4), "", PL_op_name[o->op_type]);
382 PerlIO_printf(file, "%d\n", o->op_next->op_seq);
384 PerlIO_printf(file, "(%d)\n", o->op_next->op_seq);
387 PerlIO_printf(file, "DONE\n");
389 if (o->op_type == OP_NULL)
390 Perl_dump_indent(aTHX_ level, file, " (was %s)\n", PL_op_name[o->op_targ]);
392 Perl_dump_indent(aTHX_ level, file, "TARG = %ld\n", (long)o->op_targ);
395 Perl_dump_indent(aTHX_ level, file, "ADDR = 0x%"UVxf" => 0x%"UVxf"\n", (UV)o, (UV)o->op_next);
398 SV *tmpsv = newSVpvn("", 0);
399 switch (o->op_flags & OPf_WANT) {
401 sv_catpv(tmpsv, ",VOID");
403 case OPf_WANT_SCALAR:
404 sv_catpv(tmpsv, ",SCALAR");
407 sv_catpv(tmpsv, ",LIST");
410 sv_catpv(tmpsv, ",UNKNOWN");
413 if (o->op_flags & OPf_KIDS)
414 sv_catpv(tmpsv, ",KIDS");
415 if (o->op_flags & OPf_PARENS)
416 sv_catpv(tmpsv, ",PARENS");
417 if (o->op_flags & OPf_STACKED)
418 sv_catpv(tmpsv, ",STACKED");
419 if (o->op_flags & OPf_REF)
420 sv_catpv(tmpsv, ",REF");
421 if (o->op_flags & OPf_MOD)
422 sv_catpv(tmpsv, ",MOD");
423 if (o->op_flags & OPf_SPECIAL)
424 sv_catpv(tmpsv, ",SPECIAL");
425 Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
429 SV *tmpsv = newSVpvn("", 0);
430 if (PL_opargs[o->op_type] & OA_TARGLEX) {
431 if (o->op_private & OPpTARGET_MY)
432 sv_catpv(tmpsv, ",TARGET_MY");
434 if (o->op_type == OP_AASSIGN) {
435 if (o->op_private & OPpASSIGN_COMMON)
436 sv_catpv(tmpsv, ",COMMON");
437 if (o->op_private & OPpASSIGN_HASH)
438 sv_catpv(tmpsv, ",HASH");
440 else if (o->op_type == OP_SASSIGN) {
441 if (o->op_private & OPpASSIGN_BACKWARDS)
442 sv_catpv(tmpsv, ",BACKWARDS");
444 else if (o->op_type == OP_TRANS) {
445 if (o->op_private & OPpTRANS_SQUASH)
446 sv_catpv(tmpsv, ",SQUASH");
447 if (o->op_private & OPpTRANS_DELETE)
448 sv_catpv(tmpsv, ",DELETE");
449 if (o->op_private & OPpTRANS_COMPLEMENT)
450 sv_catpv(tmpsv, ",COMPLEMENT");
452 else if (o->op_type == OP_REPEAT) {
453 if (o->op_private & OPpREPEAT_DOLIST)
454 sv_catpv(tmpsv, ",DOLIST");
456 else if (o->op_type == OP_ENTERSUB ||
457 o->op_type == OP_RV2SV ||
458 o->op_type == OP_GVSV ||
459 o->op_type == OP_RV2AV ||
460 o->op_type == OP_RV2HV ||
461 o->op_type == OP_RV2GV ||
462 o->op_type == OP_AELEM ||
463 o->op_type == OP_HELEM )
465 if (o->op_type == OP_ENTERSUB) {
466 if (o->op_private & OPpENTERSUB_AMPER)
467 sv_catpv(tmpsv, ",AMPER");
468 if (o->op_private & OPpENTERSUB_DB)
469 sv_catpv(tmpsv, ",DB");
470 if (o->op_private & OPpENTERSUB_HASTARG)
471 sv_catpv(tmpsv, ",HASTARG");
474 switch (o->op_private & OPpDEREF) {
476 sv_catpv(tmpsv, ",SV");
479 sv_catpv(tmpsv, ",AV");
482 sv_catpv(tmpsv, ",HV");
485 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
486 if (o->op_private & OPpLVAL_DEFER)
487 sv_catpv(tmpsv, ",LVAL_DEFER");
490 if (o->op_private & HINT_STRICT_REFS)
491 sv_catpv(tmpsv, ",STRICT_REFS");
492 if (o->op_private & OPpOUR_INTRO)
493 sv_catpv(tmpsv, ",OUR_INTRO");
496 else if (o->op_type == OP_CONST) {
497 if (o->op_private & OPpCONST_BARE)
498 sv_catpv(tmpsv, ",BARE");
499 if (o->op_private & OPpCONST_STRICT)
500 sv_catpv(tmpsv, ",STRICT");
502 else if (o->op_type == OP_FLIP) {
503 if (o->op_private & OPpFLIP_LINENUM)
504 sv_catpv(tmpsv, ",LINENUM");
506 else if (o->op_type == OP_FLOP) {
507 if (o->op_private & OPpFLIP_LINENUM)
508 sv_catpv(tmpsv, ",LINENUM");
509 } else if (o->op_type == OP_RV2CV) {
510 if (o->op_private & OPpLVAL_INTRO)
511 sv_catpv(tmpsv, ",INTRO");
513 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
514 sv_catpv(tmpsv, ",INTRO");
516 Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX(tmpsv) + 1);
520 switch (o->op_type) {
525 Perl_dump_indent(aTHX_ level, file, "PADIX = %d\n", cPADOPo->op_padix);
528 SV *tmpsv = NEWSV(0,0);
532 gv_fullname3(tmpsv, (GV*)cSVOPo->op_sv, Nullch);
533 Perl_dump_indent(aTHX_ level, file, "GV = %s\n", SvPV(tmpsv, n_a));
537 Perl_dump_indent(aTHX_ level, file, "GV = NULL\n");
541 case OP_METHOD_NAMED:
542 Perl_dump_indent(aTHX_ level, file, "SV = %s\n", SvPEEK(cSVOPo->op_sv));
548 Perl_dump_indent(aTHX_ level, file, "LINE = %d\n",CopLINE(cCOPo));
549 if (CopSTASHPV(cCOPo))
550 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
552 if (cCOPo->cop_label)
553 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
557 Perl_dump_indent(aTHX_ level, file, "REDO ===> ");
558 if (cLOOPo->op_redoop)
559 PerlIO_printf(file, "%d\n", cLOOPo->op_redoop->op_seq);
561 PerlIO_printf(file, "DONE\n");
562 Perl_dump_indent(aTHX_ level, file, "NEXT ===> ");
563 if (cLOOPo->op_nextop)
564 PerlIO_printf(file, "%d\n", cLOOPo->op_nextop->op_seq);
566 PerlIO_printf(file, "DONE\n");
567 Perl_dump_indent(aTHX_ level, file, "LAST ===> ");
568 if (cLOOPo->op_lastop)
569 PerlIO_printf(file, "%d\n", cLOOPo->op_lastop->op_seq);
571 PerlIO_printf(file, "DONE\n");
579 Perl_dump_indent(aTHX_ level, file, "OTHER ===> ");
580 if (cLOGOPo->op_other)
581 PerlIO_printf(file, "%d\n", cLOGOPo->op_other->op_seq);
583 PerlIO_printf(file, "DONE\n");
589 do_pmop_dump(level, file, cPMOPo);
597 if (o->op_private & OPpREFCOUNTED)
598 Perl_dump_indent(aTHX_ level, file, "REFCNT = %"UVuf"\n", (UV)o->op_targ);
603 if (o->op_flags & OPf_KIDS) {
605 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
606 do_op_dump(level, file, kid);
608 Perl_dump_indent(aTHX_ level-1, file, "}\n");
612 Perl_op_dump(pTHX_ OP *o)
614 do_op_dump(0, Perl_debug_log, o);
618 Perl_gv_dump(pTHX_ GV *gv)
623 PerlIO_printf(Perl_debug_log, "{}\n");
627 PerlIO_printf(Perl_debug_log, "{\n");
628 gv_fullname3(sv, gv, Nullch);
629 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s", SvPVX(sv));
630 if (gv != GvEGV(gv)) {
631 gv_efullname3(sv, GvEGV(gv), Nullch);
632 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s", SvPVX(sv));
634 PerlIO_putc(Perl_debug_log, '\n');
635 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "}\n");
639 Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
641 for (; mg; mg = mg->mg_moremagic) {
642 Perl_dump_indent(aTHX_ level, file,
643 " MAGIC = 0x%"UVxf"\n", PTR2UV(mg));
644 if (mg->mg_virtual) {
645 MGVTBL *v = mg->mg_virtual;
647 if (v == &PL_vtbl_sv) s = "sv";
648 else if (v == &PL_vtbl_env) s = "env";
649 else if (v == &PL_vtbl_envelem) s = "envelem";
650 else if (v == &PL_vtbl_sig) s = "sig";
651 else if (v == &PL_vtbl_sigelem) s = "sigelem";
652 else if (v == &PL_vtbl_pack) s = "pack";
653 else if (v == &PL_vtbl_packelem) s = "packelem";
654 else if (v == &PL_vtbl_dbline) s = "dbline";
655 else if (v == &PL_vtbl_isa) s = "isa";
656 else if (v == &PL_vtbl_arylen) s = "arylen";
657 else if (v == &PL_vtbl_glob) s = "glob";
658 else if (v == &PL_vtbl_mglob) s = "mglob";
659 else if (v == &PL_vtbl_nkeys) s = "nkeys";
660 else if (v == &PL_vtbl_taint) s = "taint";
661 else if (v == &PL_vtbl_substr) s = "substr";
662 else if (v == &PL_vtbl_vec) s = "vec";
663 else if (v == &PL_vtbl_pos) s = "pos";
664 else if (v == &PL_vtbl_bm) s = "bm";
665 else if (v == &PL_vtbl_fm) s = "fm";
666 else if (v == &PL_vtbl_uvar) s = "uvar";
667 else if (v == &PL_vtbl_defelem) s = "defelem";
668 #ifdef USE_LOCALE_COLLATE
669 else if (v == &PL_vtbl_collxfrm) s = "collxfrm";
671 else if (v == &PL_vtbl_amagic) s = "amagic";
672 else if (v == &PL_vtbl_amagicelem) s = "amagicelem";
673 else if (v == &PL_vtbl_backref) s = "backref";
675 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", s);
677 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0x%"UVxf"\n", PTR2UV(v));
680 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0\n");
683 Perl_dump_indent(aTHX_ level, file, " MG_PRIVATE = %d\n", mg->mg_private);
685 if (isPRINT(mg->mg_type))
686 Perl_dump_indent(aTHX_ level, file, " MG_TYPE = '%c'\n", mg->mg_type);
688 Perl_dump_indent(aTHX_ level, file, " MG_TYPE = '\\%o'\n", mg->mg_type);
691 Perl_dump_indent(aTHX_ level, file, " MG_FLAGS = 0x%02X\n", mg->mg_flags);
692 if (mg->mg_flags & MGf_TAINTEDDIR)
693 Perl_dump_indent(aTHX_ level, file, " TAINTEDDIR\n");
694 if (mg->mg_flags & MGf_REFCOUNTED)
695 Perl_dump_indent(aTHX_ level, file, " REFCOUNTED\n");
696 if (mg->mg_flags & MGf_GSKIP)
697 Perl_dump_indent(aTHX_ level, file, " GSKIP\n");
698 if (mg->mg_flags & MGf_MINMATCH)
699 Perl_dump_indent(aTHX_ level, file, " MINMATCH\n");
702 Perl_dump_indent(aTHX_ level, file, " MG_OBJ = 0x%"UVxf"\n", PTR2UV(mg->mg_obj));
703 if (mg->mg_flags & MGf_REFCOUNTED)
704 do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
707 Perl_dump_indent(aTHX_ level, file, " MG_LEN = %ld\n", (long)mg->mg_len);
709 Perl_dump_indent(aTHX_ level, file, " MG_PTR = 0x%"UVxf, PTR2UV(mg->mg_ptr));
710 if (mg->mg_len >= 0) {
711 SV *sv = newSVpvn("", 0);
712 PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim));
715 else if (mg->mg_len == HEf_SVKEY) {
716 PerlIO_puts(file, " => HEf_SVKEY\n");
717 do_sv_dump(level+2, file, (SV*)((mg)->mg_ptr), nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
721 PerlIO_puts(file, " ???? - please notify IZ");
722 PerlIO_putc(file, '\n');
728 Perl_magic_dump(pTHX_ MAGIC *mg)
730 do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0);
734 Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, char *name, HV *sv)
736 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
737 if (sv && HvNAME(sv))
738 PerlIO_printf(file, "\t\"%s\"\n", HvNAME(sv));
740 PerlIO_putc(file, '\n');
744 Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv)
746 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
747 if (sv && GvNAME(sv))
748 PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv));
750 PerlIO_putc(file, '\n');
754 Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv)
756 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
757 if (sv && GvNAME(sv)) {
758 PerlIO_printf(file, "\t\"");
759 if (GvSTASH(sv) && HvNAME(GvSTASH(sv)))
760 PerlIO_printf(file, "%s\" :: \"", HvNAME(GvSTASH(sv)));
761 PerlIO_printf(file, "%s\"\n", GvNAME(sv));
764 PerlIO_putc(file, '\n');
768 Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
777 Perl_dump_indent(aTHX_ level, file, "SV = 0\n");
784 d = Perl_newSVpvf(aTHX_
785 "(0x%"UVxf") at 0x%"UVxf"\n%*s REFCNT = %"IVdf"\n%*s FLAGS = (",
786 PTR2UV(SvANY(sv)), PTR2UV(sv),
787 (int)(PL_dumpindent*level), "", (IV)SvREFCNT(sv),
788 (int)(PL_dumpindent*level), "");
790 if (flags & SVs_PADBUSY) sv_catpv(d, "PADBUSY,");
791 if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,");
792 if (flags & SVs_PADMY) sv_catpv(d, "PADMY,");
793 if (flags & SVs_TEMP) sv_catpv(d, "TEMP,");
794 if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,");
795 if (flags & SVs_GMG) sv_catpv(d, "GMG,");
796 if (flags & SVs_SMG) sv_catpv(d, "SMG,");
797 if (flags & SVs_RMG) sv_catpv(d, "RMG,");
799 if (flags & SVf_IOK) sv_catpv(d, "IOK,");
800 if (flags & SVf_NOK) sv_catpv(d, "NOK,");
801 if (flags & SVf_POK) sv_catpv(d, "POK,");
802 if (flags & SVf_ROK) {
804 if (SvWEAKREF(sv)) sv_catpv(d, "WEAKREF,");
806 if (flags & SVf_OOK) sv_catpv(d, "OOK,");
807 if (flags & SVf_FAKE) sv_catpv(d, "FAKE,");
808 if (flags & SVf_READONLY) sv_catpv(d, "READONLY,");
810 if (flags & SVf_AMAGIC) sv_catpv(d, "OVERLOAD,");
811 if (flags & SVp_IOK) sv_catpv(d, "pIOK,");
812 if (flags & SVp_NOK) sv_catpv(d, "pNOK,");
813 if (flags & SVp_POK) sv_catpv(d, "pPOK,");
814 if (flags & SVp_SCREAM) sv_catpv(d, "SCREAM,");
819 if (CvANON(sv)) sv_catpv(d, "ANON,");
820 if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
821 if (CvCLONE(sv)) sv_catpv(d, "CLONE,");
822 if (CvCLONED(sv)) sv_catpv(d, "CLONED,");
823 if (CvCONST(sv)) sv_catpv(d, "CONST,");
824 if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,");
825 if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,");
826 if (CvLVALUE(sv)) sv_catpv(d, "LVALUE,");
827 if (CvMETHOD(sv)) sv_catpv(d, "METHOD,");
830 if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,");
831 if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,");
834 if (GvINTRO(sv)) sv_catpv(d, "INTRO,");
835 if (GvMULTI(sv)) sv_catpv(d, "MULTI,");
836 if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,");
837 if (GvIN_PAD(sv)) sv_catpv(d, "IN_PAD,");
838 if (GvIMPORTED(sv)) {
839 sv_catpv(d, "IMPORT");
840 if (GvIMPORTED(sv) == GVf_IMPORTED)
844 if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV");
845 if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV");
846 if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV");
847 if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV");
853 if (SvEVALED(sv)) sv_catpv(d, "EVALED,");
854 if (SvIsUV(sv)) sv_catpv(d, "IsUV,");
855 if (SvUTF8(sv)) sv_catpv(d, "UTF8");
858 if (SvTAIL(sv)) sv_catpv(d, "TAIL,");
859 if (SvVALID(sv)) sv_catpv(d, "VALID,");
863 if (*(SvEND(d) - 1) == ',')
864 SvPVX(d)[--SvCUR(d)] = '\0';
868 Perl_dump_indent(aTHX_ level, file, "SV = ");
871 PerlIO_printf(file, "NULL%s\n", s);
875 PerlIO_printf(file, "IV%s\n", s);
878 PerlIO_printf(file, "NV%s\n", s);
881 PerlIO_printf(file, "RV%s\n", s);
884 PerlIO_printf(file, "PV%s\n", s);
887 PerlIO_printf(file, "PVIV%s\n", s);
890 PerlIO_printf(file, "PVNV%s\n", s);
893 PerlIO_printf(file, "PVBM%s\n", s);
896 PerlIO_printf(file, "PVMG%s\n", s);
899 PerlIO_printf(file, "PVLV%s\n", s);
902 PerlIO_printf(file, "PVAV%s\n", s);
905 PerlIO_printf(file, "PVHV%s\n", s);
908 PerlIO_printf(file, "PVCV%s\n", s);
911 PerlIO_printf(file, "PVGV%s\n", s);
914 PerlIO_printf(file, "PVFM%s\n", s);
917 PerlIO_printf(file, "PVIO%s\n", s);
920 PerlIO_printf(file, "UNKNOWN(0x%"UVxf") %s\n", (UV)type, s);
924 if (type >= SVt_PVIV || type == SVt_IV) {
926 Perl_dump_indent(aTHX_ level, file, " UV = %"UVuf, (UV)SvUVX(sv));
928 Perl_dump_indent(aTHX_ level, file, " IV = %"IVdf, (IV)SvIVX(sv));
930 PerlIO_printf(file, " (OFFSET)");
931 PerlIO_putc(file, '\n');
933 if (type >= SVt_PVNV || type == SVt_NV) {
934 STORE_NUMERIC_LOCAL_SET_STANDARD();
935 /* %Vg doesn't work? --jhi */
936 #ifdef USE_LONG_DOUBLE
937 Perl_dump_indent(aTHX_ level, file, " NV = %.*" PERL_PRIgldbl "\n", LDBL_DIG, SvNVX(sv));
939 Perl_dump_indent(aTHX_ level, file, " NV = %.*g\n", DBL_DIG, SvNVX(sv));
941 RESTORE_NUMERIC_LOCAL();
944 Perl_dump_indent(aTHX_ level, file, " RV = 0x%"UVxf"\n", PTR2UV(SvRV(sv)));
946 do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim);
954 if (type <= SVt_PVLV) {
956 Perl_dump_indent(aTHX_ level, file," PV = 0x%"UVxf" ", PTR2UV(SvPVX(sv)));
958 PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim));
959 PerlIO_printf(file, "%s\n", pv_display(d, SvPVX(sv), SvCUR(sv), SvLEN(sv), pvlim));
960 Perl_dump_indent(aTHX_ level, file, " CUR = %"IVdf"\n", (IV)SvCUR(sv));
961 Perl_dump_indent(aTHX_ level, file, " LEN = %"IVdf"\n", (IV)SvLEN(sv));
964 Perl_dump_indent(aTHX_ level, file, " PV = 0\n");
966 if (type >= SVt_PVMG) {
968 do_magic_dump(level, file, SvMAGIC(sv), nest, maxnest, dumpops, pvlim);
970 do_hv_dump(level, file, " STASH", SvSTASH(sv));
974 Perl_dump_indent(aTHX_ level, file, " TYPE = %c\n", LvTYPE(sv));
975 Perl_dump_indent(aTHX_ level, file, " TARGOFF = %"IVdf"\n", (IV)LvTARGOFF(sv));
976 Perl_dump_indent(aTHX_ level, file, " TARGLEN = %"IVdf"\n", (IV)LvTARGLEN(sv));
977 Perl_dump_indent(aTHX_ level, file, " TARG = 0x%"UVxf"\n", PTR2UV(LvTARG(sv)));
978 /* XXX level+1 ??? */
979 do_sv_dump(level, file, LvTARG(sv), nest+1, maxnest, dumpops, pvlim);
982 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(AvARRAY(sv)));
983 if (AvARRAY(sv) != AvALLOC(sv)) {
984 PerlIO_printf(file, " (offset=%"IVdf")\n", (IV)(AvARRAY(sv) - AvALLOC(sv)));
985 Perl_dump_indent(aTHX_ level, file, " ALLOC = 0x%"UVxf"\n", PTR2UV(AvALLOC(sv)));
988 PerlIO_putc(file, '\n');
989 Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)AvFILLp(sv));
990 Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)AvMAX(sv));
991 Perl_dump_indent(aTHX_ level, file, " ARYLEN = 0x%"UVxf"\n", PTR2UV(AvARYLEN(sv)));
994 if (flags & AVf_REAL) sv_catpv(d, ",REAL");
995 if (flags & AVf_REIFY) sv_catpv(d, ",REIFY");
996 if (flags & AVf_REUSED) sv_catpv(d, ",REUSED");
997 Perl_dump_indent(aTHX_ level, file, " FLAGS = (%s)\n", SvCUR(d) ? SvPVX(d) + 1 : "");
998 if (nest < maxnest && av_len((AV*)sv) >= 0) {
1000 for (count = 0; count <= av_len((AV*)sv) && count < maxnest; count++) {
1001 SV** elt = av_fetch((AV*)sv,count,0);
1003 Perl_dump_indent(aTHX_ level + 1, file, "Elt No. %"IVdf"\n", (IV)count);
1005 do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim);
1010 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv)));
1011 if (HvARRAY(sv) && HvKEYS(sv)) {
1012 /* Show distribution of HEs in the ARRAY */
1014 #define FREQ_MAX (sizeof freq / sizeof freq[0] - 1)
1017 U32 pow2 = 2, keys = HvKEYS(sv);
1018 NV theoret, sum = 0;
1020 PerlIO_printf(file, " (");
1021 Zero(freq, FREQ_MAX + 1, int);
1022 for (i = 0; i <= HvMAX(sv); i++) {
1023 HE* h; int count = 0;
1024 for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h))
1026 if (count > FREQ_MAX)
1032 for (i = 0; i <= max; i++) {
1034 PerlIO_printf(file, "%d%s:%d", i,
1035 (i == FREQ_MAX) ? "+" : "",
1038 PerlIO_printf(file, ", ");
1041 PerlIO_putc(file, ')');
1042 /* Now calculate quality wrt theoretical value */
1043 for (i = max; i > 0; i--) { /* Precision: count down. */
1044 sum += freq[i] * i * i;
1046 while ((keys = keys >> 1))
1048 /* Approximate by Poisson distribution */
1049 theoret = HvKEYS(sv);
1050 theoret += theoret * theoret/pow2;
1051 PerlIO_putc(file, '\n');
1052 Perl_dump_indent(aTHX_ level, file, " hash quality = %.1"NVff"%%", theoret/sum*100);
1054 PerlIO_putc(file, '\n');
1055 Perl_dump_indent(aTHX_ level, file, " KEYS = %"IVdf"\n", (IV)HvKEYS(sv));
1056 Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)HvFILL(sv));
1057 Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)HvMAX(sv));
1058 Perl_dump_indent(aTHX_ level, file, " RITER = %"IVdf"\n", (IV)HvRITER(sv));
1059 Perl_dump_indent(aTHX_ level, file, " EITER = 0x%"UVxf"\n", PTR2UV(HvEITER(sv)));
1061 Perl_dump_indent(aTHX_ level, file, " PMROOT = 0x%"UVxf"\n", PTR2UV(HvPMROOT(sv)));
1063 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", HvNAME(sv));
1064 if (nest < maxnest && !HvEITER(sv)) { /* Try to preserve iterator */
1067 int count = maxnest - nest;
1070 while ((he = hv_iternext(hv)) && count--) {
1074 U32 hash = HeHASH(he);
1076 key = hv_iterkey(he, &len);
1077 elt = hv_iterval(hv, he);
1078 Perl_dump_indent(aTHX_ level+1, file, "Elt %s HASH = 0x%"UVxf"\n", pv_display(d, key, len, 0, pvlim), (UV)hash);
1079 do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim);
1081 hv_iterinit(hv); /* Return to status quo */
1086 Perl_dump_indent(aTHX_ level, file, " PROTOTYPE = \"%s\"\n", SvPV(sv,n_a));
1089 do_hv_dump(level, file, " COMP_STASH", CvSTASH(sv));
1091 Perl_dump_indent(aTHX_ level, file, " START = 0x%"UVxf" ===> %"IVdf"\n", PTR2UV(CvSTART(sv)), (IV)CvSTART(sv)->op_seq);
1092 Perl_dump_indent(aTHX_ level, file, " ROOT = 0x%"UVxf"\n", PTR2UV(CvROOT(sv)));
1093 if (CvROOT(sv) && dumpops)
1094 do_op_dump(level+1, file, CvROOT(sv));
1095 Perl_dump_indent(aTHX_ level, file, " XSUB = 0x%"UVxf"\n", PTR2UV(CvXSUB(sv)));
1096 Perl_dump_indent(aTHX_ level, file, " XSUBANY = %"IVdf"\n", (IV)CvXSUBANY(sv).any_i32);
1097 do_gvgv_dump(level, file, " GVGV::GV", CvGV(sv));
1098 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", CvFILE(sv));
1099 Perl_dump_indent(aTHX_ level, file, " DEPTH = %"IVdf"\n", (IV)CvDEPTH(sv));
1101 Perl_dump_indent(aTHX_ level, file, " MUTEXP = 0x%"UVxf"\n", PTR2UV(CvMUTEXP(sv)));
1102 Perl_dump_indent(aTHX_ level, file, " OWNER = 0x%"UVxf"\n", PTR2UV(CvOWNER(sv)));
1103 #endif /* USE_THREADS */
1104 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)CvFLAGS(sv));
1105 if (type == SVt_PVFM)
1106 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)FmLINES(sv));
1107 Perl_dump_indent(aTHX_ level, file, " PADLIST = 0x%"UVxf"\n", PTR2UV(CvPADLIST(sv)));
1108 if (nest < maxnest && CvPADLIST(sv)) {
1109 AV* padlist = CvPADLIST(sv);
1110 AV* pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
1111 AV* pad = (AV*)*av_fetch(padlist, 1, FALSE);
1112 SV** pname = AvARRAY(pad_name);
1113 SV** ppad = AvARRAY(pad);
1116 for (ix = 1; ix <= AvFILL(pad_name); ix++) {
1117 if (SvPOK(pname[ix]))
1118 Perl_dump_indent(aTHX_ level,
1119 /* %5d below is enough whitespace. */
1121 "%5d. 0x%"UVxf" (%s\"%s\" %"IVdf"-%"IVdf")\n",
1122 (int)ix, PTR2UV(ppad[ix]),
1123 SvFAKE(pname[ix]) ? "FAKE " : "",
1125 (IV)SvNVX(pname[ix]),
1126 (IV)SvIVX(pname[ix]));
1130 CV *outside = CvOUTSIDE(sv);
1131 Perl_dump_indent(aTHX_ level, file, " OUTSIDE = 0x%"UVxf" (%s)\n",
1134 : CvANON(outside) ? "ANON"
1135 : (outside == PL_main_cv) ? "MAIN"
1136 : CvUNIQUE(outside) ? "UNIQUE"
1137 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
1139 if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv)))
1140 do_sv_dump(level+1, file, (SV*)CvOUTSIDE(sv), nest+1, maxnest, dumpops, pvlim);
1143 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", GvNAME(sv));
1144 Perl_dump_indent(aTHX_ level, file, " NAMELEN = %"IVdf"\n", (IV)GvNAMELEN(sv));
1145 do_hv_dump (level, file, " GvSTASH", GvSTASH(sv));
1146 Perl_dump_indent(aTHX_ level, file, " GP = 0x%"UVxf"\n", PTR2UV(GvGP(sv)));
1149 Perl_dump_indent(aTHX_ level, file, " SV = 0x%"UVxf"\n", PTR2UV(GvSV(sv)));
1150 Perl_dump_indent(aTHX_ level, file, " REFCNT = %"IVdf"\n", (IV)GvREFCNT(sv));
1151 Perl_dump_indent(aTHX_ level, file, " IO = 0x%"UVxf"\n", PTR2UV(GvIOp(sv)));
1152 Perl_dump_indent(aTHX_ level, file, " FORM = 0x%"UVxf" \n", PTR2UV(GvFORM(sv)));
1153 Perl_dump_indent(aTHX_ level, file, " AV = 0x%"UVxf"\n", PTR2UV(GvAV(sv)));
1154 Perl_dump_indent(aTHX_ level, file, " HV = 0x%"UVxf"\n", PTR2UV(GvHV(sv)));
1155 Perl_dump_indent(aTHX_ level, file, " CV = 0x%"UVxf"\n", PTR2UV(GvCV(sv)));
1156 Perl_dump_indent(aTHX_ level, file, " CVGEN = 0x%"UVxf"\n", (UV)GvCVGEN(sv));
1157 Perl_dump_indent(aTHX_ level, file, " GPFLAGS = 0x%"UVxf"\n", (UV)GvGPFLAGS(sv));
1158 Perl_dump_indent(aTHX_ level, file, " LINE = %"IVdf"\n", (IV)GvLINE(sv));
1159 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", GvFILE(sv));
1160 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)GvFLAGS(sv));
1161 do_gv_dump (level, file, " EGV", GvEGV(sv));
1164 Perl_dump_indent(aTHX_ level, file, " IFP = 0x%"UVxf"\n", PTR2UV(IoIFP(sv)));
1165 Perl_dump_indent(aTHX_ level, file, " OFP = 0x%"UVxf"\n", PTR2UV(IoOFP(sv)));
1166 Perl_dump_indent(aTHX_ level, file, " DIRP = 0x%"UVxf"\n", PTR2UV(IoDIRP(sv)));
1167 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)IoLINES(sv));
1168 Perl_dump_indent(aTHX_ level, file, " PAGE = %"IVdf"\n", (IV)IoPAGE(sv));
1169 Perl_dump_indent(aTHX_ level, file, " PAGE_LEN = %"IVdf"\n", (IV)IoPAGE_LEN(sv));
1170 Perl_dump_indent(aTHX_ level, file, " LINES_LEFT = %"IVdf"\n", (IV)IoLINES_LEFT(sv));
1172 Perl_dump_indent(aTHX_ level, file, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
1173 do_gv_dump (level, file, " TOP_GV", IoTOP_GV(sv));
1175 Perl_dump_indent(aTHX_ level, file, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
1176 do_gv_dump (level, file, " FMT_GV", IoFMT_GV(sv));
1177 if (IoBOTTOM_NAME(sv))
1178 Perl_dump_indent(aTHX_ level, file, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
1179 do_gv_dump (level, file, " BOTTOM_GV", IoBOTTOM_GV(sv));
1180 Perl_dump_indent(aTHX_ level, file, " SUBPROCESS = %"IVdf"\n", (IV)IoSUBPROCESS(sv));
1181 if (isPRINT(IoTYPE(sv)))
1182 Perl_dump_indent(aTHX_ level, file, " TYPE = '%c'\n", IoTYPE(sv));
1184 Perl_dump_indent(aTHX_ level, file, " TYPE = '\\%o'\n", IoTYPE(sv));
1185 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)IoFLAGS(sv));
1192 Perl_sv_dump(pTHX_ SV *sv)
1194 do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0);