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