xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/dump.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*    dump.c
2*0Sstevel@tonic-gate  *
3*0Sstevel@tonic-gate  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4*0Sstevel@tonic-gate  *    2000, 2001, 2002, 2003, 2004, by Larry Wall and others
5*0Sstevel@tonic-gate  *
6*0Sstevel@tonic-gate  *    You may distribute under the terms of either the GNU General Public
7*0Sstevel@tonic-gate  *    License or the Artistic License, as specified in the README file.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  */
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate /*
12*0Sstevel@tonic-gate  * "'You have talked long in your sleep, Frodo,' said Gandalf gently, 'and
13*0Sstevel@tonic-gate  * it has not been hard for me to read your mind and memory.'"
14*0Sstevel@tonic-gate  */
15*0Sstevel@tonic-gate 
16*0Sstevel@tonic-gate #include "EXTERN.h"
17*0Sstevel@tonic-gate #define PERL_IN_DUMP_C
18*0Sstevel@tonic-gate #include "perl.h"
19*0Sstevel@tonic-gate #include "regcomp.h"
20*0Sstevel@tonic-gate 
21*0Sstevel@tonic-gate void
Perl_dump_indent(pTHX_ I32 level,PerlIO * file,const char * pat,...)22*0Sstevel@tonic-gate Perl_dump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
23*0Sstevel@tonic-gate {
24*0Sstevel@tonic-gate     va_list args;
25*0Sstevel@tonic-gate     va_start(args, pat);
26*0Sstevel@tonic-gate     dump_vindent(level, file, pat, &args);
27*0Sstevel@tonic-gate     va_end(args);
28*0Sstevel@tonic-gate }
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate void
Perl_dump_vindent(pTHX_ I32 level,PerlIO * file,const char * pat,va_list * args)31*0Sstevel@tonic-gate Perl_dump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args)
32*0Sstevel@tonic-gate {
33*0Sstevel@tonic-gate     PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), "");
34*0Sstevel@tonic-gate     PerlIO_vprintf(file, pat, *args);
35*0Sstevel@tonic-gate }
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate void
Perl_dump_all(pTHX)38*0Sstevel@tonic-gate Perl_dump_all(pTHX)
39*0Sstevel@tonic-gate {
40*0Sstevel@tonic-gate     PerlIO_setlinebuf(Perl_debug_log);
41*0Sstevel@tonic-gate     if (PL_main_root)
42*0Sstevel@tonic-gate 	op_dump(PL_main_root);
43*0Sstevel@tonic-gate     dump_packsubs(PL_defstash);
44*0Sstevel@tonic-gate }
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate void
Perl_dump_packsubs(pTHX_ HV * stash)47*0Sstevel@tonic-gate Perl_dump_packsubs(pTHX_ HV *stash)
48*0Sstevel@tonic-gate {
49*0Sstevel@tonic-gate     I32	i;
50*0Sstevel@tonic-gate     HE	*entry;
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate     if (!HvARRAY(stash))
53*0Sstevel@tonic-gate 	return;
54*0Sstevel@tonic-gate     for (i = 0; i <= (I32) HvMAX(stash); i++) {
55*0Sstevel@tonic-gate 	for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
56*0Sstevel@tonic-gate 	    GV *gv = (GV*)HeVAL(entry);
57*0Sstevel@tonic-gate 	    HV *hv;
58*0Sstevel@tonic-gate 	    if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
59*0Sstevel@tonic-gate 		continue;
60*0Sstevel@tonic-gate 	    if (GvCVu(gv))
61*0Sstevel@tonic-gate 		dump_sub(gv);
62*0Sstevel@tonic-gate 	    if (GvFORM(gv))
63*0Sstevel@tonic-gate 		dump_form(gv);
64*0Sstevel@tonic-gate 	    if (HeKEY(entry)[HeKLEN(entry)-1] == ':'
65*0Sstevel@tonic-gate 		&& (hv = GvHV(gv)) && hv != PL_defstash)
66*0Sstevel@tonic-gate 		dump_packsubs(hv);		/* nested package */
67*0Sstevel@tonic-gate 	}
68*0Sstevel@tonic-gate     }
69*0Sstevel@tonic-gate }
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate void
Perl_dump_sub(pTHX_ GV * gv)72*0Sstevel@tonic-gate Perl_dump_sub(pTHX_ GV *gv)
73*0Sstevel@tonic-gate {
74*0Sstevel@tonic-gate     SV *sv = sv_newmortal();
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate     gv_fullname3(sv, gv, Nullch);
77*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ", SvPVX(sv));
78*0Sstevel@tonic-gate     if (CvXSUB(GvCV(gv)))
79*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ 0, Perl_debug_log, "(xsub 0x%"UVxf" %d)\n",
80*0Sstevel@tonic-gate 	    PTR2UV(CvXSUB(GvCV(gv))),
81*0Sstevel@tonic-gate 	    (int)CvXSUBANY(GvCV(gv)).any_i32);
82*0Sstevel@tonic-gate     else if (CvROOT(GvCV(gv)))
83*0Sstevel@tonic-gate 	op_dump(CvROOT(GvCV(gv)));
84*0Sstevel@tonic-gate     else
85*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
86*0Sstevel@tonic-gate }
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate void
Perl_dump_form(pTHX_ GV * gv)89*0Sstevel@tonic-gate Perl_dump_form(pTHX_ GV *gv)
90*0Sstevel@tonic-gate {
91*0Sstevel@tonic-gate     SV *sv = sv_newmortal();
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate     gv_fullname3(sv, gv, Nullch);
94*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nFORMAT %s = ", SvPVX(sv));
95*0Sstevel@tonic-gate     if (CvROOT(GvFORM(gv)))
96*0Sstevel@tonic-gate 	op_dump(CvROOT(GvFORM(gv)));
97*0Sstevel@tonic-gate     else
98*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
99*0Sstevel@tonic-gate }
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate void
Perl_dump_eval(pTHX)102*0Sstevel@tonic-gate Perl_dump_eval(pTHX)
103*0Sstevel@tonic-gate {
104*0Sstevel@tonic-gate     op_dump(PL_eval_root);
105*0Sstevel@tonic-gate }
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate char *
Perl_pv_display(pTHX_ SV * dsv,char * pv,STRLEN cur,STRLEN len,STRLEN pvlim)108*0Sstevel@tonic-gate Perl_pv_display(pTHX_ SV *dsv, char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
109*0Sstevel@tonic-gate {
110*0Sstevel@tonic-gate     int truncated = 0;
111*0Sstevel@tonic-gate     int nul_terminated = len > cur && pv[cur] == '\0';
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate     sv_setpvn(dsv, "\"", 1);
114*0Sstevel@tonic-gate     for (; cur--; pv++) {
115*0Sstevel@tonic-gate 	if (pvlim && SvCUR(dsv) >= pvlim) {
116*0Sstevel@tonic-gate             truncated++;
117*0Sstevel@tonic-gate 	    break;
118*0Sstevel@tonic-gate         }
119*0Sstevel@tonic-gate 	switch (*pv) {
120*0Sstevel@tonic-gate 	case '\t': sv_catpvn(dsv, "\\t", 2);  break;
121*0Sstevel@tonic-gate 	case '\n': sv_catpvn(dsv, "\\n", 2);  break;
122*0Sstevel@tonic-gate 	case '\r': sv_catpvn(dsv, "\\r", 2);  break;
123*0Sstevel@tonic-gate 	case '\f': sv_catpvn(dsv, "\\f", 2);  break;
124*0Sstevel@tonic-gate 	case '"':  sv_catpvn(dsv, "\\\"", 2); break;
125*0Sstevel@tonic-gate 	case '\\': sv_catpvn(dsv, "\\\\", 2); break;
126*0Sstevel@tonic-gate 	default:
127*0Sstevel@tonic-gate 	    if (isPRINT(*pv))
128*0Sstevel@tonic-gate 		sv_catpvn(dsv, pv, 1);
129*0Sstevel@tonic-gate 	    else if (cur && isDIGIT(*(pv+1)))
130*0Sstevel@tonic-gate 		Perl_sv_catpvf(aTHX_ dsv, "\\%03o", (U8)*pv);
131*0Sstevel@tonic-gate 	    else
132*0Sstevel@tonic-gate 		Perl_sv_catpvf(aTHX_ dsv, "\\%o", (U8)*pv);
133*0Sstevel@tonic-gate         }
134*0Sstevel@tonic-gate     }
135*0Sstevel@tonic-gate     sv_catpvn(dsv, "\"", 1);
136*0Sstevel@tonic-gate     if (truncated)
137*0Sstevel@tonic-gate 	sv_catpvn(dsv, "...", 3);
138*0Sstevel@tonic-gate     if (nul_terminated)
139*0Sstevel@tonic-gate 	sv_catpvn(dsv, "\\0", 2);
140*0Sstevel@tonic-gate 
141*0Sstevel@tonic-gate     return SvPVX(dsv);
142*0Sstevel@tonic-gate }
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate char *
Perl_sv_peek(pTHX_ SV * sv)145*0Sstevel@tonic-gate Perl_sv_peek(pTHX_ SV *sv)
146*0Sstevel@tonic-gate {
147*0Sstevel@tonic-gate     SV *t = sv_newmortal();
148*0Sstevel@tonic-gate     STRLEN n_a;
149*0Sstevel@tonic-gate     int unref = 0;
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate     sv_setpvn(t, "", 0);
152*0Sstevel@tonic-gate   retry:
153*0Sstevel@tonic-gate     if (!sv) {
154*0Sstevel@tonic-gate 	sv_catpv(t, "VOID");
155*0Sstevel@tonic-gate 	goto finish;
156*0Sstevel@tonic-gate     }
157*0Sstevel@tonic-gate     else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') {
158*0Sstevel@tonic-gate 	sv_catpv(t, "WILD");
159*0Sstevel@tonic-gate 	goto finish;
160*0Sstevel@tonic-gate     }
161*0Sstevel@tonic-gate     else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) {
162*0Sstevel@tonic-gate 	if (sv == &PL_sv_undef) {
163*0Sstevel@tonic-gate 	    sv_catpv(t, "SV_UNDEF");
164*0Sstevel@tonic-gate 	    if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
165*0Sstevel@tonic-gate 				 SVs_GMG|SVs_SMG|SVs_RMG)) &&
166*0Sstevel@tonic-gate 		SvREADONLY(sv))
167*0Sstevel@tonic-gate 		goto finish;
168*0Sstevel@tonic-gate 	}
169*0Sstevel@tonic-gate 	else if (sv == &PL_sv_no) {
170*0Sstevel@tonic-gate 	    sv_catpv(t, "SV_NO");
171*0Sstevel@tonic-gate 	    if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
172*0Sstevel@tonic-gate 				 SVs_GMG|SVs_SMG|SVs_RMG)) &&
173*0Sstevel@tonic-gate 		!(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
174*0Sstevel@tonic-gate 				  SVp_POK|SVp_NOK)) &&
175*0Sstevel@tonic-gate 		SvCUR(sv) == 0 &&
176*0Sstevel@tonic-gate 		SvNVX(sv) == 0.0)
177*0Sstevel@tonic-gate 		goto finish;
178*0Sstevel@tonic-gate 	}
179*0Sstevel@tonic-gate 	else if (sv == &PL_sv_yes) {
180*0Sstevel@tonic-gate 	    sv_catpv(t, "SV_YES");
181*0Sstevel@tonic-gate 	    if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
182*0Sstevel@tonic-gate 				 SVs_GMG|SVs_SMG|SVs_RMG)) &&
183*0Sstevel@tonic-gate 		!(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
184*0Sstevel@tonic-gate 				  SVp_POK|SVp_NOK)) &&
185*0Sstevel@tonic-gate 		SvCUR(sv) == 1 &&
186*0Sstevel@tonic-gate 		SvPVX(sv) && *SvPVX(sv) == '1' &&
187*0Sstevel@tonic-gate 		SvNVX(sv) == 1.0)
188*0Sstevel@tonic-gate 		goto finish;
189*0Sstevel@tonic-gate 	}
190*0Sstevel@tonic-gate 	else {
191*0Sstevel@tonic-gate 	    sv_catpv(t, "SV_PLACEHOLDER");
192*0Sstevel@tonic-gate 	    if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
193*0Sstevel@tonic-gate 				 SVs_GMG|SVs_SMG|SVs_RMG)) &&
194*0Sstevel@tonic-gate 		SvREADONLY(sv))
195*0Sstevel@tonic-gate 		goto finish;
196*0Sstevel@tonic-gate 	}
197*0Sstevel@tonic-gate 	sv_catpv(t, ":");
198*0Sstevel@tonic-gate     }
199*0Sstevel@tonic-gate     else if (SvREFCNT(sv) == 0) {
200*0Sstevel@tonic-gate 	sv_catpv(t, "(");
201*0Sstevel@tonic-gate 	unref++;
202*0Sstevel@tonic-gate     }
203*0Sstevel@tonic-gate     else if (DEBUG_R_TEST_) {
204*0Sstevel@tonic-gate 	int is_tmp = 0;
205*0Sstevel@tonic-gate 	I32 ix;
206*0Sstevel@tonic-gate 	/* is this SV on the tmps stack? */
207*0Sstevel@tonic-gate 	for (ix=PL_tmps_ix; ix>=0; ix--) {
208*0Sstevel@tonic-gate 	    if (PL_tmps_stack[ix] == sv) {
209*0Sstevel@tonic-gate 		is_tmp = 1;
210*0Sstevel@tonic-gate 		break;
211*0Sstevel@tonic-gate 	    }
212*0Sstevel@tonic-gate 	}
213*0Sstevel@tonic-gate 	if (SvREFCNT(sv) > 1)
214*0Sstevel@tonic-gate 	    Perl_sv_catpvf(aTHX_ t, "<%"UVuf"%s>", (UV)SvREFCNT(sv),
215*0Sstevel@tonic-gate 		    is_tmp ? "T" : "");
216*0Sstevel@tonic-gate 	else if (is_tmp)
217*0Sstevel@tonic-gate 	    sv_catpv(t, "<T>");
218*0Sstevel@tonic-gate     }
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate     if (SvROK(sv)) {
221*0Sstevel@tonic-gate 	sv_catpv(t, "\\");
222*0Sstevel@tonic-gate 	if (SvCUR(t) + unref > 10) {
223*0Sstevel@tonic-gate 	    SvCUR(t) = unref + 3;
224*0Sstevel@tonic-gate 	    *SvEND(t) = '\0';
225*0Sstevel@tonic-gate 	    sv_catpv(t, "...");
226*0Sstevel@tonic-gate 	    goto finish;
227*0Sstevel@tonic-gate 	}
228*0Sstevel@tonic-gate 	sv = (SV*)SvRV(sv);
229*0Sstevel@tonic-gate 	goto retry;
230*0Sstevel@tonic-gate     }
231*0Sstevel@tonic-gate     switch (SvTYPE(sv)) {
232*0Sstevel@tonic-gate     default:
233*0Sstevel@tonic-gate 	sv_catpv(t, "FREED");
234*0Sstevel@tonic-gate 	goto finish;
235*0Sstevel@tonic-gate 
236*0Sstevel@tonic-gate     case SVt_NULL:
237*0Sstevel@tonic-gate 	sv_catpv(t, "UNDEF");
238*0Sstevel@tonic-gate 	goto finish;
239*0Sstevel@tonic-gate     case SVt_IV:
240*0Sstevel@tonic-gate 	sv_catpv(t, "IV");
241*0Sstevel@tonic-gate 	break;
242*0Sstevel@tonic-gate     case SVt_NV:
243*0Sstevel@tonic-gate 	sv_catpv(t, "NV");
244*0Sstevel@tonic-gate 	break;
245*0Sstevel@tonic-gate     case SVt_RV:
246*0Sstevel@tonic-gate 	sv_catpv(t, "RV");
247*0Sstevel@tonic-gate 	break;
248*0Sstevel@tonic-gate     case SVt_PV:
249*0Sstevel@tonic-gate 	sv_catpv(t, "PV");
250*0Sstevel@tonic-gate 	break;
251*0Sstevel@tonic-gate     case SVt_PVIV:
252*0Sstevel@tonic-gate 	sv_catpv(t, "PVIV");
253*0Sstevel@tonic-gate 	break;
254*0Sstevel@tonic-gate     case SVt_PVNV:
255*0Sstevel@tonic-gate 	sv_catpv(t, "PVNV");
256*0Sstevel@tonic-gate 	break;
257*0Sstevel@tonic-gate     case SVt_PVMG:
258*0Sstevel@tonic-gate 	sv_catpv(t, "PVMG");
259*0Sstevel@tonic-gate 	break;
260*0Sstevel@tonic-gate     case SVt_PVLV:
261*0Sstevel@tonic-gate 	sv_catpv(t, "PVLV");
262*0Sstevel@tonic-gate 	break;
263*0Sstevel@tonic-gate     case SVt_PVAV:
264*0Sstevel@tonic-gate 	sv_catpv(t, "AV");
265*0Sstevel@tonic-gate 	break;
266*0Sstevel@tonic-gate     case SVt_PVHV:
267*0Sstevel@tonic-gate 	sv_catpv(t, "HV");
268*0Sstevel@tonic-gate 	break;
269*0Sstevel@tonic-gate     case SVt_PVCV:
270*0Sstevel@tonic-gate 	if (CvGV(sv))
271*0Sstevel@tonic-gate 	    Perl_sv_catpvf(aTHX_ t, "CV(%s)", GvNAME(CvGV(sv)));
272*0Sstevel@tonic-gate 	else
273*0Sstevel@tonic-gate 	    sv_catpv(t, "CV()");
274*0Sstevel@tonic-gate 	goto finish;
275*0Sstevel@tonic-gate     case SVt_PVGV:
276*0Sstevel@tonic-gate 	sv_catpv(t, "GV");
277*0Sstevel@tonic-gate 	break;
278*0Sstevel@tonic-gate     case SVt_PVBM:
279*0Sstevel@tonic-gate 	sv_catpv(t, "BM");
280*0Sstevel@tonic-gate 	break;
281*0Sstevel@tonic-gate     case SVt_PVFM:
282*0Sstevel@tonic-gate 	sv_catpv(t, "FM");
283*0Sstevel@tonic-gate 	break;
284*0Sstevel@tonic-gate     case SVt_PVIO:
285*0Sstevel@tonic-gate 	sv_catpv(t, "IO");
286*0Sstevel@tonic-gate 	break;
287*0Sstevel@tonic-gate     }
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate     if (SvPOKp(sv)) {
290*0Sstevel@tonic-gate 	if (!SvPVX(sv))
291*0Sstevel@tonic-gate 	    sv_catpv(t, "(null)");
292*0Sstevel@tonic-gate 	else {
293*0Sstevel@tonic-gate 	    SV *tmp = newSVpvn("", 0);
294*0Sstevel@tonic-gate 	    sv_catpv(t, "(");
295*0Sstevel@tonic-gate 	    if (SvOOK(sv))
296*0Sstevel@tonic-gate 		Perl_sv_catpvf(aTHX_ t, "[%s]", pv_display(tmp, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, 127));
297*0Sstevel@tonic-gate 	    Perl_sv_catpvf(aTHX_ t, "%s)", pv_display(tmp, SvPVX(sv), SvCUR(sv), SvLEN(sv), 127));
298*0Sstevel@tonic-gate 	    if (SvUTF8(sv))
299*0Sstevel@tonic-gate 		Perl_sv_catpvf(aTHX_ t, " [UTF8 \"%s\"]",
300*0Sstevel@tonic-gate 			       sv_uni_display(tmp, sv, 8 * sv_len_utf8(sv),
301*0Sstevel@tonic-gate 					      UNI_DISPLAY_QQ));
302*0Sstevel@tonic-gate 	    SvREFCNT_dec(tmp);
303*0Sstevel@tonic-gate 	}
304*0Sstevel@tonic-gate     }
305*0Sstevel@tonic-gate     else if (SvNOKp(sv)) {
306*0Sstevel@tonic-gate 	STORE_NUMERIC_LOCAL_SET_STANDARD();
307*0Sstevel@tonic-gate 	Perl_sv_catpvf(aTHX_ t, "(%"NVgf")",SvNVX(sv));
308*0Sstevel@tonic-gate 	RESTORE_NUMERIC_LOCAL();
309*0Sstevel@tonic-gate     }
310*0Sstevel@tonic-gate     else if (SvIOKp(sv)) {
311*0Sstevel@tonic-gate 	if (SvIsUV(sv))
312*0Sstevel@tonic-gate 	    Perl_sv_catpvf(aTHX_ t, "(%"UVuf")", (UV)SvUVX(sv));
313*0Sstevel@tonic-gate 	else
314*0Sstevel@tonic-gate             Perl_sv_catpvf(aTHX_ t, "(%"IVdf")", (IV)SvIVX(sv));
315*0Sstevel@tonic-gate     }
316*0Sstevel@tonic-gate     else
317*0Sstevel@tonic-gate 	sv_catpv(t, "()");
318*0Sstevel@tonic-gate 
319*0Sstevel@tonic-gate   finish:
320*0Sstevel@tonic-gate     if (unref) {
321*0Sstevel@tonic-gate 	while (unref--)
322*0Sstevel@tonic-gate 	    sv_catpv(t, ")");
323*0Sstevel@tonic-gate     }
324*0Sstevel@tonic-gate     return SvPV(t, n_a);
325*0Sstevel@tonic-gate }
326*0Sstevel@tonic-gate 
327*0Sstevel@tonic-gate void
Perl_do_pmop_dump(pTHX_ I32 level,PerlIO * file,PMOP * pm)328*0Sstevel@tonic-gate Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, PMOP *pm)
329*0Sstevel@tonic-gate {
330*0Sstevel@tonic-gate     char ch;
331*0Sstevel@tonic-gate 
332*0Sstevel@tonic-gate     if (!pm) {
333*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "{}\n");
334*0Sstevel@tonic-gate 	return;
335*0Sstevel@tonic-gate     }
336*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ level, file, "{\n");
337*0Sstevel@tonic-gate     level++;
338*0Sstevel@tonic-gate     if (pm->op_pmflags & PMf_ONCE)
339*0Sstevel@tonic-gate 	ch = '?';
340*0Sstevel@tonic-gate     else
341*0Sstevel@tonic-gate 	ch = '/';
342*0Sstevel@tonic-gate     if (PM_GETRE(pm))
343*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "PMf_PRE %c%s%c%s\n",
344*0Sstevel@tonic-gate 	     ch, PM_GETRE(pm)->precomp, ch,
345*0Sstevel@tonic-gate 	     (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
346*0Sstevel@tonic-gate     else
347*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "PMf_PRE (RUNTIME)\n");
348*0Sstevel@tonic-gate     if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
349*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "PMf_REPL = ");
350*0Sstevel@tonic-gate 	op_dump(pm->op_pmreplroot);
351*0Sstevel@tonic-gate     }
352*0Sstevel@tonic-gate     if (pm->op_pmflags || (PM_GETRE(pm) && PM_GETRE(pm)->check_substr)) {
353*0Sstevel@tonic-gate 	SV *tmpsv = newSVpvn("", 0);
354*0Sstevel@tonic-gate 	if (pm->op_pmdynflags & PMdf_USED)
355*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",USED");
356*0Sstevel@tonic-gate 	if (pm->op_pmdynflags & PMdf_TAINTED)
357*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",TAINTED");
358*0Sstevel@tonic-gate 	if (pm->op_pmflags & PMf_ONCE)
359*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",ONCE");
360*0Sstevel@tonic-gate 	if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr
361*0Sstevel@tonic-gate 	    && !(PM_GETRE(pm)->reganch & ROPT_NOSCAN))
362*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",SCANFIRST");
363*0Sstevel@tonic-gate 	if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr
364*0Sstevel@tonic-gate 	    && PM_GETRE(pm)->reganch & ROPT_CHECK_ALL)
365*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",ALL");
366*0Sstevel@tonic-gate 	if (pm->op_pmflags & PMf_SKIPWHITE)
367*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",SKIPWHITE");
368*0Sstevel@tonic-gate 	if (pm->op_pmflags & PMf_CONST)
369*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",CONST");
370*0Sstevel@tonic-gate 	if (pm->op_pmflags & PMf_KEEP)
371*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",KEEP");
372*0Sstevel@tonic-gate 	if (pm->op_pmflags & PMf_GLOBAL)
373*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",GLOBAL");
374*0Sstevel@tonic-gate 	if (pm->op_pmflags & PMf_CONTINUE)
375*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",CONTINUE");
376*0Sstevel@tonic-gate 	if (pm->op_pmflags & PMf_RETAINT)
377*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",RETAINT");
378*0Sstevel@tonic-gate 	if (pm->op_pmflags & PMf_EVAL)
379*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",EVAL");
380*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
381*0Sstevel@tonic-gate 	SvREFCNT_dec(tmpsv);
382*0Sstevel@tonic-gate     }
383*0Sstevel@tonic-gate 
384*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ level-1, file, "}\n");
385*0Sstevel@tonic-gate }
386*0Sstevel@tonic-gate 
387*0Sstevel@tonic-gate void
Perl_pmop_dump(pTHX_ PMOP * pm)388*0Sstevel@tonic-gate Perl_pmop_dump(pTHX_ PMOP *pm)
389*0Sstevel@tonic-gate {
390*0Sstevel@tonic-gate     do_pmop_dump(0, Perl_debug_log, pm);
391*0Sstevel@tonic-gate }
392*0Sstevel@tonic-gate 
393*0Sstevel@tonic-gate void
Perl_do_op_dump(pTHX_ I32 level,PerlIO * file,OP * o)394*0Sstevel@tonic-gate Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, OP *o)
395*0Sstevel@tonic-gate {
396*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ level, file, "{\n");
397*0Sstevel@tonic-gate     level++;
398*0Sstevel@tonic-gate     if (o->op_seq)
399*0Sstevel@tonic-gate 	PerlIO_printf(file, "%-4d", o->op_seq);
400*0Sstevel@tonic-gate     else
401*0Sstevel@tonic-gate 	PerlIO_printf(file, "    ");
402*0Sstevel@tonic-gate     PerlIO_printf(file,
403*0Sstevel@tonic-gate 		  "%*sTYPE = %s  ===> ",
404*0Sstevel@tonic-gate 		  (int)(PL_dumpindent*level-4), "", OP_NAME(o));
405*0Sstevel@tonic-gate     if (o->op_next) {
406*0Sstevel@tonic-gate 	if (o->op_seq)
407*0Sstevel@tonic-gate 	    PerlIO_printf(file, "%d\n", o->op_next->op_seq);
408*0Sstevel@tonic-gate 	else
409*0Sstevel@tonic-gate 	    PerlIO_printf(file, "(%d)\n", o->op_next->op_seq);
410*0Sstevel@tonic-gate     }
411*0Sstevel@tonic-gate     else
412*0Sstevel@tonic-gate 	PerlIO_printf(file, "DONE\n");
413*0Sstevel@tonic-gate     if (o->op_targ) {
414*0Sstevel@tonic-gate 	if (o->op_type == OP_NULL)
415*0Sstevel@tonic-gate 	{
416*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  (was %s)\n", PL_op_name[o->op_targ]);
417*0Sstevel@tonic-gate 	    if (o->op_targ == OP_NEXTSTATE)
418*0Sstevel@tonic-gate 	    {
419*0Sstevel@tonic-gate 		if (CopLINE(cCOPo))
420*0Sstevel@tonic-gate 		    Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n",
421*0Sstevel@tonic-gate 				     (UV)CopLINE(cCOPo));
422*0Sstevel@tonic-gate 		if (CopSTASHPV(cCOPo))
423*0Sstevel@tonic-gate 		    Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
424*0Sstevel@tonic-gate 				     CopSTASHPV(cCOPo));
425*0Sstevel@tonic-gate 		if (cCOPo->cop_label)
426*0Sstevel@tonic-gate 		    Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
427*0Sstevel@tonic-gate 				     cCOPo->cop_label);
428*0Sstevel@tonic-gate 	    }
429*0Sstevel@tonic-gate 	}
430*0Sstevel@tonic-gate 	else
431*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "TARG = %ld\n", (long)o->op_targ);
432*0Sstevel@tonic-gate     }
433*0Sstevel@tonic-gate #ifdef DUMPADDR
434*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ level, file, "ADDR = 0x%"UVxf" => 0x%"UVxf"\n", (UV)o, (UV)o->op_next);
435*0Sstevel@tonic-gate #endif
436*0Sstevel@tonic-gate     if (o->op_flags) {
437*0Sstevel@tonic-gate 	SV *tmpsv = newSVpvn("", 0);
438*0Sstevel@tonic-gate 	switch (o->op_flags & OPf_WANT) {
439*0Sstevel@tonic-gate 	case OPf_WANT_VOID:
440*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",VOID");
441*0Sstevel@tonic-gate 	    break;
442*0Sstevel@tonic-gate 	case OPf_WANT_SCALAR:
443*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",SCALAR");
444*0Sstevel@tonic-gate 	    break;
445*0Sstevel@tonic-gate 	case OPf_WANT_LIST:
446*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",LIST");
447*0Sstevel@tonic-gate 	    break;
448*0Sstevel@tonic-gate 	default:
449*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",UNKNOWN");
450*0Sstevel@tonic-gate 	    break;
451*0Sstevel@tonic-gate 	}
452*0Sstevel@tonic-gate 	if (o->op_flags & OPf_KIDS)
453*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",KIDS");
454*0Sstevel@tonic-gate 	if (o->op_flags & OPf_PARENS)
455*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",PARENS");
456*0Sstevel@tonic-gate 	if (o->op_flags & OPf_STACKED)
457*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",STACKED");
458*0Sstevel@tonic-gate 	if (o->op_flags & OPf_REF)
459*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",REF");
460*0Sstevel@tonic-gate 	if (o->op_flags & OPf_MOD)
461*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",MOD");
462*0Sstevel@tonic-gate 	if (o->op_flags & OPf_SPECIAL)
463*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",SPECIAL");
464*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
465*0Sstevel@tonic-gate 	SvREFCNT_dec(tmpsv);
466*0Sstevel@tonic-gate     }
467*0Sstevel@tonic-gate     if (o->op_private) {
468*0Sstevel@tonic-gate 	SV *tmpsv = newSVpvn("", 0);
469*0Sstevel@tonic-gate 	if (PL_opargs[o->op_type] & OA_TARGLEX) {
470*0Sstevel@tonic-gate 	    if (o->op_private & OPpTARGET_MY)
471*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",TARGET_MY");
472*0Sstevel@tonic-gate 	}
473*0Sstevel@tonic-gate 	else if (o->op_type == OP_LEAVESUB ||
474*0Sstevel@tonic-gate 		 o->op_type == OP_LEAVE ||
475*0Sstevel@tonic-gate 		 o->op_type == OP_LEAVESUBLV ||
476*0Sstevel@tonic-gate 		 o->op_type == OP_LEAVEWRITE) {
477*0Sstevel@tonic-gate 	    if (o->op_private & OPpREFCOUNTED)
478*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",REFCOUNTED");
479*0Sstevel@tonic-gate 	}
480*0Sstevel@tonic-gate         else if (o->op_type == OP_AASSIGN) {
481*0Sstevel@tonic-gate 	    if (o->op_private & OPpASSIGN_COMMON)
482*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",COMMON");
483*0Sstevel@tonic-gate 	    if (o->op_private & OPpASSIGN_HASH)
484*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",HASH");
485*0Sstevel@tonic-gate 	}
486*0Sstevel@tonic-gate 	else if (o->op_type == OP_SASSIGN) {
487*0Sstevel@tonic-gate 	    if (o->op_private & OPpASSIGN_BACKWARDS)
488*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",BACKWARDS");
489*0Sstevel@tonic-gate 	}
490*0Sstevel@tonic-gate 	else if (o->op_type == OP_TRANS) {
491*0Sstevel@tonic-gate 	    if (o->op_private & OPpTRANS_SQUASH)
492*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",SQUASH");
493*0Sstevel@tonic-gate 	    if (o->op_private & OPpTRANS_DELETE)
494*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",DELETE");
495*0Sstevel@tonic-gate 	    if (o->op_private & OPpTRANS_COMPLEMENT)
496*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",COMPLEMENT");
497*0Sstevel@tonic-gate 	    if (o->op_private & OPpTRANS_IDENTICAL)
498*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",IDENTICAL");
499*0Sstevel@tonic-gate 	    if (o->op_private & OPpTRANS_GROWS)
500*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",GROWS");
501*0Sstevel@tonic-gate 	}
502*0Sstevel@tonic-gate 	else if (o->op_type == OP_REPEAT) {
503*0Sstevel@tonic-gate 	    if (o->op_private & OPpREPEAT_DOLIST)
504*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",DOLIST");
505*0Sstevel@tonic-gate 	}
506*0Sstevel@tonic-gate 	else if (o->op_type == OP_ENTERSUB ||
507*0Sstevel@tonic-gate 		 o->op_type == OP_RV2SV ||
508*0Sstevel@tonic-gate 		 o->op_type == OP_GVSV ||
509*0Sstevel@tonic-gate 		 o->op_type == OP_RV2AV ||
510*0Sstevel@tonic-gate 		 o->op_type == OP_RV2HV ||
511*0Sstevel@tonic-gate 		 o->op_type == OP_RV2GV ||
512*0Sstevel@tonic-gate 		 o->op_type == OP_AELEM ||
513*0Sstevel@tonic-gate 		 o->op_type == OP_HELEM )
514*0Sstevel@tonic-gate 	{
515*0Sstevel@tonic-gate 	    if (o->op_type == OP_ENTERSUB) {
516*0Sstevel@tonic-gate 		if (o->op_private & OPpENTERSUB_AMPER)
517*0Sstevel@tonic-gate 		    sv_catpv(tmpsv, ",AMPER");
518*0Sstevel@tonic-gate 		if (o->op_private & OPpENTERSUB_DB)
519*0Sstevel@tonic-gate 		    sv_catpv(tmpsv, ",DB");
520*0Sstevel@tonic-gate 		if (o->op_private & OPpENTERSUB_HASTARG)
521*0Sstevel@tonic-gate 		    sv_catpv(tmpsv, ",HASTARG");
522*0Sstevel@tonic-gate 		if (o->op_private & OPpENTERSUB_NOPAREN)
523*0Sstevel@tonic-gate 		    sv_catpv(tmpsv, ",NOPAREN");
524*0Sstevel@tonic-gate 		if (o->op_private & OPpENTERSUB_INARGS)
525*0Sstevel@tonic-gate 		    sv_catpv(tmpsv, ",INARGS");
526*0Sstevel@tonic-gate 		if (o->op_private & OPpENTERSUB_NOMOD)
527*0Sstevel@tonic-gate 		    sv_catpv(tmpsv, ",NOMOD");
528*0Sstevel@tonic-gate 	    }
529*0Sstevel@tonic-gate 	    else {
530*0Sstevel@tonic-gate 		switch (o->op_private & OPpDEREF) {
531*0Sstevel@tonic-gate 	    case OPpDEREF_SV:
532*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",SV");
533*0Sstevel@tonic-gate 		break;
534*0Sstevel@tonic-gate 	    case OPpDEREF_AV:
535*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",AV");
536*0Sstevel@tonic-gate 		break;
537*0Sstevel@tonic-gate 	    case OPpDEREF_HV:
538*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",HV");
539*0Sstevel@tonic-gate 		break;
540*0Sstevel@tonic-gate 	    }
541*0Sstevel@tonic-gate 		if (o->op_private & OPpMAYBE_LVSUB)
542*0Sstevel@tonic-gate 		    sv_catpv(tmpsv, ",MAYBE_LVSUB");
543*0Sstevel@tonic-gate 	    }
544*0Sstevel@tonic-gate 	    if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
545*0Sstevel@tonic-gate 		if (o->op_private & OPpLVAL_DEFER)
546*0Sstevel@tonic-gate 		    sv_catpv(tmpsv, ",LVAL_DEFER");
547*0Sstevel@tonic-gate 	    }
548*0Sstevel@tonic-gate 	    else {
549*0Sstevel@tonic-gate 		if (o->op_private & HINT_STRICT_REFS)
550*0Sstevel@tonic-gate 		    sv_catpv(tmpsv, ",STRICT_REFS");
551*0Sstevel@tonic-gate 		if (o->op_private & OPpOUR_INTRO)
552*0Sstevel@tonic-gate 		    sv_catpv(tmpsv, ",OUR_INTRO");
553*0Sstevel@tonic-gate 	    }
554*0Sstevel@tonic-gate 	}
555*0Sstevel@tonic-gate 	else if (o->op_type == OP_CONST) {
556*0Sstevel@tonic-gate 	    if (o->op_private & OPpCONST_BARE)
557*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",BARE");
558*0Sstevel@tonic-gate 	    if (o->op_private & OPpCONST_STRICT)
559*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",STRICT");
560*0Sstevel@tonic-gate 	    if (o->op_private & OPpCONST_ARYBASE)
561*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",ARYBASE");
562*0Sstevel@tonic-gate 	    if (o->op_private & OPpCONST_WARNING)
563*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",WARNING");
564*0Sstevel@tonic-gate 	    if (o->op_private & OPpCONST_ENTERED)
565*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",ENTERED");
566*0Sstevel@tonic-gate 	}
567*0Sstevel@tonic-gate 	else if (o->op_type == OP_FLIP) {
568*0Sstevel@tonic-gate 	    if (o->op_private & OPpFLIP_LINENUM)
569*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",LINENUM");
570*0Sstevel@tonic-gate 	}
571*0Sstevel@tonic-gate 	else if (o->op_type == OP_FLOP) {
572*0Sstevel@tonic-gate 	    if (o->op_private & OPpFLIP_LINENUM)
573*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",LINENUM");
574*0Sstevel@tonic-gate 	}
575*0Sstevel@tonic-gate 	else if (o->op_type == OP_RV2CV) {
576*0Sstevel@tonic-gate 	    if (o->op_private & OPpLVAL_INTRO)
577*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",INTRO");
578*0Sstevel@tonic-gate 	}
579*0Sstevel@tonic-gate 	else if (o->op_type == OP_GV) {
580*0Sstevel@tonic-gate 	    if (o->op_private & OPpEARLY_CV)
581*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",EARLY_CV");
582*0Sstevel@tonic-gate 	}
583*0Sstevel@tonic-gate 	else if (o->op_type == OP_LIST) {
584*0Sstevel@tonic-gate 	    if (o->op_private & OPpLIST_GUESSED)
585*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",GUESSED");
586*0Sstevel@tonic-gate 	}
587*0Sstevel@tonic-gate 	else if (o->op_type == OP_DELETE) {
588*0Sstevel@tonic-gate 	    if (o->op_private & OPpSLICE)
589*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",SLICE");
590*0Sstevel@tonic-gate 	}
591*0Sstevel@tonic-gate 	else if (o->op_type == OP_EXISTS) {
592*0Sstevel@tonic-gate 	    if (o->op_private & OPpEXISTS_SUB)
593*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",EXISTS_SUB");
594*0Sstevel@tonic-gate 	}
595*0Sstevel@tonic-gate 	else if (o->op_type == OP_SORT) {
596*0Sstevel@tonic-gate 	    if (o->op_private & OPpSORT_NUMERIC)
597*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",NUMERIC");
598*0Sstevel@tonic-gate 	    if (o->op_private & OPpSORT_INTEGER)
599*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",INTEGER");
600*0Sstevel@tonic-gate 	    if (o->op_private & OPpSORT_REVERSE)
601*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",REVERSE");
602*0Sstevel@tonic-gate 	}
603*0Sstevel@tonic-gate 	else if (o->op_type == OP_THREADSV) {
604*0Sstevel@tonic-gate 	    if (o->op_private & OPpDONE_SVREF)
605*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",SVREF");
606*0Sstevel@tonic-gate 	}
607*0Sstevel@tonic-gate 	else if (o->op_type == OP_OPEN || o->op_type == OP_BACKTICK) {
608*0Sstevel@tonic-gate 	    if (o->op_private & OPpOPEN_IN_RAW)
609*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",IN_RAW");
610*0Sstevel@tonic-gate 	    if (o->op_private & OPpOPEN_IN_CRLF)
611*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",IN_CRLF");
612*0Sstevel@tonic-gate 	    if (o->op_private & OPpOPEN_OUT_RAW)
613*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",OUT_RAW");
614*0Sstevel@tonic-gate 	    if (o->op_private & OPpOPEN_OUT_CRLF)
615*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",OUT_CRLF");
616*0Sstevel@tonic-gate 	}
617*0Sstevel@tonic-gate 	else if (o->op_type == OP_EXIT) {
618*0Sstevel@tonic-gate 	    if (o->op_private & OPpEXIT_VMSISH)
619*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",EXIT_VMSISH");
620*0Sstevel@tonic-gate 	    if (o->op_private & OPpHUSH_VMSISH)
621*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",HUSH_VMSISH");
622*0Sstevel@tonic-gate 	}
623*0Sstevel@tonic-gate 	else if (o->op_type == OP_DIE) {
624*0Sstevel@tonic-gate 	    if (o->op_private & OPpHUSH_VMSISH)
625*0Sstevel@tonic-gate 		sv_catpv(tmpsv, ",HUSH_VMSISH");
626*0Sstevel@tonic-gate 	}
627*0Sstevel@tonic-gate 	else if (OP_IS_FILETEST_ACCESS(o)) {
628*0Sstevel@tonic-gate 	     if (o->op_private & OPpFT_ACCESS)
629*0Sstevel@tonic-gate 		  sv_catpv(tmpsv, ",FT_ACCESS");
630*0Sstevel@tonic-gate 	}
631*0Sstevel@tonic-gate 	if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
632*0Sstevel@tonic-gate 	    sv_catpv(tmpsv, ",INTRO");
633*0Sstevel@tonic-gate 	if (SvCUR(tmpsv))
634*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX(tmpsv) + 1);
635*0Sstevel@tonic-gate 	SvREFCNT_dec(tmpsv);
636*0Sstevel@tonic-gate     }
637*0Sstevel@tonic-gate 
638*0Sstevel@tonic-gate     switch (o->op_type) {
639*0Sstevel@tonic-gate     case OP_AELEMFAST:
640*0Sstevel@tonic-gate     case OP_GVSV:
641*0Sstevel@tonic-gate     case OP_GV:
642*0Sstevel@tonic-gate #ifdef USE_ITHREADS
643*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "PADIX = %" IVdf "\n", (IV)cPADOPo->op_padix);
644*0Sstevel@tonic-gate #else
645*0Sstevel@tonic-gate 	if ( ! PL_op->op_flags & OPf_SPECIAL) { /* not lexical */
646*0Sstevel@tonic-gate 	    if (cSVOPo->op_sv) {
647*0Sstevel@tonic-gate 		SV *tmpsv = NEWSV(0,0);
648*0Sstevel@tonic-gate 		STRLEN n_a;
649*0Sstevel@tonic-gate 		ENTER;
650*0Sstevel@tonic-gate 		SAVEFREESV(tmpsv);
651*0Sstevel@tonic-gate 		gv_fullname3(tmpsv, (GV*)cSVOPo->op_sv, Nullch);
652*0Sstevel@tonic-gate 		Perl_dump_indent(aTHX_ level, file, "GV = %s\n", SvPV(tmpsv, n_a));
653*0Sstevel@tonic-gate 		LEAVE;
654*0Sstevel@tonic-gate 	    }
655*0Sstevel@tonic-gate 	    else
656*0Sstevel@tonic-gate 		Perl_dump_indent(aTHX_ level, file, "GV = NULL\n");
657*0Sstevel@tonic-gate 	}
658*0Sstevel@tonic-gate #endif
659*0Sstevel@tonic-gate 	break;
660*0Sstevel@tonic-gate     case OP_CONST:
661*0Sstevel@tonic-gate     case OP_METHOD_NAMED:
662*0Sstevel@tonic-gate #ifndef USE_ITHREADS
663*0Sstevel@tonic-gate 	/* with ITHREADS, consts are stored in the pad, and the right pad
664*0Sstevel@tonic-gate 	 * may not be active here, so skip */
665*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "SV = %s\n", SvPEEK(cSVOPo_sv));
666*0Sstevel@tonic-gate #endif
667*0Sstevel@tonic-gate 	break;
668*0Sstevel@tonic-gate     case OP_SETSTATE:
669*0Sstevel@tonic-gate     case OP_NEXTSTATE:
670*0Sstevel@tonic-gate     case OP_DBSTATE:
671*0Sstevel@tonic-gate 	if (CopLINE(cCOPo))
672*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n",
673*0Sstevel@tonic-gate 			     (UV)CopLINE(cCOPo));
674*0Sstevel@tonic-gate 	if (CopSTASHPV(cCOPo))
675*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
676*0Sstevel@tonic-gate 			     CopSTASHPV(cCOPo));
677*0Sstevel@tonic-gate 	if (cCOPo->cop_label)
678*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
679*0Sstevel@tonic-gate 			     cCOPo->cop_label);
680*0Sstevel@tonic-gate 	break;
681*0Sstevel@tonic-gate     case OP_ENTERLOOP:
682*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "REDO ===> ");
683*0Sstevel@tonic-gate 	if (cLOOPo->op_redoop)
684*0Sstevel@tonic-gate 	    PerlIO_printf(file, "%d\n", cLOOPo->op_redoop->op_seq);
685*0Sstevel@tonic-gate 	else
686*0Sstevel@tonic-gate 	    PerlIO_printf(file, "DONE\n");
687*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "NEXT ===> ");
688*0Sstevel@tonic-gate 	if (cLOOPo->op_nextop)
689*0Sstevel@tonic-gate 	    PerlIO_printf(file, "%d\n", cLOOPo->op_nextop->op_seq);
690*0Sstevel@tonic-gate 	else
691*0Sstevel@tonic-gate 	    PerlIO_printf(file, "DONE\n");
692*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "LAST ===> ");
693*0Sstevel@tonic-gate 	if (cLOOPo->op_lastop)
694*0Sstevel@tonic-gate 	    PerlIO_printf(file, "%d\n", cLOOPo->op_lastop->op_seq);
695*0Sstevel@tonic-gate 	else
696*0Sstevel@tonic-gate 	    PerlIO_printf(file, "DONE\n");
697*0Sstevel@tonic-gate 	break;
698*0Sstevel@tonic-gate     case OP_COND_EXPR:
699*0Sstevel@tonic-gate     case OP_RANGE:
700*0Sstevel@tonic-gate     case OP_MAPWHILE:
701*0Sstevel@tonic-gate     case OP_GREPWHILE:
702*0Sstevel@tonic-gate     case OP_OR:
703*0Sstevel@tonic-gate     case OP_AND:
704*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "OTHER ===> ");
705*0Sstevel@tonic-gate 	if (cLOGOPo->op_other)
706*0Sstevel@tonic-gate 	    PerlIO_printf(file, "%d\n", cLOGOPo->op_other->op_seq);
707*0Sstevel@tonic-gate 	else
708*0Sstevel@tonic-gate 	    PerlIO_printf(file, "DONE\n");
709*0Sstevel@tonic-gate 	break;
710*0Sstevel@tonic-gate     case OP_PUSHRE:
711*0Sstevel@tonic-gate     case OP_MATCH:
712*0Sstevel@tonic-gate     case OP_QR:
713*0Sstevel@tonic-gate     case OP_SUBST:
714*0Sstevel@tonic-gate 	do_pmop_dump(level, file, cPMOPo);
715*0Sstevel@tonic-gate 	break;
716*0Sstevel@tonic-gate     case OP_LEAVE:
717*0Sstevel@tonic-gate     case OP_LEAVEEVAL:
718*0Sstevel@tonic-gate     case OP_LEAVESUB:
719*0Sstevel@tonic-gate     case OP_LEAVESUBLV:
720*0Sstevel@tonic-gate     case OP_LEAVEWRITE:
721*0Sstevel@tonic-gate     case OP_SCOPE:
722*0Sstevel@tonic-gate 	if (o->op_private & OPpREFCOUNTED)
723*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "REFCNT = %"UVuf"\n", (UV)o->op_targ);
724*0Sstevel@tonic-gate 	break;
725*0Sstevel@tonic-gate     default:
726*0Sstevel@tonic-gate 	break;
727*0Sstevel@tonic-gate     }
728*0Sstevel@tonic-gate     if (o->op_flags & OPf_KIDS) {
729*0Sstevel@tonic-gate 	OP *kid;
730*0Sstevel@tonic-gate 	for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
731*0Sstevel@tonic-gate 	    do_op_dump(level, file, kid);
732*0Sstevel@tonic-gate     }
733*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ level-1, file, "}\n");
734*0Sstevel@tonic-gate }
735*0Sstevel@tonic-gate 
736*0Sstevel@tonic-gate void
Perl_op_dump(pTHX_ OP * o)737*0Sstevel@tonic-gate Perl_op_dump(pTHX_ OP *o)
738*0Sstevel@tonic-gate {
739*0Sstevel@tonic-gate     do_op_dump(0, Perl_debug_log, o);
740*0Sstevel@tonic-gate }
741*0Sstevel@tonic-gate 
742*0Sstevel@tonic-gate void
Perl_gv_dump(pTHX_ GV * gv)743*0Sstevel@tonic-gate Perl_gv_dump(pTHX_ GV *gv)
744*0Sstevel@tonic-gate {
745*0Sstevel@tonic-gate     SV *sv;
746*0Sstevel@tonic-gate 
747*0Sstevel@tonic-gate     if (!gv) {
748*0Sstevel@tonic-gate 	PerlIO_printf(Perl_debug_log, "{}\n");
749*0Sstevel@tonic-gate 	return;
750*0Sstevel@tonic-gate     }
751*0Sstevel@tonic-gate     sv = sv_newmortal();
752*0Sstevel@tonic-gate     PerlIO_printf(Perl_debug_log, "{\n");
753*0Sstevel@tonic-gate     gv_fullname3(sv, gv, Nullch);
754*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s", SvPVX(sv));
755*0Sstevel@tonic-gate     if (gv != GvEGV(gv)) {
756*0Sstevel@tonic-gate 	gv_efullname3(sv, GvEGV(gv), Nullch);
757*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s", SvPVX(sv));
758*0Sstevel@tonic-gate     }
759*0Sstevel@tonic-gate     PerlIO_putc(Perl_debug_log, '\n');
760*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ 0, Perl_debug_log, "}\n");
761*0Sstevel@tonic-gate }
762*0Sstevel@tonic-gate 
763*0Sstevel@tonic-gate 
764*0Sstevel@tonic-gate /* map magic types to the symbolic names
765*0Sstevel@tonic-gate  * (with the PERL_MAGIC_ prefixed stripped)
766*0Sstevel@tonic-gate  */
767*0Sstevel@tonic-gate 
768*0Sstevel@tonic-gate static struct { char type; char *name; } magic_names[] = {
769*0Sstevel@tonic-gate 	{ PERL_MAGIC_sv,             "sv(\\0)" },
770*0Sstevel@tonic-gate 	{ PERL_MAGIC_arylen,         "arylen(#)" },
771*0Sstevel@tonic-gate 	{ PERL_MAGIC_glob,           "glob(*)" },
772*0Sstevel@tonic-gate 	{ PERL_MAGIC_pos,            "pos(.)" },
773*0Sstevel@tonic-gate 	{ PERL_MAGIC_backref,        "backref(<)" },
774*0Sstevel@tonic-gate 	{ PERL_MAGIC_overload,       "overload(A)" },
775*0Sstevel@tonic-gate 	{ PERL_MAGIC_bm,             "bm(B)" },
776*0Sstevel@tonic-gate 	{ PERL_MAGIC_regdata,        "regdata(D)" },
777*0Sstevel@tonic-gate 	{ PERL_MAGIC_env,            "env(E)" },
778*0Sstevel@tonic-gate 	{ PERL_MAGIC_isa,            "isa(I)" },
779*0Sstevel@tonic-gate 	{ PERL_MAGIC_dbfile,         "dbfile(L)" },
780*0Sstevel@tonic-gate 	{ PERL_MAGIC_shared,         "shared(N)" },
781*0Sstevel@tonic-gate 	{ PERL_MAGIC_tied,           "tied(P)" },
782*0Sstevel@tonic-gate 	{ PERL_MAGIC_sig,            "sig(S)" },
783*0Sstevel@tonic-gate 	{ PERL_MAGIC_uvar,           "uvar(U)" },
784*0Sstevel@tonic-gate 	{ PERL_MAGIC_overload_elem,  "overload_elem(a)" },
785*0Sstevel@tonic-gate 	{ PERL_MAGIC_overload_table, "overload_table(c)" },
786*0Sstevel@tonic-gate 	{ PERL_MAGIC_regdatum,       "regdatum(d)" },
787*0Sstevel@tonic-gate 	{ PERL_MAGIC_envelem,        "envelem(e)" },
788*0Sstevel@tonic-gate 	{ PERL_MAGIC_fm,             "fm(f)" },
789*0Sstevel@tonic-gate 	{ PERL_MAGIC_regex_global,   "regex_global(g)" },
790*0Sstevel@tonic-gate 	{ PERL_MAGIC_isaelem,        "isaelem(i)" },
791*0Sstevel@tonic-gate 	{ PERL_MAGIC_nkeys,          "nkeys(k)" },
792*0Sstevel@tonic-gate 	{ PERL_MAGIC_dbline,         "dbline(l)" },
793*0Sstevel@tonic-gate 	{ PERL_MAGIC_mutex,          "mutex(m)" },
794*0Sstevel@tonic-gate 	{ PERL_MAGIC_shared_scalar,  "shared_scalar(n)" },
795*0Sstevel@tonic-gate 	{ PERL_MAGIC_collxfrm,       "collxfrm(o)" },
796*0Sstevel@tonic-gate 	{ PERL_MAGIC_tiedelem,       "tiedelem(p)" },
797*0Sstevel@tonic-gate 	{ PERL_MAGIC_tiedscalar,     "tiedscalar(q)" },
798*0Sstevel@tonic-gate 	{ PERL_MAGIC_qr,             "qr(r)" },
799*0Sstevel@tonic-gate 	{ PERL_MAGIC_sigelem,        "sigelem(s)" },
800*0Sstevel@tonic-gate 	{ PERL_MAGIC_taint,          "taint(t)" },
801*0Sstevel@tonic-gate 	{ PERL_MAGIC_uvar_elem,      "uvar_elem(v)" },
802*0Sstevel@tonic-gate 	{ PERL_MAGIC_vec,            "vec(v)" },
803*0Sstevel@tonic-gate 	{ PERL_MAGIC_vstring,        "v-string(V)" },
804*0Sstevel@tonic-gate 	{ PERL_MAGIC_utf8,           "utf8(w)" },
805*0Sstevel@tonic-gate 	{ PERL_MAGIC_substr,         "substr(x)" },
806*0Sstevel@tonic-gate 	{ PERL_MAGIC_defelem,        "defelem(y)" },
807*0Sstevel@tonic-gate 	{ PERL_MAGIC_ext,            "ext(~)" },
808*0Sstevel@tonic-gate 	/* this null string terminates the list */
809*0Sstevel@tonic-gate 	{ 0,                         0 },
810*0Sstevel@tonic-gate };
811*0Sstevel@tonic-gate 
812*0Sstevel@tonic-gate void
Perl_do_magic_dump(pTHX_ I32 level,PerlIO * file,MAGIC * mg,I32 nest,I32 maxnest,bool dumpops,STRLEN pvlim)813*0Sstevel@tonic-gate Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
814*0Sstevel@tonic-gate {
815*0Sstevel@tonic-gate     for (; mg; mg = mg->mg_moremagic) {
816*0Sstevel@tonic-gate  	Perl_dump_indent(aTHX_ level, file,
817*0Sstevel@tonic-gate 			 "  MAGIC = 0x%"UVxf"\n", PTR2UV(mg));
818*0Sstevel@tonic-gate  	if (mg->mg_virtual) {
819*0Sstevel@tonic-gate             MGVTBL *v = mg->mg_virtual;
820*0Sstevel@tonic-gate  	    char *s = 0;
821*0Sstevel@tonic-gate  	    if      (v == &PL_vtbl_sv)         s = "sv";
822*0Sstevel@tonic-gate             else if (v == &PL_vtbl_env)        s = "env";
823*0Sstevel@tonic-gate             else if (v == &PL_vtbl_envelem)    s = "envelem";
824*0Sstevel@tonic-gate             else if (v == &PL_vtbl_sig)        s = "sig";
825*0Sstevel@tonic-gate             else if (v == &PL_vtbl_sigelem)    s = "sigelem";
826*0Sstevel@tonic-gate             else if (v == &PL_vtbl_pack)       s = "pack";
827*0Sstevel@tonic-gate             else if (v == &PL_vtbl_packelem)   s = "packelem";
828*0Sstevel@tonic-gate             else if (v == &PL_vtbl_dbline)     s = "dbline";
829*0Sstevel@tonic-gate             else if (v == &PL_vtbl_isa)        s = "isa";
830*0Sstevel@tonic-gate             else if (v == &PL_vtbl_arylen)     s = "arylen";
831*0Sstevel@tonic-gate             else if (v == &PL_vtbl_glob)       s = "glob";
832*0Sstevel@tonic-gate             else if (v == &PL_vtbl_mglob)      s = "mglob";
833*0Sstevel@tonic-gate             else if (v == &PL_vtbl_nkeys)      s = "nkeys";
834*0Sstevel@tonic-gate             else if (v == &PL_vtbl_taint)      s = "taint";
835*0Sstevel@tonic-gate             else if (v == &PL_vtbl_substr)     s = "substr";
836*0Sstevel@tonic-gate             else if (v == &PL_vtbl_vec)        s = "vec";
837*0Sstevel@tonic-gate             else if (v == &PL_vtbl_pos)        s = "pos";
838*0Sstevel@tonic-gate             else if (v == &PL_vtbl_bm)         s = "bm";
839*0Sstevel@tonic-gate             else if (v == &PL_vtbl_fm)         s = "fm";
840*0Sstevel@tonic-gate             else if (v == &PL_vtbl_uvar)       s = "uvar";
841*0Sstevel@tonic-gate             else if (v == &PL_vtbl_defelem)    s = "defelem";
842*0Sstevel@tonic-gate #ifdef USE_LOCALE_COLLATE
843*0Sstevel@tonic-gate 	    else if (v == &PL_vtbl_collxfrm)   s = "collxfrm";
844*0Sstevel@tonic-gate #endif
845*0Sstevel@tonic-gate 	    else if (v == &PL_vtbl_amagic)     s = "amagic";
846*0Sstevel@tonic-gate 	    else if (v == &PL_vtbl_amagicelem) s = "amagicelem";
847*0Sstevel@tonic-gate 	    else if (v == &PL_vtbl_backref)    s = "backref";
848*0Sstevel@tonic-gate 	    else if (v == &PL_vtbl_utf8)       s = "utf8";
849*0Sstevel@tonic-gate 	    if (s)
850*0Sstevel@tonic-gate 	        Perl_dump_indent(aTHX_ level, file, "    MG_VIRTUAL = &PL_vtbl_%s\n", s);
851*0Sstevel@tonic-gate 	    else
852*0Sstevel@tonic-gate 	        Perl_dump_indent(aTHX_ level, file, "    MG_VIRTUAL = 0x%"UVxf"\n", PTR2UV(v));
853*0Sstevel@tonic-gate         }
854*0Sstevel@tonic-gate 	else
855*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "    MG_VIRTUAL = 0\n");
856*0Sstevel@tonic-gate 
857*0Sstevel@tonic-gate 	if (mg->mg_private)
858*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "    MG_PRIVATE = %d\n", mg->mg_private);
859*0Sstevel@tonic-gate 
860*0Sstevel@tonic-gate 	{
861*0Sstevel@tonic-gate 	    int n;
862*0Sstevel@tonic-gate 	    char *name = 0;
863*0Sstevel@tonic-gate 	    for (n=0; magic_names[n].name; n++) {
864*0Sstevel@tonic-gate 		if (mg->mg_type == magic_names[n].type) {
865*0Sstevel@tonic-gate 		    name = magic_names[n].name;
866*0Sstevel@tonic-gate 		    break;
867*0Sstevel@tonic-gate 		}
868*0Sstevel@tonic-gate 	    }
869*0Sstevel@tonic-gate 	    if (name)
870*0Sstevel@tonic-gate 		Perl_dump_indent(aTHX_ level, file,
871*0Sstevel@tonic-gate 				"    MG_TYPE = PERL_MAGIC_%s\n", name);
872*0Sstevel@tonic-gate 	    else
873*0Sstevel@tonic-gate 		Perl_dump_indent(aTHX_ level, file,
874*0Sstevel@tonic-gate 				"    MG_TYPE = UNKNOWN(\\%o)\n", mg->mg_type);
875*0Sstevel@tonic-gate 	}
876*0Sstevel@tonic-gate 
877*0Sstevel@tonic-gate         if (mg->mg_flags) {
878*0Sstevel@tonic-gate             Perl_dump_indent(aTHX_ level, file, "    MG_FLAGS = 0x%02X\n", mg->mg_flags);
879*0Sstevel@tonic-gate 	    if (mg->mg_type == PERL_MAGIC_envelem &&
880*0Sstevel@tonic-gate 		mg->mg_flags & MGf_TAINTEDDIR)
881*0Sstevel@tonic-gate 	        Perl_dump_indent(aTHX_ level, file, "      TAINTEDDIR\n");
882*0Sstevel@tonic-gate 	    if (mg->mg_flags & MGf_REFCOUNTED)
883*0Sstevel@tonic-gate 	        Perl_dump_indent(aTHX_ level, file, "      REFCOUNTED\n");
884*0Sstevel@tonic-gate             if (mg->mg_flags & MGf_GSKIP)
885*0Sstevel@tonic-gate 	        Perl_dump_indent(aTHX_ level, file, "      GSKIP\n");
886*0Sstevel@tonic-gate 	    if (mg->mg_type == PERL_MAGIC_regex_global &&
887*0Sstevel@tonic-gate 		mg->mg_flags & MGf_MINMATCH)
888*0Sstevel@tonic-gate 	        Perl_dump_indent(aTHX_ level, file, "      MINMATCH\n");
889*0Sstevel@tonic-gate         }
890*0Sstevel@tonic-gate 	if (mg->mg_obj) {
891*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "    MG_OBJ = 0x%"UVxf"\n", PTR2UV(mg->mg_obj));
892*0Sstevel@tonic-gate 	    if (mg->mg_flags & MGf_REFCOUNTED)
893*0Sstevel@tonic-gate 		do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
894*0Sstevel@tonic-gate 	}
895*0Sstevel@tonic-gate         if (mg->mg_len)
896*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "    MG_LEN = %ld\n", (long)mg->mg_len);
897*0Sstevel@tonic-gate         if (mg->mg_ptr) {
898*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "    MG_PTR = 0x%"UVxf, PTR2UV(mg->mg_ptr));
899*0Sstevel@tonic-gate 	    if (mg->mg_len >= 0) {
900*0Sstevel@tonic-gate 		 if (mg->mg_type != PERL_MAGIC_utf8) {
901*0Sstevel@tonic-gate 		      SV *sv = newSVpvn("", 0);
902*0Sstevel@tonic-gate 		      PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim));
903*0Sstevel@tonic-gate 		      SvREFCNT_dec(sv);
904*0Sstevel@tonic-gate 		 }
905*0Sstevel@tonic-gate             }
906*0Sstevel@tonic-gate 	    else if (mg->mg_len == HEf_SVKEY) {
907*0Sstevel@tonic-gate 		PerlIO_puts(file, " => HEf_SVKEY\n");
908*0Sstevel@tonic-gate 		do_sv_dump(level+2, file, (SV*)((mg)->mg_ptr), nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
909*0Sstevel@tonic-gate 		continue;
910*0Sstevel@tonic-gate 	    }
911*0Sstevel@tonic-gate 	    else
912*0Sstevel@tonic-gate 		PerlIO_puts(file, " ???? - please notify IZ");
913*0Sstevel@tonic-gate             PerlIO_putc(file, '\n');
914*0Sstevel@tonic-gate         }
915*0Sstevel@tonic-gate 	if (mg->mg_type == PERL_MAGIC_utf8) {
916*0Sstevel@tonic-gate 	     STRLEN *cache = (STRLEN *) mg->mg_ptr;
917*0Sstevel@tonic-gate 	     if (cache) {
918*0Sstevel@tonic-gate 		  IV i;
919*0Sstevel@tonic-gate 		  for (i = 0; i < PERL_MAGIC_UTF8_CACHESIZE; i++)
920*0Sstevel@tonic-gate 		       Perl_dump_indent(aTHX_ level, file,
921*0Sstevel@tonic-gate 					"      %2"IVdf": %"UVuf" -> %"UVuf"\n",
922*0Sstevel@tonic-gate 					i,
923*0Sstevel@tonic-gate 					(UV)cache[i * 2],
924*0Sstevel@tonic-gate 					(UV)cache[i * 2 + 1]);
925*0Sstevel@tonic-gate 	     }
926*0Sstevel@tonic-gate 	}
927*0Sstevel@tonic-gate     }
928*0Sstevel@tonic-gate }
929*0Sstevel@tonic-gate 
930*0Sstevel@tonic-gate void
Perl_magic_dump(pTHX_ MAGIC * mg)931*0Sstevel@tonic-gate Perl_magic_dump(pTHX_ MAGIC *mg)
932*0Sstevel@tonic-gate {
933*0Sstevel@tonic-gate     do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0);
934*0Sstevel@tonic-gate }
935*0Sstevel@tonic-gate 
936*0Sstevel@tonic-gate void
Perl_do_hv_dump(pTHX_ I32 level,PerlIO * file,char * name,HV * sv)937*0Sstevel@tonic-gate Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, char *name, HV *sv)
938*0Sstevel@tonic-gate {
939*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
940*0Sstevel@tonic-gate     if (sv && HvNAME(sv))
941*0Sstevel@tonic-gate 	PerlIO_printf(file, "\t\"%s\"\n", HvNAME(sv));
942*0Sstevel@tonic-gate     else
943*0Sstevel@tonic-gate 	PerlIO_putc(file, '\n');
944*0Sstevel@tonic-gate }
945*0Sstevel@tonic-gate 
946*0Sstevel@tonic-gate void
Perl_do_gv_dump(pTHX_ I32 level,PerlIO * file,char * name,GV * sv)947*0Sstevel@tonic-gate Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv)
948*0Sstevel@tonic-gate {
949*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
950*0Sstevel@tonic-gate     if (sv && GvNAME(sv))
951*0Sstevel@tonic-gate 	PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv));
952*0Sstevel@tonic-gate     else
953*0Sstevel@tonic-gate 	PerlIO_putc(file, '\n');
954*0Sstevel@tonic-gate }
955*0Sstevel@tonic-gate 
956*0Sstevel@tonic-gate void
Perl_do_gvgv_dump(pTHX_ I32 level,PerlIO * file,char * name,GV * sv)957*0Sstevel@tonic-gate Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv)
958*0Sstevel@tonic-gate {
959*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
960*0Sstevel@tonic-gate     if (sv && GvNAME(sv)) {
961*0Sstevel@tonic-gate 	PerlIO_printf(file, "\t\"");
962*0Sstevel@tonic-gate 	if (GvSTASH(sv))
963*0Sstevel@tonic-gate 	    PerlIO_printf(file, "%s\" :: \"", HvNAME(GvSTASH(sv)));
964*0Sstevel@tonic-gate 	PerlIO_printf(file, "%s\"\n", GvNAME(sv));
965*0Sstevel@tonic-gate     }
966*0Sstevel@tonic-gate     else
967*0Sstevel@tonic-gate 	PerlIO_putc(file, '\n');
968*0Sstevel@tonic-gate }
969*0Sstevel@tonic-gate 
970*0Sstevel@tonic-gate void
Perl_do_sv_dump(pTHX_ I32 level,PerlIO * file,SV * sv,I32 nest,I32 maxnest,bool dumpops,STRLEN pvlim)971*0Sstevel@tonic-gate Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
972*0Sstevel@tonic-gate {
973*0Sstevel@tonic-gate     SV *d;
974*0Sstevel@tonic-gate     char *s;
975*0Sstevel@tonic-gate     U32 flags;
976*0Sstevel@tonic-gate     U32 type;
977*0Sstevel@tonic-gate 
978*0Sstevel@tonic-gate     if (!sv) {
979*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "SV = 0\n");
980*0Sstevel@tonic-gate 	return;
981*0Sstevel@tonic-gate     }
982*0Sstevel@tonic-gate 
983*0Sstevel@tonic-gate     flags = SvFLAGS(sv);
984*0Sstevel@tonic-gate     type = SvTYPE(sv);
985*0Sstevel@tonic-gate 
986*0Sstevel@tonic-gate     d = Perl_newSVpvf(aTHX_
987*0Sstevel@tonic-gate 		   "(0x%"UVxf") at 0x%"UVxf"\n%*s  REFCNT = %"IVdf"\n%*s  FLAGS = (",
988*0Sstevel@tonic-gate 		   PTR2UV(SvANY(sv)), PTR2UV(sv),
989*0Sstevel@tonic-gate 		   (int)(PL_dumpindent*level), "", (IV)SvREFCNT(sv),
990*0Sstevel@tonic-gate 		   (int)(PL_dumpindent*level), "");
991*0Sstevel@tonic-gate 
992*0Sstevel@tonic-gate     if (flags & SVs_PADBUSY)	sv_catpv(d, "PADBUSY,");
993*0Sstevel@tonic-gate     if (flags & SVs_PADTMP)	sv_catpv(d, "PADTMP,");
994*0Sstevel@tonic-gate     if (flags & SVs_PADMY)	sv_catpv(d, "PADMY,");
995*0Sstevel@tonic-gate     if (flags & SVs_TEMP)	sv_catpv(d, "TEMP,");
996*0Sstevel@tonic-gate     if (flags & SVs_OBJECT)	sv_catpv(d, "OBJECT,");
997*0Sstevel@tonic-gate     if (flags & SVs_GMG)	sv_catpv(d, "GMG,");
998*0Sstevel@tonic-gate     if (flags & SVs_SMG)	sv_catpv(d, "SMG,");
999*0Sstevel@tonic-gate     if (flags & SVs_RMG)	sv_catpv(d, "RMG,");
1000*0Sstevel@tonic-gate 
1001*0Sstevel@tonic-gate     if (flags & SVf_IOK)	sv_catpv(d, "IOK,");
1002*0Sstevel@tonic-gate     if (flags & SVf_NOK)	sv_catpv(d, "NOK,");
1003*0Sstevel@tonic-gate     if (flags & SVf_POK)	sv_catpv(d, "POK,");
1004*0Sstevel@tonic-gate     if (flags & SVf_ROK)  {
1005*0Sstevel@tonic-gate     				sv_catpv(d, "ROK,");
1006*0Sstevel@tonic-gate 	if (SvWEAKREF(sv))	sv_catpv(d, "WEAKREF,");
1007*0Sstevel@tonic-gate     }
1008*0Sstevel@tonic-gate     if (flags & SVf_OOK)	sv_catpv(d, "OOK,");
1009*0Sstevel@tonic-gate     if (flags & SVf_FAKE)	sv_catpv(d, "FAKE,");
1010*0Sstevel@tonic-gate     if (flags & SVf_READONLY)	sv_catpv(d, "READONLY,");
1011*0Sstevel@tonic-gate 
1012*0Sstevel@tonic-gate     if (flags & SVf_AMAGIC && type != SVt_PVHV)
1013*0Sstevel@tonic-gate 				sv_catpv(d, "OVERLOAD,");
1014*0Sstevel@tonic-gate     if (flags & SVp_IOK)	sv_catpv(d, "pIOK,");
1015*0Sstevel@tonic-gate     if (flags & SVp_NOK)	sv_catpv(d, "pNOK,");
1016*0Sstevel@tonic-gate     if (flags & SVp_POK)	sv_catpv(d, "pPOK,");
1017*0Sstevel@tonic-gate     if (flags & SVp_SCREAM)	sv_catpv(d, "SCREAM,");
1018*0Sstevel@tonic-gate 
1019*0Sstevel@tonic-gate     switch (type) {
1020*0Sstevel@tonic-gate     case SVt_PVCV:
1021*0Sstevel@tonic-gate     case SVt_PVFM:
1022*0Sstevel@tonic-gate 	if (CvANON(sv))		sv_catpv(d, "ANON,");
1023*0Sstevel@tonic-gate 	if (CvUNIQUE(sv))	sv_catpv(d, "UNIQUE,");
1024*0Sstevel@tonic-gate 	if (CvCLONE(sv))	sv_catpv(d, "CLONE,");
1025*0Sstevel@tonic-gate 	if (CvCLONED(sv))	sv_catpv(d, "CLONED,");
1026*0Sstevel@tonic-gate 	if (CvCONST(sv))	sv_catpv(d, "CONST,");
1027*0Sstevel@tonic-gate 	if (CvNODEBUG(sv))	sv_catpv(d, "NODEBUG,");
1028*0Sstevel@tonic-gate 	if (SvCOMPILED(sv))	sv_catpv(d, "COMPILED,");
1029*0Sstevel@tonic-gate 	if (CvLVALUE(sv))	sv_catpv(d, "LVALUE,");
1030*0Sstevel@tonic-gate 	if (CvMETHOD(sv))	sv_catpv(d, "METHOD,");
1031*0Sstevel@tonic-gate 	if (CvLOCKED(sv))	sv_catpv(d, "LOCKED,");
1032*0Sstevel@tonic-gate 	if (CvWEAKOUTSIDE(sv))	sv_catpv(d, "WEAKOUTSIDE,");
1033*0Sstevel@tonic-gate 	break;
1034*0Sstevel@tonic-gate     case SVt_PVHV:
1035*0Sstevel@tonic-gate 	if (HvSHAREKEYS(sv))	sv_catpv(d, "SHAREKEYS,");
1036*0Sstevel@tonic-gate 	if (HvLAZYDEL(sv))	sv_catpv(d, "LAZYDEL,");
1037*0Sstevel@tonic-gate 	if (HvHASKFLAGS(sv))	sv_catpv(d, "HASKFLAGS,");
1038*0Sstevel@tonic-gate 	if (HvREHASH(sv))	sv_catpv(d, "REHASH,");
1039*0Sstevel@tonic-gate 	break;
1040*0Sstevel@tonic-gate     case SVt_PVGV:
1041*0Sstevel@tonic-gate 	if (GvINTRO(sv))	sv_catpv(d, "INTRO,");
1042*0Sstevel@tonic-gate 	if (GvMULTI(sv))	sv_catpv(d, "MULTI,");
1043*0Sstevel@tonic-gate 	if (GvUNIQUE(sv))       sv_catpv(d, "UNIQUE,");
1044*0Sstevel@tonic-gate 	if (GvASSUMECV(sv))	sv_catpv(d, "ASSUMECV,");
1045*0Sstevel@tonic-gate 	if (GvIN_PAD(sv))       sv_catpv(d, "IN_PAD,");
1046*0Sstevel@tonic-gate 	if (flags & SVpad_OUR)	sv_catpv(d, "OUR,");
1047*0Sstevel@tonic-gate 	if (GvIMPORTED(sv)) {
1048*0Sstevel@tonic-gate 	    sv_catpv(d, "IMPORT");
1049*0Sstevel@tonic-gate 	    if (GvIMPORTED(sv) == GVf_IMPORTED)
1050*0Sstevel@tonic-gate 		sv_catpv(d, "ALL,");
1051*0Sstevel@tonic-gate 	    else {
1052*0Sstevel@tonic-gate 		sv_catpv(d, "(");
1053*0Sstevel@tonic-gate 		if (GvIMPORTED_SV(sv))	sv_catpv(d, " SV");
1054*0Sstevel@tonic-gate 		if (GvIMPORTED_AV(sv))	sv_catpv(d, " AV");
1055*0Sstevel@tonic-gate 		if (GvIMPORTED_HV(sv))	sv_catpv(d, " HV");
1056*0Sstevel@tonic-gate 		if (GvIMPORTED_CV(sv))	sv_catpv(d, " CV");
1057*0Sstevel@tonic-gate 		sv_catpv(d, " ),");
1058*0Sstevel@tonic-gate 	    }
1059*0Sstevel@tonic-gate 	}
1060*0Sstevel@tonic-gate 	/* FALL THROUGH */
1061*0Sstevel@tonic-gate     default:
1062*0Sstevel@tonic-gate 	if (SvEVALED(sv))	sv_catpv(d, "EVALED,");
1063*0Sstevel@tonic-gate 	if (SvIsUV(sv))		sv_catpv(d, "IsUV,");
1064*0Sstevel@tonic-gate 	break;
1065*0Sstevel@tonic-gate     case SVt_PVBM:
1066*0Sstevel@tonic-gate 	if (SvTAIL(sv))		sv_catpv(d, "TAIL,");
1067*0Sstevel@tonic-gate 	if (SvVALID(sv))	sv_catpv(d, "VALID,");
1068*0Sstevel@tonic-gate 	break;
1069*0Sstevel@tonic-gate     case SVt_PVMG:
1070*0Sstevel@tonic-gate 	if (flags & SVpad_TYPED)
1071*0Sstevel@tonic-gate 				sv_catpv(d, "TYPED,");
1072*0Sstevel@tonic-gate 	break;
1073*0Sstevel@tonic-gate     }
1074*0Sstevel@tonic-gate     if ((SvPOK(sv) || SvPOKp(sv)) && SvUTF8(sv))
1075*0Sstevel@tonic-gate         sv_catpv(d, "UTF8");
1076*0Sstevel@tonic-gate 
1077*0Sstevel@tonic-gate     if (*(SvEND(d) - 1) == ',')
1078*0Sstevel@tonic-gate 	SvPVX(d)[--SvCUR(d)] = '\0';
1079*0Sstevel@tonic-gate     sv_catpv(d, ")");
1080*0Sstevel@tonic-gate     s = SvPVX(d);
1081*0Sstevel@tonic-gate 
1082*0Sstevel@tonic-gate     Perl_dump_indent(aTHX_ level, file, "SV = ");
1083*0Sstevel@tonic-gate     switch (type) {
1084*0Sstevel@tonic-gate     case SVt_NULL:
1085*0Sstevel@tonic-gate 	PerlIO_printf(file, "NULL%s\n", s);
1086*0Sstevel@tonic-gate 	SvREFCNT_dec(d);
1087*0Sstevel@tonic-gate 	return;
1088*0Sstevel@tonic-gate     case SVt_IV:
1089*0Sstevel@tonic-gate 	PerlIO_printf(file, "IV%s\n", s);
1090*0Sstevel@tonic-gate 	break;
1091*0Sstevel@tonic-gate     case SVt_NV:
1092*0Sstevel@tonic-gate 	PerlIO_printf(file, "NV%s\n", s);
1093*0Sstevel@tonic-gate 	break;
1094*0Sstevel@tonic-gate     case SVt_RV:
1095*0Sstevel@tonic-gate 	PerlIO_printf(file, "RV%s\n", s);
1096*0Sstevel@tonic-gate 	break;
1097*0Sstevel@tonic-gate     case SVt_PV:
1098*0Sstevel@tonic-gate 	PerlIO_printf(file, "PV%s\n", s);
1099*0Sstevel@tonic-gate 	break;
1100*0Sstevel@tonic-gate     case SVt_PVIV:
1101*0Sstevel@tonic-gate 	PerlIO_printf(file, "PVIV%s\n", s);
1102*0Sstevel@tonic-gate 	break;
1103*0Sstevel@tonic-gate     case SVt_PVNV:
1104*0Sstevel@tonic-gate 	PerlIO_printf(file, "PVNV%s\n", s);
1105*0Sstevel@tonic-gate 	break;
1106*0Sstevel@tonic-gate     case SVt_PVBM:
1107*0Sstevel@tonic-gate 	PerlIO_printf(file, "PVBM%s\n", s);
1108*0Sstevel@tonic-gate 	break;
1109*0Sstevel@tonic-gate     case SVt_PVMG:
1110*0Sstevel@tonic-gate 	PerlIO_printf(file, "PVMG%s\n", s);
1111*0Sstevel@tonic-gate 	break;
1112*0Sstevel@tonic-gate     case SVt_PVLV:
1113*0Sstevel@tonic-gate 	PerlIO_printf(file, "PVLV%s\n", s);
1114*0Sstevel@tonic-gate 	break;
1115*0Sstevel@tonic-gate     case SVt_PVAV:
1116*0Sstevel@tonic-gate 	PerlIO_printf(file, "PVAV%s\n", s);
1117*0Sstevel@tonic-gate 	break;
1118*0Sstevel@tonic-gate     case SVt_PVHV:
1119*0Sstevel@tonic-gate 	PerlIO_printf(file, "PVHV%s\n", s);
1120*0Sstevel@tonic-gate 	break;
1121*0Sstevel@tonic-gate     case SVt_PVCV:
1122*0Sstevel@tonic-gate 	PerlIO_printf(file, "PVCV%s\n", s);
1123*0Sstevel@tonic-gate 	break;
1124*0Sstevel@tonic-gate     case SVt_PVGV:
1125*0Sstevel@tonic-gate 	PerlIO_printf(file, "PVGV%s\n", s);
1126*0Sstevel@tonic-gate 	break;
1127*0Sstevel@tonic-gate     case SVt_PVFM:
1128*0Sstevel@tonic-gate 	PerlIO_printf(file, "PVFM%s\n", s);
1129*0Sstevel@tonic-gate 	break;
1130*0Sstevel@tonic-gate     case SVt_PVIO:
1131*0Sstevel@tonic-gate 	PerlIO_printf(file, "PVIO%s\n", s);
1132*0Sstevel@tonic-gate 	break;
1133*0Sstevel@tonic-gate     default:
1134*0Sstevel@tonic-gate 	PerlIO_printf(file, "UNKNOWN(0x%"UVxf") %s\n", (UV)type, s);
1135*0Sstevel@tonic-gate 	SvREFCNT_dec(d);
1136*0Sstevel@tonic-gate 	return;
1137*0Sstevel@tonic-gate     }
1138*0Sstevel@tonic-gate     if (type >= SVt_PVIV || type == SVt_IV) {
1139*0Sstevel@tonic-gate 	if (SvIsUV(sv))
1140*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  UV = %"UVuf, (UV)SvUVX(sv));
1141*0Sstevel@tonic-gate 	else
1142*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  IV = %"IVdf, (IV)SvIVX(sv));
1143*0Sstevel@tonic-gate 	if (SvOOK(sv))
1144*0Sstevel@tonic-gate 	    PerlIO_printf(file, "  (OFFSET)");
1145*0Sstevel@tonic-gate 	PerlIO_putc(file, '\n');
1146*0Sstevel@tonic-gate     }
1147*0Sstevel@tonic-gate     if (type >= SVt_PVNV || type == SVt_NV) {
1148*0Sstevel@tonic-gate 	STORE_NUMERIC_LOCAL_SET_STANDARD();
1149*0Sstevel@tonic-gate 	/* %Vg doesn't work? --jhi */
1150*0Sstevel@tonic-gate #ifdef USE_LONG_DOUBLE
1151*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  NV = %.*" PERL_PRIgldbl "\n", LDBL_DIG, SvNVX(sv));
1152*0Sstevel@tonic-gate #else
1153*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  NV = %.*g\n", DBL_DIG, SvNVX(sv));
1154*0Sstevel@tonic-gate #endif
1155*0Sstevel@tonic-gate 	RESTORE_NUMERIC_LOCAL();
1156*0Sstevel@tonic-gate     }
1157*0Sstevel@tonic-gate     if (SvROK(sv)) {
1158*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  RV = 0x%"UVxf"\n", PTR2UV(SvRV(sv)));
1159*0Sstevel@tonic-gate 	if (nest < maxnest)
1160*0Sstevel@tonic-gate 	    do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim);
1161*0Sstevel@tonic-gate     }
1162*0Sstevel@tonic-gate     if (type < SVt_PV) {
1163*0Sstevel@tonic-gate 	SvREFCNT_dec(d);
1164*0Sstevel@tonic-gate 	return;
1165*0Sstevel@tonic-gate     }
1166*0Sstevel@tonic-gate     if (type <= SVt_PVLV) {
1167*0Sstevel@tonic-gate 	if (SvPVX(sv)) {
1168*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file,"  PV = 0x%"UVxf" ", PTR2UV(SvPVX(sv)));
1169*0Sstevel@tonic-gate 	    if (SvOOK(sv))
1170*0Sstevel@tonic-gate 		PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim));
1171*0Sstevel@tonic-gate 	    PerlIO_printf(file, "%s", pv_display(d, SvPVX(sv), SvCUR(sv), SvLEN(sv), pvlim));
1172*0Sstevel@tonic-gate 	    if (SvUTF8(sv)) /* the 8?  \x{....} */
1173*0Sstevel@tonic-gate 	        PerlIO_printf(file, " [UTF8 \"%s\"]", sv_uni_display(d, sv, 8 * sv_len_utf8(sv), UNI_DISPLAY_QQ));
1174*0Sstevel@tonic-gate 	    PerlIO_printf(file, "\n");
1175*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  CUR = %"IVdf"\n", (IV)SvCUR(sv));
1176*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  LEN = %"IVdf"\n", (IV)SvLEN(sv));
1177*0Sstevel@tonic-gate 	}
1178*0Sstevel@tonic-gate 	else
1179*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  PV = 0\n");
1180*0Sstevel@tonic-gate     }
1181*0Sstevel@tonic-gate     if (type >= SVt_PVMG) {
1182*0Sstevel@tonic-gate 	if (SvMAGIC(sv))
1183*0Sstevel@tonic-gate             do_magic_dump(level, file, SvMAGIC(sv), nest, maxnest, dumpops, pvlim);
1184*0Sstevel@tonic-gate 	if (SvSTASH(sv))
1185*0Sstevel@tonic-gate 	    do_hv_dump(level, file, "  STASH", SvSTASH(sv));
1186*0Sstevel@tonic-gate     }
1187*0Sstevel@tonic-gate     switch (type) {
1188*0Sstevel@tonic-gate     case SVt_PVLV:
1189*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  TYPE = %c\n", LvTYPE(sv));
1190*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  TARGOFF = %"IVdf"\n", (IV)LvTARGOFF(sv));
1191*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  TARGLEN = %"IVdf"\n", (IV)LvTARGLEN(sv));
1192*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  TARG = 0x%"UVxf"\n", PTR2UV(LvTARG(sv)));
1193*0Sstevel@tonic-gate 	if (LvTYPE(sv) != 't' && LvTYPE(sv) != 'T')
1194*0Sstevel@tonic-gate 	    do_sv_dump(level+1, file, LvTARG(sv), nest+1, maxnest,
1195*0Sstevel@tonic-gate 		    dumpops, pvlim);
1196*0Sstevel@tonic-gate 	break;
1197*0Sstevel@tonic-gate     case SVt_PVAV:
1198*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  ARRAY = 0x%"UVxf, PTR2UV(AvARRAY(sv)));
1199*0Sstevel@tonic-gate 	if (AvARRAY(sv) != AvALLOC(sv)) {
1200*0Sstevel@tonic-gate 	    PerlIO_printf(file, " (offset=%"IVdf")\n", (IV)(AvARRAY(sv) - AvALLOC(sv)));
1201*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  ALLOC = 0x%"UVxf"\n", PTR2UV(AvALLOC(sv)));
1202*0Sstevel@tonic-gate 	}
1203*0Sstevel@tonic-gate 	else
1204*0Sstevel@tonic-gate 	    PerlIO_putc(file, '\n');
1205*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  FILL = %"IVdf"\n", (IV)AvFILLp(sv));
1206*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  MAX = %"IVdf"\n", (IV)AvMAX(sv));
1207*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  ARYLEN = 0x%"UVxf"\n", PTR2UV(AvARYLEN(sv)));
1208*0Sstevel@tonic-gate 	flags = AvFLAGS(sv);
1209*0Sstevel@tonic-gate 	sv_setpv(d, "");
1210*0Sstevel@tonic-gate 	if (flags & AVf_REAL)	sv_catpv(d, ",REAL");
1211*0Sstevel@tonic-gate 	if (flags & AVf_REIFY)	sv_catpv(d, ",REIFY");
1212*0Sstevel@tonic-gate 	if (flags & AVf_REUSED)	sv_catpv(d, ",REUSED");
1213*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  FLAGS = (%s)\n", SvCUR(d) ? SvPVX(d) + 1 : "");
1214*0Sstevel@tonic-gate 	if (nest < maxnest && av_len((AV*)sv) >= 0) {
1215*0Sstevel@tonic-gate 	    int count;
1216*0Sstevel@tonic-gate 	    for (count = 0; count <=  av_len((AV*)sv) && count < maxnest; count++) {
1217*0Sstevel@tonic-gate 		SV** elt = av_fetch((AV*)sv,count,0);
1218*0Sstevel@tonic-gate 
1219*0Sstevel@tonic-gate 		Perl_dump_indent(aTHX_ level + 1, file, "Elt No. %"IVdf"\n", (IV)count);
1220*0Sstevel@tonic-gate 		if (elt)
1221*0Sstevel@tonic-gate 		    do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim);
1222*0Sstevel@tonic-gate 	    }
1223*0Sstevel@tonic-gate 	}
1224*0Sstevel@tonic-gate 	break;
1225*0Sstevel@tonic-gate     case SVt_PVHV:
1226*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv)));
1227*0Sstevel@tonic-gate 	if (HvARRAY(sv) && HvKEYS(sv)) {
1228*0Sstevel@tonic-gate 	    /* Show distribution of HEs in the ARRAY */
1229*0Sstevel@tonic-gate 	    int freq[200];
1230*0Sstevel@tonic-gate #define FREQ_MAX (sizeof freq / sizeof freq[0] - 1)
1231*0Sstevel@tonic-gate 	    int i;
1232*0Sstevel@tonic-gate 	    int max = 0;
1233*0Sstevel@tonic-gate 	    U32 pow2 = 2, keys = HvKEYS(sv);
1234*0Sstevel@tonic-gate 	    NV theoret, sum = 0;
1235*0Sstevel@tonic-gate 
1236*0Sstevel@tonic-gate 	    PerlIO_printf(file, "  (");
1237*0Sstevel@tonic-gate 	    Zero(freq, FREQ_MAX + 1, int);
1238*0Sstevel@tonic-gate 	    for (i = 0; (STRLEN)i <= HvMAX(sv); i++) {
1239*0Sstevel@tonic-gate 		HE* h; int count = 0;
1240*0Sstevel@tonic-gate                 for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h))
1241*0Sstevel@tonic-gate 		    count++;
1242*0Sstevel@tonic-gate 		if (count > FREQ_MAX)
1243*0Sstevel@tonic-gate 		    count = FREQ_MAX;
1244*0Sstevel@tonic-gate 	        freq[count]++;
1245*0Sstevel@tonic-gate 	        if (max < count)
1246*0Sstevel@tonic-gate 		    max = count;
1247*0Sstevel@tonic-gate 	    }
1248*0Sstevel@tonic-gate 	    for (i = 0; i <= max; i++) {
1249*0Sstevel@tonic-gate 		if (freq[i]) {
1250*0Sstevel@tonic-gate 		    PerlIO_printf(file, "%d%s:%d", i,
1251*0Sstevel@tonic-gate 				  (i == FREQ_MAX) ? "+" : "",
1252*0Sstevel@tonic-gate 				  freq[i]);
1253*0Sstevel@tonic-gate 		    if (i != max)
1254*0Sstevel@tonic-gate 			PerlIO_printf(file, ", ");
1255*0Sstevel@tonic-gate 		}
1256*0Sstevel@tonic-gate             }
1257*0Sstevel@tonic-gate 	    PerlIO_putc(file, ')');
1258*0Sstevel@tonic-gate 	    /* The "quality" of a hash is defined as the total number of
1259*0Sstevel@tonic-gate 	       comparisons needed to access every element once, relative
1260*0Sstevel@tonic-gate 	       to the expected number needed for a random hash.
1261*0Sstevel@tonic-gate 
1262*0Sstevel@tonic-gate 	       The total number of comparisons is equal to the sum of
1263*0Sstevel@tonic-gate 	       the squares of the number of entries in each bucket.
1264*0Sstevel@tonic-gate 	       For a random hash of n keys into k buckets, the expected
1265*0Sstevel@tonic-gate 	       value is
1266*0Sstevel@tonic-gate 				n + n(n-1)/2k
1267*0Sstevel@tonic-gate 	    */
1268*0Sstevel@tonic-gate 
1269*0Sstevel@tonic-gate 	    for (i = max; i > 0; i--) { /* Precision: count down. */
1270*0Sstevel@tonic-gate 		sum += freq[i] * i * i;
1271*0Sstevel@tonic-gate             }
1272*0Sstevel@tonic-gate 	    while ((keys = keys >> 1))
1273*0Sstevel@tonic-gate 		pow2 = pow2 << 1;
1274*0Sstevel@tonic-gate 	    theoret = HvKEYS(sv);
1275*0Sstevel@tonic-gate 	    theoret += theoret * (theoret-1)/pow2;
1276*0Sstevel@tonic-gate 	    PerlIO_putc(file, '\n');
1277*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  hash quality = %.1"NVff"%%", theoret/sum*100);
1278*0Sstevel@tonic-gate 	}
1279*0Sstevel@tonic-gate 	PerlIO_putc(file, '\n');
1280*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  KEYS = %"IVdf"\n", (IV)HvKEYS(sv));
1281*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  FILL = %"IVdf"\n", (IV)HvFILL(sv));
1282*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  MAX = %"IVdf"\n", (IV)HvMAX(sv));
1283*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  RITER = %"IVdf"\n", (IV)HvRITER(sv));
1284*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  EITER = 0x%"UVxf"\n", PTR2UV(HvEITER(sv)));
1285*0Sstevel@tonic-gate 	if (HvPMROOT(sv))
1286*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  PMROOT = 0x%"UVxf"\n", PTR2UV(HvPMROOT(sv)));
1287*0Sstevel@tonic-gate 	if (HvNAME(sv))
1288*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  NAME = \"%s\"\n", HvNAME(sv));
1289*0Sstevel@tonic-gate 	if (nest < maxnest && !HvEITER(sv)) { /* Try to preserve iterator */
1290*0Sstevel@tonic-gate 	    HE *he;
1291*0Sstevel@tonic-gate 	    HV *hv = (HV*)sv;
1292*0Sstevel@tonic-gate 	    int count = maxnest - nest;
1293*0Sstevel@tonic-gate 
1294*0Sstevel@tonic-gate 	    hv_iterinit(hv);
1295*0Sstevel@tonic-gate 	    while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))
1296*0Sstevel@tonic-gate                    && count--) {
1297*0Sstevel@tonic-gate 		SV *elt, *keysv;
1298*0Sstevel@tonic-gate 		char *keypv;
1299*0Sstevel@tonic-gate 		STRLEN len;
1300*0Sstevel@tonic-gate 		U32 hash = HeHASH(he);
1301*0Sstevel@tonic-gate 
1302*0Sstevel@tonic-gate 		keysv = hv_iterkeysv(he);
1303*0Sstevel@tonic-gate 		keypv = SvPV(keysv, len);
1304*0Sstevel@tonic-gate 		elt = hv_iterval(hv, he);
1305*0Sstevel@tonic-gate 		Perl_dump_indent(aTHX_ level+1, file, "Elt %s ", pv_display(d, keypv, len, 0, pvlim));
1306*0Sstevel@tonic-gate 		if (SvUTF8(keysv))
1307*0Sstevel@tonic-gate 		    PerlIO_printf(file, "[UTF8 \"%s\"] ", sv_uni_display(d, keysv, 8 * sv_len_utf8(keysv), UNI_DISPLAY_QQ));
1308*0Sstevel@tonic-gate 		if (HeKREHASH(he))
1309*0Sstevel@tonic-gate 		    PerlIO_printf(file, "[REHASH] ");
1310*0Sstevel@tonic-gate 		PerlIO_printf(file, "HASH = 0x%"UVxf"\n", (UV)hash);
1311*0Sstevel@tonic-gate 		do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim);
1312*0Sstevel@tonic-gate 	    }
1313*0Sstevel@tonic-gate 	    hv_iterinit(hv);		/* Return to status quo */
1314*0Sstevel@tonic-gate 	}
1315*0Sstevel@tonic-gate 	break;
1316*0Sstevel@tonic-gate     case SVt_PVCV:
1317*0Sstevel@tonic-gate 	if (SvPOK(sv))
1318*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  PROTOTYPE = \"%s\"\n", SvPV_nolen(sv));
1319*0Sstevel@tonic-gate 	/* FALL THROUGH */
1320*0Sstevel@tonic-gate     case SVt_PVFM:
1321*0Sstevel@tonic-gate 	do_hv_dump(level, file, "  COMP_STASH", CvSTASH(sv));
1322*0Sstevel@tonic-gate 	if (CvSTART(sv))
1323*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  START = 0x%"UVxf" ===> %"IVdf"\n", PTR2UV(CvSTART(sv)), (IV)CvSTART(sv)->op_seq);
1324*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  ROOT = 0x%"UVxf"\n", PTR2UV(CvROOT(sv)));
1325*0Sstevel@tonic-gate         if (CvROOT(sv) && dumpops)
1326*0Sstevel@tonic-gate 	    do_op_dump(level+1, file, CvROOT(sv));
1327*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  XSUB = 0x%"UVxf"\n", PTR2UV(CvXSUB(sv)));
1328*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  XSUBANY = %"IVdf"\n", (IV)CvXSUBANY(sv).any_i32);
1329*0Sstevel@tonic-gate  	do_gvgv_dump(level, file, "  GVGV::GV", CvGV(sv));
1330*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  FILE = \"%s\"\n", CvFILE(sv));
1331*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  DEPTH = %"IVdf"\n", (IV)CvDEPTH(sv));
1332*0Sstevel@tonic-gate #ifdef USE_5005THREADS
1333*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  MUTEXP = 0x%"UVxf"\n", PTR2UV(CvMUTEXP(sv)));
1334*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  OWNER = 0x%"UVxf"\n",  PTR2UV(CvOWNER(sv)));
1335*0Sstevel@tonic-gate #endif /* USE_5005THREADS */
1336*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  FLAGS = 0x%"UVxf"\n", (UV)CvFLAGS(sv));
1337*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  OUTSIDE_SEQ = %"UVuf"\n", (UV)CvOUTSIDE_SEQ(sv));
1338*0Sstevel@tonic-gate 	if (type == SVt_PVFM)
1339*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  LINES = %"IVdf"\n", (IV)FmLINES(sv));
1340*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  PADLIST = 0x%"UVxf"\n", PTR2UV(CvPADLIST(sv)));
1341*0Sstevel@tonic-gate 	if (nest < maxnest) {
1342*0Sstevel@tonic-gate 	    do_dump_pad(level+1, file, CvPADLIST(sv), 0);
1343*0Sstevel@tonic-gate 	}
1344*0Sstevel@tonic-gate 	{
1345*0Sstevel@tonic-gate 	    CV *outside = CvOUTSIDE(sv);
1346*0Sstevel@tonic-gate 	    Perl_dump_indent(aTHX_ level, file, "  OUTSIDE = 0x%"UVxf" (%s)\n",
1347*0Sstevel@tonic-gate 			PTR2UV(outside),
1348*0Sstevel@tonic-gate 			(!outside ? "null"
1349*0Sstevel@tonic-gate 			 : CvANON(outside) ? "ANON"
1350*0Sstevel@tonic-gate 			 : (outside == PL_main_cv) ? "MAIN"
1351*0Sstevel@tonic-gate 			 : CvUNIQUE(outside) ? "UNIQUE"
1352*0Sstevel@tonic-gate 			 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
1353*0Sstevel@tonic-gate 	}
1354*0Sstevel@tonic-gate 	if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv)))
1355*0Sstevel@tonic-gate 	    do_sv_dump(level+1, file, (SV*)CvOUTSIDE(sv), nest+1, maxnest, dumpops, pvlim);
1356*0Sstevel@tonic-gate 	break;
1357*0Sstevel@tonic-gate     case SVt_PVGV:
1358*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  NAME = \"%s\"\n", GvNAME(sv));
1359*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  NAMELEN = %"IVdf"\n", (IV)GvNAMELEN(sv));
1360*0Sstevel@tonic-gate 	do_hv_dump (level, file, "  GvSTASH", GvSTASH(sv));
1361*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  GP = 0x%"UVxf"\n", PTR2UV(GvGP(sv)));
1362*0Sstevel@tonic-gate 	if (!GvGP(sv))
1363*0Sstevel@tonic-gate 	    break;
1364*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "    SV = 0x%"UVxf"\n", PTR2UV(GvSV(sv)));
1365*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "    REFCNT = %"IVdf"\n", (IV)GvREFCNT(sv));
1366*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "    IO = 0x%"UVxf"\n", PTR2UV(GvIOp(sv)));
1367*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "    FORM = 0x%"UVxf"  \n", PTR2UV(GvFORM(sv)));
1368*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "    AV = 0x%"UVxf"\n", PTR2UV(GvAV(sv)));
1369*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "    HV = 0x%"UVxf"\n", PTR2UV(GvHV(sv)));
1370*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "    CV = 0x%"UVxf"\n", PTR2UV(GvCV(sv)));
1371*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "    CVGEN = 0x%"UVxf"\n", (UV)GvCVGEN(sv));
1372*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "    GPFLAGS = 0x%"UVxf"\n", (UV)GvGPFLAGS(sv));
1373*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "    LINE = %"IVdf"\n", (IV)GvLINE(sv));
1374*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "    FILE = \"%s\"\n", GvFILE(sv));
1375*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "    FLAGS = 0x%"UVxf"\n", (UV)GvFLAGS(sv));
1376*0Sstevel@tonic-gate 	do_gv_dump (level, file, "    EGV", GvEGV(sv));
1377*0Sstevel@tonic-gate 	break;
1378*0Sstevel@tonic-gate     case SVt_PVIO:
1379*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  IFP = 0x%"UVxf"\n", PTR2UV(IoIFP(sv)));
1380*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  OFP = 0x%"UVxf"\n", PTR2UV(IoOFP(sv)));
1381*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  DIRP = 0x%"UVxf"\n", PTR2UV(IoDIRP(sv)));
1382*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  LINES = %"IVdf"\n", (IV)IoLINES(sv));
1383*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  PAGE = %"IVdf"\n", (IV)IoPAGE(sv));
1384*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  PAGE_LEN = %"IVdf"\n", (IV)IoPAGE_LEN(sv));
1385*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  LINES_LEFT = %"IVdf"\n", (IV)IoLINES_LEFT(sv));
1386*0Sstevel@tonic-gate         if (IoTOP_NAME(sv))
1387*0Sstevel@tonic-gate             Perl_dump_indent(aTHX_ level, file, "  TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
1388*0Sstevel@tonic-gate 	do_gv_dump (level, file, "  TOP_GV", IoTOP_GV(sv));
1389*0Sstevel@tonic-gate         if (IoFMT_NAME(sv))
1390*0Sstevel@tonic-gate             Perl_dump_indent(aTHX_ level, file, "  FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
1391*0Sstevel@tonic-gate 	do_gv_dump (level, file, "  FMT_GV", IoFMT_GV(sv));
1392*0Sstevel@tonic-gate         if (IoBOTTOM_NAME(sv))
1393*0Sstevel@tonic-gate             Perl_dump_indent(aTHX_ level, file, "  BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
1394*0Sstevel@tonic-gate 	do_gv_dump (level, file, "  BOTTOM_GV", IoBOTTOM_GV(sv));
1395*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  SUBPROCESS = %"IVdf"\n", (IV)IoSUBPROCESS(sv));
1396*0Sstevel@tonic-gate 	if (isPRINT(IoTYPE(sv)))
1397*0Sstevel@tonic-gate             Perl_dump_indent(aTHX_ level, file, "  TYPE = '%c'\n", IoTYPE(sv));
1398*0Sstevel@tonic-gate 	else
1399*0Sstevel@tonic-gate             Perl_dump_indent(aTHX_ level, file, "  TYPE = '\\%o'\n", IoTYPE(sv));
1400*0Sstevel@tonic-gate 	Perl_dump_indent(aTHX_ level, file, "  FLAGS = 0x%"UVxf"\n", (UV)IoFLAGS(sv));
1401*0Sstevel@tonic-gate 	break;
1402*0Sstevel@tonic-gate     }
1403*0Sstevel@tonic-gate     SvREFCNT_dec(d);
1404*0Sstevel@tonic-gate }
1405*0Sstevel@tonic-gate 
1406*0Sstevel@tonic-gate void
Perl_sv_dump(pTHX_ SV * sv)1407*0Sstevel@tonic-gate Perl_sv_dump(pTHX_ SV *sv)
1408*0Sstevel@tonic-gate {
1409*0Sstevel@tonic-gate     do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0);
1410*0Sstevel@tonic-gate }
1411*0Sstevel@tonic-gate 
1412*0Sstevel@tonic-gate int
Perl_runops_debug(pTHX)1413*0Sstevel@tonic-gate Perl_runops_debug(pTHX)
1414*0Sstevel@tonic-gate {
1415*0Sstevel@tonic-gate     if (!PL_op) {
1416*0Sstevel@tonic-gate 	if (ckWARN_d(WARN_DEBUGGING))
1417*0Sstevel@tonic-gate 	    Perl_warner(aTHX_ packWARN(WARN_DEBUGGING), "NULL OP IN RUN");
1418*0Sstevel@tonic-gate 	return 0;
1419*0Sstevel@tonic-gate     }
1420*0Sstevel@tonic-gate 
1421*0Sstevel@tonic-gate     do {
1422*0Sstevel@tonic-gate 	PERL_ASYNC_CHECK();
1423*0Sstevel@tonic-gate 	if (PL_debug) {
1424*0Sstevel@tonic-gate 	    if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok)
1425*0Sstevel@tonic-gate 		PerlIO_printf(Perl_debug_log,
1426*0Sstevel@tonic-gate 			      "WARNING: %"UVxf" changed from %"UVxf" to %"UVxf"\n",
1427*0Sstevel@tonic-gate 			      PTR2UV(PL_watchaddr), PTR2UV(PL_watchok),
1428*0Sstevel@tonic-gate 			      PTR2UV(*PL_watchaddr));
1429*0Sstevel@tonic-gate 	    if (DEBUG_s_TEST_) {
1430*0Sstevel@tonic-gate 		if (DEBUG_v_TEST_) {
1431*0Sstevel@tonic-gate 		    PerlIO_printf(Perl_debug_log, "\n");
1432*0Sstevel@tonic-gate 		    deb_stack_all();
1433*0Sstevel@tonic-gate 		}
1434*0Sstevel@tonic-gate 		else
1435*0Sstevel@tonic-gate 		    debstack();
1436*0Sstevel@tonic-gate 	    }
1437*0Sstevel@tonic-gate 
1438*0Sstevel@tonic-gate 
1439*0Sstevel@tonic-gate 	    if (DEBUG_t_TEST_) debop(PL_op);
1440*0Sstevel@tonic-gate 	    if (DEBUG_P_TEST_) debprof(PL_op);
1441*0Sstevel@tonic-gate 	}
1442*0Sstevel@tonic-gate     } while ((PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX)));
1443*0Sstevel@tonic-gate 
1444*0Sstevel@tonic-gate     TAINT_NOT;
1445*0Sstevel@tonic-gate     return 0;
1446*0Sstevel@tonic-gate }
1447*0Sstevel@tonic-gate 
1448*0Sstevel@tonic-gate I32
Perl_debop(pTHX_ OP * o)1449*0Sstevel@tonic-gate Perl_debop(pTHX_ OP *o)
1450*0Sstevel@tonic-gate {
1451*0Sstevel@tonic-gate     AV *padlist, *comppad;
1452*0Sstevel@tonic-gate     CV *cv;
1453*0Sstevel@tonic-gate     SV *sv;
1454*0Sstevel@tonic-gate 
1455*0Sstevel@tonic-gate     if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
1456*0Sstevel@tonic-gate 	return 0;
1457*0Sstevel@tonic-gate 
1458*0Sstevel@tonic-gate     Perl_deb(aTHX_ "%s", OP_NAME(o));
1459*0Sstevel@tonic-gate     switch (o->op_type) {
1460*0Sstevel@tonic-gate     case OP_CONST:
1461*0Sstevel@tonic-gate 	PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo_sv));
1462*0Sstevel@tonic-gate 	break;
1463*0Sstevel@tonic-gate     case OP_GVSV:
1464*0Sstevel@tonic-gate     case OP_GV:
1465*0Sstevel@tonic-gate 	if (cGVOPo_gv) {
1466*0Sstevel@tonic-gate 	    sv = NEWSV(0,0);
1467*0Sstevel@tonic-gate 	    gv_fullname3(sv, cGVOPo_gv, Nullch);
1468*0Sstevel@tonic-gate 	    PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen(sv));
1469*0Sstevel@tonic-gate 	    SvREFCNT_dec(sv);
1470*0Sstevel@tonic-gate 	}
1471*0Sstevel@tonic-gate 	else
1472*0Sstevel@tonic-gate 	    PerlIO_printf(Perl_debug_log, "(NULL)");
1473*0Sstevel@tonic-gate 	break;
1474*0Sstevel@tonic-gate     case OP_PADSV:
1475*0Sstevel@tonic-gate     case OP_PADAV:
1476*0Sstevel@tonic-gate     case OP_PADHV:
1477*0Sstevel@tonic-gate 	/* print the lexical's name */
1478*0Sstevel@tonic-gate         cv = deb_curcv(cxstack_ix);
1479*0Sstevel@tonic-gate         if (cv) {
1480*0Sstevel@tonic-gate             padlist = CvPADLIST(cv);
1481*0Sstevel@tonic-gate             comppad = (AV*)(*av_fetch(padlist, 0, FALSE));
1482*0Sstevel@tonic-gate             sv = *av_fetch(comppad, o->op_targ, FALSE);
1483*0Sstevel@tonic-gate         } else
1484*0Sstevel@tonic-gate             sv = Nullsv;
1485*0Sstevel@tonic-gate         if (sv)
1486*0Sstevel@tonic-gate            PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen(sv));
1487*0Sstevel@tonic-gate         else
1488*0Sstevel@tonic-gate            PerlIO_printf(Perl_debug_log, "[%"UVuf"]", (UV)o->op_targ);
1489*0Sstevel@tonic-gate         break;
1490*0Sstevel@tonic-gate     default:
1491*0Sstevel@tonic-gate 	break;
1492*0Sstevel@tonic-gate     }
1493*0Sstevel@tonic-gate     PerlIO_printf(Perl_debug_log, "\n");
1494*0Sstevel@tonic-gate     return 0;
1495*0Sstevel@tonic-gate }
1496*0Sstevel@tonic-gate 
1497*0Sstevel@tonic-gate STATIC CV*
S_deb_curcv(pTHX_ I32 ix)1498*0Sstevel@tonic-gate S_deb_curcv(pTHX_ I32 ix)
1499*0Sstevel@tonic-gate {
1500*0Sstevel@tonic-gate     PERL_CONTEXT *cx = &cxstack[ix];
1501*0Sstevel@tonic-gate     if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT)
1502*0Sstevel@tonic-gate         return cx->blk_sub.cv;
1503*0Sstevel@tonic-gate     else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
1504*0Sstevel@tonic-gate         return PL_compcv;
1505*0Sstevel@tonic-gate     else if (ix == 0 && PL_curstackinfo->si_type == PERLSI_MAIN)
1506*0Sstevel@tonic-gate         return PL_main_cv;
1507*0Sstevel@tonic-gate     else if (ix <= 0)
1508*0Sstevel@tonic-gate         return Nullcv;
1509*0Sstevel@tonic-gate     else
1510*0Sstevel@tonic-gate         return deb_curcv(ix - 1);
1511*0Sstevel@tonic-gate }
1512*0Sstevel@tonic-gate 
1513*0Sstevel@tonic-gate void
Perl_watch(pTHX_ char ** addr)1514*0Sstevel@tonic-gate Perl_watch(pTHX_ char **addr)
1515*0Sstevel@tonic-gate {
1516*0Sstevel@tonic-gate     PL_watchaddr = addr;
1517*0Sstevel@tonic-gate     PL_watchok = *addr;
1518*0Sstevel@tonic-gate     PerlIO_printf(Perl_debug_log, "WATCHING, %"UVxf" is currently %"UVxf"\n",
1519*0Sstevel@tonic-gate 	PTR2UV(PL_watchaddr), PTR2UV(PL_watchok));
1520*0Sstevel@tonic-gate }
1521*0Sstevel@tonic-gate 
1522*0Sstevel@tonic-gate STATIC void
S_debprof(pTHX_ OP * o)1523*0Sstevel@tonic-gate S_debprof(pTHX_ OP *o)
1524*0Sstevel@tonic-gate {
1525*0Sstevel@tonic-gate     if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
1526*0Sstevel@tonic-gate 	return;
1527*0Sstevel@tonic-gate     if (!PL_profiledata)
1528*0Sstevel@tonic-gate 	Newz(000, PL_profiledata, MAXO, U32);
1529*0Sstevel@tonic-gate     ++PL_profiledata[o->op_type];
1530*0Sstevel@tonic-gate }
1531*0Sstevel@tonic-gate 
1532*0Sstevel@tonic-gate void
Perl_debprofdump(pTHX)1533*0Sstevel@tonic-gate Perl_debprofdump(pTHX)
1534*0Sstevel@tonic-gate {
1535*0Sstevel@tonic-gate     unsigned i;
1536*0Sstevel@tonic-gate     if (!PL_profiledata)
1537*0Sstevel@tonic-gate 	return;
1538*0Sstevel@tonic-gate     for (i = 0; i < MAXO; i++) {
1539*0Sstevel@tonic-gate 	if (PL_profiledata[i])
1540*0Sstevel@tonic-gate 	    PerlIO_printf(Perl_debug_log,
1541*0Sstevel@tonic-gate 			  "%5lu %s\n", (unsigned long)PL_profiledata[i],
1542*0Sstevel@tonic-gate                                        PL_op_name[i]);
1543*0Sstevel@tonic-gate     }
1544*0Sstevel@tonic-gate }
1545