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