This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_do_vop can profitably use Perl_sv_usepvn_flags, as it has
[perl5.git] / dump.c
CommitLineData
a0d0e21e 1/* dump.c
a687059c 2 *
4bb101f2 3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
acde74e1 4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 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
166f8a29 16/* This file contains utility routines to dump the contents of SV and OP
61296642 17 * structures, as used by command-line options like -Dt and -Dx, and
166f8a29
DM
18 * by Devel::Peek.
19 *
20 * It also holds the debugging version of the runops function.
21 */
22
8d063cd8 23#include "EXTERN.h"
864dbfa3 24#define PERL_IN_DUMP_C
8d063cd8 25#include "perl.h"
f722798b 26#include "regcomp.h"
0bd48802
AL
27#include "proto.h"
28
8d063cd8 29
27da23d5 30#define Sequence PL_op_sequence
2814eb74 31
3967c732 32void
864dbfa3 33Perl_dump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
3967c732 34{
3967c732 35 va_list args;
3967c732 36 va_start(args, pat);
c5be433b 37 dump_vindent(level, file, pat, &args);
3967c732
JD
38 va_end(args);
39}
8adcabd8
LW
40
41void
c5be433b
GS
42Perl_dump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args)
43{
97aff369 44 dVAR;
c8db6e60 45 PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), "");
c5be433b
GS
46 PerlIO_vprintf(file, pat, *args);
47}
48
49void
864dbfa3 50Perl_dump_all(pTHX)
79072805 51{
97aff369 52 dVAR;
760ac839 53 PerlIO_setlinebuf(Perl_debug_log);
3280af22 54 if (PL_main_root)
3967c732 55 op_dump(PL_main_root);
3280af22 56 dump_packsubs(PL_defstash);
463ee0b2
LW
57}
58
59void
e1ec3a88 60Perl_dump_packsubs(pTHX_ const HV *stash)
463ee0b2 61{
97aff369 62 dVAR;
a0d0e21e 63 I32 i;
463ee0b2 64
8990e307
LW
65 if (!HvARRAY(stash))
66 return;
a0d0e21e 67 for (i = 0; i <= (I32) HvMAX(stash); i++) {
e1ec3a88 68 const HE *entry;
4db58590 69 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
e1ec3a88
AL
70 const GV *gv = (GV*)HeVAL(entry);
71 const HV *hv;
e29cdcb3
GS
72 if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
73 continue;
8ebc5c01 74 if (GvCVu(gv))
463ee0b2 75 dump_sub(gv);
85e6fe83
LW
76 if (GvFORM(gv))
77 dump_form(gv);
6676db26
AMS
78 if (HeKEY(entry)[HeKLEN(entry)-1] == ':'
79 && (hv = GvHV(gv)) && hv != PL_defstash)
463ee0b2
LW
80 dump_packsubs(hv); /* nested package */
81 }
79072805
LW
82 }
83}
84
85void
e1ec3a88 86Perl_dump_sub(pTHX_ const GV *gv)
a687059c 87{
b464bac0 88 SV * const sv = sv_newmortal();
85e6fe83 89
bd61b366 90 gv_fullname3(sv, gv, NULL);
b15aece3 91 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ", SvPVX_const(sv));
aed2304a 92 if (CvISXSUB(GvCV(gv)))
91f3b821
GS
93 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "(xsub 0x%"UVxf" %d)\n",
94 PTR2UV(CvXSUB(GvCV(gv))),
894356b3 95 (int)CvXSUBANY(GvCV(gv)).any_i32);
85e6fe83 96 else if (CvROOT(GvCV(gv)))
3967c732 97 op_dump(CvROOT(GvCV(gv)));
85e6fe83 98 else
cea2e8a9 99 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
85e6fe83
LW
100}
101
102void
e1ec3a88 103Perl_dump_form(pTHX_ const GV *gv)
85e6fe83 104{
b464bac0 105 SV * const sv = sv_newmortal();
85e6fe83 106
bd61b366 107 gv_fullname3(sv, gv, NULL);
b15aece3 108 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nFORMAT %s = ", SvPVX_const(sv));
85e6fe83 109 if (CvROOT(GvFORM(gv)))
3967c732 110 op_dump(CvROOT(GvFORM(gv)));
85e6fe83 111 else
cea2e8a9 112 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
a687059c
LW
113}
114
8adcabd8 115void
864dbfa3 116Perl_dump_eval(pTHX)
8d063cd8 117{
97aff369 118 dVAR;
3967c732
JD
119 op_dump(PL_eval_root);
120}
121
122char *
e1ec3a88 123Perl_pv_display(pTHX_ SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
3967c732 124{
e1ec3a88
AL
125 const bool nul_terminated = len > cur && pv[cur] == '\0';
126 bool truncated = 0;
3967c732 127
e6abe6d8 128 sv_setpvn(dsv, "\"", 1);
3967c732 129 for (; cur--; pv++) {
e6abe6d8 130 if (pvlim && SvCUR(dsv) >= pvlim) {
e1ec3a88 131 truncated = 1;
3967c732
JD
132 break;
133 }
46316b0a 134 switch (*pv) {
396482e1
GA
135 case '\t': sv_catpvs(dsv, "\\t"); break;
136 case '\n': sv_catpvs(dsv, "\\n"); break;
137 case '\r': sv_catpvs(dsv, "\\r"); break;
138 case '\f': sv_catpvs(dsv, "\\f"); break;
139 case '"': sv_catpvs(dsv, "\\\""); break;
140 case '\\': sv_catpvs(dsv, "\\\\"); break;
46316b0a
DM
141 default:
142 if (isPRINT(*pv))
143 sv_catpvn(dsv, pv, 1);
144 else if (cur && isDIGIT(*(pv+1)))
e6abe6d8 145 Perl_sv_catpvf(aTHX_ dsv, "\\%03o", (U8)*pv);
3967c732 146 else
e6abe6d8 147 Perl_sv_catpvf(aTHX_ dsv, "\\%o", (U8)*pv);
3967c732
JD
148 }
149 }
396482e1 150 sv_catpvs(dsv, "\"");
3967c732 151 if (truncated)
396482e1 152 sv_catpvs(dsv, "...");
3967c732 153 if (nul_terminated)
396482e1 154 sv_catpvs(dsv, "\\0");
3967c732 155
e6abe6d8
JH
156 return SvPVX(dsv);
157}
158
159char *
864dbfa3 160Perl_sv_peek(pTHX_ SV *sv)
3967c732 161{
27da23d5 162 dVAR;
aec46f14 163 SV * const t = sv_newmortal();
3967c732
JD
164 int unref = 0;
165
166 sv_setpvn(t, "", 0);
167 retry:
168 if (!sv) {
169 sv_catpv(t, "VOID");
170 goto finish;
171 }
172 else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') {
173 sv_catpv(t, "WILD");
174 goto finish;
175 }
7996736c 176 else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) {
3967c732
JD
177 if (sv == &PL_sv_undef) {
178 sv_catpv(t, "SV_UNDEF");
179 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
180 SVs_GMG|SVs_SMG|SVs_RMG)) &&
181 SvREADONLY(sv))
182 goto finish;
183 }
184 else if (sv == &PL_sv_no) {
185 sv_catpv(t, "SV_NO");
186 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
187 SVs_GMG|SVs_SMG|SVs_RMG)) &&
188 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
189 SVp_POK|SVp_NOK)) &&
190 SvCUR(sv) == 0 &&
191 SvNVX(sv) == 0.0)
192 goto finish;
193 }
7996736c 194 else if (sv == &PL_sv_yes) {
3967c732
JD
195 sv_catpv(t, "SV_YES");
196 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
197 SVs_GMG|SVs_SMG|SVs_RMG)) &&
198 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
199 SVp_POK|SVp_NOK)) &&
200 SvCUR(sv) == 1 &&
b15aece3 201 SvPVX_const(sv) && *SvPVX_const(sv) == '1' &&
3967c732
JD
202 SvNVX(sv) == 1.0)
203 goto finish;
7996736c
MHM
204 }
205 else {
206 sv_catpv(t, "SV_PLACEHOLDER");
207 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
208 SVs_GMG|SVs_SMG|SVs_RMG)) &&
209 SvREADONLY(sv))
210 goto finish;
3967c732
JD
211 }
212 sv_catpv(t, ":");
213 }
214 else if (SvREFCNT(sv) == 0) {
215 sv_catpv(t, "(");
216 unref++;
217 }
a3b4c9c6
DM
218 else if (DEBUG_R_TEST_) {
219 int is_tmp = 0;
220 I32 ix;
221 /* is this SV on the tmps stack? */
222 for (ix=PL_tmps_ix; ix>=0; ix--) {
223 if (PL_tmps_stack[ix] == sv) {
224 is_tmp = 1;
225 break;
226 }
227 }
228 if (SvREFCNT(sv) > 1)
229 Perl_sv_catpvf(aTHX_ t, "<%"UVuf"%s>", (UV)SvREFCNT(sv),
230 is_tmp ? "T" : "");
231 else if (is_tmp)
232 sv_catpv(t, "<T>");
04932ac8
DM
233 }
234
3967c732
JD
235 if (SvROK(sv)) {
236 sv_catpv(t, "\\");
237 if (SvCUR(t) + unref > 10) {
b162af07 238 SvCUR_set(t, unref + 3);
3967c732
JD
239 *SvEND(t) = '\0';
240 sv_catpv(t, "...");
241 goto finish;
242 }
243 sv = (SV*)SvRV(sv);
244 goto retry;
245 }
246 switch (SvTYPE(sv)) {
247 default:
248 sv_catpv(t, "FREED");
249 goto finish;
250
251 case SVt_NULL:
252 sv_catpv(t, "UNDEF");
253 goto finish;
254 case SVt_IV:
255 sv_catpv(t, "IV");
256 break;
257 case SVt_NV:
258 sv_catpv(t, "NV");
259 break;
260 case SVt_RV:
261 sv_catpv(t, "RV");
262 break;
263 case SVt_PV:
264 sv_catpv(t, "PV");
265 break;
266 case SVt_PVIV:
267 sv_catpv(t, "PVIV");
268 break;
269 case SVt_PVNV:
270 sv_catpv(t, "PVNV");
271 break;
272 case SVt_PVMG:
273 sv_catpv(t, "PVMG");
274 break;
275 case SVt_PVLV:
276 sv_catpv(t, "PVLV");
277 break;
278 case SVt_PVAV:
279 sv_catpv(t, "AV");
280 break;
281 case SVt_PVHV:
282 sv_catpv(t, "HV");
283 break;
284 case SVt_PVCV:
285 if (CvGV(sv))
cea2e8a9 286 Perl_sv_catpvf(aTHX_ t, "CV(%s)", GvNAME(CvGV(sv)));
3967c732
JD
287 else
288 sv_catpv(t, "CV()");
289 goto finish;
290 case SVt_PVGV:
291 sv_catpv(t, "GV");
292 break;
293 case SVt_PVBM:
294 sv_catpv(t, "BM");
295 break;
296 case SVt_PVFM:
297 sv_catpv(t, "FM");
298 break;
299 case SVt_PVIO:
300 sv_catpv(t, "IO");
301 break;
302 }
303
304 if (SvPOKp(sv)) {
b15aece3 305 if (!SvPVX_const(sv))
3967c732
JD
306 sv_catpv(t, "(null)");
307 else {
396482e1 308 SV *tmp = newSVpvs("");
3967c732
JD
309 sv_catpv(t, "(");
310 if (SvOOK(sv))
b15aece3
SP
311 Perl_sv_catpvf(aTHX_ t, "[%s]", pv_display(tmp, SvPVX_const(sv)-SvIVX(sv), SvIVX(sv), 0, 127));
312 Perl_sv_catpvf(aTHX_ t, "%s)", pv_display(tmp, SvPVX_const(sv), SvCUR(sv), SvLEN(sv), 127));
32639b87 313 if (SvUTF8(sv))
b2ff9928 314 Perl_sv_catpvf(aTHX_ t, " [UTF8 \"%s\"]",
c728cb41
JH
315 sv_uni_display(tmp, sv, 8 * sv_len_utf8(sv),
316 UNI_DISPLAY_QQ));
3967c732
JD
317 SvREFCNT_dec(tmp);
318 }
319 }
320 else if (SvNOKp(sv)) {
e54dc35b 321 STORE_NUMERIC_LOCAL_SET_STANDARD();
1779d84d 322 Perl_sv_catpvf(aTHX_ t, "(%"NVgf")",SvNVX(sv));
e54dc35b 323 RESTORE_NUMERIC_LOCAL();
3967c732 324 }
57def98f 325 else if (SvIOKp(sv)) {
cf2093f6 326 if (SvIsUV(sv))
57def98f 327 Perl_sv_catpvf(aTHX_ t, "(%"UVuf")", (UV)SvUVX(sv));
cf2093f6 328 else
57def98f 329 Perl_sv_catpvf(aTHX_ t, "(%"IVdf")", (IV)SvIVX(sv));
25da4f38 330 }
3967c732
JD
331 else
332 sv_catpv(t, "()");
2ef28da1 333
3967c732
JD
334 finish:
335 if (unref) {
336 while (unref--)
337 sv_catpv(t, ")");
338 }
8b6b16e7 339 return SvPV_nolen(t);
3967c732
JD
340}
341
342void
6867be6d 343Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, const PMOP *pm)
3967c732
JD
344{
345 char ch;
346
347 if (!pm) {
cea2e8a9 348 Perl_dump_indent(aTHX_ level, file, "{}\n");
3967c732
JD
349 return;
350 }
cea2e8a9 351 Perl_dump_indent(aTHX_ level, file, "{\n");
3967c732
JD
352 level++;
353 if (pm->op_pmflags & PMf_ONCE)
354 ch = '?';
355 else
356 ch = '/';
aaa362c4 357 if (PM_GETRE(pm))
cea2e8a9 358 Perl_dump_indent(aTHX_ level, file, "PMf_PRE %c%s%c%s\n",
aaa362c4 359 ch, PM_GETRE(pm)->precomp, ch,
3967c732
JD
360 (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
361 else
cea2e8a9 362 Perl_dump_indent(aTHX_ level, file, "PMf_PRE (RUNTIME)\n");
3967c732 363 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
cea2e8a9 364 Perl_dump_indent(aTHX_ level, file, "PMf_REPL = ");
3967c732
JD
365 op_dump(pm->op_pmreplroot);
366 }
aaa362c4 367 if (pm->op_pmflags || (PM_GETRE(pm) && PM_GETRE(pm)->check_substr)) {
d4c19fe8 368 SV * const tmpsv = newSVpvs("");
3967c732
JD
369 if (pm->op_pmdynflags & PMdf_USED)
370 sv_catpv(tmpsv, ",USED");
371 if (pm->op_pmdynflags & PMdf_TAINTED)
372 sv_catpv(tmpsv, ",TAINTED");
373 if (pm->op_pmflags & PMf_ONCE)
374 sv_catpv(tmpsv, ",ONCE");
aaa362c4
RS
375 if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr
376 && !(PM_GETRE(pm)->reganch & ROPT_NOSCAN))
3967c732 377 sv_catpv(tmpsv, ",SCANFIRST");
aaa362c4
RS
378 if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr
379 && PM_GETRE(pm)->reganch & ROPT_CHECK_ALL)
3967c732
JD
380 sv_catpv(tmpsv, ",ALL");
381 if (pm->op_pmflags & PMf_SKIPWHITE)
382 sv_catpv(tmpsv, ",SKIPWHITE");
383 if (pm->op_pmflags & PMf_CONST)
384 sv_catpv(tmpsv, ",CONST");
385 if (pm->op_pmflags & PMf_KEEP)
386 sv_catpv(tmpsv, ",KEEP");
387 if (pm->op_pmflags & PMf_GLOBAL)
388 sv_catpv(tmpsv, ",GLOBAL");
389 if (pm->op_pmflags & PMf_CONTINUE)
390 sv_catpv(tmpsv, ",CONTINUE");
391 if (pm->op_pmflags & PMf_RETAINT)
392 sv_catpv(tmpsv, ",RETAINT");
393 if (pm->op_pmflags & PMf_EVAL)
394 sv_catpv(tmpsv, ",EVAL");
b15aece3 395 Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
3967c732
JD
396 SvREFCNT_dec(tmpsv);
397 }
398
cea2e8a9 399 Perl_dump_indent(aTHX_ level-1, file, "}\n");
3967c732
JD
400}
401
402void
864dbfa3 403Perl_pmop_dump(pTHX_ PMOP *pm)
3967c732
JD
404{
405 do_pmop_dump(0, Perl_debug_log, pm);
79072805
LW
406}
407
2814eb74
PJ
408/* An op sequencer. We visit the ops in the order they're to execute. */
409
410STATIC void
0bd48802 411S_sequence(pTHX_ register const OP *o)
2814eb74 412{
27da23d5 413 dVAR;
2814eb74 414 SV *op;
93524f2b 415 const char *key;
2814eb74 416 STRLEN len;
c445ea15 417 const OP *oldop = NULL;
6867be6d 418 OP *l;
2814eb74 419
2814eb74
PJ
420 if (!o)
421 return;
422
3b721df9
NC
423#ifdef PERL_MAD
424 if (o->op_next == 0)
425 return;
426#endif
427
724e67cb
RGS
428 if (!Sequence)
429 Sequence = newHV();
2814eb74
PJ
430
431 for (; o; o = o->op_next) {
c0fd1b42 432 op = newSVuv(PTR2UV(o));
93524f2b 433 key = SvPV_const(op, len);
2814eb74
PJ
434 if (hv_exists(Sequence, key, len))
435 break;
436
437 switch (o->op_type) {
438 case OP_STUB:
439 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
27da23d5 440 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
2814eb74
PJ
441 break;
442 }
443 goto nothin;
444 case OP_NULL:
3b721df9
NC
445#ifdef PERL_MAD
446 if (o == o->op_next)
447 return;
448#endif
2814eb74
PJ
449 if (oldop && o->op_next)
450 continue;
451 break;
452 case OP_SCALAR:
453 case OP_LINESEQ:
454 case OP_SCOPE:
455 nothin:
456 if (oldop && o->op_next)
457 continue;
27da23d5 458 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
2814eb74
PJ
459 break;
460
461 case OP_MAPWHILE:
462 case OP_GREPWHILE:
463 case OP_AND:
464 case OP_OR:
465 case OP_DOR:
466 case OP_ANDASSIGN:
467 case OP_ORASSIGN:
468 case OP_DORASSIGN:
469 case OP_COND_EXPR:
470 case OP_RANGE:
27da23d5 471 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
5411ce9f 472 for (l = cLOGOPo->op_other; l && l->op_type == OP_NULL; l = l->op_next)
2814eb74 473 ;
0bd48802 474 sequence(l);
2814eb74
PJ
475 break;
476
477 case OP_ENTERLOOP:
478 case OP_ENTERITER:
27da23d5 479 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
5411ce9f 480 for (l = cLOOPo->op_redoop; l && l->op_type == OP_NULL; l = l->op_next)
2814eb74 481 ;
0bd48802 482 sequence(l);
5411ce9f 483 for (l = cLOOPo->op_nextop; l && l->op_type == OP_NULL; l = l->op_next)
2814eb74 484 ;
0bd48802 485 sequence(l);
5411ce9f 486 for (l = cLOOPo->op_lastop; l && l->op_type == OP_NULL; l = l->op_next)
2814eb74 487 ;
0bd48802 488 sequence(l);
2814eb74
PJ
489 break;
490
491 case OP_QR:
492 case OP_MATCH:
493 case OP_SUBST:
27da23d5 494 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
5411ce9f 495 for (l = cPMOPo->op_pmreplstart; l && l->op_type == OP_NULL; l = l->op_next)
2814eb74 496 ;
0bd48802 497 sequence(l);
2814eb74
PJ
498 break;
499
500 case OP_HELEM:
501 break;
502
503 default:
27da23d5 504 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
2814eb74
PJ
505 break;
506 }
507 oldop = o;
508 }
509}
510
511STATIC UV
0bd48802 512S_sequence_num(pTHX_ const OP *o)
2814eb74 513{
27da23d5 514 dVAR;
2814eb74
PJ
515 SV *op,
516 **seq;
93524f2b 517 const char *key;
2814eb74
PJ
518 STRLEN len;
519 if (!o) return 0;
c0fd1b42 520 op = newSVuv(PTR2UV(o));
93524f2b 521 key = SvPV_const(op, len);
2814eb74
PJ
522 seq = hv_fetch(Sequence, key, len, 0);
523 return seq ? SvUV(*seq): 0;
524}
525
79072805 526void
6867be6d 527Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
79072805 528{
27da23d5 529 dVAR;
2814eb74 530 UV seq;
0bd48802 531 sequence(o);
cea2e8a9 532 Perl_dump_indent(aTHX_ level, file, "{\n");
3967c732 533 level++;
0bd48802 534 seq = sequence_num(o);
2814eb74 535 if (seq)
c0fd1b42 536 PerlIO_printf(file, "%-4"UVf, seq);
93a17b20 537 else
3967c732 538 PerlIO_printf(file, " ");
c8db6e60
JH
539 PerlIO_printf(file,
540 "%*sTYPE = %s ===> ",
53e06cf0 541 (int)(PL_dumpindent*level-4), "", OP_NAME(o));
2814eb74 542 if (o->op_next)
c0fd1b42 543 PerlIO_printf(file, seq ? "%"UVf"\n" : "(%"UVf")\n",
0bd48802 544 sequence_num(o->op_next));
79072805 545 else
3967c732 546 PerlIO_printf(file, "DONE\n");
11343788 547 if (o->op_targ) {
acb36ea4 548 if (o->op_type == OP_NULL)
ae7d165c 549 {
cea2e8a9 550 Perl_dump_indent(aTHX_ level, file, " (was %s)\n", PL_op_name[o->op_targ]);
ae7d165c
PJ
551 if (o->op_targ == OP_NEXTSTATE)
552 {
553 if (CopLINE(cCOPo))
9d98dee5
RB
554 Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n",
555 (UV)CopLINE(cCOPo));
ae7d165c
PJ
556 if (CopSTASHPV(cCOPo))
557 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
558 CopSTASHPV(cCOPo));
559 if (cCOPo->cop_label)
560 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
561 cCOPo->cop_label);
562 }
563 }
8990e307 564 else
894356b3 565 Perl_dump_indent(aTHX_ level, file, "TARG = %ld\n", (long)o->op_targ);
8990e307 566 }
748a9306 567#ifdef DUMPADDR
57def98f 568 Perl_dump_indent(aTHX_ level, file, "ADDR = 0x%"UVxf" => 0x%"UVxf"\n", (UV)o, (UV)o->op_next);
79072805 569#endif
11343788 570 if (o->op_flags) {
396482e1 571 SV *tmpsv = newSVpvs("");
5dc0d613 572 switch (o->op_flags & OPf_WANT) {
54310121 573 case OPf_WANT_VOID:
46fc3d4c 574 sv_catpv(tmpsv, ",VOID");
54310121
PP
575 break;
576 case OPf_WANT_SCALAR:
46fc3d4c 577 sv_catpv(tmpsv, ",SCALAR");
54310121
PP
578 break;
579 case OPf_WANT_LIST:
46fc3d4c 580 sv_catpv(tmpsv, ",LIST");
54310121
PP
581 break;
582 default:
46fc3d4c 583 sv_catpv(tmpsv, ",UNKNOWN");
54310121
PP
584 break;
585 }
11343788 586 if (o->op_flags & OPf_KIDS)
46fc3d4c 587 sv_catpv(tmpsv, ",KIDS");
11343788 588 if (o->op_flags & OPf_PARENS)
46fc3d4c 589 sv_catpv(tmpsv, ",PARENS");
11343788 590 if (o->op_flags & OPf_STACKED)
46fc3d4c 591 sv_catpv(tmpsv, ",STACKED");
11343788 592 if (o->op_flags & OPf_REF)
46fc3d4c 593 sv_catpv(tmpsv, ",REF");
11343788 594 if (o->op_flags & OPf_MOD)
46fc3d4c 595 sv_catpv(tmpsv, ",MOD");
11343788 596 if (o->op_flags & OPf_SPECIAL)
46fc3d4c 597 sv_catpv(tmpsv, ",SPECIAL");
b15aece3 598 Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
46fc3d4c 599 SvREFCNT_dec(tmpsv);
79072805 600 }
11343788 601 if (o->op_private) {
396482e1 602 SV *tmpsv = newSVpvs("");
07447971
GS
603 if (PL_opargs[o->op_type] & OA_TARGLEX) {
604 if (o->op_private & OPpTARGET_MY)
605 sv_catpv(tmpsv, ",TARGET_MY");
606 }
bf91b999
SC
607 else if (o->op_type == OP_LEAVESUB ||
608 o->op_type == OP_LEAVE ||
609 o->op_type == OP_LEAVESUBLV ||
610 o->op_type == OP_LEAVEWRITE) {
611 if (o->op_private & OPpREFCOUNTED)
612 sv_catpv(tmpsv, ",REFCOUNTED");
613 }
614 else if (o->op_type == OP_AASSIGN) {
11343788 615 if (o->op_private & OPpASSIGN_COMMON)
46fc3d4c 616 sv_catpv(tmpsv, ",COMMON");
8d063cd8 617 }
11343788
MB
618 else if (o->op_type == OP_SASSIGN) {
619 if (o->op_private & OPpASSIGN_BACKWARDS)
46fc3d4c 620 sv_catpv(tmpsv, ",BACKWARDS");
a0d0e21e 621 }
11343788
MB
622 else if (o->op_type == OP_TRANS) {
623 if (o->op_private & OPpTRANS_SQUASH)
46fc3d4c 624 sv_catpv(tmpsv, ",SQUASH");
11343788 625 if (o->op_private & OPpTRANS_DELETE)
46fc3d4c 626 sv_catpv(tmpsv, ",DELETE");
11343788 627 if (o->op_private & OPpTRANS_COMPLEMENT)
46fc3d4c 628 sv_catpv(tmpsv, ",COMPLEMENT");
bf91b999
SC
629 if (o->op_private & OPpTRANS_IDENTICAL)
630 sv_catpv(tmpsv, ",IDENTICAL");
631 if (o->op_private & OPpTRANS_GROWS)
632 sv_catpv(tmpsv, ",GROWS");
8d063cd8 633 }
11343788
MB
634 else if (o->op_type == OP_REPEAT) {
635 if (o->op_private & OPpREPEAT_DOLIST)
46fc3d4c 636 sv_catpv(tmpsv, ",DOLIST");
8d063cd8 637 }
11343788
MB
638 else if (o->op_type == OP_ENTERSUB ||
639 o->op_type == OP_RV2SV ||
23f1ca44 640 o->op_type == OP_GVSV ||
11343788
MB
641 o->op_type == OP_RV2AV ||
642 o->op_type == OP_RV2HV ||
643 o->op_type == OP_RV2GV ||
644 o->op_type == OP_AELEM ||
645 o->op_type == OP_HELEM )
85e6fe83 646 {
5dc0d613
MB
647 if (o->op_type == OP_ENTERSUB) {
648 if (o->op_private & OPpENTERSUB_AMPER)
46fc3d4c 649 sv_catpv(tmpsv, ",AMPER");
5dc0d613 650 if (o->op_private & OPpENTERSUB_DB)
46fc3d4c 651 sv_catpv(tmpsv, ",DB");
d3011074
IZ
652 if (o->op_private & OPpENTERSUB_HASTARG)
653 sv_catpv(tmpsv, ",HASTARG");
bf91b999
SC
654 if (o->op_private & OPpENTERSUB_NOPAREN)
655 sv_catpv(tmpsv, ",NOPAREN");
656 if (o->op_private & OPpENTERSUB_INARGS)
657 sv_catpv(tmpsv, ",INARGS");
95f0a2f1
SB
658 if (o->op_private & OPpENTERSUB_NOMOD)
659 sv_catpv(tmpsv, ",NOMOD");
68dc0745 660 }
bf91b999 661 else {
d3011074 662 switch (o->op_private & OPpDEREF) {
5f05dabc 663 case OPpDEREF_SV:
46fc3d4c 664 sv_catpv(tmpsv, ",SV");
5f05dabc
PP
665 break;
666 case OPpDEREF_AV:
46fc3d4c 667 sv_catpv(tmpsv, ",AV");
5f05dabc
PP
668 break;
669 case OPpDEREF_HV:
46fc3d4c 670 sv_catpv(tmpsv, ",HV");
5f05dabc
PP
671 break;
672 }
bf91b999
SC
673 if (o->op_private & OPpMAYBE_LVSUB)
674 sv_catpv(tmpsv, ",MAYBE_LVSUB");
675 }
5dc0d613
MB
676 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
677 if (o->op_private & OPpLVAL_DEFER)
46fc3d4c 678 sv_catpv(tmpsv, ",LVAL_DEFER");
68dc0745
PP
679 }
680 else {
5dc0d613 681 if (o->op_private & HINT_STRICT_REFS)
46fc3d4c 682 sv_catpv(tmpsv, ",STRICT_REFS");
192587c2
GS
683 if (o->op_private & OPpOUR_INTRO)
684 sv_catpv(tmpsv, ",OUR_INTRO");
68dc0745 685 }
8d063cd8 686 }
11343788
MB
687 else if (o->op_type == OP_CONST) {
688 if (o->op_private & OPpCONST_BARE)
46fc3d4c 689 sv_catpv(tmpsv, ",BARE");
7a52d87a
GS
690 if (o->op_private & OPpCONST_STRICT)
691 sv_catpv(tmpsv, ",STRICT");
bf91b999
SC
692 if (o->op_private & OPpCONST_ARYBASE)
693 sv_catpv(tmpsv, ",ARYBASE");
694 if (o->op_private & OPpCONST_WARNING)
695 sv_catpv(tmpsv, ",WARNING");
696 if (o->op_private & OPpCONST_ENTERED)
697 sv_catpv(tmpsv, ",ENTERED");
79072805 698 }
11343788
MB
699 else if (o->op_type == OP_FLIP) {
700 if (o->op_private & OPpFLIP_LINENUM)
46fc3d4c 701 sv_catpv(tmpsv, ",LINENUM");
79072805 702 }
11343788
MB
703 else if (o->op_type == OP_FLOP) {
704 if (o->op_private & OPpFLIP_LINENUM)
46fc3d4c 705 sv_catpv(tmpsv, ",LINENUM");
95f0a2f1
SB
706 }
707 else if (o->op_type == OP_RV2CV) {
cd06dffe
GS
708 if (o->op_private & OPpLVAL_INTRO)
709 sv_catpv(tmpsv, ",INTRO");
79072805 710 }
bf91b999
SC
711 else if (o->op_type == OP_GV) {
712 if (o->op_private & OPpEARLY_CV)
713 sv_catpv(tmpsv, ",EARLY_CV");
714 }
715 else if (o->op_type == OP_LIST) {
716 if (o->op_private & OPpLIST_GUESSED)
717 sv_catpv(tmpsv, ",GUESSED");
718 }
719 else if (o->op_type == OP_DELETE) {
720 if (o->op_private & OPpSLICE)
721 sv_catpv(tmpsv, ",SLICE");
722 }
723 else if (o->op_type == OP_EXISTS) {
724 if (o->op_private & OPpEXISTS_SUB)
725 sv_catpv(tmpsv, ",EXISTS_SUB");
726 }
727 else if (o->op_type == OP_SORT) {
728 if (o->op_private & OPpSORT_NUMERIC)
729 sv_catpv(tmpsv, ",NUMERIC");
730 if (o->op_private & OPpSORT_INTEGER)
731 sv_catpv(tmpsv, ",INTEGER");
732 if (o->op_private & OPpSORT_REVERSE)
733 sv_catpv(tmpsv, ",REVERSE");
734 }
735 else if (o->op_type == OP_THREADSV) {
736 if (o->op_private & OPpDONE_SVREF)
737 sv_catpv(tmpsv, ",SVREF");
738 }
739 else if (o->op_type == OP_OPEN || o->op_type == OP_BACKTICK) {
740 if (o->op_private & OPpOPEN_IN_RAW)
741 sv_catpv(tmpsv, ",IN_RAW");
742 if (o->op_private & OPpOPEN_IN_CRLF)
743 sv_catpv(tmpsv, ",IN_CRLF");
744 if (o->op_private & OPpOPEN_OUT_RAW)
745 sv_catpv(tmpsv, ",OUT_RAW");
746 if (o->op_private & OPpOPEN_OUT_CRLF)
747 sv_catpv(tmpsv, ",OUT_CRLF");
748 }
749 else if (o->op_type == OP_EXIT) {
750 if (o->op_private & OPpEXIT_VMSISH)
96e176bf
CL
751 sv_catpv(tmpsv, ",EXIT_VMSISH");
752 if (o->op_private & OPpHUSH_VMSISH)
753 sv_catpv(tmpsv, ",HUSH_VMSISH");
754 }
755 else if (o->op_type == OP_DIE) {
756 if (o->op_private & OPpHUSH_VMSISH)
757 sv_catpv(tmpsv, ",HUSH_VMSISH");
bf91b999 758 }
fbb0b3b3
RGS
759 else if (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)) {
760 if (OP_IS_FILETEST_ACCESS(o) && o->op_private & OPpFT_ACCESS)
761 sv_catpv(tmpsv, ",FT_ACCESS");
762 if (o->op_private & OPpFT_STACKED)
763 sv_catpv(tmpsv, ",FT_STACKED");
1af34c76 764 }
11343788 765 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
46fc3d4c
PP
766 sv_catpv(tmpsv, ",INTRO");
767 if (SvCUR(tmpsv))
b15aece3 768 Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX_const(tmpsv) + 1);
46fc3d4c 769 SvREFCNT_dec(tmpsv);
8d063cd8 770 }
8d063cd8 771
3b721df9
NC
772#ifdef PERL_MAD
773 if (PL_madskills && o->op_madprop) {
d4c19fe8 774 SV * const tmpsv = newSVpvn("", 0);
3b721df9
NC
775 MADPROP* mp = o->op_madprop;
776 Perl_dump_indent(aTHX_ level, file, "MADPROPS = {\n");
777 level++;
778 while (mp) {
779 char tmp = mp->mad_key;
780 sv_setpvn(tmpsv,"'",1);
781 if (tmp)
782 sv_catpvn(tmpsv, &tmp, 1);
783 sv_catpv(tmpsv, "'=");
784 switch (mp->mad_type) {
785 case MAD_NULL:
786 sv_catpv(tmpsv, "NULL");
787 Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv));
788 break;
789 case MAD_PV:
790 sv_catpv(tmpsv, "<");
791 sv_catpvn(tmpsv, (char*)mp->mad_val, mp->mad_vlen);
792 sv_catpv(tmpsv, ">");
793 Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv));
794 break;
795 case MAD_OP:
796 if ((OP*)mp->mad_val) {
797 Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv));
798 do_op_dump(level, file, (OP*)mp->mad_val);
799 }
800 break;
801 default:
802 sv_catpv(tmpsv, "(UNK)");
803 Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv));
804 break;
805 }
806 mp = mp->mad_next;
807 }
808 level--;
809 Perl_dump_indent(aTHX_ level, file, "}\n");
810
811 SvREFCNT_dec(tmpsv);
812 }
813#endif
814
11343788 815 switch (o->op_type) {
971a9dd3 816 case OP_AELEMFAST:
93a17b20 817 case OP_GVSV:
79072805 818 case OP_GV:
971a9dd3 819#ifdef USE_ITHREADS
c803eecc 820 Perl_dump_indent(aTHX_ level, file, "PADIX = %" IVdf "\n", (IV)cPADOPo->op_padix);
971a9dd3 821#else
38c076c7
DM
822 if ( ! PL_op->op_flags & OPf_SPECIAL) { /* not lexical */
823 if (cSVOPo->op_sv) {
d4c19fe8 824 SV * const tmpsv = newSV(0);
38c076c7
DM
825 ENTER;
826 SAVEFREESV(tmpsv);
3b721df9
NC
827#ifdef PERL_MAD
828 /* FIXME - it this making unwarranted assumptions about the
829 UTF-8 cleanliness of the dump file handle? */
830 SvUTF8_on(tmpsv);
831#endif
bd61b366 832 gv_fullname3(tmpsv, (GV*)cSVOPo->op_sv, NULL);
8b6b16e7 833 Perl_dump_indent(aTHX_ level, file, "GV = %s\n",
d5263905 834 SvPV_nolen_const(tmpsv));
38c076c7
DM
835 LEAVE;
836 }
837 else
838 Perl_dump_indent(aTHX_ level, file, "GV = NULL\n");
378cc40b 839 }
971a9dd3 840#endif
79072805
LW
841 break;
842 case OP_CONST:
f5d5a27c 843 case OP_METHOD_NAMED:
b6a15bc5
DM
844#ifndef USE_ITHREADS
845 /* with ITHREADS, consts are stored in the pad, and the right pad
846 * may not be active here, so skip */
3848b962 847 Perl_dump_indent(aTHX_ level, file, "SV = %s\n", SvPEEK(cSVOPo_sv));
b6a15bc5 848#endif
79072805 849 break;
7399586d 850 case OP_SETSTATE:
93a17b20
LW
851 case OP_NEXTSTATE:
852 case OP_DBSTATE:
57843af0 853 if (CopLINE(cCOPo))
9d98dee5
RB
854 Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n",
855 (UV)CopLINE(cCOPo));
ed094faf
GS
856 if (CopSTASHPV(cCOPo))
857 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
858 CopSTASHPV(cCOPo));
11343788 859 if (cCOPo->cop_label)
ed094faf
GS
860 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
861 cCOPo->cop_label);
79072805
LW
862 break;
863 case OP_ENTERLOOP:
cea2e8a9 864 Perl_dump_indent(aTHX_ level, file, "REDO ===> ");
11343788 865 if (cLOOPo->op_redoop)
0bd48802 866 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_redoop));
79072805 867 else
3967c732 868 PerlIO_printf(file, "DONE\n");
cea2e8a9 869 Perl_dump_indent(aTHX_ level, file, "NEXT ===> ");
11343788 870 if (cLOOPo->op_nextop)
0bd48802 871 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_nextop));
79072805 872 else
3967c732 873 PerlIO_printf(file, "DONE\n");
cea2e8a9 874 Perl_dump_indent(aTHX_ level, file, "LAST ===> ");
11343788 875 if (cLOOPo->op_lastop)
0bd48802 876 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_lastop));
79072805 877 else
3967c732 878 PerlIO_printf(file, "DONE\n");
79072805
LW
879 break;
880 case OP_COND_EXPR:
1a67a97c 881 case OP_RANGE:
a0d0e21e 882 case OP_MAPWHILE:
79072805
LW
883 case OP_GREPWHILE:
884 case OP_OR:
885 case OP_AND:
cea2e8a9 886 Perl_dump_indent(aTHX_ level, file, "OTHER ===> ");
11343788 887 if (cLOGOPo->op_other)
0bd48802 888 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOGOPo->op_other));
79072805 889 else
3967c732 890 PerlIO_printf(file, "DONE\n");
79072805
LW
891 break;
892 case OP_PUSHRE:
893 case OP_MATCH:
8782bef2 894 case OP_QR:
79072805 895 case OP_SUBST:
3967c732 896 do_pmop_dump(level, file, cPMOPo);
79072805 897 break;
7934575e
GS
898 case OP_LEAVE:
899 case OP_LEAVEEVAL:
900 case OP_LEAVESUB:
901 case OP_LEAVESUBLV:
902 case OP_LEAVEWRITE:
903 case OP_SCOPE:
904 if (o->op_private & OPpREFCOUNTED)
905 Perl_dump_indent(aTHX_ level, file, "REFCNT = %"UVuf"\n", (UV)o->op_targ);
906 break;
a0d0e21e
LW
907 default:
908 break;
79072805 909 }
11343788 910 if (o->op_flags & OPf_KIDS) {
79072805 911 OP *kid;
11343788 912 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
3967c732 913 do_op_dump(level, file, kid);
8d063cd8 914 }
cea2e8a9 915 Perl_dump_indent(aTHX_ level-1, file, "}\n");
3967c732
JD
916}
917
918void
6867be6d 919Perl_op_dump(pTHX_ const OP *o)
3967c732
JD
920{
921 do_op_dump(0, Perl_debug_log, o);
8d063cd8
LW
922}
923
8adcabd8 924void
864dbfa3 925Perl_gv_dump(pTHX_ GV *gv)
378cc40b 926{
79072805 927 SV *sv;
378cc40b 928
79072805 929 if (!gv) {
760ac839 930 PerlIO_printf(Perl_debug_log, "{}\n");
378cc40b
LW
931 return;
932 }
8990e307 933 sv = sv_newmortal();
760ac839 934 PerlIO_printf(Perl_debug_log, "{\n");
bd61b366 935 gv_fullname3(sv, gv, NULL);
b15aece3 936 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s", SvPVX_const(sv));
79072805 937 if (gv != GvEGV(gv)) {
bd61b366 938 gv_efullname3(sv, GvEGV(gv), NULL);
b15aece3 939 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s", SvPVX_const(sv));
8adcabd8 940 }
3967c732 941 PerlIO_putc(Perl_debug_log, '\n');
cea2e8a9 942 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "}\n");
8d063cd8
LW
943}
944
14befaf4 945
afe38520 946/* map magic types to the symbolic names
14befaf4
DM
947 * (with the PERL_MAGIC_ prefixed stripped)
948 */
949
27da23d5 950static const struct { const char type; const char *name; } magic_names[] = {
516a5887
JH
951 { PERL_MAGIC_sv, "sv(\\0)" },
952 { PERL_MAGIC_arylen, "arylen(#)" },
ca732855 953 { PERL_MAGIC_rhash, "rhash(%)" },
516a5887 954 { PERL_MAGIC_pos, "pos(.)" },
8d2f4536 955 { PERL_MAGIC_symtab, "symtab(:)" },
516a5887 956 { PERL_MAGIC_backref, "backref(<)" },
a3874608 957 { PERL_MAGIC_arylen_p, "arylen_p(@)" },
516a5887
JH
958 { PERL_MAGIC_overload, "overload(A)" },
959 { PERL_MAGIC_bm, "bm(B)" },
960 { PERL_MAGIC_regdata, "regdata(D)" },
961 { PERL_MAGIC_env, "env(E)" },
b3ca2e83 962 { PERL_MAGIC_hints, "hints(H)" },
516a5887
JH
963 { PERL_MAGIC_isa, "isa(I)" },
964 { PERL_MAGIC_dbfile, "dbfile(L)" },
afe38520 965 { PERL_MAGIC_shared, "shared(N)" },
516a5887
JH
966 { PERL_MAGIC_tied, "tied(P)" },
967 { PERL_MAGIC_sig, "sig(S)" },
968 { PERL_MAGIC_uvar, "uvar(U)" },
969 { PERL_MAGIC_overload_elem, "overload_elem(a)" },
970 { PERL_MAGIC_overload_table, "overload_table(c)" },
971 { PERL_MAGIC_regdatum, "regdatum(d)" },
972 { PERL_MAGIC_envelem, "envelem(e)" },
973 { PERL_MAGIC_fm, "fm(f)" },
974 { PERL_MAGIC_regex_global, "regex_global(g)" },
b3ca2e83 975 { PERL_MAGIC_hintselem, "hintselem(h)" },
516a5887
JH
976 { PERL_MAGIC_isaelem, "isaelem(i)" },
977 { PERL_MAGIC_nkeys, "nkeys(k)" },
978 { PERL_MAGIC_dbline, "dbline(l)" },
979 { PERL_MAGIC_mutex, "mutex(m)" },
afe38520 980 { PERL_MAGIC_shared_scalar, "shared_scalar(n)" },
516a5887
JH
981 { PERL_MAGIC_collxfrm, "collxfrm(o)" },
982 { PERL_MAGIC_tiedelem, "tiedelem(p)" },
983 { PERL_MAGIC_tiedscalar, "tiedscalar(q)" },
984 { PERL_MAGIC_qr, "qr(r)" },
985 { PERL_MAGIC_sigelem, "sigelem(s)" },
986 { PERL_MAGIC_taint, "taint(t)" },
afe38520 987 { PERL_MAGIC_uvar_elem, "uvar_elem(v)" },
516a5887 988 { PERL_MAGIC_vec, "vec(v)" },
cb50f42d 989 { PERL_MAGIC_vstring, "vstring(V)" },
7e8c5dac 990 { PERL_MAGIC_utf8, "utf8(w)" },
516a5887
JH
991 { PERL_MAGIC_substr, "substr(x)" },
992 { PERL_MAGIC_defelem, "defelem(y)" },
993 { PERL_MAGIC_ext, "ext(~)" },
994 /* this null string terminates the list */
995 { 0, 0 },
14befaf4
DM
996};
997
8adcabd8 998void
6867be6d 999Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, const MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
8d063cd8 1000{
3967c732 1001 for (; mg; mg = mg->mg_moremagic) {
b900a521
JH
1002 Perl_dump_indent(aTHX_ level, file,
1003 " MAGIC = 0x%"UVxf"\n", PTR2UV(mg));
3967c732 1004 if (mg->mg_virtual) {
bfed75c6 1005 const MGVTBL * const v = mg->mg_virtual;
c445ea15 1006 const char *s = NULL;
3967c732
JD
1007 if (v == &PL_vtbl_sv) s = "sv";
1008 else if (v == &PL_vtbl_env) s = "env";
1009 else if (v == &PL_vtbl_envelem) s = "envelem";
1010 else if (v == &PL_vtbl_sig) s = "sig";
1011 else if (v == &PL_vtbl_sigelem) s = "sigelem";
1012 else if (v == &PL_vtbl_pack) s = "pack";
1013 else if (v == &PL_vtbl_packelem) s = "packelem";
1014 else if (v == &PL_vtbl_dbline) s = "dbline";
1015 else if (v == &PL_vtbl_isa) s = "isa";
1016 else if (v == &PL_vtbl_arylen) s = "arylen";
3967c732
JD
1017 else if (v == &PL_vtbl_mglob) s = "mglob";
1018 else if (v == &PL_vtbl_nkeys) s = "nkeys";
1019 else if (v == &PL_vtbl_taint) s = "taint";
1020 else if (v == &PL_vtbl_substr) s = "substr";
1021 else if (v == &PL_vtbl_vec) s = "vec";
1022 else if (v == &PL_vtbl_pos) s = "pos";
1023 else if (v == &PL_vtbl_bm) s = "bm";
1024 else if (v == &PL_vtbl_fm) s = "fm";
1025 else if (v == &PL_vtbl_uvar) s = "uvar";
1026 else if (v == &PL_vtbl_defelem) s = "defelem";
1027#ifdef USE_LOCALE_COLLATE
1028 else if (v == &PL_vtbl_collxfrm) s = "collxfrm";
1029#endif
3967c732
JD
1030 else if (v == &PL_vtbl_amagic) s = "amagic";
1031 else if (v == &PL_vtbl_amagicelem) s = "amagicelem";
810b8aa5 1032 else if (v == &PL_vtbl_backref) s = "backref";
7e8c5dac 1033 else if (v == &PL_vtbl_utf8) s = "utf8";
83bf042f 1034 else if (v == &PL_vtbl_arylen_p) s = "arylen_p";
b3ca2e83 1035 else if (v == &PL_vtbl_hintselem) s = "hintselem";
3967c732 1036 if (s)
cea2e8a9 1037 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", s);
3967c732 1038 else
b900a521 1039 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0x%"UVxf"\n", PTR2UV(v));
3967c732
JD
1040 }
1041 else
cea2e8a9 1042 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0\n");
8d063cd8 1043
3967c732 1044 if (mg->mg_private)
cea2e8a9 1045 Perl_dump_indent(aTHX_ level, file, " MG_PRIVATE = %d\n", mg->mg_private);
3967c732 1046
14befaf4
DM
1047 {
1048 int n;
c445ea15 1049 const char *name = NULL;
27da23d5 1050 for (n = 0; magic_names[n].name; n++) {
14befaf4
DM
1051 if (mg->mg_type == magic_names[n].type) {
1052 name = magic_names[n].name;
1053 break;
1054 }
1055 }
1056 if (name)
1057 Perl_dump_indent(aTHX_ level, file,
1058 " MG_TYPE = PERL_MAGIC_%s\n", name);
1059 else
1060 Perl_dump_indent(aTHX_ level, file,
1061 " MG_TYPE = UNKNOWN(\\%o)\n", mg->mg_type);
1062 }
3967c732
JD
1063
1064 if (mg->mg_flags) {
cea2e8a9 1065 Perl_dump_indent(aTHX_ level, file, " MG_FLAGS = 0x%02X\n", mg->mg_flags);
cb50f42d
YST
1066 if (mg->mg_type == PERL_MAGIC_envelem &&
1067 mg->mg_flags & MGf_TAINTEDDIR)
cea2e8a9 1068 Perl_dump_indent(aTHX_ level, file, " TAINTEDDIR\n");
3967c732 1069 if (mg->mg_flags & MGf_REFCOUNTED)
cea2e8a9 1070 Perl_dump_indent(aTHX_ level, file, " REFCOUNTED\n");
3967c732 1071 if (mg->mg_flags & MGf_GSKIP)
cea2e8a9 1072 Perl_dump_indent(aTHX_ level, file, " GSKIP\n");
cb50f42d
YST
1073 if (mg->mg_type == PERL_MAGIC_regex_global &&
1074 mg->mg_flags & MGf_MINMATCH)
cea2e8a9 1075 Perl_dump_indent(aTHX_ level, file, " MINMATCH\n");
3967c732
JD
1076 }
1077 if (mg->mg_obj) {
b900a521 1078 Perl_dump_indent(aTHX_ level, file, " MG_OBJ = 0x%"UVxf"\n", PTR2UV(mg->mg_obj));
3967c732
JD
1079 if (mg->mg_flags & MGf_REFCOUNTED)
1080 do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
1081 }
1082 if (mg->mg_len)
894356b3 1083 Perl_dump_indent(aTHX_ level, file, " MG_LEN = %ld\n", (long)mg->mg_len);
3967c732 1084 if (mg->mg_ptr) {
b900a521 1085 Perl_dump_indent(aTHX_ level, file, " MG_PTR = 0x%"UVxf, PTR2UV(mg->mg_ptr));
3967c732 1086 if (mg->mg_len >= 0) {
7e8c5dac 1087 if (mg->mg_type != PERL_MAGIC_utf8) {
396482e1 1088 SV *sv = newSVpvs("");
7e8c5dac
HS
1089 PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim));
1090 SvREFCNT_dec(sv);
1091 }
3967c732
JD
1092 }
1093 else if (mg->mg_len == HEf_SVKEY) {
1094 PerlIO_puts(file, " => HEf_SVKEY\n");
1095 do_sv_dump(level+2, file, (SV*)((mg)->mg_ptr), nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
1096 continue;
1097 }
1098 else
1099 PerlIO_puts(file, " ???? - please notify IZ");
1100 PerlIO_putc(file, '\n');
1101 }
7e8c5dac
HS
1102 if (mg->mg_type == PERL_MAGIC_utf8) {
1103 STRLEN *cache = (STRLEN *) mg->mg_ptr;
1104 if (cache) {
1105 IV i;
1106 for (i = 0; i < PERL_MAGIC_UTF8_CACHESIZE; i++)
1107 Perl_dump_indent(aTHX_ level, file,
1108 " %2"IVdf": %"UVuf" -> %"UVuf"\n",
1109 i,
1110 (UV)cache[i * 2],
1111 (UV)cache[i * 2 + 1]);
1112 }
1113 }
378cc40b 1114 }
3967c732
JD
1115}
1116
1117void
6867be6d 1118Perl_magic_dump(pTHX_ const MAGIC *mg)
3967c732
JD
1119{
1120 do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0);
1121}
1122
1123void
e1ec3a88 1124Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, const char *name, HV *sv)
3967c732 1125{
bfcb3514 1126 const char *hvname;
b900a521 1127 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
bfcb3514
NC
1128 if (sv && (hvname = HvNAME_get(sv)))
1129 PerlIO_printf(file, "\t\"%s\"\n", hvname);
79072805 1130 else
3967c732
JD
1131 PerlIO_putc(file, '\n');
1132}
1133
1134void
e1ec3a88 1135Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
3967c732 1136{
b900a521 1137 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
3967c732
JD
1138 if (sv && GvNAME(sv))
1139 PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv));
c90c0ff4 1140 else
3967c732
JD
1141 PerlIO_putc(file, '\n');
1142}
1143
1144void
e1ec3a88 1145Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
3967c732 1146{
b900a521 1147 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
3967c732 1148 if (sv && GvNAME(sv)) {
bfcb3514 1149 const char *hvname;
3967c732 1150 PerlIO_printf(file, "\t\"");
bfcb3514
NC
1151 if (GvSTASH(sv) && (hvname = HvNAME_get(GvSTASH(sv))))
1152 PerlIO_printf(file, "%s\" :: \"", hvname);
3967c732 1153 PerlIO_printf(file, "%s\"\n", GvNAME(sv));
8d063cd8 1154 }
3967c732
JD
1155 else
1156 PerlIO_putc(file, '\n');
1157}
1158
1159void
864dbfa3 1160Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
3967c732 1161{
97aff369 1162 dVAR;
cea89e20 1163 SV *d;
e1ec3a88 1164 const char *s;
3967c732
JD
1165 U32 flags;
1166 U32 type;
1167
1168 if (!sv) {
cea2e8a9 1169 Perl_dump_indent(aTHX_ level, file, "SV = 0\n");
3967c732 1170 return;
378cc40b 1171 }
2ef28da1 1172
3967c732
JD
1173 flags = SvFLAGS(sv);
1174 type = SvTYPE(sv);
79072805 1175
cea89e20 1176 d = Perl_newSVpvf(aTHX_
57def98f 1177 "(0x%"UVxf") at 0x%"UVxf"\n%*s REFCNT = %"IVdf"\n%*s FLAGS = (",
56431972 1178 PTR2UV(SvANY(sv)), PTR2UV(sv),
894356b3
GS
1179 (int)(PL_dumpindent*level), "", (IV)SvREFCNT(sv),
1180 (int)(PL_dumpindent*level), "");
8d063cd8 1181
d9d18af6 1182 if (flags & SVs_PADSTALE) sv_catpv(d, "PADSTALE,");
3967c732
JD
1183 if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,");
1184 if (flags & SVs_PADMY) sv_catpv(d, "PADMY,");
1185 if (flags & SVs_TEMP) sv_catpv(d, "TEMP,");
1186 if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,");
1187 if (flags & SVs_GMG) sv_catpv(d, "GMG,");
1188 if (flags & SVs_SMG) sv_catpv(d, "SMG,");
1189 if (flags & SVs_RMG) sv_catpv(d, "RMG,");
4db58590 1190
3967c732
JD
1191 if (flags & SVf_IOK) sv_catpv(d, "IOK,");
1192 if (flags & SVf_NOK) sv_catpv(d, "NOK,");
1193 if (flags & SVf_POK) sv_catpv(d, "POK,");
810b8aa5
GS
1194 if (flags & SVf_ROK) {
1195 sv_catpv(d, "ROK,");
1196 if (SvWEAKREF(sv)) sv_catpv(d, "WEAKREF,");
1197 }
3967c732
JD
1198 if (flags & SVf_OOK) sv_catpv(d, "OOK,");
1199 if (flags & SVf_FAKE) sv_catpv(d, "FAKE,");
1200 if (flags & SVf_READONLY) sv_catpv(d, "READONLY,");
4db58590 1201
dd2eae66 1202 if (flags & SVf_AMAGIC) sv_catpv(d, "OVERLOAD,");
3967c732
JD
1203 if (flags & SVp_IOK) sv_catpv(d, "pIOK,");
1204 if (flags & SVp_NOK) sv_catpv(d, "pNOK,");
1205 if (flags & SVp_POK) sv_catpv(d, "pPOK,");
9660f481
DM
1206 if (flags & SVp_SCREAM && type != SVt_PVHV)
1207 sv_catpv(d, "SCREAM,");
3967c732
JD
1208
1209 switch (type) {
1210 case SVt_PVCV:
1211 case SVt_PVFM:
1212 if (CvANON(sv)) sv_catpv(d, "ANON,");
1213 if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
1214 if (CvCLONE(sv)) sv_catpv(d, "CLONE,");
1215 if (CvCLONED(sv)) sv_catpv(d, "CLONED,");
de3f1649 1216 if (CvCONST(sv)) sv_catpv(d, "CONST,");
3967c732 1217 if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,");
25da4f38 1218 if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,");
18f7acf9
TJ
1219 if (CvLVALUE(sv)) sv_catpv(d, "LVALUE,");
1220 if (CvMETHOD(sv)) sv_catpv(d, "METHOD,");
662a8415 1221 if (CvLOCKED(sv)) sv_catpv(d, "LOCKED,");
7dafbf52 1222 if (CvWEAKOUTSIDE(sv)) sv_catpv(d, "WEAKOUTSIDE,");
06492da6 1223 if (CvASSERTION(sv)) sv_catpv(d, "ASSERTION,");
3967c732
JD
1224 break;
1225 case SVt_PVHV:
1226 if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,");
1227 if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,");
19692e8d 1228 if (HvHASKFLAGS(sv)) sv_catpv(d, "HASKFLAGS,");
afce8e55 1229 if (HvREHASH(sv)) sv_catpv(d, "REHASH,");
9660f481 1230 if (flags & SVphv_CLONEABLE) sv_catpv(d, "CLONEABLE,");
3967c732 1231 break;
4ce457a6 1232 case SVt_PVGV: case SVt_PVLV:
3967c732
JD
1233 if (GvINTRO(sv)) sv_catpv(d, "INTRO,");
1234 if (GvMULTI(sv)) sv_catpv(d, "MULTI,");
7fb37951 1235 if (GvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
3967c732 1236 if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,");
12c18039 1237 if (GvIN_PAD(sv)) sv_catpv(d, "IN_PAD,");
00b1698f
NC
1238 if (SvPAD_OUR(sv)) sv_catpv(d, "OUR,");
1239 if (SvPAD_TYPED(sv)) sv_catpv(d, "TYPED,");
3967c732
JD
1240 if (GvIMPORTED(sv)) {
1241 sv_catpv(d, "IMPORT");
1242 if (GvIMPORTED(sv) == GVf_IMPORTED)
1243 sv_catpv(d, "ALL,");
1244 else {
1245 sv_catpv(d, "(");
1246 if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV");
1247 if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV");
1248 if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV");
1249 if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV");
1250 sv_catpv(d, " ),");
1251 }
1252 }
addd1794 1253 /* FALL THROUGH */
25da4f38
IZ
1254 default:
1255 if (SvEVALED(sv)) sv_catpv(d, "EVALED,");
69c678eb 1256 if (SvIsUV(sv) && !(flags & SVf_ROK)) sv_catpv(d, "IsUV,");
25da4f38 1257 break;
3967c732
JD
1258 case SVt_PVBM:
1259 if (SvTAIL(sv)) sv_catpv(d, "TAIL,");
25da4f38 1260 if (SvVALID(sv)) sv_catpv(d, "VALID,");
3967c732 1261 break;
addd1794 1262 case SVt_PVMG:
00b1698f 1263 if (SvPAD_TYPED(sv)) sv_catpv(d, "TYPED,");
addd1794 1264 break;
11ca45c0
NC
1265 case SVt_PVAV:
1266 break;
3967c732 1267 }
86f0d186
NC
1268 /* SVphv_SHAREKEYS is also 0x20000000 */
1269 if ((type != SVt_PVHV) && SvUTF8(sv))
9fe74ede 1270 sv_catpv(d, "UTF8");
3967c732 1271
b162af07
SP
1272 if (*(SvEND(d) - 1) == ',') {
1273 SvCUR_set(d, SvCUR(d) - 1);
1274 SvPVX(d)[SvCUR(d)] = '\0';
1275 }
3967c732 1276 sv_catpv(d, ")");
b15aece3 1277 s = SvPVX_const(d);
3967c732 1278
fd0854ff
DM
1279#ifdef DEBUG_LEAKING_SCALARS
1280 Perl_dump_indent(aTHX_ level, file, "ALLOCATED at %s:%d %s %s%s\n",
1281 sv->sv_debug_file ? sv->sv_debug_file : "(unknown)",
1282 sv->sv_debug_line,
1283 sv->sv_debug_inpad ? "for" : "by",
1284 sv->sv_debug_optype ? PL_op_name[sv->sv_debug_optype]: "(none)",
1285 sv->sv_debug_cloned ? " (cloned)" : "");
1286#endif
cea2e8a9 1287 Perl_dump_indent(aTHX_ level, file, "SV = ");
3967c732
JD
1288 switch (type) {
1289 case SVt_NULL:
1290 PerlIO_printf(file, "NULL%s\n", s);
cea89e20 1291 SvREFCNT_dec(d);
3967c732
JD
1292 return;
1293 case SVt_IV:
1294 PerlIO_printf(file, "IV%s\n", s);
1295 break;
1296 case SVt_NV:
1297 PerlIO_printf(file, "NV%s\n", s);
1298 break;
1299 case SVt_RV:
1300 PerlIO_printf(file, "RV%s\n", s);
1301 break;
1302 case SVt_PV:
1303 PerlIO_printf(file, "PV%s\n", s);
1304 break;
1305 case SVt_PVIV:
1306 PerlIO_printf(file, "PVIV%s\n", s);
1307 break;
1308 case SVt_PVNV:
1309 PerlIO_printf(file, "PVNV%s\n", s);
1310 break;
1311 case SVt_PVBM:
1312 PerlIO_printf(file, "PVBM%s\n", s);
1313 break;
1314 case SVt_PVMG:
1315 PerlIO_printf(file, "PVMG%s\n", s);
1316 break;
1317 case SVt_PVLV:
1318 PerlIO_printf(file, "PVLV%s\n", s);
1319 break;
1320 case SVt_PVAV:
1321 PerlIO_printf(file, "PVAV%s\n", s);
1322 break;
1323 case SVt_PVHV:
1324 PerlIO_printf(file, "PVHV%s\n", s);
1325 break;
1326 case SVt_PVCV:
1327 PerlIO_printf(file, "PVCV%s\n", s);
1328 break;
1329 case SVt_PVGV:
1330 PerlIO_printf(file, "PVGV%s\n", s);
1331 break;
1332 case SVt_PVFM:
1333 PerlIO_printf(file, "PVFM%s\n", s);
1334 break;
1335 case SVt_PVIO:
1336 PerlIO_printf(file, "PVIO%s\n", s);
1337 break;
1338 default:
faccc32b 1339 PerlIO_printf(file, "UNKNOWN(0x%"UVxf") %s\n", (UV)type, s);
cea89e20 1340 SvREFCNT_dec(d);
3967c732
JD
1341 return;
1342 }
27bd069f
NC
1343 if ((type >= SVt_PVIV && type != SVt_PVAV && type != SVt_PVHV
1344 && type != SVt_PVCV && !isGV_with_GP(sv))
1345 || type == SVt_IV) {
765f542d 1346 if (SvIsUV(sv)
f8c7b90f 1347#ifdef PERL_OLD_COPY_ON_WRITE
765f542d
NC
1348 || SvIsCOW(sv)
1349#endif
1350 )
57def98f 1351 Perl_dump_indent(aTHX_ level, file, " UV = %"UVuf, (UV)SvUVX(sv));
cf2093f6 1352 else
57def98f 1353 Perl_dump_indent(aTHX_ level, file, " IV = %"IVdf, (IV)SvIVX(sv));
3967c732
JD
1354 if (SvOOK(sv))
1355 PerlIO_printf(file, " (OFFSET)");
f8c7b90f 1356#ifdef PERL_OLD_COPY_ON_WRITE
765f542d
NC
1357 if (SvIsCOW_shared_hash(sv))
1358 PerlIO_printf(file, " (HASH)");
1359 else if (SvIsCOW_normal(sv))
1360 PerlIO_printf(file, " (COW from 0x%"UVxf")", (UV)SvUVX(sv));
1361#endif
3967c732
JD
1362 PerlIO_putc(file, '\n');
1363 }
8a27f21b 1364 if ((type >= SVt_PVNV && type != SVt_PVAV && type != SVt_PVHV
27bd069f 1365 && type != SVt_PVCV && type != SVt_PVFM && !isGV_with_GP(sv))
e4305a63 1366 || type == SVt_NV) {
e54dc35b 1367 STORE_NUMERIC_LOCAL_SET_STANDARD();
57def98f 1368 /* %Vg doesn't work? --jhi */
cf2093f6 1369#ifdef USE_LONG_DOUBLE
2d4389e4 1370 Perl_dump_indent(aTHX_ level, file, " NV = %.*" PERL_PRIgldbl "\n", LDBL_DIG, SvNVX(sv));
cf2093f6 1371#else
cea2e8a9 1372 Perl_dump_indent(aTHX_ level, file, " NV = %.*g\n", DBL_DIG, SvNVX(sv));
cf2093f6 1373#endif
e54dc35b 1374 RESTORE_NUMERIC_LOCAL();
3967c732
JD
1375 }
1376 if (SvROK(sv)) {
57def98f 1377 Perl_dump_indent(aTHX_ level, file, " RV = 0x%"UVxf"\n", PTR2UV(SvRV(sv)));
3967c732
JD
1378 if (nest < maxnest)
1379 do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim);
3967c732 1380 }
cea89e20
JH
1381 if (type < SVt_PV) {
1382 SvREFCNT_dec(d);
3967c732 1383 return;
cea89e20 1384 }
f7877b28 1385 if (type <= SVt_PVLV && !isGV_with_GP(sv)) {
b15aece3
SP
1386 if (SvPVX_const(sv)) {
1387 Perl_dump_indent(aTHX_ level, file," PV = 0x%"UVxf" ", PTR2UV(SvPVX_const(sv)));
3967c732 1388 if (SvOOK(sv))
b15aece3
SP
1389 PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX_const(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim));
1390 PerlIO_printf(file, "%s", pv_display(d, SvPVX_const(sv), SvCUR(sv), SvLEN(sv), pvlim));
e6abe6d8 1391 if (SvUTF8(sv)) /* the 8? \x{....} */
c728cb41 1392 PerlIO_printf(file, " [UTF8 \"%s\"]", sv_uni_display(d, sv, 8 * sv_len_utf8(sv), UNI_DISPLAY_QQ));
e6abe6d8 1393 PerlIO_printf(file, "\n");
57def98f
JH
1394 Perl_dump_indent(aTHX_ level, file, " CUR = %"IVdf"\n", (IV)SvCUR(sv));
1395 Perl_dump_indent(aTHX_ level, file, " LEN = %"IVdf"\n", (IV)SvLEN(sv));
3967c732
JD
1396 }
1397 else
cea2e8a9 1398 Perl_dump_indent(aTHX_ level, file, " PV = 0\n");
3967c732
JD
1399 }
1400 if (type >= SVt_PVMG) {
1401 if (SvMAGIC(sv))
1402 do_magic_dump(level, file, SvMAGIC(sv), nest, maxnest, dumpops, pvlim);
1403 if (SvSTASH(sv))
1404 do_hv_dump(level, file, " STASH", SvSTASH(sv));
1405 }
1406 switch (type) {
3967c732 1407 case SVt_PVAV:
57def98f 1408 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(AvARRAY(sv)));
3967c732 1409 if (AvARRAY(sv) != AvALLOC(sv)) {
57def98f
JH
1410 PerlIO_printf(file, " (offset=%"IVdf")\n", (IV)(AvARRAY(sv) - AvALLOC(sv)));
1411 Perl_dump_indent(aTHX_ level, file, " ALLOC = 0x%"UVxf"\n", PTR2UV(AvALLOC(sv)));
3967c732
JD
1412 }
1413 else
1414 PerlIO_putc(file, '\n');
57def98f
JH
1415 Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)AvFILLp(sv));
1416 Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)AvMAX(sv));
a3874608 1417 Perl_dump_indent(aTHX_ level, file, " ARYLEN = 0x%"UVxf"\n", SvMAGIC(sv) ? PTR2UV(AvARYLEN(sv)) : 0);
c69006e4 1418 sv_setpvn(d, "", 0);
11ca45c0
NC
1419 if (AvREAL(sv)) sv_catpv(d, ",REAL");
1420 if (AvREIFY(sv)) sv_catpv(d, ",REIFY");
b15aece3
SP
1421 Perl_dump_indent(aTHX_ level, file, " FLAGS = (%s)\n",
1422 SvCUR(d) ? SvPVX_const(d) + 1 : "");
3967c732
JD
1423 if (nest < maxnest && av_len((AV*)sv) >= 0) {
1424 int count;
1425 for (count = 0; count <= av_len((AV*)sv) && count < maxnest; count++) {
1426 SV** elt = av_fetch((AV*)sv,count,0);
1427
57def98f 1428 Perl_dump_indent(aTHX_ level + 1, file, "Elt No. %"IVdf"\n", (IV)count);
2ef28da1 1429 if (elt)
3967c732
JD
1430 do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim);
1431 }
1432 }
1433 break;
1434 case SVt_PVHV:
57def98f 1435 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv)));
3967c732
JD
1436 if (HvARRAY(sv) && HvKEYS(sv)) {
1437 /* Show distribution of HEs in the ARRAY */
1438 int freq[200];
1439#define FREQ_MAX (sizeof freq / sizeof freq[0] - 1)
1440 int i;
1441 int max = 0;
1442 U32 pow2 = 2, keys = HvKEYS(sv);
65202027 1443 NV theoret, sum = 0;
3967c732
JD
1444
1445 PerlIO_printf(file, " (");
1446 Zero(freq, FREQ_MAX + 1, int);
eb160463 1447 for (i = 0; (STRLEN)i <= HvMAX(sv); i++) {
c445ea15
AL
1448 HE* h;
1449 int count = 0;
3967c732
JD
1450 for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h))
1451 count++;
1452 if (count > FREQ_MAX)
1453 count = FREQ_MAX;
1454 freq[count]++;
1455 if (max < count)
1456 max = count;
1457 }
1458 for (i = 0; i <= max; i++) {
1459 if (freq[i]) {
1460 PerlIO_printf(file, "%d%s:%d", i,
1461 (i == FREQ_MAX) ? "+" : "",
1462 freq[i]);
1463 if (i != max)
1464 PerlIO_printf(file, ", ");
1465 }
1466 }
1467 PerlIO_putc(file, ')');
b8fa94d8
MG
1468 /* The "quality" of a hash is defined as the total number of
1469 comparisons needed to access every element once, relative
1470 to the expected number needed for a random hash.
1471
1472 The total number of comparisons is equal to the sum of
e76cd0fa
AMS
1473 the squares of the number of entries in each bucket.
1474 For a random hash of n keys into k buckets, the expected
b8fa94d8
MG
1475 value is
1476 n + n(n-1)/2k
1477 */
1478
3967c732
JD
1479 for (i = max; i > 0; i--) { /* Precision: count down. */
1480 sum += freq[i] * i * i;
1481 }
155aba94 1482 while ((keys = keys >> 1))
3967c732 1483 pow2 = pow2 << 1;
3967c732 1484 theoret = HvKEYS(sv);
b8fa94d8 1485 theoret += theoret * (theoret-1)/pow2;
3967c732 1486 PerlIO_putc(file, '\n');
6b4667fc 1487 Perl_dump_indent(aTHX_ level, file, " hash quality = %.1"NVff"%%", theoret/sum*100);
3967c732
JD
1488 }
1489 PerlIO_putc(file, '\n');
57def98f
JH
1490 Perl_dump_indent(aTHX_ level, file, " KEYS = %"IVdf"\n", (IV)HvKEYS(sv));
1491 Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)HvFILL(sv));
1492 Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)HvMAX(sv));
bfcb3514
NC
1493 Perl_dump_indent(aTHX_ level, file, " RITER = %"IVdf"\n", (IV)HvRITER_get(sv));
1494 Perl_dump_indent(aTHX_ level, file, " EITER = 0x%"UVxf"\n", PTR2UV(HvEITER_get(sv)));
8d2f4536
NC
1495 {
1496 MAGIC *mg = mg_find(sv, PERL_MAGIC_symtab);
1497 if (mg && mg->mg_obj) {
1498 Perl_dump_indent(aTHX_ level, file, " PMROOT = 0x%"UVxf"\n", PTR2UV(mg->mg_obj));
1499 }
1500 }
bfcb3514
NC
1501 {
1502 const char *hvname = HvNAME_get(sv);
1503 if (hvname)
1504 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", hvname);
1505 }
86f55936
NC
1506 if (SvOOK(sv)) {
1507 AV *backrefs = *Perl_hv_backreferences_p(aTHX_ (HV*)sv);
1508 if (backrefs) {
1509 Perl_dump_indent(aTHX_ level, file, " BACKREFS = 0x%"UVxf"\n",
1510 PTR2UV(backrefs));
1511 do_sv_dump(level+1, file, (SV*)backrefs, nest+1, maxnest,
1512 dumpops, pvlim);
1513 }
1514 }
bfcb3514 1515 if (nest < maxnest && !HvEITER_get(sv)) { /* Try to preserve iterator */
3967c732 1516 HE *he;
7a5b473e 1517 HV * const hv = (HV*)sv;
3967c732
JD
1518 int count = maxnest - nest;
1519
1520 hv_iterinit(hv);
e16e2ff8
NC
1521 while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))
1522 && count--) {
98c991d1 1523 SV *elt, *keysv;
e1ec3a88 1524 const char *keypv;
98c991d1 1525 STRLEN len;
7a5b473e 1526 const U32 hash = HeHASH(he);
3967c732 1527
98c991d1 1528 keysv = hv_iterkeysv(he);
93524f2b 1529 keypv = SvPV_const(keysv, len);
3967c732 1530 elt = hv_iterval(hv, he);
98c991d1
JH
1531 Perl_dump_indent(aTHX_ level+1, file, "Elt %s ", pv_display(d, keypv, len, 0, pvlim));
1532 if (SvUTF8(keysv))
c728cb41 1533 PerlIO_printf(file, "[UTF8 \"%s\"] ", sv_uni_display(d, keysv, 8 * sv_len_utf8(keysv), UNI_DISPLAY_QQ));
afce8e55
NC
1534 if (HeKREHASH(he))
1535 PerlIO_printf(file, "[REHASH] ");
98c991d1 1536 PerlIO_printf(file, "HASH = 0x%"UVxf"\n", (UV)hash);
3967c732
JD
1537 do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim);
1538 }
1539 hv_iterinit(hv); /* Return to status quo */
1540 }
1541 break;
1542 case SVt_PVCV:
1543 if (SvPOK(sv))
93524f2b 1544 Perl_dump_indent(aTHX_ level, file, " PROTOTYPE = \"%s\"\n", SvPV_nolen_const(sv));
3967c732
JD
1545 /* FALL THROUGH */
1546 case SVt_PVFM:
1547 do_hv_dump(level, file, " COMP_STASH", CvSTASH(sv));
d04ba589
NC
1548 if (!CvISXSUB(sv)) {
1549 if (CvSTART(sv)) {
1550 Perl_dump_indent(aTHX_ level, file,
1551 " START = 0x%"UVxf" ===> %"IVdf"\n",
1552 PTR2UV(CvSTART(sv)),
1553 (IV)sequence_num(CvSTART(sv)));
1554 }
1555 Perl_dump_indent(aTHX_ level, file, " ROOT = 0x%"UVxf"\n",
1556 PTR2UV(CvROOT(sv)));
1557 if (CvROOT(sv) && dumpops) {
1558 do_op_dump(level+1, file, CvROOT(sv));
1559 }
1560 } else {
b1886099
NC
1561 SV *constant = cv_const_sv((CV *)sv);
1562
d04ba589 1563 Perl_dump_indent(aTHX_ level, file, " XSUB = 0x%"UVxf"\n", PTR2UV(CvXSUB(sv)));
b1886099
NC
1564
1565 if (constant) {
1566 Perl_dump_indent(aTHX_ level, file, " XSUBANY = 0x%"UVxf
1567 " (CONST SV)\n",
1568 PTR2UV(CvXSUBANY(sv).any_ptr));
1569 do_sv_dump(level+1, file, constant, nest+1, maxnest, dumpops,
1570 pvlim);
1571 } else {
1572 Perl_dump_indent(aTHX_ level, file, " XSUBANY = %"IVdf"\n",
1573 (IV)CvXSUBANY(sv).any_i32);
1574 }
1575 }
3967c732 1576 do_gvgv_dump(level, file, " GVGV::GV", CvGV(sv));
57843af0 1577 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", CvFILE(sv));
57def98f 1578 Perl_dump_indent(aTHX_ level, file, " DEPTH = %"IVdf"\n", (IV)CvDEPTH(sv));
894356b3 1579 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)CvFLAGS(sv));
a3985cdc 1580 Perl_dump_indent(aTHX_ level, file, " OUTSIDE_SEQ = %"UVuf"\n", (UV)CvOUTSIDE_SEQ(sv));
3967c732 1581 if (type == SVt_PVFM)
57def98f
JH
1582 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)FmLINES(sv));
1583 Perl_dump_indent(aTHX_ level, file, " PADLIST = 0x%"UVxf"\n", PTR2UV(CvPADLIST(sv)));
dd2155a4
DM
1584 if (nest < maxnest) {
1585 do_dump_pad(level+1, file, CvPADLIST(sv), 0);
3967c732
JD
1586 }
1587 {
e1ec3a88 1588 const CV *outside = CvOUTSIDE(sv);
2ef28da1 1589 Perl_dump_indent(aTHX_ level, file, " OUTSIDE = 0x%"UVxf" (%s)\n",
57def98f 1590 PTR2UV(outside),
cf2093f6
JH
1591 (!outside ? "null"
1592 : CvANON(outside) ? "ANON"
1593 : (outside == PL_main_cv) ? "MAIN"
1594 : CvUNIQUE(outside) ? "UNIQUE"
1595 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
3967c732
JD
1596 }
1597 if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv)))
1598 do_sv_dump(level+1, file, (SV*)CvOUTSIDE(sv), nest+1, maxnest, dumpops, pvlim);
1599 break;
4ce457a6
TP
1600 case SVt_PVGV: case SVt_PVLV:
1601 if (type == SVt_PVLV) {
1602 Perl_dump_indent(aTHX_ level, file, " TYPE = %c\n", LvTYPE(sv));
1603 Perl_dump_indent(aTHX_ level, file, " TARGOFF = %"IVdf"\n", (IV)LvTARGOFF(sv));
1604 Perl_dump_indent(aTHX_ level, file, " TARGLEN = %"IVdf"\n", (IV)LvTARGLEN(sv));
1605 Perl_dump_indent(aTHX_ level, file, " TARG = 0x%"UVxf"\n", PTR2UV(LvTARG(sv)));
1606 if (LvTYPE(sv) != 't' && LvTYPE(sv) != 'T')
1607 do_sv_dump(level+1, file, LvTARG(sv), nest+1, maxnest,
1608 dumpops, pvlim);
1609 }
cea2e8a9 1610 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", GvNAME(sv));
57def98f 1611 Perl_dump_indent(aTHX_ level, file, " NAMELEN = %"IVdf"\n", (IV)GvNAMELEN(sv));
3967c732 1612 do_hv_dump (level, file, " GvSTASH", GvSTASH(sv));
f7877b28
NC
1613 if (!isGV_with_GP(sv))
1614 break;
57def98f 1615 Perl_dump_indent(aTHX_ level, file, " GP = 0x%"UVxf"\n", PTR2UV(GvGP(sv)));
f472eb5c
GS
1616 if (!GvGP(sv))
1617 break;
57def98f
JH
1618 Perl_dump_indent(aTHX_ level, file, " SV = 0x%"UVxf"\n", PTR2UV(GvSV(sv)));
1619 Perl_dump_indent(aTHX_ level, file, " REFCNT = %"IVdf"\n", (IV)GvREFCNT(sv));
1620 Perl_dump_indent(aTHX_ level, file, " IO = 0x%"UVxf"\n", PTR2UV(GvIOp(sv)));
1621 Perl_dump_indent(aTHX_ level, file, " FORM = 0x%"UVxf" \n", PTR2UV(GvFORM(sv)));
1622 Perl_dump_indent(aTHX_ level, file, " AV = 0x%"UVxf"\n", PTR2UV(GvAV(sv)));
1623 Perl_dump_indent(aTHX_ level, file, " HV = 0x%"UVxf"\n", PTR2UV(GvHV(sv)));
1624 Perl_dump_indent(aTHX_ level, file, " CV = 0x%"UVxf"\n", PTR2UV(GvCV(sv)));
1625 Perl_dump_indent(aTHX_ level, file, " CVGEN = 0x%"UVxf"\n", (UV)GvCVGEN(sv));
57def98f 1626 Perl_dump_indent(aTHX_ level, file, " LINE = %"IVdf"\n", (IV)GvLINE(sv));
b195d487 1627 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", GvFILE(sv));
e39917cc 1628 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)GvFLAGS(sv));
3967c732
JD
1629 do_gv_dump (level, file, " EGV", GvEGV(sv));
1630 break;
1631 case SVt_PVIO:
57def98f
JH
1632 Perl_dump_indent(aTHX_ level, file, " IFP = 0x%"UVxf"\n", PTR2UV(IoIFP(sv)));
1633 Perl_dump_indent(aTHX_ level, file, " OFP = 0x%"UVxf"\n", PTR2UV(IoOFP(sv)));
1634 Perl_dump_indent(aTHX_ level, file, " DIRP = 0x%"UVxf"\n", PTR2UV(IoDIRP(sv)));
1635 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)IoLINES(sv));
1636 Perl_dump_indent(aTHX_ level, file, " PAGE = %"IVdf"\n", (IV)IoPAGE(sv));
1637 Perl_dump_indent(aTHX_ level, file, " PAGE_LEN = %"IVdf"\n", (IV)IoPAGE_LEN(sv));
1638 Perl_dump_indent(aTHX_ level, file, " LINES_LEFT = %"IVdf"\n", (IV)IoLINES_LEFT(sv));
27533608 1639 if (IoTOP_NAME(sv))
cea2e8a9 1640 Perl_dump_indent(aTHX_ level, file, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
9ba1f565
NC
1641 if (!IoTOP_GV(sv) || SvTYPE(IoTOP_GV(sv)) == SVt_PVGV)
1642 do_gv_dump (level, file, " TOP_GV", IoTOP_GV(sv));
1643 else {
1644 Perl_dump_indent(aTHX_ level, file, " TOP_GV = 0x%"UVxf"\n",
1645 PTR2UV(IoTOP_GV(sv)));
1646 do_sv_dump (level+1, file, (SV *) IoTOP_GV(sv), nest+1, maxnest,
1647 dumpops, pvlim);
1648 }
1649 /* Source filters hide things that are not GVs in these three, so let's
1650 be careful out there. */
27533608 1651 if (IoFMT_NAME(sv))
cea2e8a9 1652 Perl_dump_indent(aTHX_ level, file, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
9ba1f565
NC
1653 if (!IoFMT_GV(sv) || SvTYPE(IoFMT_GV(sv)) == SVt_PVGV)
1654 do_gv_dump (level, file, " FMT_GV", IoFMT_GV(sv));
1655 else {
1656 Perl_dump_indent(aTHX_ level, file, " FMT_GV = 0x%"UVxf"\n",
1657 PTR2UV(IoFMT_GV(sv)));
1658 do_sv_dump (level+1, file, (SV *) IoFMT_GV(sv), nest+1, maxnest,
1659 dumpops, pvlim);
1660 }
27533608 1661 if (IoBOTTOM_NAME(sv))
cea2e8a9 1662 Perl_dump_indent(aTHX_ level, file, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
9ba1f565
NC
1663 if (!IoBOTTOM_GV(sv) || SvTYPE(IoBOTTOM_GV(sv)) == SVt_PVGV)
1664 do_gv_dump (level, file, " BOTTOM_GV", IoBOTTOM_GV(sv));
1665 else {
1666 Perl_dump_indent(aTHX_ level, file, " BOTTOM_GV = 0x%"UVxf"\n",
1667 PTR2UV(IoBOTTOM_GV(sv)));
1668 do_sv_dump (level+1, file, (SV *) IoBOTTOM_GV(sv), nest+1, maxnest,
1669 dumpops, pvlim);
1670 }
57def98f 1671 Perl_dump_indent(aTHX_ level, file, " SUBPROCESS = %"IVdf"\n", (IV)IoSUBPROCESS(sv));
27533608 1672 if (isPRINT(IoTYPE(sv)))
cea2e8a9 1673 Perl_dump_indent(aTHX_ level, file, " TYPE = '%c'\n", IoTYPE(sv));
27533608 1674 else
cea2e8a9 1675 Perl_dump_indent(aTHX_ level, file, " TYPE = '\\%o'\n", IoTYPE(sv));
57def98f 1676 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)IoFLAGS(sv));
3967c732
JD
1677 break;
1678 }
cea89e20 1679 SvREFCNT_dec(d);
3967c732
JD
1680}
1681
1682void
864dbfa3 1683Perl_sv_dump(pTHX_ SV *sv)
3967c732 1684{
97aff369 1685 dVAR;
3967c732 1686 do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0);
8d063cd8 1687}
bd16a5f0
IZ
1688
1689int
1690Perl_runops_debug(pTHX)
1691{
97aff369 1692 dVAR;
bd16a5f0
IZ
1693 if (!PL_op) {
1694 if (ckWARN_d(WARN_DEBUGGING))
9014280d 1695 Perl_warner(aTHX_ packWARN(WARN_DEBUGGING), "NULL OP IN RUN");
bd16a5f0
IZ
1696 return 0;
1697 }
1698
9f3673fb 1699 DEBUG_l(Perl_deb(aTHX_ "Entering new RUNOPS level\n"));
bd16a5f0
IZ
1700 do {
1701 PERL_ASYNC_CHECK();
1702 if (PL_debug) {
1703 if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok)
1704 PerlIO_printf(Perl_debug_log,
1705 "WARNING: %"UVxf" changed from %"UVxf" to %"UVxf"\n",
1706 PTR2UV(PL_watchaddr), PTR2UV(PL_watchok),
1707 PTR2UV(*PL_watchaddr));
d6721266
DM
1708 if (DEBUG_s_TEST_) {
1709 if (DEBUG_v_TEST_) {
1710 PerlIO_printf(Perl_debug_log, "\n");
1711 deb_stack_all();
1712 }
1713 else
1714 debstack();
1715 }
1716
1717
bd16a5f0
IZ
1718 if (DEBUG_t_TEST_) debop(PL_op);
1719 if (DEBUG_P_TEST_) debprof(PL_op);
1720 }
1721 } while ((PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX)));
9f3673fb 1722 DEBUG_l(Perl_deb(aTHX_ "leaving RUNOPS level\n"));
bd16a5f0
IZ
1723
1724 TAINT_NOT;
1725 return 0;
1726}
1727
1728I32
6867be6d 1729Perl_debop(pTHX_ const OP *o)
bd16a5f0 1730{
97aff369 1731 dVAR;
1045810a
IZ
1732 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
1733 return 0;
1734
bd16a5f0
IZ
1735 Perl_deb(aTHX_ "%s", OP_NAME(o));
1736 switch (o->op_type) {
1737 case OP_CONST:
1738 PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo_sv));
1739 break;
1740 case OP_GVSV:
1741 case OP_GV:
1742 if (cGVOPo_gv) {
561b68a9 1743 SV *sv = newSV(0);
3b721df9
NC
1744#ifdef PERL_MAD
1745 /* FIXME - it this making unwarranted assumptions about the
1746 UTF-8 cleanliness of the dump file handle? */
1747 SvUTF8_on(sv);
1748#endif
bd61b366 1749 gv_fullname3(sv, cGVOPo_gv, NULL);
93524f2b 1750 PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv));
bd16a5f0
IZ
1751 SvREFCNT_dec(sv);
1752 }
1753 else
1754 PerlIO_printf(Perl_debug_log, "(NULL)");
1755 break;
1756 case OP_PADSV:
1757 case OP_PADAV:
1758 case OP_PADHV:
a3b680e6 1759 {
bd16a5f0 1760 /* print the lexical's name */
a3b680e6
AL
1761 CV *cv = deb_curcv(cxstack_ix);
1762 SV *sv;
bd16a5f0 1763 if (cv) {
b464bac0
AL
1764 AV * const padlist = CvPADLIST(cv);
1765 AV * const comppad = (AV*)(*av_fetch(padlist, 0, FALSE));
bd16a5f0
IZ
1766 sv = *av_fetch(comppad, o->op_targ, FALSE);
1767 } else
a0714e2c 1768 sv = NULL;
bd16a5f0 1769 if (sv)
93524f2b 1770 PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv));
bd16a5f0
IZ
1771 else
1772 PerlIO_printf(Perl_debug_log, "[%"UVuf"]", (UV)o->op_targ);
a3b680e6 1773 }
bd16a5f0
IZ
1774 break;
1775 default:
091ab601 1776 break;
bd16a5f0
IZ
1777 }
1778 PerlIO_printf(Perl_debug_log, "\n");
1779 return 0;
1780}
1781
1782STATIC CV*
1783S_deb_curcv(pTHX_ I32 ix)
1784{
97aff369 1785 dVAR;
e1ec3a88 1786 const PERL_CONTEXT *cx = &cxstack[ix];
bd16a5f0
IZ
1787 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT)
1788 return cx->blk_sub.cv;
1789 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
1790 return PL_compcv;
1791 else if (ix == 0 && PL_curstackinfo->si_type == PERLSI_MAIN)
1792 return PL_main_cv;
1793 else if (ix <= 0)
601f1833 1794 return NULL;
bd16a5f0
IZ
1795 else
1796 return deb_curcv(ix - 1);
1797}
1798
1799void
1800Perl_watch(pTHX_ char **addr)
1801{
97aff369 1802 dVAR;
bd16a5f0
IZ
1803 PL_watchaddr = addr;
1804 PL_watchok = *addr;
1805 PerlIO_printf(Perl_debug_log, "WATCHING, %"UVxf" is currently %"UVxf"\n",
1806 PTR2UV(PL_watchaddr), PTR2UV(PL_watchok));
1807}
1808
1809STATIC void
e1ec3a88 1810S_debprof(pTHX_ const OP *o)
bd16a5f0 1811{
97aff369 1812 dVAR;
1045810a
IZ
1813 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
1814 return;
bd16a5f0 1815 if (!PL_profiledata)
a02a5408 1816 Newxz(PL_profiledata, MAXO, U32);
bd16a5f0
IZ
1817 ++PL_profiledata[o->op_type];
1818}
1819
1820void
1821Perl_debprofdump(pTHX)
1822{
97aff369 1823 dVAR;
bd16a5f0
IZ
1824 unsigned i;
1825 if (!PL_profiledata)
1826 return;
1827 for (i = 0; i < MAXO; i++) {
1828 if (PL_profiledata[i])
1829 PerlIO_printf(Perl_debug_log,
1830 "%5lu %s\n", (unsigned long)PL_profiledata[i],
1831 PL_op_name[i]);
1832 }
1833}
66610fdd 1834
3b721df9
NC
1835#ifdef PERL_MAD
1836/*
1837 * XML variants of most of the above routines
1838 */
1839
1840STATIC
1841void
1842S_xmldump_attr(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
1843{
1844 va_list args;
1845 PerlIO_printf(file, "\n ");
1846 va_start(args, pat);
1847 xmldump_vindent(level, file, pat, &args);
1848 va_end(args);
1849}
1850
1851
1852void
1853Perl_xmldump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
1854{
1855 va_list args;
1856 va_start(args, pat);
1857 xmldump_vindent(level, file, pat, &args);
1858 va_end(args);
1859}
1860
1861void
1862Perl_xmldump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args)
1863{
1864 PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), "");
1865 PerlIO_vprintf(file, pat, *args);
1866}
1867
1868void
1869Perl_xmldump_all(pTHX)
1870{
1871 PerlIO_setlinebuf(PL_xmlfp);
1872 if (PL_main_root)
1873 op_xmldump(PL_main_root);
1874 if (PL_xmlfp != (PerlIO*)PerlIO_stdout())
1875 PerlIO_close(PL_xmlfp);
1876 PL_xmlfp = 0;
1877}
1878
1879void
1880Perl_xmldump_packsubs(pTHX_ const HV *stash)
1881{
1882 I32 i;
1883 HE *entry;
1884
1885 if (!HvARRAY(stash))
1886 return;
1887 for (i = 0; i <= (I32) HvMAX(stash); i++) {
1888 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
1889 GV *gv = (GV*)HeVAL(entry);
1890 HV *hv;
1891 if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
1892 continue;
1893 if (GvCVu(gv))
1894 xmldump_sub(gv);
1895 if (GvFORM(gv))
1896 xmldump_form(gv);
1897 if (HeKEY(entry)[HeKLEN(entry)-1] == ':'
1898 && (hv = GvHV(gv)) && hv != PL_defstash)
1899 xmldump_packsubs(hv); /* nested package */
1900 }
1901 }
1902}
1903
1904void
1905Perl_xmldump_sub(pTHX_ const GV *gv)
1906{
1907 SV *sv = sv_newmortal();
1908
1909 gv_fullname3(sv, gv, Nullch);
1910 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "\nSUB %s = ", SvPVX(sv));
1911 if (CvXSUB(GvCV(gv)))
1912 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "(xsub 0x%"UVxf" %d)\n",
1913 PTR2UV(CvXSUB(GvCV(gv))),
1914 (int)CvXSUBANY(GvCV(gv)).any_i32);
1915 else if (CvROOT(GvCV(gv)))
1916 op_xmldump(CvROOT(GvCV(gv)));
1917 else
1918 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "<undef>\n");
1919}
1920
1921void
1922Perl_xmldump_form(pTHX_ const GV *gv)
1923{
1924 SV *sv = sv_newmortal();
1925
1926 gv_fullname3(sv, gv, Nullch);
1927 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "\nFORMAT %s = ", SvPVX(sv));
1928 if (CvROOT(GvFORM(gv)))
1929 op_xmldump(CvROOT(GvFORM(gv)));
1930 else
1931 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "<undef>\n");
1932}
1933
1934void
1935Perl_xmldump_eval(pTHX)
1936{
1937 op_xmldump(PL_eval_root);
1938}
1939
1940char *
1941Perl_sv_catxmlsv(pTHX_ SV *dsv, SV *ssv)
1942{
1943 return sv_catxmlpvn(dsv, SvPVX(ssv), SvCUR(ssv), SvUTF8(ssv));
1944}
1945
1946char *
1947Perl_sv_catxmlpvn(pTHX_ SV *dsv, char* pv, STRLEN len, int utf8)
1948{
1949 unsigned int c;
1950 char *e = pv + len;
1951 char *start = pv;
1952 STRLEN dsvcur;
1953 STRLEN cl;
1954
1955 sv_catpvn(dsv,"",0);
1956 dsvcur = SvCUR(dsv); /* in case we have to restart */
1957
1958 retry:
1959 while (pv < e) {
1960 if (utf8) {
1961 c = utf8_to_uvchr((U8*)pv, &cl);
1962 if (cl == 0) {
1963 SvCUR(dsv) = dsvcur;
1964 pv = start;
1965 utf8 = 0;
1966 goto retry;
1967 }
1968 }
1969 else
1970 c = (*pv & 255);
1971
1972 switch (c) {
1973 case 0x00:
1974 case 0x01:
1975 case 0x02:
1976 case 0x03:
1977 case 0x04:
1978 case 0x05:
1979 case 0x06:
1980 case 0x07:
1981 case 0x08:
1982 case 0x0b:
1983 case 0x0c:
1984 case 0x0e:
1985 case 0x0f:
1986 case 0x10:
1987 case 0x11:
1988 case 0x12:
1989 case 0x13:
1990 case 0x14:
1991 case 0x15:
1992 case 0x16:
1993 case 0x17:
1994 case 0x18:
1995 case 0x19:
1996 case 0x1a:
1997 case 0x1b:
1998 case 0x1c:
1999 case 0x1d:
2000 case 0x1e:
2001 case 0x1f:
2002 case 0x7f:
2003 case 0x80:
2004 case 0x81:
2005 case 0x82:
2006 case 0x83:
2007 case 0x84:
2008 case 0x86:
2009 case 0x87:
2010 case 0x88:
2011 case 0x89:
2012 case 0x90:
2013 case 0x91:
2014 case 0x92:
2015 case 0x93:
2016 case 0x94:
2017 case 0x95:
2018 case 0x96:
2019 case 0x97:
2020 case 0x98:
2021 case 0x99:
2022 case 0x9a:
2023 case 0x9b:
2024 case 0x9c:
2025 case 0x9d:
2026 case 0x9e:
2027 case 0x9f:
2028 Perl_sv_catpvf(aTHX_ dsv, "STUPIDXML(#x%X)", c);
2029 break;
2030 case '<':
2031 Perl_sv_catpvf(aTHX_ dsv, "&lt;");
2032 break;
2033 case '>':
2034 Perl_sv_catpvf(aTHX_ dsv, "&gt;");
2035 break;
2036 case '&':
2037 Perl_sv_catpvf(aTHX_ dsv, "&amp;");
2038 break;
2039 case '"':
2040 Perl_sv_catpvf(aTHX_ dsv, "&#34;");
2041 break;
2042 default:
2043 if (c < 0xD800) {
2044 if (c < 32 || c > 127) {
2045 Perl_sv_catpvf(aTHX_ dsv, "&#x%X;", c);
2046 }
2047 else {
2048 Perl_sv_catpvf(aTHX_ dsv, "%c", c);
2049 }
2050 break;
2051 }
2052 if ((c >= 0xD800 && c <= 0xDB7F) ||
2053 (c >= 0xDC00 && c <= 0xDFFF) ||
2054 (c >= 0xFFF0 && c <= 0xFFFF) ||
2055 c > 0x10ffff)
2056 Perl_sv_catpvf(aTHX_ dsv, "STUPIDXML(#x%X)", c);
2057 else
2058 Perl_sv_catpvf(aTHX_ dsv, "&#x%X;", c);
2059 }
2060
2061 if (utf8)
2062 pv += UTF8SKIP(pv);
2063 else
2064 pv++;
2065 }
2066
2067 return SvPVX(dsv);
2068}
2069
2070char *
2071Perl_sv_xmlpeek(pTHX_ SV *sv)
2072{
2073 SV *t = sv_newmortal();
2074 STRLEN n_a;
2075 int unref = 0;
2076
2077 sv_utf8_upgrade(t);
2078 sv_setpvn(t, "", 0);
2079 /* retry: */
2080 if (!sv) {
2081 sv_catpv(t, "VOID=\"\"");
2082 goto finish;
2083 }
2084 else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') {
2085 sv_catpv(t, "WILD=\"\"");
2086 goto finish;
2087 }
2088 else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) {
2089 if (sv == &PL_sv_undef) {
2090 sv_catpv(t, "SV_UNDEF=\"1\"");
2091 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
2092 SVs_GMG|SVs_SMG|SVs_RMG)) &&
2093 SvREADONLY(sv))
2094 goto finish;
2095 }
2096 else if (sv == &PL_sv_no) {
2097 sv_catpv(t, "SV_NO=\"1\"");
2098 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
2099 SVs_GMG|SVs_SMG|SVs_RMG)) &&
2100 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
2101 SVp_POK|SVp_NOK)) &&
2102 SvCUR(sv) == 0 &&
2103 SvNVX(sv) == 0.0)
2104 goto finish;
2105 }
2106 else if (sv == &PL_sv_yes) {
2107 sv_catpv(t, "SV_YES=\"1\"");
2108 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
2109 SVs_GMG|SVs_SMG|SVs_RMG)) &&
2110 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
2111 SVp_POK|SVp_NOK)) &&
2112 SvCUR(sv) == 1 &&
2113 SvPVX(sv) && *SvPVX(sv) == '1' &&
2114 SvNVX(sv) == 1.0)
2115 goto finish;
2116 }
2117 else {
2118 sv_catpv(t, "SV_PLACEHOLDER=\"1\"");
2119 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
2120 SVs_GMG|SVs_SMG|SVs_RMG)) &&
2121 SvREADONLY(sv))
2122 goto finish;
2123 }
2124 sv_catpv(t, " XXX=\"\" ");
2125 }
2126 else if (SvREFCNT(sv) == 0) {
2127 sv_catpv(t, " refcnt=\"0\"");
2128 unref++;
2129 }
2130 else if (DEBUG_R_TEST_) {
2131 int is_tmp = 0;
2132 I32 ix;
2133 /* is this SV on the tmps stack? */
2134 for (ix=PL_tmps_ix; ix>=0; ix--) {
2135 if (PL_tmps_stack[ix] == sv) {
2136 is_tmp = 1;
2137 break;
2138 }
2139 }
2140 if (SvREFCNT(sv) > 1)
2141 Perl_sv_catpvf(aTHX_ t, " DRT=\"<%"UVuf"%s>\"", (UV)SvREFCNT(sv),
2142 is_tmp ? "T" : "");
2143 else if (is_tmp)
2144 sv_catpv(t, " DRT=\"<T>\"");
2145 }
2146
2147 if (SvROK(sv)) {
2148 sv_catpv(t, " ROK=\"\"");
2149 }
2150 switch (SvTYPE(sv)) {
2151 default:
2152 sv_catpv(t, " FREED=\"1\"");
2153 goto finish;
2154
2155 case SVt_NULL:
2156 sv_catpv(t, " UNDEF=\"1\"");
2157 goto finish;
2158 case SVt_IV:
2159 sv_catpv(t, " IV=\"");
2160 break;
2161 case SVt_NV:
2162 sv_catpv(t, " NV=\"");
2163 break;
2164 case SVt_RV:
2165 sv_catpv(t, " RV=\"");
2166 break;
2167 case SVt_PV:
2168 sv_catpv(t, " PV=\"");
2169 break;
2170 case SVt_PVIV:
2171 sv_catpv(t, " PVIV=\"");
2172 break;
2173 case SVt_PVNV:
2174 sv_catpv(t, " PVNV=\"");
2175 break;
2176 case SVt_PVMG:
2177 sv_catpv(t, " PVMG=\"");
2178 break;
2179 case SVt_PVLV:
2180 sv_catpv(t, " PVLV=\"");
2181 break;
2182 case SVt_PVAV:
2183 sv_catpv(t, " AV=\"");
2184 break;
2185 case SVt_PVHV:
2186 sv_catpv(t, " HV=\"");
2187 break;
2188 case SVt_PVCV:
2189 if (CvGV(sv))
2190 Perl_sv_catpvf(aTHX_ t, " CV=\"(%s)\"", GvNAME(CvGV(sv)));
2191 else
2192 sv_catpv(t, " CV=\"()\"");
2193 goto finish;
2194 case SVt_PVGV:
2195 sv_catpv(t, " GV=\"");
2196 break;
2197 case SVt_PVBM:
2198 sv_catpv(t, " BM=\"");
2199 break;
2200 case SVt_PVFM:
2201 sv_catpv(t, " FM=\"");
2202 break;
2203 case SVt_PVIO:
2204 sv_catpv(t, " IO=\"");
2205 break;
2206 }
2207
2208 if (SvPOKp(sv)) {
2209 if (SvPVX(sv)) {
2210 sv_catxmlsv(t, sv);
2211 }
2212 }
2213 else if (SvNOKp(sv)) {
2214 STORE_NUMERIC_LOCAL_SET_STANDARD();
2215 Perl_sv_catpvf(aTHX_ t, "%"NVgf"",SvNVX(sv));
2216 RESTORE_NUMERIC_LOCAL();
2217 }
2218 else if (SvIOKp(sv)) {
2219 if (SvIsUV(sv))
2220 Perl_sv_catpvf(aTHX_ t, "%"UVuf"", (UV)SvUVX(sv));
2221 else
2222 Perl_sv_catpvf(aTHX_ t, "%"IVdf"", (IV)SvIVX(sv));
2223 }
2224 else
2225 sv_catpv(t, "");
2226 sv_catpv(t, "\"");
2227
2228 finish:
2229 if (unref) {
2230 while (unref--)
2231 sv_catpv(t, ")");
2232 }
2233 return SvPV(t, n_a);
2234}
2235
2236void
2237Perl_do_pmop_xmldump(pTHX_ I32 level, PerlIO *file, const PMOP *pm)
2238{
2239 if (!pm) {
2240 Perl_xmldump_indent(aTHX_ level, file, "<pmop/>\n");
2241 return;
2242 }
2243 Perl_xmldump_indent(aTHX_ level, file, "<pmop \n");
2244 level++;
2245 if (PM_GETRE(pm)) {
2246 char *s = PM_GETRE(pm)->precomp;
2247 SV *tmpsv = newSV(0);
2248 SvUTF8_on(tmpsv);
2249 sv_catxmlpvn(tmpsv, s, strlen(s), 1);
2250 Perl_xmldump_indent(aTHX_ level, file, "pre=\"%s\"\n",
2251 SvPVX(tmpsv));
2252 SvREFCNT_dec(tmpsv);
2253 Perl_xmldump_indent(aTHX_ level, file, "when=\"%s\"\n",
2254 (pm->op_private & OPpRUNTIME) ? "RUN" : "COMP");
2255 }
2256 else
2257 Perl_xmldump_indent(aTHX_ level, file, "pre=\"\" when=\"RUN\"\n");
2258 if (pm->op_pmflags || (PM_GETRE(pm) && PM_GETRE(pm)->check_substr)) {
2259 SV *tmpsv = newSVpvn("", 0);
2260 if (pm->op_pmdynflags & PMdf_USED)
2261 sv_catpv(tmpsv, ",USED");
2262 if (pm->op_pmdynflags & PMdf_TAINTED)
2263 sv_catpv(tmpsv, ",TAINTED");
2264 if (pm->op_pmflags & PMf_ONCE)
2265 sv_catpv(tmpsv, ",ONCE");
2266 if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr
2267 && !(PM_GETRE(pm)->reganch & ROPT_NOSCAN))
2268 sv_catpv(tmpsv, ",SCANFIRST");
2269 if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr
2270 && PM_GETRE(pm)->reganch & ROPT_CHECK_ALL)
2271 sv_catpv(tmpsv, ",ALL");
2272 if (pm->op_pmflags & PMf_SKIPWHITE)
2273 sv_catpv(tmpsv, ",SKIPWHITE");
2274 if (pm->op_pmflags & PMf_CONST)
2275 sv_catpv(tmpsv, ",CONST");
2276 if (pm->op_pmflags & PMf_KEEP)
2277 sv_catpv(tmpsv, ",KEEP");
2278 if (pm->op_pmflags & PMf_GLOBAL)
2279 sv_catpv(tmpsv, ",GLOBAL");
2280 if (pm->op_pmflags & PMf_CONTINUE)
2281 sv_catpv(tmpsv, ",CONTINUE");
2282 if (pm->op_pmflags & PMf_RETAINT)
2283 sv_catpv(tmpsv, ",RETAINT");
2284 if (pm->op_pmflags & PMf_EVAL)
2285 sv_catpv(tmpsv, ",EVAL");
2286 Perl_xmldump_indent(aTHX_ level, file, "pmflags=\"%s\"\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
2287 SvREFCNT_dec(tmpsv);
2288 }
2289
2290 level--;
2291 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
2292 Perl_xmldump_indent(aTHX_ level, file, ">\n");
2293 Perl_xmldump_indent(aTHX_ level+1, file, "<pm_repl>\n");
2294 do_op_xmldump(level+2, file, pm->op_pmreplroot);
2295 Perl_xmldump_indent(aTHX_ level+1, file, "</pm_repl>\n");
2296 Perl_xmldump_indent(aTHX_ level, file, "</pmop>\n");
2297 }
2298 else
2299 Perl_xmldump_indent(aTHX_ level, file, "/>\n");
2300}
2301
2302void
2303Perl_pmop_xmldump(pTHX_ const PMOP *pm)
2304{
2305 do_pmop_xmldump(0, PL_xmlfp, pm);
2306}
2307
2308void
2309Perl_do_op_xmldump(pTHX_ I32 level, PerlIO *file, const OP *o)
2310{
2311 UV seq;
2312 int contents = 0;
2313 if (!o)
2314 return;
2315 sequence(o);
2316 seq = sequence_num(o);
2317 Perl_xmldump_indent(aTHX_ level, file,
2318 "<op_%s seq=\"%"UVuf" -> ",
2319 OP_NAME(o),
2320 seq);
2321 level++;
2322 if (o->op_next)
2323 PerlIO_printf(file, seq ? "%"UVuf"\"" : "(%"UVuf")\"",
2324 sequence_num(o->op_next));
2325 else
2326 PerlIO_printf(file, "DONE\"");
2327
2328 if (o->op_targ) {
2329 if (o->op_type == OP_NULL)
2330 {
2331 PerlIO_printf(file, " was=\"%s\"", PL_op_name[o->op_targ]);
2332 if (o->op_targ == OP_NEXTSTATE)
2333 {
2334 if (CopLINE(cCOPo))
2335 PerlIO_printf(file, " line=\"%"UVf"\"",
2336 (UV)CopLINE(cCOPo));
2337 if (CopSTASHPV(cCOPo))
2338 PerlIO_printf(file, " package=\"%s\"",
2339 CopSTASHPV(cCOPo));
2340 if (cCOPo->cop_label)
2341 PerlIO_printf(file, " label=\"%s\"",
2342 cCOPo->cop_label);
2343 }
2344 }
2345 else
2346 PerlIO_printf(file, " targ=\"%ld\"", (long)o->op_targ);
2347 }
2348#ifdef DUMPADDR
2349 PerlIO_printf(file, " addr=\"0x%"UVxf" => 0x%"UVxf"\"", (UV)o, (UV)o->op_next);
2350#endif
2351 if (o->op_flags) {
2352 SV *tmpsv = newSVpvn("", 0);
2353 switch (o->op_flags & OPf_WANT) {
2354 case OPf_WANT_VOID:
2355 sv_catpv(tmpsv, ",VOID");
2356 break;
2357 case OPf_WANT_SCALAR:
2358 sv_catpv(tmpsv, ",SCALAR");
2359 break;
2360 case OPf_WANT_LIST:
2361 sv_catpv(tmpsv, ",LIST");
2362 break;
2363 default:
2364 sv_catpv(tmpsv, ",UNKNOWN");
2365 break;
2366 }
2367 if (o->op_flags & OPf_KIDS)
2368 sv_catpv(tmpsv, ",KIDS");
2369 if (o->op_flags & OPf_PARENS)
2370 sv_catpv(tmpsv, ",PARENS");
2371 if (o->op_flags & OPf_STACKED)
2372 sv_catpv(tmpsv, ",STACKED");
2373 if (o->op_flags & OPf_REF)
2374 sv_catpv(tmpsv, ",REF");
2375 if (o->op_flags & OPf_MOD)
2376 sv_catpv(tmpsv, ",MOD");
2377 if (o->op_flags & OPf_SPECIAL)
2378 sv_catpv(tmpsv, ",SPECIAL");
2379 PerlIO_printf(file, " flags=\"%s\"", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
2380 SvREFCNT_dec(tmpsv);
2381 }
2382 if (o->op_private) {
2383 SV *tmpsv = newSVpvn("", 0);
2384 if (PL_opargs[o->op_type] & OA_TARGLEX) {
2385 if (o->op_private & OPpTARGET_MY)
2386 sv_catpv(tmpsv, ",TARGET_MY");
2387 }
2388 else if (o->op_type == OP_LEAVESUB ||
2389 o->op_type == OP_LEAVE ||
2390 o->op_type == OP_LEAVESUBLV ||
2391 o->op_type == OP_LEAVEWRITE) {
2392 if (o->op_private & OPpREFCOUNTED)
2393 sv_catpv(tmpsv, ",REFCOUNTED");
2394 }
2395 else if (o->op_type == OP_AASSIGN) {
2396 if (o->op_private & OPpASSIGN_COMMON)
2397 sv_catpv(tmpsv, ",COMMON");
2398 }
2399 else if (o->op_type == OP_SASSIGN) {
2400 if (o->op_private & OPpASSIGN_BACKWARDS)
2401 sv_catpv(tmpsv, ",BACKWARDS");
2402 }
2403 else if (o->op_type == OP_TRANS) {
2404 if (o->op_private & OPpTRANS_SQUASH)
2405 sv_catpv(tmpsv, ",SQUASH");
2406 if (o->op_private & OPpTRANS_DELETE)
2407 sv_catpv(tmpsv, ",DELETE");
2408 if (o->op_private & OPpTRANS_COMPLEMENT)
2409 sv_catpv(tmpsv, ",COMPLEMENT");
2410 if (o->op_private & OPpTRANS_IDENTICAL)
2411 sv_catpv(tmpsv, ",IDENTICAL");
2412 if (o->op_private & OPpTRANS_GROWS)
2413 sv_catpv(tmpsv, ",GROWS");
2414 }
2415 else if (o->op_type == OP_REPEAT) {
2416 if (o->op_private & OPpREPEAT_DOLIST)
2417 sv_catpv(tmpsv, ",DOLIST");
2418 }
2419 else if (o->op_type == OP_ENTERSUB ||
2420 o->op_type == OP_RV2SV ||
2421 o->op_type == OP_GVSV ||
2422 o->op_type == OP_RV2AV ||
2423 o->op_type == OP_RV2HV ||
2424 o->op_type == OP_RV2GV ||
2425 o->op_type == OP_AELEM ||
2426 o->op_type == OP_HELEM )
2427 {
2428 if (o->op_type == OP_ENTERSUB) {
2429 if (o->op_private & OPpENTERSUB_AMPER)
2430 sv_catpv(tmpsv, ",AMPER");
2431 if (o->op_private & OPpENTERSUB_DB)
2432 sv_catpv(tmpsv, ",DB");
2433 if (o->op_private & OPpENTERSUB_HASTARG)
2434 sv_catpv(tmpsv, ",HASTARG");
2435 if (o->op_private & OPpENTERSUB_NOPAREN)
2436 sv_catpv(tmpsv, ",NOPAREN");
2437 if (o->op_private & OPpENTERSUB_INARGS)
2438 sv_catpv(tmpsv, ",INARGS");
2439 if (o->op_private & OPpENTERSUB_NOMOD)
2440 sv_catpv(tmpsv, ",NOMOD");
2441 }
2442 else {
2443 switch (o->op_private & OPpDEREF) {
2444 case OPpDEREF_SV:
2445 sv_catpv(tmpsv, ",SV");
2446 break;
2447 case OPpDEREF_AV:
2448 sv_catpv(tmpsv, ",AV");
2449 break;
2450 case OPpDEREF_HV:
2451 sv_catpv(tmpsv, ",HV");
2452 break;
2453 }
2454 if (o->op_private & OPpMAYBE_LVSUB)
2455 sv_catpv(tmpsv, ",MAYBE_LVSUB");
2456 }
2457 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
2458 if (o->op_private & OPpLVAL_DEFER)
2459 sv_catpv(tmpsv, ",LVAL_DEFER");
2460 }
2461 else {
2462 if (o->op_private & HINT_STRICT_REFS)
2463 sv_catpv(tmpsv, ",STRICT_REFS");
2464 if (o->op_private & OPpOUR_INTRO)
2465 sv_catpv(tmpsv, ",OUR_INTRO");
2466 }
2467 }
2468 else if (o->op_type == OP_CONST) {
2469 if (o->op_private & OPpCONST_BARE)
2470 sv_catpv(tmpsv, ",BARE");
2471 if (o->op_private & OPpCONST_STRICT)
2472 sv_catpv(tmpsv, ",STRICT");
2473 if (o->op_private & OPpCONST_ARYBASE)
2474 sv_catpv(tmpsv, ",ARYBASE");
2475 if (o->op_private & OPpCONST_WARNING)
2476 sv_catpv(tmpsv, ",WARNING");
2477 if (o->op_private & OPpCONST_ENTERED)
2478 sv_catpv(tmpsv, ",ENTERED");
2479 }
2480 else if (o->op_type == OP_FLIP) {
2481 if (o->op_private & OPpFLIP_LINENUM)
2482 sv_catpv(tmpsv, ",LINENUM");
2483 }
2484 else if (o->op_type == OP_FLOP) {
2485 if (o->op_private & OPpFLIP_LINENUM)
2486 sv_catpv(tmpsv, ",LINENUM");
2487 }
2488 else if (o->op_type == OP_RV2CV) {
2489 if (o->op_private & OPpLVAL_INTRO)
2490 sv_catpv(tmpsv, ",INTRO");
2491 }
2492 else if (o->op_type == OP_GV) {
2493 if (o->op_private & OPpEARLY_CV)
2494 sv_catpv(tmpsv, ",EARLY_CV");
2495 }
2496 else if (o->op_type == OP_LIST) {
2497 if (o->op_private & OPpLIST_GUESSED)
2498 sv_catpv(tmpsv, ",GUESSED");
2499 }
2500 else if (o->op_type == OP_DELETE) {
2501 if (o->op_private & OPpSLICE)
2502 sv_catpv(tmpsv, ",SLICE");
2503 }
2504 else if (o->op_type == OP_EXISTS) {
2505 if (o->op_private & OPpEXISTS_SUB)
2506 sv_catpv(tmpsv, ",EXISTS_SUB");
2507 }
2508 else if (o->op_type == OP_SORT) {
2509 if (o->op_private & OPpSORT_NUMERIC)
2510 sv_catpv(tmpsv, ",NUMERIC");
2511 if (o->op_private & OPpSORT_INTEGER)
2512 sv_catpv(tmpsv, ",INTEGER");
2513 if (o->op_private & OPpSORT_REVERSE)
2514 sv_catpv(tmpsv, ",REVERSE");
2515 }
2516 else if (o->op_type == OP_THREADSV) {
2517 if (o->op_private & OPpDONE_SVREF)
2518 sv_catpv(tmpsv, ",SVREF");
2519 }
2520 else if (o->op_type == OP_OPEN || o->op_type == OP_BACKTICK) {
2521 if (o->op_private & OPpOPEN_IN_RAW)
2522 sv_catpv(tmpsv, ",IN_RAW");
2523 if (o->op_private & OPpOPEN_IN_CRLF)
2524 sv_catpv(tmpsv, ",IN_CRLF");
2525 if (o->op_private & OPpOPEN_OUT_RAW)
2526 sv_catpv(tmpsv, ",OUT_RAW");
2527 if (o->op_private & OPpOPEN_OUT_CRLF)
2528 sv_catpv(tmpsv, ",OUT_CRLF");
2529 }
2530 else if (o->op_type == OP_EXIT) {
2531 if (o->op_private & OPpEXIT_VMSISH)
2532 sv_catpv(tmpsv, ",EXIT_VMSISH");
2533 if (o->op_private & OPpHUSH_VMSISH)
2534 sv_catpv(tmpsv, ",HUSH_VMSISH");
2535 }
2536 else if (o->op_type == OP_DIE) {
2537 if (o->op_private & OPpHUSH_VMSISH)
2538 sv_catpv(tmpsv, ",HUSH_VMSISH");
2539 }
2540 else if (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)) {
2541 if (OP_IS_FILETEST_ACCESS(o) && o->op_private & OPpFT_ACCESS)
2542 sv_catpv(tmpsv, ",FT_ACCESS");
2543 if (o->op_private & OPpFT_STACKED)
2544 sv_catpv(tmpsv, ",FT_STACKED");
2545 }
2546 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
2547 sv_catpv(tmpsv, ",INTRO");
2548 if (SvCUR(tmpsv))
2549 S_xmldump_attr(aTHX_ level, file, "private=\"%s\"", SvPVX(tmpsv) + 1);
2550 SvREFCNT_dec(tmpsv);
2551 }
2552
2553 switch (o->op_type) {
2554 case OP_AELEMFAST:
2555 if (o->op_flags & OPf_SPECIAL) {
2556 break;
2557 }
2558 case OP_GVSV:
2559 case OP_GV:
2560#ifdef USE_ITHREADS
2561 S_xmldump_attr(aTHX_ level, file, "padix=\"%" IVdf "\"", (IV)cPADOPo->op_padix);
2562#else
2563 if (cSVOPo->op_sv) {
ef2570c4
NC
2564 SV *tmpsv1 = newSV(0);
2565 SV *tmpsv2 = newSV(0);
3b721df9
NC
2566 char *s;
2567 STRLEN len;
b123ab9d
NC
2568 SvUTF8_on(tmpsv1);
2569 SvUTF8_on(tmpsv2);
3b721df9
NC
2570 ENTER;
2571 SAVEFREESV(tmpsv1);
2572 SAVEFREESV(tmpsv2);
2573 gv_fullname3(tmpsv1, (GV*)cSVOPo->op_sv, Nullch);
2574 s = SvPV(tmpsv1,len);
2575 sv_catxmlpvn(tmpsv2, s, len, 1);
2576 S_xmldump_attr(aTHX_ level, file, "gv=\"%s\"", SvPV(tmpsv2, len));
2577 LEAVE;
2578 }
2579 else
2580 S_xmldump_attr(aTHX_ level, file, "gv=\"NULL\"");
2581#endif
2582 break;
2583 case OP_CONST:
2584 case OP_METHOD_NAMED:
2585#ifndef USE_ITHREADS
2586 /* with ITHREADS, consts are stored in the pad, and the right pad
2587 * may not be active here, so skip */
2588 S_xmldump_attr(aTHX_ level, file, "%s", sv_xmlpeek(cSVOPo_sv));
2589#endif
2590 break;
2591 case OP_ANONCODE:
2592 if (!contents) {
2593 contents = 1;
2594 PerlIO_printf(file, ">\n");
2595 }
2596 do_op_xmldump(level+1, file, CvROOT(cSVOPo_sv));
2597 break;
2598 case OP_SETSTATE:
2599 case OP_NEXTSTATE:
2600 case OP_DBSTATE:
2601 if (CopLINE(cCOPo))
2602 S_xmldump_attr(aTHX_ level, file, "line=\"%"UVf"\"",
2603 (UV)CopLINE(cCOPo));
2604 if (CopSTASHPV(cCOPo))
2605 S_xmldump_attr(aTHX_ level, file, "package=\"%s\"",
2606 CopSTASHPV(cCOPo));
2607 if (cCOPo->cop_label)
2608 S_xmldump_attr(aTHX_ level, file, "label=\"%s\"",
2609 cCOPo->cop_label);
2610 break;
2611 case OP_ENTERLOOP:
2612 S_xmldump_attr(aTHX_ level, file, "redo=\"");
2613 if (cLOOPo->op_redoop)
2614 PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOOPo->op_redoop));
2615 else
2616 PerlIO_printf(file, "DONE\"");
2617 S_xmldump_attr(aTHX_ level, file, "next=\"");
2618 if (cLOOPo->op_nextop)
2619 PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOOPo->op_nextop));
2620 else
2621 PerlIO_printf(file, "DONE\"");
2622 S_xmldump_attr(aTHX_ level, file, "last=\"");
2623 if (cLOOPo->op_lastop)
2624 PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOOPo->op_lastop));
2625 else
2626 PerlIO_printf(file, "DONE\"");
2627 break;
2628 case OP_COND_EXPR:
2629 case OP_RANGE:
2630 case OP_MAPWHILE:
2631 case OP_GREPWHILE:
2632 case OP_OR:
2633 case OP_AND:
2634 S_xmldump_attr(aTHX_ level, file, "other=\"");
2635 if (cLOGOPo->op_other)
2636 PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOGOPo->op_other));
2637 else
2638 PerlIO_printf(file, "DONE\"");
2639 break;
2640 case OP_LEAVE:
2641 case OP_LEAVEEVAL:
2642 case OP_LEAVESUB:
2643 case OP_LEAVESUBLV:
2644 case OP_LEAVEWRITE:
2645 case OP_SCOPE:
2646 if (o->op_private & OPpREFCOUNTED)
2647 S_xmldump_attr(aTHX_ level, file, "refcnt=\"%"UVuf"\"", (UV)o->op_targ);
2648 break;
2649 default:
2650 break;
2651 }
2652
2653 if (PL_madskills && o->op_madprop) {
2654 SV *tmpsv = newSVpvn("", 0);
2655 MADPROP* mp = o->op_madprop;
2656 sv_utf8_upgrade(tmpsv);
2657 if (!contents) {
2658 contents = 1;
2659 PerlIO_printf(file, ">\n");
2660 }
2661 Perl_xmldump_indent(aTHX_ level, file, "<madprops>\n");
2662 level++;
2663 while (mp) {
2664 char tmp = mp->mad_key;
2665 sv_setpvn(tmpsv,"\"",1);
2666 if (tmp)
2667 sv_catxmlpvn(tmpsv, &tmp, 1, 0);
2668 sv_catpv(tmpsv, "\"");
2669 switch (mp->mad_type) {
2670 case MAD_NULL:
2671 sv_catpv(tmpsv, "NULL");
2672 Perl_xmldump_indent(aTHX_ level, file, "<mad_null key=%s/>\n", SvPVX(tmpsv));
2673 break;
2674 case MAD_PV:
2675 sv_catpv(tmpsv, " val=\"");
2676 sv_catxmlpvn(tmpsv, (char*)mp->mad_val, mp->mad_vlen,1);
2677 sv_catpv(tmpsv, "\"");
2678 Perl_xmldump_indent(aTHX_ level, file, "<mad_pv key=%s/>\n", SvPVX(tmpsv));
2679 break;
2680 case MAD_SV:
2681 sv_catpv(tmpsv, " val=\"");
2682 sv_catxmlsv(tmpsv, (SV*)mp->mad_val);
2683 sv_catpv(tmpsv, "\"");
2684 Perl_xmldump_indent(aTHX_ level, file, "<mad_sv key=%s/>\n", SvPVX(tmpsv));
2685 break;
2686 case MAD_OP:
2687 if ((OP*)mp->mad_val) {
2688 Perl_xmldump_indent(aTHX_ level, file, "<mad_op key=%s>\n", SvPVX(tmpsv));
2689 do_op_xmldump(level+1, file, (OP*)mp->mad_val);
2690 Perl_xmldump_indent(aTHX_ level, file, "</mad_op>\n");
2691 }
2692 break;
2693 default:
2694 Perl_xmldump_indent(aTHX_ level, file, "<mad_unk key=%s/>\n", SvPVX(tmpsv));
2695 break;
2696 }
2697 mp = mp->mad_next;
2698 }
2699 level--;
2700 Perl_xmldump_indent(aTHX_ level, file, "</madprops>\n");
2701
2702 SvREFCNT_dec(tmpsv);
2703 }
2704
2705 switch (o->op_type) {
2706 case OP_PUSHRE:
2707 case OP_MATCH:
2708 case OP_QR:
2709 case OP_SUBST:
2710 if (!contents) {
2711 contents = 1;
2712 PerlIO_printf(file, ">\n");
2713 }
2714 do_pmop_xmldump(level, file, cPMOPo);
2715 break;
2716 default:
2717 break;
2718 }
2719
2720 if (o->op_flags & OPf_KIDS) {
2721 OP *kid;
2722 if (!contents) {
2723 contents = 1;
2724 PerlIO_printf(file, ">\n");
2725 }
2726 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
2727 do_op_xmldump(level, file, kid);
2728 }
2729
2730 if (contents)
2731 Perl_xmldump_indent(aTHX_ level-1, file, "</op_%s>\n", OP_NAME(o));
2732 else
2733 PerlIO_printf(file, " />\n");
2734}
2735
2736void
2737Perl_op_xmldump(pTHX_ const OP *o)
2738{
2739 do_op_xmldump(0, PL_xmlfp, o);
2740}
2741#endif
2742
66610fdd
RGS
2743/*
2744 * Local variables:
2745 * c-indentation-style: bsd
2746 * c-basic-offset: 4
2747 * indent-tabs-mode: t
2748 * End:
2749 *
37442d52
RGS
2750 * ex: set ts=8 sts=4 sw=4 noet:
2751 */