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