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