This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix dumping of PMf_CODELIST_PRIVATE flag
[perl5.git] / dump.c
CommitLineData
a0d0e21e 1/* dump.c
a687059c 2 *
1129b882
NC
3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 * 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 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/*
4ac71550
TC
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.'
14 *
15 * [p.220 of _The Lord of the Rings_, II/i: "Many Meetings"]
8d063cd8
LW
16 */
17
166f8a29 18/* This file contains utility routines to dump the contents of SV and OP
61296642 19 * structures, as used by command-line options like -Dt and -Dx, and
166f8a29
DM
20 * by Devel::Peek.
21 *
22 * It also holds the debugging version of the runops function.
23 */
24
8d063cd8 25#include "EXTERN.h"
864dbfa3 26#define PERL_IN_DUMP_C
8d063cd8 27#include "perl.h"
f722798b 28#include "regcomp.h"
0bd48802
AL
29#include "proto.h"
30
8d063cd8 31
5357ca29
NC
32static const char* const svtypenames[SVt_LAST] = {
33 "NULL",
1cb9cd50 34 "BIND",
5357ca29 35 "IV",
b53eecb4 36 "NV",
5357ca29
NC
37 "PV",
38 "PVIV",
39 "PVNV",
40 "PVMG",
5c35adbb 41 "REGEXP",
5357ca29
NC
42 "PVGV",
43 "PVLV",
44 "PVAV",
45 "PVHV",
46 "PVCV",
47 "PVFM",
48 "PVIO"
49};
50
51
52static const char* const svshorttypenames[SVt_LAST] = {
53 "UNDEF",
1cb9cd50 54 "BIND",
5357ca29 55 "IV",
b53eecb4 56 "NV",
5357ca29
NC
57 "PV",
58 "PVIV",
59 "PVNV",
60 "PVMG",
5c35adbb 61 "REGEXP",
5357ca29
NC
62 "GV",
63 "PVLV",
64 "AV",
65 "HV",
66 "CV",
67 "FM",
68 "IO"
69};
70
a0c2f4dd
NC
71struct flag_to_name {
72 U32 flag;
73 const char *name;
74};
75
76static void
77S_append_flags(pTHX_ SV *sv, U32 flags, const struct flag_to_name *start,
78 const struct flag_to_name *const end)
79{
80 do {
81 if (flags & start->flag)
82 sv_catpv(sv, start->name);
83 } while (++start < end);
84}
85
86#define append_flags(sv, f, flags) \
cd431fde 87 S_append_flags(aTHX_ (sv), (f), (flags), C_ARRAY_END(flags))
a0c2f4dd
NC
88
89
2814eb74 90
3967c732 91void
864dbfa3 92Perl_dump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
3967c732 93{
3967c732 94 va_list args;
7918f24d 95 PERL_ARGS_ASSERT_DUMP_INDENT;
3967c732 96 va_start(args, pat);
c5be433b 97 dump_vindent(level, file, pat, &args);
3967c732
JD
98 va_end(args);
99}
8adcabd8
LW
100
101void
c5be433b
GS
102Perl_dump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args)
103{
97aff369 104 dVAR;
7918f24d 105 PERL_ARGS_ASSERT_DUMP_VINDENT;
c8db6e60 106 PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), "");
c5be433b
GS
107 PerlIO_vprintf(file, pat, *args);
108}
109
110void
864dbfa3 111Perl_dump_all(pTHX)
79072805 112{
712a6fe4 113 dump_all_perl(FALSE);
f0e3f042
CS
114}
115
116void
117Perl_dump_all_perl(pTHX_ bool justperl)
118{
119
97aff369 120 dVAR;
760ac839 121 PerlIO_setlinebuf(Perl_debug_log);
3280af22 122 if (PL_main_root)
3967c732 123 op_dump(PL_main_root);
f0e3f042 124 dump_packsubs_perl(PL_defstash, justperl);
463ee0b2
LW
125}
126
127void
e1ec3a88 128Perl_dump_packsubs(pTHX_ const HV *stash)
463ee0b2 129{
28eb953d 130 PERL_ARGS_ASSERT_DUMP_PACKSUBS;
f0e3f042
CS
131 dump_packsubs_perl(stash, FALSE);
132}
133
134void
135Perl_dump_packsubs_perl(pTHX_ const HV *stash, bool justperl)
136{
97aff369 137 dVAR;
a0d0e21e 138 I32 i;
463ee0b2 139
28eb953d 140 PERL_ARGS_ASSERT_DUMP_PACKSUBS_PERL;
7918f24d 141
8990e307
LW
142 if (!HvARRAY(stash))
143 return;
a0d0e21e 144 for (i = 0; i <= (I32) HvMAX(stash); i++) {
e1ec3a88 145 const HE *entry;
4db58590 146 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
159b6efe 147 const GV * const gv = (const GV *)HeVAL(entry);
e29cdcb3
GS
148 if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
149 continue;
8ebc5c01 150 if (GvCVu(gv))
f0e3f042 151 dump_sub_perl(gv, justperl);
85e6fe83
LW
152 if (GvFORM(gv))
153 dump_form(gv);
61f9802b
AL
154 if (HeKEY(entry)[HeKLEN(entry)-1] == ':') {
155 const HV * const hv = GvHV(gv);
156 if (hv && (hv != PL_defstash))
f0e3f042 157 dump_packsubs_perl(hv, justperl); /* nested package */
61f9802b 158 }
463ee0b2 159 }
79072805
LW
160 }
161}
162
163void
e1ec3a88 164Perl_dump_sub(pTHX_ const GV *gv)
a687059c 165{
28eb953d 166 PERL_ARGS_ASSERT_DUMP_SUB;
f0e3f042
CS
167 dump_sub_perl(gv, FALSE);
168}
169
170void
171Perl_dump_sub_perl(pTHX_ const GV *gv, bool justperl)
172{
173 SV * sv;
85e6fe83 174
28eb953d 175 PERL_ARGS_ASSERT_DUMP_SUB_PERL;
7918f24d 176
f0e3f042
CS
177 if (justperl && (CvISXSUB(GvCV(gv)) || !CvROOT(GvCV(gv))))
178 return;
179
180 sv = sv_newmortal();
bd61b366 181 gv_fullname3(sv, gv, NULL);
b15aece3 182 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ", SvPVX_const(sv));
aed2304a 183 if (CvISXSUB(GvCV(gv)))
91f3b821
GS
184 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "(xsub 0x%"UVxf" %d)\n",
185 PTR2UV(CvXSUB(GvCV(gv))),
894356b3 186 (int)CvXSUBANY(GvCV(gv)).any_i32);
85e6fe83 187 else if (CvROOT(GvCV(gv)))
3967c732 188 op_dump(CvROOT(GvCV(gv)));
85e6fe83 189 else
cea2e8a9 190 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
85e6fe83
LW
191}
192
193void
e1ec3a88 194Perl_dump_form(pTHX_ const GV *gv)
85e6fe83 195{
b464bac0 196 SV * const sv = sv_newmortal();
85e6fe83 197
7918f24d
NC
198 PERL_ARGS_ASSERT_DUMP_FORM;
199
bd61b366 200 gv_fullname3(sv, gv, NULL);
b15aece3 201 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nFORMAT %s = ", SvPVX_const(sv));
85e6fe83 202 if (CvROOT(GvFORM(gv)))
3967c732 203 op_dump(CvROOT(GvFORM(gv)));
85e6fe83 204 else
cea2e8a9 205 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
a687059c
LW
206}
207
8adcabd8 208void
864dbfa3 209Perl_dump_eval(pTHX)
8d063cd8 210{
97aff369 211 dVAR;
3967c732
JD
212 op_dump(PL_eval_root);
213}
214
3df15adc
YO
215
216/*
87cea99e 217=for apidoc pv_escape
3df15adc
YO
218
219Escapes at most the first "count" chars of pv and puts the results into
ab3bbdeb 220dsv such that the size of the escaped string will not exceed "max" chars
3df15adc
YO
221and will not contain any incomplete escape sequences.
222
ab3bbdeb
YO
223If flags contains PERL_PV_ESCAPE_QUOTE then any double quotes in the string
224will also be escaped.
3df15adc
YO
225
226Normally the SV will be cleared before the escaped string is prepared,
ab3bbdeb
YO
227but when PERL_PV_ESCAPE_NOCLEAR is set this will not occur.
228
38a44b82 229If PERL_PV_ESCAPE_UNI is set then the input string is treated as Unicode,
ab3bbdeb 230if PERL_PV_ESCAPE_UNI_DETECT is set then the input string is scanned
38a44b82 231using C<is_utf8_string()> to determine if it is Unicode.
ab3bbdeb
YO
232
233If PERL_PV_ESCAPE_ALL is set then all input chars will be output
681f01c2
KW
234using C<\x01F1> style escapes, otherwise if PERL_PV_ESCAPE_NONASCII is set, only
235chars above 127 will be escaped using this style; otherwise, only chars above
236255 will be so escaped; other non printable chars will use octal or
237common escaped patterns like C<\n>. Otherwise, if PERL_PV_ESCAPE_NOBACKSLASH
238then all chars below 255 will be treated as printable and
ab3bbdeb
YO
239will be output as literals.
240
241If PERL_PV_ESCAPE_FIRSTCHAR is set then only the first char of the
c8536afa
KW
242string will be escaped, regardless of max. If the output is to be in hex,
243then it will be returned as a plain hex
244sequence. Thus the output will either be a single char,
245an octal escape sequence, a special escape like C<\n> or a hex value.
3df15adc 246
44a2ac75
YO
247If PERL_PV_ESCAPE_RE is set then the escape char used will be a '%' and
248not a '\\'. This is because regexes very often contain backslashed
249sequences, whereas '%' is not a particularly common character in patterns.
250
ab3bbdeb 251Returns a pointer to the escaped text as held by dsv.
3df15adc
YO
252
253=cut
254*/
ab3bbdeb 255#define PV_ESCAPE_OCTBUFSIZE 32
ddc5bc0f 256
3967c732 257char *
ddc5bc0f 258Perl_pv_escape( pTHX_ SV *dsv, char const * const str,
ab3bbdeb
YO
259 const STRLEN count, const STRLEN max,
260 STRLEN * const escaped, const U32 flags )
261{
61f9802b
AL
262 const char esc = (flags & PERL_PV_ESCAPE_RE) ? '%' : '\\';
263 const char dq = (flags & PERL_PV_ESCAPE_QUOTE) ? '"' : esc;
44a2ac75 264 char octbuf[PV_ESCAPE_OCTBUFSIZE] = "%123456789ABCDF";
ab3bbdeb
YO
265 STRLEN wrote = 0; /* chars written so far */
266 STRLEN chsize = 0; /* size of data to be written */
267 STRLEN readsize = 1; /* size of data just read */
38a44b82 268 bool isuni= flags & PERL_PV_ESCAPE_UNI ? 1 : 0; /* is this Unicode */
ddc5bc0f 269 const char *pv = str;
61f9802b 270 const char * const end = pv + count; /* end of string */
44a2ac75 271 octbuf[0] = esc;
ab3bbdeb 272
7918f24d
NC
273 PERL_ARGS_ASSERT_PV_ESCAPE;
274
9ed8b5e5 275 if (!(flags & PERL_PV_ESCAPE_NOCLEAR)) {
7fddd944 276 /* This won't alter the UTF-8 flag */
76f68e9b 277 sv_setpvs(dsv, "");
7fddd944 278 }
ab3bbdeb 279
ddc5bc0f 280 if ((flags & PERL_PV_ESCAPE_UNI_DETECT) && is_utf8_string((U8*)pv, count))
ab3bbdeb
YO
281 isuni = 1;
282
283 for ( ; (pv < end && (!max || (wrote < max))) ; pv += readsize ) {
4b88fb76 284 const UV u= (isuni) ? utf8_to_uvchr_buf((U8*)pv, (U8*) end, &readsize) : (U8)*pv;
ab3bbdeb
YO
285 const U8 c = (U8)u & 0xFF;
286
681f01c2
KW
287 if ( ( u > 255 )
288 || (flags & PERL_PV_ESCAPE_ALL)
289 || (( u > 127 ) && (flags & PERL_PV_ESCAPE_NONASCII)))
290 {
ab3bbdeb
YO
291 if (flags & PERL_PV_ESCAPE_FIRSTCHAR)
292 chsize = my_snprintf( octbuf, PV_ESCAPE_OCTBUFSIZE,
293 "%"UVxf, u);
294 else
295 chsize = my_snprintf( octbuf, PV_ESCAPE_OCTBUFSIZE,
44a2ac75 296 "%cx{%"UVxf"}", esc, u);
ab3bbdeb
YO
297 } else if (flags & PERL_PV_ESCAPE_NOBACKSLASH) {
298 chsize = 1;
299 } else {
44a2ac75
YO
300 if ( (c == dq) || (c == esc) || !isPRINT(c) ) {
301 chsize = 2;
ab3bbdeb 302 switch (c) {
44a2ac75
YO
303
304 case '\\' : /* fallthrough */
305 case '%' : if ( c == esc ) {
306 octbuf[1] = esc;
307 } else {
308 chsize = 1;
309 }
310 break;
3df15adc
YO
311 case '\v' : octbuf[1] = 'v'; break;
312 case '\t' : octbuf[1] = 't'; break;
313 case '\r' : octbuf[1] = 'r'; break;
314 case '\n' : octbuf[1] = 'n'; break;
315 case '\f' : octbuf[1] = 'f'; break;
44a2ac75 316 case '"' :
ab3bbdeb 317 if ( dq == '"' )
3df15adc 318 octbuf[1] = '"';
ab3bbdeb
YO
319 else
320 chsize = 1;
44a2ac75 321 break;
3df15adc 322 default:
bbae360a 323 if ( (pv+readsize < end) && isDIGIT((U8)*(pv+readsize)) )
ab3bbdeb 324 chsize = my_snprintf( octbuf, PV_ESCAPE_OCTBUFSIZE,
44a2ac75
YO
325 "%c%03o", esc, c);
326 else
ab3bbdeb 327 chsize = my_snprintf( octbuf, PV_ESCAPE_OCTBUFSIZE,
44a2ac75 328 "%c%o", esc, c);
ab3bbdeb
YO
329 }
330 } else {
44a2ac75 331 chsize = 1;
ab3bbdeb 332 }
44a2ac75
YO
333 }
334 if ( max && (wrote + chsize > max) ) {
335 break;
ab3bbdeb 336 } else if (chsize > 1) {
44a2ac75
YO
337 sv_catpvn(dsv, octbuf, chsize);
338 wrote += chsize;
3df15adc 339 } else {
7fddd944
NC
340 /* If PERL_PV_ESCAPE_NOBACKSLASH is set then bytes in the range
341 128-255 can be appended raw to the dsv. If dsv happens to be
342 UTF-8 then we need catpvf to upgrade them for us.
343 Or add a new API call sv_catpvc(). Think about that name, and
344 how to keep it clear that it's unlike the s of catpvs, which is
345 really an array octets, not a string. */
346 Perl_sv_catpvf( aTHX_ dsv, "%c", c);
3df15adc
YO
347 wrote++;
348 }
ab3bbdeb
YO
349 if ( flags & PERL_PV_ESCAPE_FIRSTCHAR )
350 break;
3967c732 351 }
ab3bbdeb
YO
352 if (escaped != NULL)
353 *escaped= pv - str;
354 return SvPVX(dsv);
355}
356/*
87cea99e 357=for apidoc pv_pretty
ab3bbdeb
YO
358
359Converts a string into something presentable, handling escaping via
95b611b0 360pv_escape() and supporting quoting and ellipses.
ab3bbdeb
YO
361
362If the PERL_PV_PRETTY_QUOTE flag is set then the result will be
363double quoted with any double quotes in the string escaped. Otherwise
364if the PERL_PV_PRETTY_LTGT flag is set then the result be wrapped in
365angle brackets.
6cba11c8 366
95b611b0
RGS
367If the PERL_PV_PRETTY_ELLIPSES flag is set and not all characters in
368string were output then an ellipsis C<...> will be appended to the
ab3bbdeb 369string. Note that this happens AFTER it has been quoted.
6cba11c8 370
ab3bbdeb
YO
371If start_color is non-null then it will be inserted after the opening
372quote (if there is one) but before the escaped text. If end_color
373is non-null then it will be inserted after the escaped text but before
95b611b0 374any quotes or ellipses.
ab3bbdeb
YO
375
376Returns a pointer to the prettified text as held by dsv.
6cba11c8 377
ab3bbdeb
YO
378=cut
379*/
380
381char *
ddc5bc0f
YO
382Perl_pv_pretty( pTHX_ SV *dsv, char const * const str, const STRLEN count,
383 const STRLEN max, char const * const start_color, char const * const end_color,
ab3bbdeb
YO
384 const U32 flags )
385{
61f9802b 386 const U8 dq = (flags & PERL_PV_PRETTY_QUOTE) ? '"' : '%';
ab3bbdeb 387 STRLEN escaped;
7918f24d
NC
388
389 PERL_ARGS_ASSERT_PV_PRETTY;
390
881a015e
NC
391 if (!(flags & PERL_PV_PRETTY_NOCLEAR)) {
392 /* This won't alter the UTF-8 flag */
76f68e9b 393 sv_setpvs(dsv, "");
881a015e
NC
394 }
395
ab3bbdeb 396 if ( dq == '"' )
76f68e9b 397 sv_catpvs(dsv, "\"");
ab3bbdeb 398 else if ( flags & PERL_PV_PRETTY_LTGT )
76f68e9b 399 sv_catpvs(dsv, "<");
ab3bbdeb
YO
400
401 if ( start_color != NULL )
76f68e9b 402 sv_catpv(dsv, start_color);
ab3bbdeb
YO
403
404 pv_escape( dsv, str, count, max, &escaped, flags | PERL_PV_ESCAPE_NOCLEAR );
405
406 if ( end_color != NULL )
76f68e9b 407 sv_catpv(dsv, end_color);
ab3bbdeb
YO
408
409 if ( dq == '"' )
76f68e9b 410 sv_catpvs( dsv, "\"");
ab3bbdeb 411 else if ( flags & PERL_PV_PRETTY_LTGT )
76f68e9b 412 sv_catpvs(dsv, ">");
ab3bbdeb 413
95b611b0 414 if ( (flags & PERL_PV_PRETTY_ELLIPSES) && ( escaped < count ) )
76f68e9b 415 sv_catpvs(dsv, "...");
ab3bbdeb 416
3df15adc
YO
417 return SvPVX(dsv);
418}
419
420/*
421=for apidoc pv_display
422
3df15adc 423Similar to
3967c732 424
3df15adc
YO
425 pv_escape(dsv,pv,cur,pvlim,PERL_PV_ESCAPE_QUOTE);
426
427except that an additional "\0" will be appended to the string when
428len > cur and pv[cur] is "\0".
429
430Note that the final string may be up to 7 chars longer than pvlim.
431
432=cut
433*/
434
435char *
436Perl_pv_display(pTHX_ SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
437{
7918f24d
NC
438 PERL_ARGS_ASSERT_PV_DISPLAY;
439
ddc5bc0f 440 pv_pretty( dsv, pv, cur, pvlim, NULL, NULL, PERL_PV_PRETTY_DUMP);
3df15adc 441 if (len > cur && pv[cur] == '\0')
76f68e9b 442 sv_catpvs( dsv, "\\0");
e6abe6d8
JH
443 return SvPVX(dsv);
444}
445
446char *
864dbfa3 447Perl_sv_peek(pTHX_ SV *sv)
3967c732 448{
27da23d5 449 dVAR;
aec46f14 450 SV * const t = sv_newmortal();
3967c732 451 int unref = 0;
5357ca29 452 U32 type;
3967c732 453
76f68e9b 454 sv_setpvs(t, "");
3967c732
JD
455 retry:
456 if (!sv) {
457 sv_catpv(t, "VOID");
458 goto finish;
459 }
ad64d0ec 460 else if (sv == (const SV *)0x55555555 || SvTYPE(sv) == 'U') {
3967c732
JD
461 sv_catpv(t, "WILD");
462 goto finish;
463 }
7996736c 464 else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) {
3967c732
JD
465 if (sv == &PL_sv_undef) {
466 sv_catpv(t, "SV_UNDEF");
467 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
468 SVs_GMG|SVs_SMG|SVs_RMG)) &&
469 SvREADONLY(sv))
470 goto finish;
471 }
472 else if (sv == &PL_sv_no) {
473 sv_catpv(t, "SV_NO");
474 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
475 SVs_GMG|SVs_SMG|SVs_RMG)) &&
476 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
477 SVp_POK|SVp_NOK)) &&
478 SvCUR(sv) == 0 &&
479 SvNVX(sv) == 0.0)
480 goto finish;
481 }
7996736c 482 else if (sv == &PL_sv_yes) {
3967c732
JD
483 sv_catpv(t, "SV_YES");
484 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
485 SVs_GMG|SVs_SMG|SVs_RMG)) &&
486 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
487 SVp_POK|SVp_NOK)) &&
488 SvCUR(sv) == 1 &&
b15aece3 489 SvPVX_const(sv) && *SvPVX_const(sv) == '1' &&
3967c732
JD
490 SvNVX(sv) == 1.0)
491 goto finish;
7996736c
MHM
492 }
493 else {
494 sv_catpv(t, "SV_PLACEHOLDER");
495 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
496 SVs_GMG|SVs_SMG|SVs_RMG)) &&
497 SvREADONLY(sv))
498 goto finish;
3967c732
JD
499 }
500 sv_catpv(t, ":");
501 }
502 else if (SvREFCNT(sv) == 0) {
503 sv_catpv(t, "(");
504 unref++;
505 }
a3b4c9c6
DM
506 else if (DEBUG_R_TEST_) {
507 int is_tmp = 0;
508 I32 ix;
509 /* is this SV on the tmps stack? */
510 for (ix=PL_tmps_ix; ix>=0; ix--) {
511 if (PL_tmps_stack[ix] == sv) {
512 is_tmp = 1;
513 break;
514 }
515 }
516 if (SvREFCNT(sv) > 1)
517 Perl_sv_catpvf(aTHX_ t, "<%"UVuf"%s>", (UV)SvREFCNT(sv),
518 is_tmp ? "T" : "");
519 else if (is_tmp)
520 sv_catpv(t, "<T>");
04932ac8
DM
521 }
522
3967c732
JD
523 if (SvROK(sv)) {
524 sv_catpv(t, "\\");
525 if (SvCUR(t) + unref > 10) {
b162af07 526 SvCUR_set(t, unref + 3);
3967c732
JD
527 *SvEND(t) = '\0';
528 sv_catpv(t, "...");
529 goto finish;
530 }
ad64d0ec 531 sv = SvRV(sv);
3967c732
JD
532 goto retry;
533 }
5357ca29
NC
534 type = SvTYPE(sv);
535 if (type == SVt_PVCV) {
536 Perl_sv_catpvf(aTHX_ t, "CV(%s)", CvGV(sv) ? GvNAME(CvGV(sv)) : "");
3967c732 537 goto finish;
5357ca29
NC
538 } else if (type < SVt_LAST) {
539 sv_catpv(t, svshorttypenames[type]);
3967c732 540
5357ca29
NC
541 if (type == SVt_NULL)
542 goto finish;
543 } else {
544 sv_catpv(t, "FREED");
3967c732 545 goto finish;
3967c732
JD
546 }
547
548 if (SvPOKp(sv)) {
b15aece3 549 if (!SvPVX_const(sv))
3967c732
JD
550 sv_catpv(t, "(null)");
551 else {
b9ac451d 552 SV * const tmp = newSVpvs("");
3967c732 553 sv_catpv(t, "(");
5115136b
DM
554 if (SvOOK(sv)) {
555 STRLEN delta;
556 SvOOK_offset(sv, delta);
557 Perl_sv_catpvf(aTHX_ t, "[%s]", pv_display(tmp, SvPVX_const(sv)-delta, delta, 0, 127));
558 }
b15aece3 559 Perl_sv_catpvf(aTHX_ t, "%s)", pv_display(tmp, SvPVX_const(sv), SvCUR(sv), SvLEN(sv), 127));
32639b87 560 if (SvUTF8(sv))
b2ff9928 561 Perl_sv_catpvf(aTHX_ t, " [UTF8 \"%s\"]",
e9569a7a 562 sv_uni_display(tmp, sv, 6 * SvCUR(sv),
c728cb41 563 UNI_DISPLAY_QQ));
3967c732
JD
564 SvREFCNT_dec(tmp);
565 }
566 }
567 else if (SvNOKp(sv)) {
e54dc35b 568 STORE_NUMERIC_LOCAL_SET_STANDARD();
1779d84d 569 Perl_sv_catpvf(aTHX_ t, "(%"NVgf")",SvNVX(sv));
e54dc35b 570 RESTORE_NUMERIC_LOCAL();
3967c732 571 }
57def98f 572 else if (SvIOKp(sv)) {
cf2093f6 573 if (SvIsUV(sv))
57def98f 574 Perl_sv_catpvf(aTHX_ t, "(%"UVuf")", (UV)SvUVX(sv));
cf2093f6 575 else
57def98f 576 Perl_sv_catpvf(aTHX_ t, "(%"IVdf")", (IV)SvIVX(sv));
25da4f38 577 }
3967c732
JD
578 else
579 sv_catpv(t, "()");
2ef28da1 580
3967c732 581 finish:
61f9802b
AL
582 while (unref--)
583 sv_catpv(t, ")");
59b714e2
RGS
584 if (PL_tainting && SvTAINTED(sv))
585 sv_catpv(t, " [tainted]");
8b6b16e7 586 return SvPV_nolen(t);
3967c732
JD
587}
588
589void
6867be6d 590Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, const PMOP *pm)
3967c732
JD
591{
592 char ch;
593
7918f24d
NC
594 PERL_ARGS_ASSERT_DO_PMOP_DUMP;
595
3967c732 596 if (!pm) {
cea2e8a9 597 Perl_dump_indent(aTHX_ level, file, "{}\n");
3967c732
JD
598 return;
599 }
cea2e8a9 600 Perl_dump_indent(aTHX_ level, file, "{\n");
3967c732
JD
601 level++;
602 if (pm->op_pmflags & PMf_ONCE)
603 ch = '?';
604 else
605 ch = '/';
aaa362c4 606 if (PM_GETRE(pm))
cea2e8a9 607 Perl_dump_indent(aTHX_ level, file, "PMf_PRE %c%s%c%s\n",
220fc49f 608 ch, RX_PRECOMP(PM_GETRE(pm)), ch,
3967c732
JD
609 (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
610 else
cea2e8a9 611 Perl_dump_indent(aTHX_ level, file, "PMf_PRE (RUNTIME)\n");
20e98b0f 612 if (pm->op_type != OP_PUSHRE && pm->op_pmreplrootu.op_pmreplroot) {
cea2e8a9 613 Perl_dump_indent(aTHX_ level, file, "PMf_REPL = ");
20e98b0f 614 op_dump(pm->op_pmreplrootu.op_pmreplroot);
3967c732 615 }
68e2671b 616 if (pm->op_code_list) {
867940b8
DM
617 if (pm->op_pmflags & PMf_CODELIST_PRIVATE) {
618 Perl_dump_indent(aTHX_ level, file, "CODE_LIST =\n");
619 do_op_dump(level, file, pm->op_code_list);
620 }
621 else
622 Perl_dump_indent(aTHX_ level, file, "CODE_LIST = 0x%"UVxf"\n",
623 PTR2UV(pm->op_code_list));
68e2671b 624 }
07bc277f 625 if (pm->op_pmflags || (PM_GETRE(pm) && RX_CHECK_SUBSTR(PM_GETRE(pm)))) {
4199688e 626 SV * const tmpsv = pm_description(pm);
b15aece3 627 Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
3967c732
JD
628 SvREFCNT_dec(tmpsv);
629 }
630
cea2e8a9 631 Perl_dump_indent(aTHX_ level-1, file, "}\n");
3967c732
JD
632}
633
a0c2f4dd
NC
634const struct flag_to_name pmflags_flags_names[] = {
635 {PMf_CONST, ",CONST"},
636 {PMf_KEEP, ",KEEP"},
637 {PMf_GLOBAL, ",GLOBAL"},
638 {PMf_CONTINUE, ",CONTINUE"},
639 {PMf_RETAINT, ",RETAINT"},
640 {PMf_EVAL, ",EVAL"},
641 {PMf_NONDESTRUCT, ",NONDESTRUCT"},
d63c20f2 642 {PMf_HAS_CV, ",HAS_CV"},
1147b55c 643 {PMf_CODELIST_PRIVATE, ",CODELIST_PRIVATE"}
a0c2f4dd
NC
644};
645
b9ac451d 646static SV *
4199688e
AL
647S_pm_description(pTHX_ const PMOP *pm)
648{
649 SV * const desc = newSVpvs("");
61f9802b 650 const REGEXP * const regex = PM_GETRE(pm);
4199688e
AL
651 const U32 pmflags = pm->op_pmflags;
652
7918f24d
NC
653 PERL_ARGS_ASSERT_PM_DESCRIPTION;
654
4199688e
AL
655 if (pmflags & PMf_ONCE)
656 sv_catpv(desc, ",ONCE");
c737faaf
YO
657#ifdef USE_ITHREADS
658 if (SvREADONLY(PL_regex_pad[pm->op_pmoffset]))
659 sv_catpv(desc, ":USED");
660#else
661 if (pmflags & PMf_USED)
662 sv_catpv(desc, ":USED");
663#endif
c737faaf 664
68d4833d 665 if (regex) {
07bc277f 666 if (RX_EXTFLAGS(regex) & RXf_TAINTED)
68d4833d 667 sv_catpv(desc, ",TAINTED");
07bc277f
NC
668 if (RX_CHECK_SUBSTR(regex)) {
669 if (!(RX_EXTFLAGS(regex) & RXf_NOSCAN))
68d4833d 670 sv_catpv(desc, ",SCANFIRST");
07bc277f 671 if (RX_EXTFLAGS(regex) & RXf_CHECK_ALL)
68d4833d
AB
672 sv_catpv(desc, ",ALL");
673 }
07bc277f 674 if (RX_EXTFLAGS(regex) & RXf_SKIPWHITE)
68d4833d 675 sv_catpv(desc, ",SKIPWHITE");
4199688e 676 }
68d4833d 677
a0c2f4dd 678 append_flags(desc, pmflags, pmflags_flags_names);
4199688e
AL
679 return desc;
680}
681
3967c732 682void
864dbfa3 683Perl_pmop_dump(pTHX_ PMOP *pm)
3967c732
JD
684{
685 do_pmop_dump(0, Perl_debug_log, pm);
79072805
LW
686}
687
b6f05621
DM
688/* Return a unique integer to represent the address of op o.
689 * If it already exists in PL_op_sequence, just return it;
690 * otherwise add it.
691 * *** Note that this isn't thread-safe */
294b3b39 692
2814eb74 693STATIC UV
0bd48802 694S_sequence_num(pTHX_ const OP *o)
2814eb74 695{
27da23d5 696 dVAR;
2814eb74
PJ
697 SV *op,
698 **seq;
93524f2b 699 const char *key;
2814eb74 700 STRLEN len;
b6f05621
DM
701 if (!o)
702 return 0;
c0fd1b42 703 op = newSVuv(PTR2UV(o));
b6f05621 704 sv_2mortal(op);
93524f2b 705 key = SvPV_const(op, len);
b6f05621
DM
706 if (!PL_op_sequence)
707 PL_op_sequence = newHV();
708 seq = hv_fetch(PL_op_sequence, key, len, 0);
709 if (seq)
710 return SvUV(*seq);
711 (void)hv_store(PL_op_sequence, key, len, newSVuv(++PL_op_seq), 0);
712 return PL_op_seq;
2814eb74
PJ
713}
714
a0c2f4dd
NC
715const struct flag_to_name op_flags_names[] = {
716 {OPf_KIDS, ",KIDS"},
717 {OPf_PARENS, ",PARENS"},
a0c2f4dd
NC
718 {OPf_REF, ",REF"},
719 {OPf_MOD, ",MOD"},
65cccc5e 720 {OPf_STACKED, ",STACKED"},
a0c2f4dd
NC
721 {OPf_SPECIAL, ",SPECIAL"}
722};
723
ea9ad1f2 724const struct flag_to_name op_trans_names[] = {
65cccc5e
VP
725 {OPpTRANS_FROM_UTF, ",FROM_UTF"},
726 {OPpTRANS_TO_UTF, ",TO_UTF"},
727 {OPpTRANS_IDENTICAL, ",IDENTICAL"},
ea9ad1f2 728 {OPpTRANS_SQUASH, ",SQUASH"},
ea9ad1f2 729 {OPpTRANS_COMPLEMENT, ",COMPLEMENT"},
65cccc5e
VP
730 {OPpTRANS_GROWS, ",GROWS"},
731 {OPpTRANS_DELETE, ",DELETE"}
ea9ad1f2
NC
732};
733
734const struct flag_to_name op_entersub_names[] = {
ea9ad1f2
NC
735 {OPpENTERSUB_DB, ",DB"},
736 {OPpENTERSUB_HASTARG, ",HASTARG"},
65cccc5e 737 {OPpENTERSUB_AMPER, ",AMPER"},
ea9ad1f2 738 {OPpENTERSUB_NOPAREN, ",NOPAREN"},
65cccc5e 739 {OPpENTERSUB_INARGS, ",INARGS"}
ea9ad1f2
NC
740};
741
742const struct flag_to_name op_const_names[] = {
65cccc5e
VP
743 {OPpCONST_NOVER, ",NOVER"},
744 {OPpCONST_SHORTCIRCUIT, ",SHORTCIRCUIT"},
ea9ad1f2 745 {OPpCONST_STRICT, ",STRICT"},
65cccc5e 746 {OPpCONST_ENTERED, ",ENTERED"},
63e0918d 747 {OPpCONST_BARE, ",BARE"}
ea9ad1f2
NC
748};
749
750const struct flag_to_name op_sort_names[] = {
751 {OPpSORT_NUMERIC, ",NUMERIC"},
752 {OPpSORT_INTEGER, ",INTEGER"},
65cccc5e
VP
753 {OPpSORT_REVERSE, ",REVERSE"},
754 {OPpSORT_INPLACE, ",INPLACE"},
755 {OPpSORT_DESCEND, ",DESCEND"},
756 {OPpSORT_QSORT, ",QSORT"},
757 {OPpSORT_STABLE, ",STABLE"}
ea9ad1f2
NC
758};
759
760const struct flag_to_name op_open_names[] = {
761 {OPpOPEN_IN_RAW, ",IN_RAW"},
762 {OPpOPEN_IN_CRLF, ",IN_CRLF"},
763 {OPpOPEN_OUT_RAW, ",OUT_RAW"},
764 {OPpOPEN_OUT_CRLF, ",OUT_CRLF"}
765};
766
261c990e
NC
767const struct flag_to_name op_exit_names[] = {
768 {OPpEXIT_VMSISH, ",EXIT_VMSISH"},
769 {OPpHUSH_VMSISH, ",HUSH_VMSISH"}
770};
771
772#define OP_PRIVATE_ONCE(op, flag, name) \
773 const struct flag_to_name CAT2(op, _names)[] = { \
774 {(flag), (name)} \
f58883a1 775 }
261c990e
NC
776
777OP_PRIVATE_ONCE(op_aassign, OPpASSIGN_COMMON, ",COMMON");
778OP_PRIVATE_ONCE(op_leavesub, OPpREFCOUNTED, ",REFCOUNTED");
779OP_PRIVATE_ONCE(op_sassign, OPpASSIGN_BACKWARDS, ",BACKWARDS");
780OP_PRIVATE_ONCE(op_repeat, OPpREPEAT_DOLIST, ",DOLIST");
65cccc5e 781OP_PRIVATE_ONCE(op_reverse, OPpREVERSE_INPLACE, ",INPLACE");
261c990e
NC
782OP_PRIVATE_ONCE(op_rv2cv, OPpLVAL_INTRO, ",INTRO");
783OP_PRIVATE_ONCE(op_flip, OPpFLIP_LINENUM, ",LINENUM");
784OP_PRIVATE_ONCE(op_gv, OPpEARLY_CV, ",EARLY_CV");
785OP_PRIVATE_ONCE(op_list, OPpLIST_GUESSED, ",GUESSED");
786OP_PRIVATE_ONCE(op_delete, OPpSLICE, ",SLICE");
787OP_PRIVATE_ONCE(op_exists, OPpEXISTS_SUB, ",EXISTS_SUB");
788OP_PRIVATE_ONCE(op_die, OPpHUSH_VMSISH, ",HUSH_VMSISH");
789
1fe3abee
NC
790struct op_private_by_op {
791 U16 op_type;
792 U16 len;
793 const struct flag_to_name *start;
794};
795
796const struct op_private_by_op op_private_names[] = {
261c990e
NC
797 {OP_LEAVESUB, C_ARRAY_LENGTH(op_leavesub_names), op_leavesub_names },
798 {OP_LEAVE, C_ARRAY_LENGTH(op_leavesub_names), op_leavesub_names },
799 {OP_LEAVESUBLV, C_ARRAY_LENGTH(op_leavesub_names), op_leavesub_names },
800 {OP_LEAVEWRITE, C_ARRAY_LENGTH(op_leavesub_names), op_leavesub_names },
801 {OP_AASSIGN, C_ARRAY_LENGTH(op_aassign_names), op_aassign_names },
802 {OP_DIE, C_ARRAY_LENGTH(op_die_names), op_die_names },
803 {OP_DELETE, C_ARRAY_LENGTH(op_delete_names), op_delete_names },
804 {OP_EXISTS, C_ARRAY_LENGTH(op_exists_names), op_exists_names },
805 {OP_EXIT, C_ARRAY_LENGTH(op_exit_names), op_exit_names },
806 {OP_FLIP, C_ARRAY_LENGTH(op_flip_names), op_flip_names },
807 {OP_FLOP, C_ARRAY_LENGTH(op_flip_names), op_flip_names },
808 {OP_GV, C_ARRAY_LENGTH(op_gv_names), op_gv_names },
809 {OP_LIST, C_ARRAY_LENGTH(op_list_names), op_list_names },
810 {OP_SASSIGN, C_ARRAY_LENGTH(op_sassign_names), op_sassign_names },
811 {OP_REPEAT, C_ARRAY_LENGTH(op_repeat_names), op_repeat_names },
812 {OP_RV2CV, C_ARRAY_LENGTH(op_rv2cv_names), op_rv2cv_names },
1fe3abee
NC
813 {OP_TRANS, C_ARRAY_LENGTH(op_trans_names), op_trans_names },
814 {OP_CONST, C_ARRAY_LENGTH(op_const_names), op_const_names },
815 {OP_SORT, C_ARRAY_LENGTH(op_sort_names), op_sort_names },
816 {OP_OPEN, C_ARRAY_LENGTH(op_open_names), op_open_names },
817 {OP_BACKTICK, C_ARRAY_LENGTH(op_open_names), op_open_names }
818};
819
820static bool
821S_op_private_to_names(pTHX_ SV *tmpsv, U32 optype, U32 op_private) {
822 const struct op_private_by_op *start = op_private_names;
823 const struct op_private_by_op *const end
824 = op_private_names + C_ARRAY_LENGTH(op_private_names);
825
826 /* This is a linear search, but no worse than the code that it replaced.
827 It's debugging code - size is more important than speed. */
828 do {
829 if (optype == start->op_type) {
830 S_append_flags(aTHX_ tmpsv, op_private, start->start,
831 start->start + start->len);
832 return TRUE;
833 }
834 } while (++start < end);
835 return FALSE;
836}
837
79072805 838void
6867be6d 839Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
79072805 840{
27da23d5 841 dVAR;
2814eb74 842 UV seq;
e15d5972
AL
843 const OPCODE optype = o->op_type;
844
7918f24d
NC
845 PERL_ARGS_ASSERT_DO_OP_DUMP;
846
cea2e8a9 847 Perl_dump_indent(aTHX_ level, file, "{\n");
3967c732 848 level++;
0bd48802 849 seq = sequence_num(o);
2814eb74 850 if (seq)
f5992bc4 851 PerlIO_printf(file, "%-4"UVuf, seq);
93a17b20 852 else
b6f05621 853 PerlIO_printf(file, "????");
c8db6e60
JH
854 PerlIO_printf(file,
855 "%*sTYPE = %s ===> ",
53e06cf0 856 (int)(PL_dumpindent*level-4), "", OP_NAME(o));
2814eb74 857 if (o->op_next)
b6f05621
DM
858 PerlIO_printf(file,
859 o->op_type == OP_NULL ? "(%"UVuf")\n" : "%"UVuf"\n",
666ea192 860 sequence_num(o->op_next));
79072805 861 else
e75ab6ad 862 PerlIO_printf(file, "NULL\n");
11343788 863 if (o->op_targ) {
e15d5972 864 if (optype == OP_NULL) {
cea2e8a9 865 Perl_dump_indent(aTHX_ level, file, " (was %s)\n", PL_op_name[o->op_targ]);
e15d5972 866 if (o->op_targ == OP_NEXTSTATE) {
ae7d165c 867 if (CopLINE(cCOPo))
f5992bc4 868 Perl_dump_indent(aTHX_ level, file, "LINE = %"UVuf"\n",
9d98dee5 869 (UV)CopLINE(cCOPo));
ae7d165c
PJ
870 if (CopSTASHPV(cCOPo))
871 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
872 CopSTASHPV(cCOPo));
4b65a919 873 if (CopLABEL(cCOPo))
ae7d165c 874 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
4b65a919 875 CopLABEL(cCOPo));
ae7d165c
PJ
876 }
877 }
8990e307 878 else
894356b3 879 Perl_dump_indent(aTHX_ level, file, "TARG = %ld\n", (long)o->op_targ);
8990e307 880 }
748a9306 881#ifdef DUMPADDR
57def98f 882 Perl_dump_indent(aTHX_ level, file, "ADDR = 0x%"UVxf" => 0x%"UVxf"\n", (UV)o, (UV)o->op_next);
79072805 883#endif
7e5d8ed2 884 if (o->op_flags || o->op_latefree || o->op_latefreed || o->op_attached) {
e15d5972 885 SV * const tmpsv = newSVpvs("");
5dc0d613 886 switch (o->op_flags & OPf_WANT) {
54310121 887 case OPf_WANT_VOID:
46fc3d4c 888 sv_catpv(tmpsv, ",VOID");
54310121
PP
889 break;
890 case OPf_WANT_SCALAR:
46fc3d4c 891 sv_catpv(tmpsv, ",SCALAR");
54310121
PP
892 break;
893 case OPf_WANT_LIST:
46fc3d4c 894 sv_catpv(tmpsv, ",LIST");
54310121
PP
895 break;
896 default:
46fc3d4c 897 sv_catpv(tmpsv, ",UNKNOWN");
54310121
PP
898 break;
899 }
a0c2f4dd 900 append_flags(tmpsv, o->op_flags, op_flags_names);
29522234
DM
901 if (o->op_latefree)
902 sv_catpv(tmpsv, ",LATEFREE");
903 if (o->op_latefreed)
904 sv_catpv(tmpsv, ",LATEFREED");
7e5d8ed2
DM
905 if (o->op_attached)
906 sv_catpv(tmpsv, ",ATTACHED");
b15aece3 907 Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
46fc3d4c 908 SvREFCNT_dec(tmpsv);
79072805 909 }
11343788 910 if (o->op_private) {
e15d5972
AL
911 SV * const tmpsv = newSVpvs("");
912 if (PL_opargs[optype] & OA_TARGLEX) {
07447971
GS
913 if (o->op_private & OPpTARGET_MY)
914 sv_catpv(tmpsv, ",TARGET_MY");
915 }
e15d5972 916 else if (optype == OP_ENTERSUB ||
5c135d48
NC
917 optype == OP_RV2SV ||
918 optype == OP_GVSV ||
919 optype == OP_RV2AV ||
920 optype == OP_RV2HV ||
921 optype == OP_RV2GV ||
922 optype == OP_AELEM ||
923 optype == OP_HELEM )
85e6fe83 924 {
e15d5972 925 if (optype == OP_ENTERSUB) {
ea9ad1f2 926 append_flags(tmpsv, o->op_private, op_entersub_names);
68dc0745 927 }
bf91b999 928 else {
d3011074 929 switch (o->op_private & OPpDEREF) {
b9ac451d
AL
930 case OPpDEREF_SV:
931 sv_catpv(tmpsv, ",SV");
932 break;
933 case OPpDEREF_AV:
934 sv_catpv(tmpsv, ",AV");
935 break;
936 case OPpDEREF_HV:
937 sv_catpv(tmpsv, ",HV");
938 break;
939 }
bf91b999
SC
940 if (o->op_private & OPpMAYBE_LVSUB)
941 sv_catpv(tmpsv, ",MAYBE_LVSUB");
942 }
0824d667 943
e15d5972 944 if (optype == OP_AELEM || optype == OP_HELEM) {
5dc0d613 945 if (o->op_private & OPpLVAL_DEFER)
46fc3d4c 946 sv_catpv(tmpsv, ",LVAL_DEFER");
68dc0745
PP
947 }
948 else {
5dc0d613 949 if (o->op_private & HINT_STRICT_REFS)
46fc3d4c 950 sv_catpv(tmpsv, ",STRICT_REFS");
192587c2
GS
951 if (o->op_private & OPpOUR_INTRO)
952 sv_catpv(tmpsv, ",OUR_INTRO");
68dc0745 953 }
8d063cd8 954 }
1fe3abee
NC
955 else if (S_op_private_to_names(aTHX_ tmpsv, optype, o->op_private)) {
956 }
ef69c8fc 957 else if (PL_check[optype] != Perl_ck_ftst) {
6ecf81d6 958 if (OP_IS_FILETEST_ACCESS(o->op_type) && o->op_private & OPpFT_ACCESS)
fbb0b3b3
RGS
959 sv_catpv(tmpsv, ",FT_ACCESS");
960 if (o->op_private & OPpFT_STACKED)
961 sv_catpv(tmpsv, ",FT_STACKED");
1af34c76 962 }
11343788 963 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
46fc3d4c
PP
964 sv_catpv(tmpsv, ",INTRO");
965 if (SvCUR(tmpsv))
b15aece3 966 Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX_const(tmpsv) + 1);
46fc3d4c 967 SvREFCNT_dec(tmpsv);
8d063cd8 968 }
8d063cd8 969
3b721df9
NC
970#ifdef PERL_MAD
971 if (PL_madskills && o->op_madprop) {
76f68e9b 972 SV * const tmpsv = newSVpvs("");
3b721df9
NC
973 MADPROP* mp = o->op_madprop;
974 Perl_dump_indent(aTHX_ level, file, "MADPROPS = {\n");
975 level++;
976 while (mp) {
61f9802b 977 const char tmp = mp->mad_key;
76f68e9b 978 sv_setpvs(tmpsv,"'");
3b721df9
NC
979 if (tmp)
980 sv_catpvn(tmpsv, &tmp, 1);
981 sv_catpv(tmpsv, "'=");
982 switch (mp->mad_type) {
983 case MAD_NULL:
984 sv_catpv(tmpsv, "NULL");
985 Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv));
986 break;
987 case MAD_PV:
988 sv_catpv(tmpsv, "<");
989 sv_catpvn(tmpsv, (char*)mp->mad_val, mp->mad_vlen);
990 sv_catpv(tmpsv, ">");
991 Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv));
992 break;
993 case MAD_OP:
994 if ((OP*)mp->mad_val) {
995 Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv));
996 do_op_dump(level, file, (OP*)mp->mad_val);
997 }
998 break;
999 default:
1000 sv_catpv(tmpsv, "(UNK)");
1001 Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv));
1002 break;
1003 }
1004 mp = mp->mad_next;
1005 }
1006 level--;
1007 Perl_dump_indent(aTHX_ level, file, "}\n");
1008
1009 SvREFCNT_dec(tmpsv);
1010 }
1011#endif
1012
e15d5972 1013 switch (optype) {
971a9dd3 1014 case OP_AELEMFAST:
93a17b20 1015 case OP_GVSV:
79072805 1016 case OP_GV:
971a9dd3 1017#ifdef USE_ITHREADS
c803eecc 1018 Perl_dump_indent(aTHX_ level, file, "PADIX = %" IVdf "\n", (IV)cPADOPo->op_padix);
971a9dd3 1019#else
1640e9f0 1020 if ( ! (o->op_flags & OPf_SPECIAL)) { /* not lexical */
38c076c7 1021 if (cSVOPo->op_sv) {
d4c19fe8 1022 SV * const tmpsv = newSV(0);
38c076c7
DM
1023 ENTER;
1024 SAVEFREESV(tmpsv);
3b721df9 1025#ifdef PERL_MAD
84021b46 1026 /* FIXME - is this making unwarranted assumptions about the
3b721df9
NC
1027 UTF-8 cleanliness of the dump file handle? */
1028 SvUTF8_on(tmpsv);
1029#endif
159b6efe 1030 gv_fullname3(tmpsv, MUTABLE_GV(cSVOPo->op_sv), NULL);
8b6b16e7 1031 Perl_dump_indent(aTHX_ level, file, "GV = %s\n",
d5263905 1032 SvPV_nolen_const(tmpsv));
38c076c7
DM
1033 LEAVE;
1034 }
1035 else
1036 Perl_dump_indent(aTHX_ level, file, "GV = NULL\n");
378cc40b 1037 }
971a9dd3 1038#endif
79072805
LW
1039 break;
1040 case OP_CONST:
996c9baa 1041 case OP_HINTSEVAL:
f5d5a27c 1042 case OP_METHOD_NAMED:
b6a15bc5
DM
1043#ifndef USE_ITHREADS
1044 /* with ITHREADS, consts are stored in the pad, and the right pad
1045 * may not be active here, so skip */
3848b962 1046 Perl_dump_indent(aTHX_ level, file, "SV = %s\n", SvPEEK(cSVOPo_sv));
b6a15bc5 1047#endif
79072805 1048 break;
93a17b20
LW
1049 case OP_NEXTSTATE:
1050 case OP_DBSTATE:
57843af0 1051 if (CopLINE(cCOPo))
f5992bc4 1052 Perl_dump_indent(aTHX_ level, file, "LINE = %"UVuf"\n",
9d98dee5 1053 (UV)CopLINE(cCOPo));
ed094faf
GS
1054 if (CopSTASHPV(cCOPo))
1055 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
1056 CopSTASHPV(cCOPo));
4b65a919 1057 if (CopLABEL(cCOPo))
ed094faf 1058 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
4b65a919 1059 CopLABEL(cCOPo));
79072805
LW
1060 break;
1061 case OP_ENTERLOOP:
cea2e8a9 1062 Perl_dump_indent(aTHX_ level, file, "REDO ===> ");
11343788 1063 if (cLOOPo->op_redoop)
f5992bc4 1064 PerlIO_printf(file, "%"UVuf"\n", sequence_num(cLOOPo->op_redoop));
79072805 1065 else
3967c732 1066 PerlIO_printf(file, "DONE\n");
cea2e8a9 1067 Perl_dump_indent(aTHX_ level, file, "NEXT ===> ");
11343788 1068 if (cLOOPo->op_nextop)
f5992bc4 1069 PerlIO_printf(file, "%"UVuf"\n", sequence_num(cLOOPo->op_nextop));
79072805 1070 else
3967c732 1071 PerlIO_printf(file, "DONE\n");
cea2e8a9 1072 Perl_dump_indent(aTHX_ level, file, "LAST ===> ");
11343788 1073 if (cLOOPo->op_lastop)
f5992bc4 1074 PerlIO_printf(file, "%"UVuf"\n", sequence_num(cLOOPo->op_lastop));
79072805 1075 else
3967c732 1076 PerlIO_printf(file, "DONE\n");
79072805
LW
1077 break;
1078 case OP_COND_EXPR:
1a67a97c 1079 case OP_RANGE:
a0d0e21e 1080 case OP_MAPWHILE:
79072805
LW
1081 case OP_GREPWHILE:
1082 case OP_OR:
1083 case OP_AND:
cea2e8a9 1084 Perl_dump_indent(aTHX_ level, file, "OTHER ===> ");
11343788 1085 if (cLOGOPo->op_other)
f5992bc4 1086 PerlIO_printf(file, "%"UVuf"\n", sequence_num(cLOGOPo->op_other));
79072805 1087 else
3967c732 1088 PerlIO_printf(file, "DONE\n");
79072805
LW
1089 break;
1090 case OP_PUSHRE:
1091 case OP_MATCH:
8782bef2 1092 case OP_QR:
79072805 1093 case OP_SUBST:
3967c732 1094 do_pmop_dump(level, file, cPMOPo);
79072805 1095 break;
7934575e
GS
1096 case OP_LEAVE:
1097 case OP_LEAVEEVAL:
1098 case OP_LEAVESUB:
1099 case OP_LEAVESUBLV:
1100 case OP_LEAVEWRITE:
1101 case OP_SCOPE:
1102 if (o->op_private & OPpREFCOUNTED)
1103 Perl_dump_indent(aTHX_ level, file, "REFCNT = %"UVuf"\n", (UV)o->op_targ);
1104 break;
a0d0e21e
LW
1105 default:
1106 break;
79072805 1107 }
11343788 1108 if (o->op_flags & OPf_KIDS) {
79072805 1109 OP *kid;
11343788 1110 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
3967c732 1111 do_op_dump(level, file, kid);
8d063cd8 1112 }
cea2e8a9 1113 Perl_dump_indent(aTHX_ level-1, file, "}\n");
3967c732
JD
1114}
1115
1116void
6867be6d 1117Perl_op_dump(pTHX_ const OP *o)
3967c732 1118{
7918f24d 1119 PERL_ARGS_ASSERT_OP_DUMP;
3967c732 1120 do_op_dump(0, Perl_debug_log, o);
8d063cd8
LW
1121}
1122
8adcabd8 1123void
864dbfa3 1124Perl_gv_dump(pTHX_ GV *gv)
378cc40b 1125{
79072805 1126 SV *sv;
378cc40b 1127
7918f24d
NC
1128 PERL_ARGS_ASSERT_GV_DUMP;
1129
79072805 1130 if (!gv) {
760ac839 1131 PerlIO_printf(Perl_debug_log, "{}\n");
378cc40b
LW
1132 return;
1133 }
8990e307 1134 sv = sv_newmortal();
760ac839 1135 PerlIO_printf(Perl_debug_log, "{\n");
bd61b366 1136 gv_fullname3(sv, gv, NULL);
b15aece3 1137 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s", SvPVX_const(sv));
79072805 1138 if (gv != GvEGV(gv)) {
bd61b366 1139 gv_efullname3(sv, GvEGV(gv), NULL);
b15aece3 1140 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s", SvPVX_const(sv));
8adcabd8 1141 }
3967c732 1142 PerlIO_putc(Perl_debug_log, '\n');
cea2e8a9 1143 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "}\n");
8d063cd8
LW
1144}
1145
14befaf4 1146
afe38520 1147/* map magic types to the symbolic names
14befaf4
DM
1148 * (with the PERL_MAGIC_ prefixed stripped)
1149 */
1150
27da23d5 1151static const struct { const char type; const char *name; } magic_names[] = {
52f49505 1152#include "mg_names.c"
516a5887 1153 /* this null string terminates the list */
b9ac451d 1154 { 0, NULL },
14befaf4
DM
1155};
1156
8adcabd8 1157void
6867be6d 1158Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, const MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
8d063cd8 1159{
7918f24d
NC
1160 PERL_ARGS_ASSERT_DO_MAGIC_DUMP;
1161
3967c732 1162 for (; mg; mg = mg->mg_moremagic) {
b900a521
JH
1163 Perl_dump_indent(aTHX_ level, file,
1164 " MAGIC = 0x%"UVxf"\n", PTR2UV(mg));
3967c732 1165 if (mg->mg_virtual) {
bfed75c6 1166 const MGVTBL * const v = mg->mg_virtual;
2d1f1fe5
NC
1167 if (v >= PL_magic_vtables
1168 && v < PL_magic_vtables + magic_vtable_max) {
1169 const U32 i = v - PL_magic_vtables;
1170 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", PL_magic_vtable_names[i]);
1171 }
3967c732 1172 else
b900a521 1173 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0x%"UVxf"\n", PTR2UV(v));
3967c732
JD
1174 }
1175 else
cea2e8a9 1176 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0\n");
8d063cd8 1177
3967c732 1178 if (mg->mg_private)
cea2e8a9 1179 Perl_dump_indent(aTHX_ level, file, " MG_PRIVATE = %d\n", mg->mg_private);
3967c732 1180
14befaf4
DM
1181 {
1182 int n;
c445ea15 1183 const char *name = NULL;
27da23d5 1184 for (n = 0; magic_names[n].name; n++) {
14befaf4
DM
1185 if (mg->mg_type == magic_names[n].type) {
1186 name = magic_names[n].name;
1187 break;
1188 }
1189 }
1190 if (name)
1191 Perl_dump_indent(aTHX_ level, file,
1192 " MG_TYPE = PERL_MAGIC_%s\n", name);
1193 else
1194 Perl_dump_indent(aTHX_ level, file,
1195 " MG_TYPE = UNKNOWN(\\%o)\n", mg->mg_type);
1196 }
3967c732
JD
1197
1198 if (mg->mg_flags) {
cea2e8a9 1199 Perl_dump_indent(aTHX_ level, file, " MG_FLAGS = 0x%02X\n", mg->mg_flags);
cb50f42d
YST
1200 if (mg->mg_type == PERL_MAGIC_envelem &&
1201 mg->mg_flags & MGf_TAINTEDDIR)
cea2e8a9 1202 Perl_dump_indent(aTHX_ level, file, " TAINTEDDIR\n");
4c02285a
FR
1203 if (mg->mg_type == PERL_MAGIC_regex_global &&
1204 mg->mg_flags & MGf_MINMATCH)
1205 Perl_dump_indent(aTHX_ level, file, " MINMATCH\n");
3967c732 1206 if (mg->mg_flags & MGf_REFCOUNTED)
cea2e8a9 1207 Perl_dump_indent(aTHX_ level, file, " REFCOUNTED\n");
3967c732 1208 if (mg->mg_flags & MGf_GSKIP)
cea2e8a9 1209 Perl_dump_indent(aTHX_ level, file, " GSKIP\n");
4c02285a
FR
1210 if (mg->mg_flags & MGf_COPY)
1211 Perl_dump_indent(aTHX_ level, file, " COPY\n");
1212 if (mg->mg_flags & MGf_DUP)
1213 Perl_dump_indent(aTHX_ level, file, " DUP\n");
1214 if (mg->mg_flags & MGf_LOCAL)
1215 Perl_dump_indent(aTHX_ level, file, " LOCAL\n");
3967c732
JD
1216 }
1217 if (mg->mg_obj) {
4c02285a 1218 Perl_dump_indent(aTHX_ level, file, " MG_OBJ = 0x%"UVxf"\n",
28d8d7f4
YO
1219 PTR2UV(mg->mg_obj));
1220 if (mg->mg_type == PERL_MAGIC_qr) {
07bc277f 1221 REGEXP* const re = (REGEXP *)mg->mg_obj;
61f9802b 1222 SV * const dsv = sv_newmortal();
866c78d1 1223 const char * const s
4c02285a 1224 = pv_pretty(dsv, RX_WRAPPED(re), RX_WRAPLEN(re),
28d8d7f4 1225 60, NULL, NULL,
95b611b0 1226 ( PERL_PV_PRETTY_QUOTE | PERL_PV_ESCAPE_RE | PERL_PV_PRETTY_ELLIPSES |
3c8556c3 1227 (RX_UTF8(re) ? PERL_PV_ESCAPE_UNI : 0))
28d8d7f4 1228 );
6483fb35
RGS
1229 Perl_dump_indent(aTHX_ level+1, file, " PAT = %s\n", s);
1230 Perl_dump_indent(aTHX_ level+1, file, " REFCNT = %"IVdf"\n",
07bc277f 1231 (IV)RX_REFCNT(re));
28d8d7f4
YO
1232 }
1233 if (mg->mg_flags & MGf_REFCOUNTED)
3967c732
JD
1234 do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
1235 }
1236 if (mg->mg_len)
894356b3 1237 Perl_dump_indent(aTHX_ level, file, " MG_LEN = %ld\n", (long)mg->mg_len);
3967c732 1238 if (mg->mg_ptr) {
b900a521 1239 Perl_dump_indent(aTHX_ level, file, " MG_PTR = 0x%"UVxf, PTR2UV(mg->mg_ptr));
3967c732 1240 if (mg->mg_len >= 0) {
7e8c5dac 1241 if (mg->mg_type != PERL_MAGIC_utf8) {
61f9802b 1242 SV * const sv = newSVpvs("");
7e8c5dac
HS
1243 PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim));
1244 SvREFCNT_dec(sv);
1245 }
3967c732
JD
1246 }
1247 else if (mg->mg_len == HEf_SVKEY) {
1248 PerlIO_puts(file, " => HEf_SVKEY\n");
ad64d0ec
NC
1249 do_sv_dump(level+2, file, MUTABLE_SV(((mg)->mg_ptr)), nest+1,
1250 maxnest, dumpops, pvlim); /* MG is already +1 */
3967c732
JD
1251 continue;
1252 }
866f9d6c 1253 else if (mg->mg_len == -1 && mg->mg_type == PERL_MAGIC_utf8);
3967c732 1254 else
866f9d6c
FC
1255 PerlIO_puts(
1256 file,
1257 " ???? - " __FILE__
1258 " does not know how to handle this MG_LEN"
1259 );
3967c732
JD
1260 PerlIO_putc(file, '\n');
1261 }
7e8c5dac 1262 if (mg->mg_type == PERL_MAGIC_utf8) {
61f9802b 1263 const STRLEN * const cache = (STRLEN *) mg->mg_ptr;
7e8c5dac
HS
1264 if (cache) {
1265 IV i;
1266 for (i = 0; i < PERL_MAGIC_UTF8_CACHESIZE; i++)
1267 Perl_dump_indent(aTHX_ level, file,
1268 " %2"IVdf": %"UVuf" -> %"UVuf"\n",
1269 i,
1270 (UV)cache[i * 2],
1271 (UV)cache[i * 2 + 1]);
1272 }
1273 }
378cc40b 1274 }
3967c732
JD
1275}
1276
1277void
6867be6d 1278Perl_magic_dump(pTHX_ const MAGIC *mg)
3967c732 1279{
b9ac451d 1280 do_magic_dump(0, Perl_debug_log, mg, 0, 0, FALSE, 0);
3967c732
JD
1281}
1282
1283void
e1ec3a88 1284Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, const char *name, HV *sv)
3967c732 1285{
bfcb3514 1286 const char *hvname;
7918f24d
NC
1287
1288 PERL_ARGS_ASSERT_DO_HV_DUMP;
1289
b900a521 1290 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
bfcb3514 1291 if (sv && (hvname = HvNAME_get(sv)))
d7d51f4b
YO
1292 {
1293 /* we have to use pv_display and HvNAMELEN_get() so that we display the real package
1294 name which quite legally could contain insane things like tabs, newlines, nulls or
1295 other scary crap - this should produce sane results - except maybe for unicode package
1296 names - but we will wait for someone to file a bug on that - demerphq */
1297 SV * const tmpsv = newSVpvs("");
1298 PerlIO_printf(file, "\t%s\n", pv_display(tmpsv, hvname, HvNAMELEN_get(sv), 0, 1024));
1299 }
79072805 1300 else
3967c732
JD
1301 PerlIO_putc(file, '\n');
1302}
1303
1304void
e1ec3a88 1305Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
3967c732 1306{
7918f24d
NC
1307 PERL_ARGS_ASSERT_DO_GV_DUMP;
1308
b900a521 1309 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
3967c732
JD
1310 if (sv && GvNAME(sv))
1311 PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv));
c90c0ff4 1312 else
3967c732
JD
1313 PerlIO_putc(file, '\n');
1314}
1315
1316void
e1ec3a88 1317Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
3967c732 1318{
7918f24d
NC
1319 PERL_ARGS_ASSERT_DO_GVGV_DUMP;
1320
b900a521 1321 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
3967c732 1322 if (sv && GvNAME(sv)) {
bfcb3514 1323 const char *hvname;
3967c732 1324 PerlIO_printf(file, "\t\"");
bfcb3514
NC
1325 if (GvSTASH(sv) && (hvname = HvNAME_get(GvSTASH(sv))))
1326 PerlIO_printf(file, "%s\" :: \"", hvname);
3967c732 1327 PerlIO_printf(file, "%s\"\n", GvNAME(sv));
8d063cd8 1328 }
3967c732
JD
1329 else
1330 PerlIO_putc(file, '\n');
1331}
1332
a0c2f4dd
NC
1333const struct flag_to_name first_sv_flags_names[] = {
1334 {SVs_TEMP, "TEMP,"},
1335 {SVs_OBJECT, "OBJECT,"},
1336 {SVs_GMG, "GMG,"},
1337 {SVs_SMG, "SMG,"},
1338 {SVs_RMG, "RMG,"},
1339 {SVf_IOK, "IOK,"},
1340 {SVf_NOK, "NOK,"},
1341 {SVf_POK, "POK,"}
1342};
1343
1344const struct flag_to_name second_sv_flags_names[] = {
1345 {SVf_OOK, "OOK,"},
1346 {SVf_FAKE, "FAKE,"},
1347 {SVf_READONLY, "READONLY,"},
1348 {SVf_BREAK, "BREAK,"},
1349 {SVf_AMAGIC, "OVERLOAD,"},
1350 {SVp_IOK, "pIOK,"},
1351 {SVp_NOK, "pNOK,"},
1352 {SVp_POK, "pPOK,"}
1353};
1354
ae1f06a1
NC
1355const struct flag_to_name cv_flags_names[] = {
1356 {CVf_ANON, "ANON,"},
1357 {CVf_UNIQUE, "UNIQUE,"},
1358 {CVf_CLONE, "CLONE,"},
1359 {CVf_CLONED, "CLONED,"},
1360 {CVf_CONST, "CONST,"},
1361 {CVf_NODEBUG, "NODEBUG,"},
1362 {CVf_LVALUE, "LVALUE,"},
1363 {CVf_METHOD, "METHOD,"},
cfc1e951 1364 {CVf_WEAKOUTSIDE, "WEAKOUTSIDE,"},
31d45e0c 1365 {CVf_CVGV_RC, "CVGV_RC,"},
bad4ae38 1366 {CVf_DYNFILE, "DYNFILE,"},
8fa6a409 1367 {CVf_AUTOLOAD, "AUTOLOAD,"},
31d45e0c 1368 {CVf_ISXSUB, "ISXSUB,"}
ae1f06a1
NC
1369};
1370
1371const struct flag_to_name hv_flags_names[] = {
1372 {SVphv_SHAREKEYS, "SHAREKEYS,"},
1373 {SVphv_LAZYDEL, "LAZYDEL,"},
1374 {SVphv_HASKFLAGS, "HASKFLAGS,"},
1375 {SVphv_REHASH, "REHASH,"},
1376 {SVphv_CLONEABLE, "CLONEABLE,"}
1377};
1378
1379const struct flag_to_name gp_flags_names[] = {
1380 {GVf_INTRO, "INTRO,"},
1381 {GVf_MULTI, "MULTI,"},
1382 {GVf_ASSUMECV, "ASSUMECV,"},
1383 {GVf_IN_PAD, "IN_PAD,"}
1384};
1385
1386const struct flag_to_name gp_flags_imported_names[] = {
1387 {GVf_IMPORTED_SV, " SV"},
1388 {GVf_IMPORTED_AV, " AV"},
1389 {GVf_IMPORTED_HV, " HV"},
1390 {GVf_IMPORTED_CV, " CV"},
1391};
1392
d63e6659
DM
1393const struct flag_to_name regexp_flags_names[] = {
1394 {RXf_PMf_MULTILINE, "PMf_MULTILINE,"},
1395 {RXf_PMf_SINGLELINE, "PMf_SINGLELINE,"},
1396 {RXf_PMf_FOLD, "PMf_FOLD,"},
1397 {RXf_PMf_EXTENDED, "PMf_EXTENDED,"},
1398 {RXf_PMf_KEEPCOPY, "PMf_KEEPCOPY,"},
1399 {RXf_ANCH_BOL, "ANCH_BOL,"},
1400 {RXf_ANCH_MBOL, "ANCH_MBOL,"},
1401 {RXf_ANCH_SBOL, "ANCH_SBOL,"},
1402 {RXf_ANCH_GPOS, "ANCH_GPOS,"},
1403 {RXf_GPOS_SEEN, "GPOS_SEEN,"},
1404 {RXf_GPOS_FLOAT, "GPOS_FLOAT,"},
1405 {RXf_LOOKBEHIND_SEEN, "LOOKBEHIND_SEEN,"},
1406 {RXf_EVAL_SEEN, "EVAL_SEEN,"},
1407 {RXf_CANY_SEEN, "CANY_SEEN,"},
1408 {RXf_NOSCAN, "NOSCAN,"},
1409 {RXf_CHECK_ALL, "CHECK_ALL,"},
1410 {RXf_MATCH_UTF8, "MATCH_UTF8,"},
1411 {RXf_USE_INTUIT_NOML, "USE_INTUIT_NOML,"},
1412 {RXf_USE_INTUIT_ML, "USE_INTUIT_ML,"},
1413 {RXf_INTUIT_TAIL, "INTUIT_TAIL,"},
1414 {RXf_SPLIT, "SPLIT,"},
1415 {RXf_COPY_DONE, "COPY_DONE,"},
1416 {RXf_TAINTED_SEEN, "TAINTED_SEEN,"},
1417 {RXf_TAINTED, "TAINTED,"},
1418 {RXf_START_ONLY, "START_ONLY,"},
1419 {RXf_SKIPWHITE, "SKIPWHITE,"},
1420 {RXf_WHITE, "WHITE,"},
1421 {RXf_NULL, "NULL,"},
1422};
1423
3967c732 1424void
864dbfa3 1425Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
3967c732 1426{
97aff369 1427 dVAR;
cea89e20 1428 SV *d;
e1ec3a88 1429 const char *s;
3967c732
JD
1430 U32 flags;
1431 U32 type;
1432
7918f24d
NC
1433 PERL_ARGS_ASSERT_DO_SV_DUMP;
1434
3967c732 1435 if (!sv) {
cea2e8a9 1436 Perl_dump_indent(aTHX_ level, file, "SV = 0\n");
3967c732 1437 return;
378cc40b 1438 }
2ef28da1 1439
3967c732
JD
1440 flags = SvFLAGS(sv);
1441 type = SvTYPE(sv);
79072805 1442
e0bbf362
DM
1443 /* process general SV flags */
1444
cea89e20 1445 d = Perl_newSVpvf(aTHX_
57def98f 1446 "(0x%"UVxf") at 0x%"UVxf"\n%*s REFCNT = %"IVdf"\n%*s FLAGS = (",
56431972 1447 PTR2UV(SvANY(sv)), PTR2UV(sv),
894356b3
GS
1448 (int)(PL_dumpindent*level), "", (IV)SvREFCNT(sv),
1449 (int)(PL_dumpindent*level), "");
8d063cd8 1450
1979170b
NC
1451 if (!((flags & SVpad_NAME) == SVpad_NAME
1452 && (type == SVt_PVMG || type == SVt_PVNV))) {
9a214eec
DM
1453 if ((flags & SVs_PADMY) && (flags & SVs_PADSTALE))
1454 sv_catpv(d, "PADSTALE,");
e604303a 1455 }
1979170b 1456 if (!((flags & SVpad_NAME) == SVpad_NAME && type == SVt_PVMG)) {
9a214eec
DM
1457 if (!(flags & SVs_PADMY) && (flags & SVs_PADTMP))
1458 sv_catpv(d, "PADTMP,");
e604303a
NC
1459 if (flags & SVs_PADMY) sv_catpv(d, "PADMY,");
1460 }
a0c2f4dd 1461 append_flags(d, flags, first_sv_flags_names);
810b8aa5
GS
1462 if (flags & SVf_ROK) {
1463 sv_catpv(d, "ROK,");
1464 if (SvWEAKREF(sv)) sv_catpv(d, "WEAKREF,");
1465 }
a0c2f4dd 1466 append_flags(d, flags, second_sv_flags_names);
1ccdb730
NC
1467 if (flags & SVp_SCREAM && type != SVt_PVHV && !isGV_with_GP(sv)) {
1468 if (SvPCS_IMPORTED(sv))
1469 sv_catpv(d, "PCS_IMPORTED,");
1470 else
9660f481 1471 sv_catpv(d, "SCREAM,");
1ccdb730 1472 }
3967c732 1473
e0bbf362
DM
1474 /* process type-specific SV flags */
1475
3967c732
JD
1476 switch (type) {
1477 case SVt_PVCV:
1478 case SVt_PVFM:
ae1f06a1 1479 append_flags(d, CvFLAGS(sv), cv_flags_names);
3967c732
JD
1480 break;
1481 case SVt_PVHV:
ae1f06a1 1482 append_flags(d, flags, hv_flags_names);
3967c732 1483 break;
926fc7b6
DM
1484 case SVt_PVGV:
1485 case SVt_PVLV:
1486 if (isGV_with_GP(sv)) {
ae1f06a1 1487 append_flags(d, GvFLAGS(sv), gp_flags_names);
926fc7b6 1488 }
926fc7b6 1489 if (isGV_with_GP(sv) && GvIMPORTED(sv)) {
3967c732
JD
1490 sv_catpv(d, "IMPORT");
1491 if (GvIMPORTED(sv) == GVf_IMPORTED)
1492 sv_catpv(d, "ALL,");
1493 else {
1494 sv_catpv(d, "(");
ae1f06a1 1495 append_flags(d, GvFLAGS(sv), gp_flags_imported_names);
3967c732
JD
1496 sv_catpv(d, " ),");
1497 }
1498 }
addd1794 1499 /* FALL THROUGH */
25da4f38 1500 default:
e604303a 1501 evaled_or_uv:
25da4f38 1502 if (SvEVALED(sv)) sv_catpv(d, "EVALED,");
69c678eb 1503 if (SvIsUV(sv) && !(flags & SVf_ROK)) sv_catpv(d, "IsUV,");
25da4f38 1504 break;
addd1794 1505 case SVt_PVMG:
c13a5c80
NC
1506 if (SvTAIL(sv)) sv_catpv(d, "TAIL,");
1507 if (SvVALID(sv)) sv_catpv(d, "VALID,");
00b1698f 1508 if (SvPAD_TYPED(sv)) sv_catpv(d, "TYPED,");
e604303a 1509 if (SvPAD_OUR(sv)) sv_catpv(d, "OUR,");
2e94196c 1510 /* FALL THROUGH */
e604303a
NC
1511 case SVt_PVNV:
1512 if (SvPAD_STATE(sv)) sv_catpv(d, "STATE,");
1513 goto evaled_or_uv;
11ca45c0
NC
1514 case SVt_PVAV:
1515 break;
3967c732 1516 }
86f0d186
NC
1517 /* SVphv_SHAREKEYS is also 0x20000000 */
1518 if ((type != SVt_PVHV) && SvUTF8(sv))
9fe74ede 1519 sv_catpv(d, "UTF8");
3967c732 1520
b162af07
SP
1521 if (*(SvEND(d) - 1) == ',') {
1522 SvCUR_set(d, SvCUR(d) - 1);
1523 SvPVX(d)[SvCUR(d)] = '\0';
1524 }
3967c732 1525 sv_catpv(d, ")");
b15aece3 1526 s = SvPVX_const(d);
3967c732 1527
e0bbf362
DM
1528 /* dump initial SV details */
1529
fd0854ff 1530#ifdef DEBUG_LEAKING_SCALARS
cbe56f1d 1531 Perl_dump_indent(aTHX_ level, file,
cd676548 1532 "ALLOCATED at %s:%d %s %s (parent 0x%"UVxf"); serial %"UVuf"\n",
fd0854ff
DM
1533 sv->sv_debug_file ? sv->sv_debug_file : "(unknown)",
1534 sv->sv_debug_line,
1535 sv->sv_debug_inpad ? "for" : "by",
1536 sv->sv_debug_optype ? PL_op_name[sv->sv_debug_optype]: "(none)",
cd676548 1537 PTR2UV(sv->sv_debug_parent),
cbe56f1d
DM
1538 sv->sv_debug_serial
1539 );
fd0854ff 1540#endif
cea2e8a9 1541 Perl_dump_indent(aTHX_ level, file, "SV = ");
e0bbf362
DM
1542
1543 /* Dump SV type */
1544
5357ca29
NC
1545 if (type < SVt_LAST) {
1546 PerlIO_printf(file, "%s%s\n", svtypenames[type], s);
1547
1548 if (type == SVt_NULL) {
1549 SvREFCNT_dec(d);
1550 return;
1551 }
1552 } else {
faccc32b 1553 PerlIO_printf(file, "UNKNOWN(0x%"UVxf") %s\n", (UV)type, s);
cea89e20 1554 SvREFCNT_dec(d);
3967c732
JD
1555 return;
1556 }
e0bbf362
DM
1557
1558 /* Dump general SV fields */
1559
27bd069f 1560 if ((type >= SVt_PVIV && type != SVt_PVAV && type != SVt_PVHV
0a0c4b76
NC
1561 && type != SVt_PVCV && type != SVt_PVFM && type != SVt_PVIO
1562 && type != SVt_REGEXP && !isGV_with_GP(sv) && !SvVALID(sv))
4df7f6af 1563 || (type == SVt_IV && !SvROK(sv))) {
765f542d 1564 if (SvIsUV(sv)
f8c7b90f 1565#ifdef PERL_OLD_COPY_ON_WRITE
765f542d
NC
1566 || SvIsCOW(sv)
1567#endif
1568 )
57def98f 1569 Perl_dump_indent(aTHX_ level, file, " UV = %"UVuf, (UV)SvUVX(sv));
cf2093f6 1570 else
57def98f 1571 Perl_dump_indent(aTHX_ level, file, " IV = %"IVdf, (IV)SvIVX(sv));
f8c7b90f 1572#ifdef PERL_OLD_COPY_ON_WRITE
765f542d
NC
1573 if (SvIsCOW_shared_hash(sv))
1574 PerlIO_printf(file, " (HASH)");
1575 else if (SvIsCOW_normal(sv))
1576 PerlIO_printf(file, " (COW from 0x%"UVxf")", (UV)SvUVX(sv));
1577#endif
3967c732
JD
1578 PerlIO_putc(file, '\n');
1579 }
e0bbf362 1580
1979170b
NC
1581 if ((type == SVt_PVNV || type == SVt_PVMG)
1582 && (SvFLAGS(sv) & SVpad_NAME) == SVpad_NAME) {
0e4c4423
NC
1583 Perl_dump_indent(aTHX_ level, file, " COP_LOW = %"UVuf"\n",
1584 (UV) COP_SEQ_RANGE_LOW(sv));
1585 Perl_dump_indent(aTHX_ level, file, " COP_HIGH = %"UVuf"\n",
1586 (UV) COP_SEQ_RANGE_HIGH(sv));
1587 } else if ((type >= SVt_PVNV && type != SVt_PVAV && type != SVt_PVHV
08e44740 1588 && type != SVt_PVCV && type != SVt_PVFM && type != SVt_REGEXP
c0a413d1 1589 && type != SVt_PVIO && !isGV_with_GP(sv) && !SvVALID(sv))
0e4c4423 1590 || type == SVt_NV) {
e54dc35b 1591 STORE_NUMERIC_LOCAL_SET_STANDARD();
57def98f 1592 /* %Vg doesn't work? --jhi */
cf2093f6 1593#ifdef USE_LONG_DOUBLE
2d4389e4 1594 Perl_dump_indent(aTHX_ level, file, " NV = %.*" PERL_PRIgldbl "\n", LDBL_DIG, SvNVX(sv));
cf2093f6 1595#else
cea2e8a9 1596 Perl_dump_indent(aTHX_ level, file, " NV = %.*g\n", DBL_DIG, SvNVX(sv));
cf2093f6 1597#endif
e54dc35b 1598 RESTORE_NUMERIC_LOCAL();
3967c732 1599 }
e0bbf362 1600
3967c732 1601 if (SvROK(sv)) {
57def98f 1602 Perl_dump_indent(aTHX_ level, file, " RV = 0x%"UVxf"\n", PTR2UV(SvRV(sv)));
3967c732
JD
1603 if (nest < maxnest)
1604 do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim);
3967c732 1605 }
e0bbf362 1606
cea89e20
JH
1607 if (type < SVt_PV) {
1608 SvREFCNT_dec(d);
3967c732 1609 return;
cea89e20 1610 }
e0bbf362 1611
a49b46c6 1612 if ((type <= SVt_PVLV && !isGV_with_GP(sv)) || type == SVt_PVFM) {
b15aece3 1613 if (SvPVX_const(sv)) {
69240efd 1614 STRLEN delta;
7a4bba22 1615 if (SvOOK(sv)) {
69240efd 1616 SvOOK_offset(sv, delta);
7a4bba22 1617 Perl_dump_indent(aTHX_ level, file," OFFSET = %"UVuf"\n",
5186cc12 1618 (UV) delta);
69240efd
NC
1619 } else {
1620 delta = 0;
7a4bba22 1621 }
b15aece3 1622 Perl_dump_indent(aTHX_ level, file," PV = 0x%"UVxf" ", PTR2UV(SvPVX_const(sv)));
7a4bba22
NC
1623 if (SvOOK(sv)) {
1624 PerlIO_printf(file, "( %s . ) ",
1625 pv_display(d, SvPVX_const(sv) - delta, delta, 0,
1626 pvlim));
1627 }
b15aece3 1628 PerlIO_printf(file, "%s", pv_display(d, SvPVX_const(sv), SvCUR(sv), SvLEN(sv), pvlim));
e9569a7a
GG
1629 if (SvUTF8(sv)) /* the 6? \x{....} */
1630 PerlIO_printf(file, " [UTF8 \"%s\"]", sv_uni_display(d, sv, 6 * SvCUR(sv), UNI_DISPLAY_QQ));
e6abe6d8 1631 PerlIO_printf(file, "\n");
57def98f
JH
1632 Perl_dump_indent(aTHX_ level, file, " CUR = %"IVdf"\n", (IV)SvCUR(sv));
1633 Perl_dump_indent(aTHX_ level, file, " LEN = %"IVdf"\n", (IV)SvLEN(sv));
3967c732
JD
1634 }
1635 else
cea2e8a9 1636 Perl_dump_indent(aTHX_ level, file, " PV = 0\n");
3967c732 1637 }
e0bbf362 1638
3967c732 1639 if (type >= SVt_PVMG) {
0e4c4423 1640 if (type == SVt_PVMG && SvPAD_OUR(sv)) {
61f9802b 1641 HV * const ost = SvOURSTASH(sv);
38cbaf55
RGS
1642 if (ost)
1643 do_hv_dump(level, file, " OURSTASH", ost);
0e4c4423
NC
1644 } else {
1645 if (SvMAGIC(sv))
8530ff28 1646 do_magic_dump(level, file, SvMAGIC(sv), nest+1, maxnest, dumpops, pvlim);
0e4c4423 1647 }
3967c732
JD
1648 if (SvSTASH(sv))
1649 do_hv_dump(level, file, " STASH", SvSTASH(sv));
c13a5c80
NC
1650
1651 if ((type == SVt_PVMG || type == SVt_PVLV) && SvVALID(sv)) {
1652 Perl_dump_indent(aTHX_ level, file, " RARE = %u\n", (U8)BmRARE(sv));
1653 Perl_dump_indent(aTHX_ level, file, " PREVIOUS = %"UVuf"\n", (UV)BmPREVIOUS(sv));
1654 Perl_dump_indent(aTHX_ level, file, " USEFUL = %"IVdf"\n", (IV)BmUSEFUL(sv));
1655 }
3967c732 1656 }
e0bbf362
DM
1657
1658 /* Dump type-specific SV fields */
1659
3967c732 1660 switch (type) {
3967c732 1661 case SVt_PVAV:
57def98f 1662 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(AvARRAY(sv)));
3967c732 1663 if (AvARRAY(sv) != AvALLOC(sv)) {
57def98f
JH
1664 PerlIO_printf(file, " (offset=%"IVdf")\n", (IV)(AvARRAY(sv) - AvALLOC(sv)));
1665 Perl_dump_indent(aTHX_ level, file, " ALLOC = 0x%"UVxf"\n", PTR2UV(AvALLOC(sv)));
3967c732
JD
1666 }
1667 else
1668 PerlIO_putc(file, '\n');
57def98f
JH
1669 Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)AvFILLp(sv));
1670 Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)AvMAX(sv));
a3874608 1671 Perl_dump_indent(aTHX_ level, file, " ARYLEN = 0x%"UVxf"\n", SvMAGIC(sv) ? PTR2UV(AvARYLEN(sv)) : 0);
76f68e9b 1672 sv_setpvs(d, "");
11ca45c0
NC
1673 if (AvREAL(sv)) sv_catpv(d, ",REAL");
1674 if (AvREIFY(sv)) sv_catpv(d, ",REIFY");
b15aece3
SP
1675 Perl_dump_indent(aTHX_ level, file, " FLAGS = (%s)\n",
1676 SvCUR(d) ? SvPVX_const(d) + 1 : "");
502c6561 1677 if (nest < maxnest && av_len(MUTABLE_AV(sv)) >= 0) {
3967c732 1678 int count;
502c6561
NC
1679 for (count = 0; count <= av_len(MUTABLE_AV(sv)) && count < maxnest; count++) {
1680 SV** const elt = av_fetch(MUTABLE_AV(sv),count,0);
3967c732 1681
57def98f 1682 Perl_dump_indent(aTHX_ level + 1, file, "Elt No. %"IVdf"\n", (IV)count);
2ef28da1 1683 if (elt)
3967c732
JD
1684 do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim);
1685 }
1686 }
1687 break;
1688 case SVt_PVHV:
57def98f 1689 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv)));
1b95d04f 1690 if (HvARRAY(sv) && HvUSEDKEYS(sv)) {
3967c732
JD
1691 /* Show distribution of HEs in the ARRAY */
1692 int freq[200];
bb7a0f54 1693#define FREQ_MAX ((int)(sizeof freq / sizeof freq[0] - 1))
3967c732
JD
1694 int i;
1695 int max = 0;
1b95d04f 1696 U32 pow2 = 2, keys = HvUSEDKEYS(sv);
65202027 1697 NV theoret, sum = 0;
3967c732
JD
1698
1699 PerlIO_printf(file, " (");
1700 Zero(freq, FREQ_MAX + 1, int);
eb160463 1701 for (i = 0; (STRLEN)i <= HvMAX(sv); i++) {
c445ea15
AL
1702 HE* h;
1703 int count = 0;
3967c732
JD
1704 for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h))
1705 count++;
1706 if (count > FREQ_MAX)
1707 count = FREQ_MAX;
1708 freq[count]++;
1709 if (max < count)
1710 max = count;
1711 }
1712 for (i = 0; i <= max; i++) {
1713 if (freq[i]) {
1714 PerlIO_printf(file, "%d%s:%d", i,
1715 (i == FREQ_MAX) ? "+" : "",
1716 freq[i]);
1717 if (i != max)
1718 PerlIO_printf(file, ", ");
1719 }
1720 }
1721 PerlIO_putc(file, ')');
b8fa94d8
MG
1722 /* The "quality" of a hash is defined as the total number of
1723 comparisons needed to access every element once, relative
1724 to the expected number needed for a random hash.
1725
1726 The total number of comparisons is equal to the sum of
e76cd0fa
AMS
1727 the squares of the number of entries in each bucket.
1728 For a random hash of n keys into k buckets, the expected
b8fa94d8
MG
1729 value is
1730 n + n(n-1)/2k
1731 */
1732
3967c732
JD
1733 for (i = max; i > 0; i--) { /* Precision: count down. */
1734 sum += freq[i] * i * i;
1735 }
155aba94 1736 while ((keys = keys >> 1))
3967c732 1737 pow2 = pow2 << 1;
1b95d04f 1738 theoret = HvUSEDKEYS(sv);
b8fa94d8 1739 theoret += theoret * (theoret-1)/pow2;
3967c732 1740 PerlIO_putc(file, '\n');
6b4667fc 1741 Perl_dump_indent(aTHX_ level, file, " hash quality = %.1"NVff"%%", theoret/sum*100);
3967c732
JD
1742 }
1743 PerlIO_putc(file, '\n');
1b95d04f 1744 Perl_dump_indent(aTHX_ level, file, " KEYS = %"IVdf"\n", (IV)HvUSEDKEYS(sv));
57def98f
JH
1745 Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)HvFILL(sv));
1746 Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)HvMAX(sv));
bfcb3514
NC
1747 Perl_dump_indent(aTHX_ level, file, " RITER = %"IVdf"\n", (IV)HvRITER_get(sv));
1748 Perl_dump_indent(aTHX_ level, file, " EITER = 0x%"UVxf"\n", PTR2UV(HvEITER_get(sv)));
8d2f4536 1749 {
b9ac451d 1750 MAGIC * const mg = mg_find(sv, PERL_MAGIC_symtab);
8d2f4536
NC
1751 if (mg && mg->mg_obj) {
1752 Perl_dump_indent(aTHX_ level, file, " PMROOT = 0x%"UVxf"\n", PTR2UV(mg->mg_obj));
1753 }
1754 }
bfcb3514 1755 {
b9ac451d 1756 const char * const hvname = HvNAME_get(sv);
bfcb3514
NC
1757 if (hvname)
1758 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", hvname);
1759 }
86f55936 1760 if (SvOOK(sv)) {
ad64d0ec 1761 AV * const backrefs
85fbaab2 1762 = *Perl_hv_backreferences_p(aTHX_ MUTABLE_HV(sv));
7d88e6c4 1763 struct mro_meta * const meta = HvAUX(sv)->xhv_mro_meta;
67e04715
FC
1764 if (HvAUX(sv)->xhv_name_count)
1765 Perl_dump_indent(aTHX_
7afc2217
FC
1766 level, file, " NAMECOUNT = %"IVdf"\n",
1767 (IV)HvAUX(sv)->xhv_name_count
67e04715 1768 );
15d9236d 1769 if (HvAUX(sv)->xhv_name_u.xhvnameu_name && HvENAME_HEK_NN(sv)) {
ec3405c8
NC
1770 const I32 count = HvAUX(sv)->xhv_name_count;
1771 if (count) {
1772 SV * const names = newSVpvs_flags("", SVs_TEMP);
1773 /* The starting point is the first element if count is
1774 positive and the second element if count is negative. */
1775 HEK *const *hekp = HvAUX(sv)->xhv_name_u.xhvnameu_names
1776 + (count < 0 ? 1 : 0);
1777 HEK *const *const endp = HvAUX(sv)->xhv_name_u.xhvnameu_names
1778 + (count < 0 ? -count : count);
1779 while (hekp < endp) {
67e04715
FC
1780 if (*hekp) {
1781 sv_catpvs(names, ", \"");
ec3405c8 1782 sv_catpvn(names, HEK_KEY(*hekp), HEK_LEN(*hekp));
67e04715 1783 sv_catpvs(names, "\"");
ec3405c8
NC
1784 } else {
1785 /* This should never happen. */
1786 sv_catpvs(names, ", (null)");
67e04715 1787 }
ec3405c8
NC
1788 ++hekp;
1789 }
67e04715
FC
1790 Perl_dump_indent(aTHX_
1791 level, file, " ENAME = %s\n", SvPV_nolen(names)+2
1792 );
1793 }
1794 else
1795 Perl_dump_indent(aTHX_
1796 level, file, " ENAME = \"%s\"\n", HvENAME_get(sv)
1797 );
1798 }
86f55936
NC
1799 if (backrefs) {
1800 Perl_dump_indent(aTHX_ level, file, " BACKREFS = 0x%"UVxf"\n",
1801 PTR2UV(backrefs));
ad64d0ec 1802 do_sv_dump(level+1, file, MUTABLE_SV(backrefs), nest+1, maxnest,
86f55936
NC
1803 dumpops, pvlim);
1804 }
7d88e6c4
NC
1805 if (meta) {
1806 /* FIXME - mro_algs kflags can signal a UTF-8 name. */
1807 Perl_dump_indent(aTHX_ level, file, " MRO_WHICH = \"%.*s\" (0x%"UVxf")\n",
1808 (int)meta->mro_which->length,
1809 meta->mro_which->name,
1810 PTR2UV(meta->mro_which));
1811 Perl_dump_indent(aTHX_ level, file, " CACHE_GEN = 0x%"UVxf"\n",
1812 (UV)meta->cache_gen);
1813 Perl_dump_indent(aTHX_ level, file, " PKG_GEN = 0x%"UVxf"\n",
1814 (UV)meta->pkg_gen);
1815 if (meta->mro_linear_all) {
1816 Perl_dump_indent(aTHX_ level, file, " MRO_LINEAR_ALL = 0x%"UVxf"\n",
1817 PTR2UV(meta->mro_linear_all));
1818 do_sv_dump(level+1, file, MUTABLE_SV(meta->mro_linear_all), nest+1, maxnest,
1819 dumpops, pvlim);
1820 }
1821 if (meta->mro_linear_current) {
1822 Perl_dump_indent(aTHX_ level, file, " MRO_LINEAR_CURRENT = 0x%"UVxf"\n",
1823 PTR2UV(meta->mro_linear_current));
1824 do_sv_dump(level+1, file, MUTABLE_SV(meta->mro_linear_current), nest+1, maxnest,
1825 dumpops, pvlim);
1826 }
1827 if (meta->mro_nextmethod) {
1828 Perl_dump_indent(aTHX_ level, file, " MRO_NEXTMETHOD = 0x%"UVxf"\n",
1829 PTR2UV(meta->mro_nextmethod));
1830 do_sv_dump(level+1, file, MUTABLE_SV(meta->mro_nextmethod), nest+1, maxnest,
1831 dumpops, pvlim);
1832 }
1833 if (meta->isa) {
1834 Perl_dump_indent(aTHX_ level, file, " ISA = 0x%"UVxf"\n",
1835 PTR2UV(meta->isa));
1836 do_sv_dump(level+1, file, MUTABLE_SV(meta->isa), nest+1, maxnest,
1837 dumpops, pvlim);
1838 }
1839 }
86f55936 1840 }
b5698553 1841 if (nest < maxnest) {
cbab3169 1842 HV * const hv = MUTABLE_HV(sv);
b5698553
TH
1843 STRLEN i;
1844 HE *he;
cbab3169 1845
b5698553
TH
1846 if (HvARRAY(hv)) {
1847 int count = maxnest - nest;
1848 for (i=0; i <= HvMAX(hv); i++) {
1849 for (he = HvARRAY(hv)[i]; he; he = HeNEXT(he)) {
1850 U32 hash;
1851 SV * keysv;
1852 const char * keypv;
1853 SV * elt;
cbab3169 1854 STRLEN len;
b5698553
TH
1855
1856 if (count-- <= 0) goto DONEHV;
1857
1858 hash = HeHASH(he);
1859 keysv = hv_iterkeysv(he);
1860 keypv = SvPV_const(keysv, len);
1861 elt = HeVAL(he);
cbab3169
FC
1862
1863 Perl_dump_indent(aTHX_ level+1, file, "Elt %s ", pv_display(d, keypv, len, 0, pvlim));
1864 if (SvUTF8(keysv))
1865 PerlIO_printf(file, "[UTF8 \"%s\"] ", sv_uni_display(d, keysv, 6 * SvCUR(keysv), UNI_DISPLAY_QQ));
b5698553
TH
1866 if (HvEITER_get(hv) == he)
1867 PerlIO_printf(file, "[CURRENT] ");
cbab3169
FC
1868 if (HeKREHASH(he))
1869 PerlIO_printf(file, "[REHASH] ");
b5698553 1870 PerlIO_printf(file, "HASH = 0x%"UVxf"\n", (UV) hash);
cbab3169 1871 do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim);
3967c732 1872 }
b5698553
TH
1873 }
1874 DONEHV:;
1875 }
3967c732
JD
1876 }
1877 break;
e0bbf362 1878
3967c732 1879 case SVt_PVCV:
8fa6a409 1880 if (CvAUTOLOAD(sv)) {
cbf82dd0 1881 STRLEN len;
8fa6a409
FC
1882 const char *const name = SvPV_const(sv, len);
1883 Perl_dump_indent(aTHX_ level, file, " AUTOLOAD = \"%.*s\"\n",
1884 (int) len, name);
1885 }
1886 if (SvPOK(sv)) {
cbf82dd0 1887 Perl_dump_indent(aTHX_ level, file, " PROTOTYPE = \"%.*s\"\n",
8fa6a409 1888 (int) CvPROTOLEN(sv), CvPROTO(sv));
cbf82dd0 1889 }
3967c732
JD
1890 /* FALL THROUGH */
1891 case SVt_PVFM:
1892 do_hv_dump(level, file, " COMP_STASH", CvSTASH(sv));
d04ba589
NC
1893 if (!CvISXSUB(sv)) {
1894 if (CvSTART(sv)) {
1895 Perl_dump_indent(aTHX_ level, file,
1896 " START = 0x%"UVxf" ===> %"IVdf"\n",
1897 PTR2UV(CvSTART(sv)),
1898 (IV)sequence_num(CvSTART(sv)));
1899 }
1900 Perl_dump_indent(aTHX_ level, file, " ROOT = 0x%"UVxf"\n",
1901 PTR2UV(CvROOT(sv)));
1902 if (CvROOT(sv) && dumpops) {
1903 do_op_dump(level+1, file, CvROOT(sv));
1904 }
1905 } else {
126f53f3 1906 SV * const constant = cv_const_sv((const CV *)sv);
b1886099 1907
d04ba589 1908 Perl_dump_indent(aTHX_ level, file, " XSUB = 0x%"UVxf"\n", PTR2UV(CvXSUB(sv)));
b1886099
NC
1909
1910 if (constant) {
1911 Perl_dump_indent(aTHX_ level, file, " XSUBANY = 0x%"UVxf
1912 " (CONST SV)\n",
1913 PTR2UV(CvXSUBANY(sv).any_ptr));
1914 do_sv_dump(level+1, file, constant, nest+1, maxnest, dumpops,
1915 pvlim);
1916 } else {
1917 Perl_dump_indent(aTHX_ level, file, " XSUBANY = %"IVdf"\n",
1918 (IV)CvXSUBANY(sv).any_i32);
1919 }
1920 }
3967c732 1921 do_gvgv_dump(level, file, " GVGV::GV", CvGV(sv));
57843af0 1922 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", CvFILE(sv));
5129b2ca
NC
1923 if (type == SVt_PVCV)
1924 Perl_dump_indent(aTHX_ level, file, " DEPTH = %"IVdf"\n", (IV)CvDEPTH(sv));
894356b3 1925 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)CvFLAGS(sv));
a3985cdc 1926 Perl_dump_indent(aTHX_ level, file, " OUTSIDE_SEQ = %"UVuf"\n", (UV)CvOUTSIDE_SEQ(sv));
3967c732 1927 if (type == SVt_PVFM)
57def98f
JH
1928 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)FmLINES(sv));
1929 Perl_dump_indent(aTHX_ level, file, " PADLIST = 0x%"UVxf"\n", PTR2UV(CvPADLIST(sv)));
dd2155a4
DM
1930 if (nest < maxnest) {
1931 do_dump_pad(level+1, file, CvPADLIST(sv), 0);
3967c732
JD
1932 }
1933 {
b9ac451d 1934 const CV * const outside = CvOUTSIDE(sv);
2ef28da1 1935 Perl_dump_indent(aTHX_ level, file, " OUTSIDE = 0x%"UVxf" (%s)\n",
57def98f 1936 PTR2UV(outside),
cf2093f6
JH
1937 (!outside ? "null"
1938 : CvANON(outside) ? "ANON"
1939 : (outside == PL_main_cv) ? "MAIN"
1940 : CvUNIQUE(outside) ? "UNIQUE"
1941 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
3967c732
JD
1942 }
1943 if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv)))
ad64d0ec 1944 do_sv_dump(level+1, file, MUTABLE_SV(CvOUTSIDE(sv)), nest+1, maxnest, dumpops, pvlim);
3967c732 1945 break;
e0bbf362 1946
926fc7b6
DM
1947 case SVt_PVGV:
1948 case SVt_PVLV:
b9ac451d
AL
1949 if (type == SVt_PVLV) {
1950 Perl_dump_indent(aTHX_ level, file, " TYPE = %c\n", LvTYPE(sv));
1951 Perl_dump_indent(aTHX_ level, file, " TARGOFF = %"IVdf"\n", (IV)LvTARGOFF(sv));
1952 Perl_dump_indent(aTHX_ level, file, " TARGLEN = %"IVdf"\n", (IV)LvTARGLEN(sv));
1953 Perl_dump_indent(aTHX_ level, file, " TARG = 0x%"UVxf"\n", PTR2UV(LvTARG(sv)));
83f78d1a 1954 Perl_dump_indent(aTHX_ level, file, " FLAGS = %"IVdf"\n", (IV)LvFLAGS(sv));
b9ac451d
AL
1955 if (LvTYPE(sv) != 't' && LvTYPE(sv) != 'T')
1956 do_sv_dump(level+1, file, LvTARG(sv), nest+1, maxnest,
1957 dumpops, pvlim);
1958 }
926fc7b6
DM
1959 if (!isGV_with_GP(sv))
1960 break;
cea2e8a9 1961 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", GvNAME(sv));
57def98f 1962 Perl_dump_indent(aTHX_ level, file, " NAMELEN = %"IVdf"\n", (IV)GvNAMELEN(sv));
3967c732 1963 do_hv_dump (level, file, " GvSTASH", GvSTASH(sv));
57def98f 1964 Perl_dump_indent(aTHX_ level, file, " GP = 0x%"UVxf"\n", PTR2UV(GvGP(sv)));
f472eb5c
GS
1965 if (!GvGP(sv))
1966 break;
57def98f
JH
1967 Perl_dump_indent(aTHX_ level, file, " SV = 0x%"UVxf"\n", PTR2UV(GvSV(sv)));
1968 Perl_dump_indent(aTHX_ level, file, " REFCNT = %"IVdf"\n", (IV)GvREFCNT(sv));
1969 Perl_dump_indent(aTHX_ level, file, " IO = 0x%"UVxf"\n", PTR2UV(GvIOp(sv)));
1970 Perl_dump_indent(aTHX_ level, file, " FORM = 0x%"UVxf" \n", PTR2UV(GvFORM(sv)));
1971 Perl_dump_indent(aTHX_ level, file, " AV = 0x%"UVxf"\n", PTR2UV(GvAV(sv)));
1972 Perl_dump_indent(aTHX_ level, file, " HV = 0x%"UVxf"\n", PTR2UV(GvHV(sv)));
1973 Perl_dump_indent(aTHX_ level, file, " CV = 0x%"UVxf"\n", PTR2UV(GvCV(sv)));
1974 Perl_dump_indent(aTHX_ level, file, " CVGEN = 0x%"UVxf"\n", (UV)GvCVGEN(sv));
57def98f 1975 Perl_dump_indent(aTHX_ level, file, " LINE = %"IVdf"\n", (IV)GvLINE(sv));
b195d487 1976 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", GvFILE(sv));
e39917cc 1977 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)GvFLAGS(sv));
3967c732
JD
1978 do_gv_dump (level, file, " EGV", GvEGV(sv));
1979 break;
1980 case SVt_PVIO:
57def98f
JH
1981 Perl_dump_indent(aTHX_ level, file, " IFP = 0x%"UVxf"\n", PTR2UV(IoIFP(sv)));
1982 Perl_dump_indent(aTHX_ level, file, " OFP = 0x%"UVxf"\n", PTR2UV(IoOFP(sv)));
1983 Perl_dump_indent(aTHX_ level, file, " DIRP = 0x%"UVxf"\n", PTR2UV(IoDIRP(sv)));
1984 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)IoLINES(sv));
1985 Perl_dump_indent(aTHX_ level, file, " PAGE = %"IVdf"\n", (IV)IoPAGE(sv));
1986 Perl_dump_indent(aTHX_ level, file, " PAGE_LEN = %"IVdf"\n", (IV)IoPAGE_LEN(sv));
1987 Perl_dump_indent(aTHX_ level, file, " LINES_LEFT = %"IVdf"\n", (IV)IoLINES_LEFT(sv));
27533608 1988 if (IoTOP_NAME(sv))
cea2e8a9 1989 Perl_dump_indent(aTHX_ level, file, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
9ba1f565
NC
1990 if (!IoTOP_GV(sv) || SvTYPE(IoTOP_GV(sv)) == SVt_PVGV)
1991 do_gv_dump (level, file, " TOP_GV", IoTOP_GV(sv));
1992 else {
1993 Perl_dump_indent(aTHX_ level, file, " TOP_GV = 0x%"UVxf"\n",
1994 PTR2UV(IoTOP_GV(sv)));
ad64d0ec
NC
1995 do_sv_dump (level+1, file, MUTABLE_SV(IoTOP_GV(sv)), nest+1,
1996 maxnest, dumpops, pvlim);
9ba1f565
NC
1997 }
1998 /* Source filters hide things that are not GVs in these three, so let's
1999 be careful out there. */
27533608 2000 if (IoFMT_NAME(sv))
cea2e8a9 2001 Perl_dump_indent(aTHX_ level, file, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
9ba1f565
NC
2002 if (!IoFMT_GV(sv) || SvTYPE(IoFMT_GV(sv)) == SVt_PVGV)
2003 do_gv_dump (level, file, " FMT_GV", IoFMT_GV(sv));
2004 else {
2005 Perl_dump_indent(aTHX_ level, file, " FMT_GV = 0x%"UVxf"\n",
2006 PTR2UV(IoFMT_GV(sv)));
ad64d0ec
NC
2007 do_sv_dump (level+1, file, MUTABLE_SV(IoFMT_GV(sv)), nest+1,
2008 maxnest, dumpops, pvlim);
9ba1f565 2009 }
27533608 2010 if (IoBOTTOM_NAME(sv))
cea2e8a9 2011 Perl_dump_indent(aTHX_ level, file, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
9ba1f565
NC
2012 if (!IoBOTTOM_GV(sv) || SvTYPE(IoBOTTOM_GV(sv)) == SVt_PVGV)
2013 do_gv_dump (level, file, " BOTTOM_GV", IoBOTTOM_GV(sv));
2014 else {
2015 Perl_dump_indent(aTHX_ level, file, " BOTTOM_GV = 0x%"UVxf"\n",
2016 PTR2UV(IoBOTTOM_GV(sv)));
ad64d0ec
NC
2017 do_sv_dump (level+1, file, MUTABLE_SV(IoBOTTOM_GV(sv)), nest+1,
2018 maxnest, dumpops, pvlim);
9ba1f565 2019 }
27533608 2020 if (isPRINT(IoTYPE(sv)))
cea2e8a9 2021 Perl_dump_indent(aTHX_ level, file, " TYPE = '%c'\n", IoTYPE(sv));
27533608 2022 else
cea2e8a9 2023 Perl_dump_indent(aTHX_ level, file, " TYPE = '\\%o'\n", IoTYPE(sv));
57def98f 2024 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)IoFLAGS(sv));
3967c732 2025 break;
206ee256 2026 case SVt_REGEXP:
d63e6659
DM
2027 {
2028 struct regexp * const r = (struct regexp *)SvANY(sv);
2029 flags = RX_EXTFLAGS((REGEXP*)sv);
2030 sv_setpv(d,"");
2031 append_flags(d, flags, regexp_flags_names);
2032 if (*(SvEND(d) - 1) == ',') {
2033 SvCUR_set(d, SvCUR(d) - 1);
2034 SvPVX(d)[SvCUR(d)] = '\0';
2035 }
2036 Perl_dump_indent(aTHX_ level, file, " EXTFLAGS = 0x%"UVxf" (%s)\n",
2037 (UV)flags, SvPVX_const(d));
2038 Perl_dump_indent(aTHX_ level, file, " INTFLAGS = 0x%"UVxf"\n",
2039 (UV)(r->intflags));
2040 Perl_dump_indent(aTHX_ level, file, " NPARENS = %"UVuf"\n",
2041 (UV)(r->nparens));
2042 Perl_dump_indent(aTHX_ level, file, " LASTPAREN = %"UVuf"\n",
2043 (UV)(r->lastparen));
2044 Perl_dump_indent(aTHX_ level, file, " LASTCLOSEPAREN = %"UVuf"\n",
2045 (UV)(r->lastcloseparen));
2046 Perl_dump_indent(aTHX_ level, file, " MINLEN = %"IVdf"\n",
2047 (IV)(r->minlen));
2048 Perl_dump_indent(aTHX_ level, file, " MINLENRET = %"IVdf"\n",
2049 (IV)(r->minlenret));
2050 Perl_dump_indent(aTHX_ level, file, " GOFS = %"UVuf"\n",
2051 (UV)(r->gofs));
2052 Perl_dump_indent(aTHX_ level, file, " PRE_PREFIX = %"UVuf"\n",
2053 (UV)(r->pre_prefix));
2054 Perl_dump_indent(aTHX_ level, file, " SEEN_EVALS = %"UVuf"\n",
2055 (UV)(r->seen_evals));
2056 Perl_dump_indent(aTHX_ level, file, " SUBLEN = %"IVdf"\n",
2057 (IV)(r->sublen));
2058 if (r->subbeg)
2059 Perl_dump_indent(aTHX_ level, file, " SUBBEG = 0x%"UVxf" %s\n",
2060 PTR2UV(r->subbeg),
2061 pv_display(d, r->subbeg, r->sublen, 50, pvlim));
2062 else
2063 Perl_dump_indent(aTHX_ level, file, " SUBBEG = 0x0\n");
2064 Perl_dump_indent(aTHX_ level, file, " ENGINE = 0x%"UVxf"\n",
2065 PTR2UV(r->engine));
2066 Perl_dump_indent(aTHX_ level, file, " MOTHER_RE = 0x%"UVxf"\n",
2067 PTR2UV(r->mother_re));
2068 Perl_dump_indent(aTHX_ level, file, " PAREN_NAMES = 0x%"UVxf"\n",
2069 PTR2UV(r->paren_names));
2070 Perl_dump_indent(aTHX_ level, file, " SUBSTRS = 0x%"UVxf"\n",
2071 PTR2UV(r->substrs));
2072 Perl_dump_indent(aTHX_ level, file, " PPRIVATE = 0x%"UVxf"\n",
2073 PTR2UV(r->pprivate));
2074 Perl_dump_indent(aTHX_ level, file, " OFFS = 0x%"UVxf"\n",
2075 PTR2UV(r->offs));
d63c20f2
DM
2076 Perl_dump_indent(aTHX_ level, file, " QR_ANONCV = 0x%"UVxf"\n",
2077 PTR2UV(r->qr_anoncv));
d63e6659
DM
2078#ifdef PERL_OLD_COPY_ON_WRITE
2079 Perl_dump_indent(aTHX_ level, file, " SAVED_COPY = 0x%"UVxf"\n",
2080 PTR2UV(r->saved_copy));
2081#endif
2082 }
206ee256 2083 break;
3967c732 2084 }
cea89e20 2085 SvREFCNT_dec(d);
3967c732
JD
2086}
2087
2088void
864dbfa3 2089Perl_sv_dump(pTHX_ SV *sv)
3967c732 2090{
97aff369 2091 dVAR;
7918f24d
NC
2092
2093 PERL_ARGS_ASSERT_SV_DUMP;
2094
d1029faa
JP
2095 if (SvROK(sv))
2096 do_sv_dump(0, Perl_debug_log, sv, 0, 4, 0, 0);
2097 else
2098 do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0);
8d063cd8 2099}
bd16a5f0
IZ
2100
2101int
2102Perl_runops_debug(pTHX)
2103{
97aff369 2104 dVAR;
bd16a5f0 2105 if (!PL_op) {
9b387841 2106 Perl_ck_warner_d(aTHX_ packWARN(WARN_DEBUGGING), "NULL OP IN RUN");
bd16a5f0
IZ
2107 return 0;
2108 }
2109
9f3673fb 2110 DEBUG_l(Perl_deb(aTHX_ "Entering new RUNOPS level\n"));
bd16a5f0 2111 do {
bd16a5f0 2112 if (PL_debug) {
b9ac451d 2113 if (PL_watchaddr && (*PL_watchaddr != PL_watchok))
bd16a5f0
IZ
2114 PerlIO_printf(Perl_debug_log,
2115 "WARNING: %"UVxf" changed from %"UVxf" to %"UVxf"\n",
2116 PTR2UV(PL_watchaddr), PTR2UV(PL_watchok),
2117 PTR2UV(*PL_watchaddr));
d6721266
DM
2118 if (DEBUG_s_TEST_) {
2119 if (DEBUG_v_TEST_) {
2120 PerlIO_printf(Perl_debug_log, "\n");
2121 deb_stack_all();
2122 }
2123 else
2124 debstack();
2125 }
2126
2127
bd16a5f0
IZ
2128 if (DEBUG_t_TEST_) debop(PL_op);
2129 if (DEBUG_P_TEST_) debprof(PL_op);
2130 }
16c91539 2131 } while ((PL_op = PL_op->op_ppaddr(aTHX)));
9f3673fb 2132 DEBUG_l(Perl_deb(aTHX_ "leaving RUNOPS level\n"));
bd16a5f0
IZ
2133
2134 TAINT_NOT;
2135 return 0;
2136}
2137
2138I32
6867be6d 2139Perl_debop(pTHX_ const OP *o)
bd16a5f0 2140{
97aff369 2141 dVAR;
7918f24d
NC
2142
2143 PERL_ARGS_ASSERT_DEBOP;
2144
1045810a
IZ
2145 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
2146 return 0;
2147
bd16a5f0
IZ
2148 Perl_deb(aTHX_ "%s", OP_NAME(o));
2149 switch (o->op_type) {
2150 case OP_CONST:
996c9baa 2151 case OP_HINTSEVAL:
6cefa69e 2152 /* With ITHREADS, consts are stored in the pad, and the right pad
7367e658 2153 * may not be active here, so check.
6cefa69e 2154 * Looks like only during compiling the pads are illegal.
7367e658 2155 */
6cefa69e
RU
2156#ifdef USE_ITHREADS
2157 if ((((SVOP*)o)->op_sv) || !IN_PERL_COMPILETIME)
2158#endif
7367e658 2159 PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo_sv));
bd16a5f0
IZ
2160 break;
2161 case OP_GVSV:
2162 case OP_GV:
2163 if (cGVOPo_gv) {
b9ac451d 2164 SV * const sv = newSV(0);
3b721df9 2165#ifdef PERL_MAD
84021b46 2166 /* FIXME - is this making unwarranted assumptions about the
3b721df9
NC
2167 UTF-8 cleanliness of the dump file handle? */
2168 SvUTF8_on(sv);
2169#endif
bd61b366 2170 gv_fullname3(sv, cGVOPo_gv, NULL);
93524f2b 2171 PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv));
bd16a5f0
IZ
2172 SvREFCNT_dec(sv);
2173 }
2174 else
2175 PerlIO_printf(Perl_debug_log, "(NULL)");
2176 break;
2177 case OP_PADSV:
2178 case OP_PADAV:
2179 case OP_PADHV:
a3b680e6 2180 {
bd16a5f0 2181 /* print the lexical's name */
b9ac451d 2182 CV * const cv = deb_curcv(cxstack_ix);
a3b680e6 2183 SV *sv;
bd16a5f0 2184 if (cv) {
b9ac451d 2185 AV * const padlist = CvPADLIST(cv);
502c6561 2186 AV * const comppad = MUTABLE_AV(*av_fetch(padlist, 0, FALSE));
bd16a5f0
IZ
2187 sv = *av_fetch(comppad, o->op_targ, FALSE);
2188 } else
a0714e2c 2189 sv = NULL;
bd16a5f0 2190 if (sv)
b9ac451d 2191 PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv));
bd16a5f0 2192 else
b9ac451d 2193 PerlIO_printf(Perl_debug_log, "[%"UVuf"]", (UV)o->op_targ);
a3b680e6 2194 }
bd16a5f0
IZ
2195 break;
2196 default:
091ab601 2197 break;
bd16a5f0
IZ
2198 }
2199 PerlIO_printf(Perl_debug_log, "\n");
2200 return 0;
2201}
2202
2203STATIC CV*
61f9802b 2204S_deb_curcv(pTHX_ const I32 ix)
bd16a5f0 2205{
97aff369 2206 dVAR;
b9ac451d 2207 const PERL_CONTEXT * const cx = &cxstack[ix];
bd16a5f0
IZ
2208 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT)
2209 return cx->blk_sub.cv;
2210 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
676a678a 2211 return cx->blk_eval.cv;
bd16a5f0
IZ
2212 else if (ix == 0 && PL_curstackinfo->si_type == PERLSI_MAIN)
2213 return PL_main_cv;
2214 else if (ix <= 0)
601f1833 2215 return NULL;
bd16a5f0
IZ
2216 else
2217 return deb_curcv(ix - 1);
2218}
2219
2220void
2221Perl_watch(pTHX_ char **addr)
2222{
97aff369 2223 dVAR;
7918f24d
NC
2224
2225 PERL_ARGS_ASSERT_WATCH;
2226
bd16a5f0
IZ
2227 PL_watchaddr = addr;
2228 PL_watchok = *addr;
2229 PerlIO_printf(Perl_debug_log, "WATCHING, %"UVxf" is currently %"UVxf"\n",
2230 PTR2UV(PL_watchaddr), PTR2UV(PL_watchok));
2231}
2232
2233STATIC void
e1ec3a88 2234S_debprof(pTHX_ const OP *o)
bd16a5f0 2235{
97aff369 2236 dVAR;
7918f24d
NC
2237
2238 PERL_ARGS_ASSERT_DEBPROF;
2239
61f9802b 2240 if (!DEBUG_J_TEST_ && CopSTASH_eq(PL_curcop, PL_debstash))
1045810a 2241 return;
bd16a5f0 2242 if (!PL_profiledata)
a02a5408 2243 Newxz(PL_profiledata, MAXO, U32);
bd16a5f0
IZ
2244 ++PL_profiledata[o->op_type];
2245}
2246
2247void
2248Perl_debprofdump(pTHX)
2249{
97aff369 2250 dVAR;
bd16a5f0
IZ
2251 unsigned i;
2252 if (!PL_profiledata)
2253 return;
2254 for (i = 0; i < MAXO; i++) {
2255 if (PL_profiledata[i])
2256 PerlIO_printf(Perl_debug_log,
2257 "%5lu %s\n", (unsigned long)PL_profiledata[i],
2258 PL_op_name[i]);
2259 }
2260}
66610fdd 2261
3b721df9
NC
2262#ifdef PERL_MAD
2263/*
2264 * XML variants of most of the above routines
2265 */
2266
4136a0f7 2267STATIC void
3b721df9
NC
2268S_xmldump_attr(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
2269{
2270 va_list args;
7918f24d
NC
2271
2272 PERL_ARGS_ASSERT_XMLDUMP_ATTR;
2273
3b721df9
NC
2274 PerlIO_printf(file, "\n ");
2275 va_start(args, pat);
2276 xmldump_vindent(level, file, pat, &args);
2277 va_end(args);
2278}
2279
2280
2281void
2282Perl_xmldump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
2283{
2284 va_list args;
7918f24d 2285 PERL_ARGS_ASSERT_XMLDUMP_INDENT;
3b721df9
NC
2286 va_start(args, pat);
2287 xmldump_vindent(level, file, pat, &args);
2288 va_end(args);
2289}
2290
2291void
2292Perl_xmldump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args)
2293{
7918f24d
NC
2294 PERL_ARGS_ASSERT_XMLDUMP_VINDENT;
2295
3b721df9
NC
2296 PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), "");
2297 PerlIO_vprintf(file, pat, *args);
2298}
2299
2300void
2301Perl_xmldump_all(pTHX)
2302{
f0e3f042
CS
2303 xmldump_all_perl(FALSE);
2304}
2305
2306void
0190d5ef 2307Perl_xmldump_all_perl(pTHX_ bool justperl PERL_UNUSED_DECL)
f0e3f042 2308{
3b721df9
NC
2309 PerlIO_setlinebuf(PL_xmlfp);
2310 if (PL_main_root)
2311 op_xmldump(PL_main_root);
0190d5ef
CS
2312 /* someday we might call this, when it outputs XML: */
2313 /* xmldump_packsubs_perl(PL_defstash, justperl); */
3b721df9
NC
2314 if (PL_xmlfp != (PerlIO*)PerlIO_stdout())
2315 PerlIO_close(PL_xmlfp);
2316 PL_xmlfp = 0;
2317}
2318
2319void
2320Perl_xmldump_packsubs(pTHX_ const HV *stash)
2321{
28eb953d 2322 PERL_ARGS_ASSERT_XMLDUMP_PACKSUBS;
3ab0c9fa
NC
2323 xmldump_packsubs_perl(stash, FALSE);
2324}
2325
2326void
2327Perl_xmldump_packsubs_perl(pTHX_ const HV *stash, bool justperl)
2328{
3b721df9
NC
2329 I32 i;
2330 HE *entry;
2331
28eb953d 2332 PERL_ARGS_ASSERT_XMLDUMP_PACKSUBS_PERL;
7918f24d 2333
3b721df9
NC
2334 if (!HvARRAY(stash))
2335 return;
2336 for (i = 0; i <= (I32) HvMAX(stash); i++) {
2337 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
159b6efe 2338 GV *gv = MUTABLE_GV(HeVAL(entry));
3b721df9
NC
2339 HV *hv;
2340 if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
2341 continue;
2342 if (GvCVu(gv))
3ab0c9fa 2343 xmldump_sub_perl(gv, justperl);
3b721df9
NC
2344 if (GvFORM(gv))
2345 xmldump_form(gv);
2346 if (HeKEY(entry)[HeKLEN(entry)-1] == ':'
2347 && (hv = GvHV(gv)) && hv != PL_defstash)
3ab0c9fa 2348 xmldump_packsubs_perl(hv, justperl); /* nested package */
3b721df9
NC
2349 }
2350 }
2351}
2352
2353void
2354Perl_xmldump_sub(pTHX_ const GV *gv)
2355{
28eb953d 2356 PERL_ARGS_ASSERT_XMLDUMP_SUB;
f0e3f042
CS
2357 xmldump_sub_perl(gv, FALSE);
2358}
2359
2360void
2361Perl_xmldump_sub_perl(pTHX_ const GV *gv, bool justperl)
2362{
2363 SV * sv;
3b721df9 2364
28eb953d 2365 PERL_ARGS_ASSERT_XMLDUMP_SUB_PERL;
7918f24d 2366
f0e3f042
CS
2367 if (justperl && (CvISXSUB(GvCV(gv)) || !CvROOT(GvCV(gv))))
2368 return;
2369
2370 sv = sv_newmortal();
1a9a51d4 2371 gv_fullname3(sv, gv, NULL);
3b721df9
NC
2372 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "\nSUB %s = ", SvPVX(sv));
2373 if (CvXSUB(GvCV(gv)))
2374 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "(xsub 0x%"UVxf" %d)\n",
2375 PTR2UV(CvXSUB(GvCV(gv))),
2376 (int)CvXSUBANY(GvCV(gv)).any_i32);
2377 else if (CvROOT(GvCV(gv)))
2378 op_xmldump(CvROOT(GvCV(gv)));
2379 else
2380 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "<undef>\n");
2381}
2382
2383void
2384Perl_xmldump_form(pTHX_ const GV *gv)
2385{
61f9802b 2386 SV * const sv = sv_newmortal();
3b721df9 2387
7918f24d
NC
2388 PERL_ARGS_ASSERT_XMLDUMP_FORM;
2389
1a9a51d4 2390 gv_fullname3(sv, gv, NULL);
3b721df9
NC
2391 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "\nFORMAT %s = ", SvPVX(sv));
2392 if (CvROOT(GvFORM(gv)))
2393 op_xmldump(CvROOT(GvFORM(gv)));
2394 else
2395 Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "<undef>\n");
2396}
2397
2398void
2399Perl_xmldump_eval(pTHX)
2400{
2401 op_xmldump(PL_eval_root);
2402}
2403
2404char *
2405Perl_sv_catxmlsv(pTHX_ SV *dsv, SV *ssv)
2406{
7918f24d 2407 PERL_ARGS_ASSERT_SV_CATXMLSV;
3b721df9
NC
2408 return sv_catxmlpvn(dsv, SvPVX(ssv), SvCUR(ssv), SvUTF8(ssv));
2409}
2410
2411char *
9dcc53ea
Z
2412Perl_sv_catxmlpv(pTHX_ SV *dsv, const char *pv, int utf8)
2413{
2414 PERL_ARGS_ASSERT_SV_CATXMLPV;
2415 return sv_catxmlpvn(dsv, pv, strlen(pv), utf8);
2416}
2417
2418char *
20f84293 2419Perl_sv_catxmlpvn(pTHX_ SV *dsv, const char *pv, STRLEN len, int utf8)
3b721df9
NC
2420{
2421 unsigned int c;
61f9802b 2422 const char * const e = pv + len;
20f84293 2423 const char * const start = pv;
3b721df9
NC
2424 STRLEN dsvcur;
2425 STRLEN cl;
2426
7918f24d
NC
2427 PERL_ARGS_ASSERT_SV_CATXMLPVN;
2428
76f68e9b 2429 sv_catpvs(dsv,"");
3b721df9
NC
2430 dsvcur = SvCUR(dsv); /* in case we have to restart */
2431
2432 retry:
2433 while (pv < e) {
2434 if (utf8) {
4b88fb76 2435 c = utf8_to_uvchr_buf((U8*)pv, (U8*)e, &cl);
3b721df9
NC
2436 if (cl == 0) {
2437 SvCUR(dsv) = dsvcur;
2438 pv = start;
2439 utf8 = 0;
2440 goto retry;
2441 }
2442 }
2443 else
2444 c = (*pv & 255);
2445
2446 switch (c) {
2447 case 0x00:
2448 case 0x01:
2449 case 0x02:
2450 case 0x03:
2451 case 0x04:
2452 case 0x05:
2453 case 0x06:
2454 case 0x07:
2455 case 0x08:
2456 case 0x0b:
2457 case 0x0c:
2458 case 0x0e:
2459 case 0x0f:
2460 case 0x10:
2461 case 0x11:
2462 case 0x12:
2463 case 0x13:
2464 case 0x14:
2465 case 0x15:
2466 case 0x16:
2467 case 0x17:
2468 case 0x18:
2469 case 0x19:
2470 case 0x1a:
2471 case 0x1b:
2472 case 0x1c:
2473 case 0x1d:
2474 case 0x1e:
2475 case 0x1f:
2476 case 0x7f:
2477 case 0x80:
2478 case 0x81:
2479 case 0x82:
2480 case 0x83:
2481 case 0x84:
2482 case 0x86:
2483 case 0x87:
2484 case 0x88:
2485 case 0x89:
2486 case 0x90:
2487 case 0x91:
2488 case 0x92:
2489 case 0x93:
2490 case 0x94:
2491 case 0x95:
2492 case 0x96:
2493 case 0x97:
2494 case 0x98:
2495 case 0x99:
2496 case 0x9a:
2497 case 0x9b:
2498 case 0x9c:
2499 case 0x9d:
2500 case 0x9e:
2501 case 0x9f:
2502 Perl_sv_catpvf(aTHX_ dsv, "STUPIDXML(#x%X)", c);
2503 break;
2504 case '<':
f3a2811a 2505 sv_catpvs(dsv, "&lt;");
3b721df9
NC
2506 break;
2507 case '>':
f3a2811a 2508 sv_catpvs(dsv, "&gt;");
3b721df9
NC
2509 break;
2510 case '&':
f3a2811a 2511 sv_catpvs(dsv, "&amp;");
3b721df9
NC
2512 break;
2513 case '"':
49de0815 2514 sv_catpvs(dsv, "&#34;");
3b721df9
NC
2515 break;
2516 default:
2517 if (c < 0xD800) {
2518 if (c < 32 || c > 127) {
2519 Perl_sv_catpvf(aTHX_ dsv, "&#x%X;", c);
2520 }
2521 else {
5e7aa789
NC
2522 const char string = (char) c;
2523 sv_catpvn(dsv, &string, 1);
3b721df9
NC
2524 }
2525 break;
2526 }
2527 if ((c >= 0xD800 && c <= 0xDB7F) ||
2528 (c >= 0xDC00 && c <= 0xDFFF) ||
2529 (c >= 0xFFF0 && c <= 0xFFFF) ||
2530 c > 0x10ffff)
2531 Perl_sv_catpvf(aTHX_ dsv, "STUPIDXML(#x%X)", c);
2532 else
2533 Perl_sv_catpvf(aTHX_ dsv, "&#x%X;", c);
2534 }
2535
2536 if (utf8)
2537 pv += UTF8SKIP(pv);
2538 else
2539 pv++;
2540 }
2541
2542 return SvPVX(dsv);
2543}
2544
2545char *
2546Perl_sv_xmlpeek(pTHX_ SV *sv)
2547{
61f9802b 2548 SV * const t = sv_newmortal();
3b721df9
NC
2549 STRLEN n_a;
2550 int unref = 0;
2551
7918f24d
NC
2552 PERL_ARGS_ASSERT_SV_XMLPEEK;
2553
3b721df9 2554 sv_utf8_upgrade(t);
76f68e9b 2555 sv_setpvs(t, "");
3b721df9
NC
2556 /* retry: */
2557 if (!sv) {
2558 sv_catpv(t, "VOID=\"\"");
2559 goto finish;
2560 }
ad64d0ec 2561 else if (sv == (const SV *)0x55555555 || SvTYPE(sv) == 'U') {
3b721df9
NC
2562 sv_catpv(t, "WILD=\"\"");
2563 goto finish;
2564 }
2565 else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) {
2566 if (sv == &PL_sv_undef) {
2567 sv_catpv(t, "SV_UNDEF=\"1\"");
2568 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
2569 SVs_GMG|SVs_SMG|SVs_RMG)) &&
2570 SvREADONLY(sv))
2571 goto finish;
2572 }
2573 else if (sv == &PL_sv_no) {
2574 sv_catpv(t, "SV_NO=\"1\"");
2575 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
2576 SVs_GMG|SVs_SMG|SVs_RMG)) &&
2577 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
2578 SVp_POK|SVp_NOK)) &&
2579 SvCUR(sv) == 0 &&
2580 SvNVX(sv) == 0.0)
2581 goto finish;
2582 }
2583 else if (sv == &PL_sv_yes) {
2584 sv_catpv(t, "SV_YES=\"1\"");
2585 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
2586 SVs_GMG|SVs_SMG|SVs_RMG)) &&
2587 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
2588 SVp_POK|SVp_NOK)) &&
2589 SvCUR(sv) == 1 &&
2590 SvPVX(sv) && *SvPVX(sv) == '1' &&
2591 SvNVX(sv) == 1.0)
2592 goto finish;
2593 }
2594 else {
2595 sv_catpv(t, "SV_PLACEHOLDER=\"1\"");
2596 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
2597 SVs_GMG|SVs_SMG|SVs_RMG)) &&
2598 SvREADONLY(sv))
2599 goto finish;
2600 }
2601 sv_catpv(t, " XXX=\"\" ");
2602 }
2603 else if (SvREFCNT(sv) == 0) {
2604 sv_catpv(t, " refcnt=\"0\"");
2605 unref++;
2606 }
2607 else if (DEBUG_R_TEST_) {
2608 int is_tmp = 0;
2609 I32 ix;
2610 /* is this SV on the tmps stack? */
2611 for (ix=PL_tmps_ix; ix>=0; ix--) {
2612 if (PL_tmps_stack[ix] == sv) {
2613 is_tmp = 1;
2614 break;
2615 }
2616 }
2617 if (SvREFCNT(sv) > 1)
2618 Perl_sv_catpvf(aTHX_ t, " DRT=\"<%"UVuf"%s>\"", (UV)SvREFCNT(sv),
2619 is_tmp ? "T" : "");
2620 else if (is_tmp)
2621 sv_catpv(t, " DRT=\"<T>\"");
2622 }
2623
2624 if (SvROK(sv)) {
2625 sv_catpv(t, " ROK=\"\"");
2626 }
2627 switch (SvTYPE(sv)) {
2628 default:
2629 sv_catpv(t, " FREED=\"1\"");
2630 goto finish;
2631
2632 case SVt_NULL:
2633 sv_catpv(t, " UNDEF=\"1\"");
2634 goto finish;
2635 case SVt_IV:
2636 sv_catpv(t, " IV=\"");
2637 break;
2638 case SVt_NV:
2639 sv_catpv(t, " NV=\"");
2640 break;
3b721df9
NC
2641 case SVt_PV:
2642 sv_catpv(t, " PV=\"");
2643 break;
2644 case SVt_PVIV:
2645 sv_catpv(t, " PVIV=\"");
2646 break;
2647 case SVt_PVNV:
2648 sv_catpv(t, " PVNV=\"");
2649 break;
2650 case SVt_PVMG:
2651 sv_catpv(t, " PVMG=\"");
2652 break;
2653 case SVt_PVLV:
2654 sv_catpv(t, " PVLV=\"");
2655 break;
2656 case SVt_PVAV:
2657 sv_catpv(t, " AV=\"");
2658 break;
2659 case SVt_PVHV:
2660 sv_catpv(t, " HV=\"");
2661 break;
2662 case SVt_PVCV:
2663 if (CvGV(sv))
2664 Perl_sv_catpvf(aTHX_ t, " CV=\"(%s)\"", GvNAME(CvGV(sv)));
2665 else
2666 sv_catpv(t, " CV=\"()\"");
2667 goto finish;
2668 case SVt_PVGV:
2669 sv_catpv(t, " GV=\"");
2670 break;
cecf5685
NC
2671 case SVt_BIND:
2672 sv_catpv(t, " BIND=\"");
3b721df9 2673 break;
d914baab 2674 case SVt_REGEXP:
8619e557 2675 sv_catpv(t, " REGEXP=\"");
4df7f6af 2676 break;
3b721df9
NC
2677 case SVt_PVFM:
2678 sv_catpv(t, " FM=\"");
2679 break;
2680 case SVt_PVIO:
2681 sv_catpv(t, " IO=\"");
2682 break;
2683 }
2684
2685 if (SvPOKp(sv)) {
2686 if (SvPVX(sv)) {
2687 sv_catxmlsv(t, sv);
2688 }
2689 }
2690 else if (SvNOKp(sv)) {
2691 STORE_NUMERIC_LOCAL_SET_STANDARD();
2692 Perl_sv_catpvf(aTHX_ t, "%"NVgf"",SvNVX(sv));
2693 RESTORE_NUMERIC_LOCAL();
2694 }
2695 else if (SvIOKp(sv)) {
2696 if (SvIsUV(sv))
2697 Perl_sv_catpvf(aTHX_ t, "%"UVuf"", (UV)SvUVX(sv));
2698 else
2699 Perl_sv_catpvf(aTHX_ t, "%"IVdf"", (IV)SvIVX(sv));
2700 }
2701 else
2702 sv_catpv(t, "");
2703 sv_catpv(t, "\"");
2704
2705 finish:
61f9802b
AL
2706 while (unref--)
2707 sv_catpv(t, ")");
3b721df9
NC
2708 return SvPV(t, n_a);
2709}
2710
2711void
2712Perl_do_pmop_xmldump(pTHX_ I32 level, PerlIO *file, const PMOP *pm)
2713{
7918f24d
NC
2714 PERL_ARGS_ASSERT_DO_PMOP_XMLDUMP;
2715
3b721df9
NC
2716 if (!pm) {
2717 Perl_xmldump_indent(aTHX_ level, file, "<pmop/>\n");
2718 return;
2719 }
2720 Perl_xmldump_indent(aTHX_ level, file, "<pmop \n");
2721 level++;
2722 if (PM_GETRE(pm)) {
d914baab 2723 REGEXP *const r = PM_GETRE(pm);
643e696a 2724 SV * const tmpsv = newSVpvn_utf8("", 0, TRUE);
ad64d0ec 2725 sv_catxmlsv(tmpsv, MUTABLE_SV(r));
3b721df9
NC
2726 Perl_xmldump_indent(aTHX_ level, file, "pre=\"%s\"\n",
2727 SvPVX(tmpsv));
2728 SvREFCNT_dec(tmpsv);
2729 Perl_xmldump_indent(aTHX_ level, file, "when=\"%s\"\n",
2730 (pm->op_private & OPpRUNTIME) ? "RUN" : "COMP");
2731 }
2732 else
2733 Perl_xmldump_indent(aTHX_ level, file, "pre=\"\" when=\"RUN\"\n");
d914baab 2734 if (pm->op_pmflags || (PM_GETRE(pm) && RX_CHECK_SUBSTR(PM_GETRE(pm)))) {
3df43ef7 2735 SV * const tmpsv = pm_description(pm);
3b721df9
NC
2736 Perl_xmldump_indent(aTHX_ level, file, "pmflags=\"%s\"\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
2737 SvREFCNT_dec(tmpsv);
2738 }
2739
2740 level--;
20e98b0f 2741 if (pm->op_type != OP_PUSHRE && pm->op_pmreplrootu.op_pmreplroot) {
3b721df9
NC
2742 Perl_xmldump_indent(aTHX_ level, file, ">\n");
2743 Perl_xmldump_indent(aTHX_ level+1, file, "<pm_repl>\n");
20e98b0f 2744 do_op_xmldump(level+2, file, pm->op_pmreplrootu.op_pmreplroot);
3b721df9
NC
2745 Perl_xmldump_indent(aTHX_ level+1, file, "</pm_repl>\n");
2746 Perl_xmldump_indent(aTHX_ level, file, "</pmop>\n");
2747 }
2748 else
2749 Perl_xmldump_indent(aTHX_ level, file, "/>\n");
2750}
2751
2752void
2753Perl_pmop_xmldump(pTHX_ const PMOP *pm)
2754{
2755 do_pmop_xmldump(0, PL_xmlfp, pm);
2756}
2757
2758void
2759Perl_do_op_xmldump(pTHX_ I32 level, PerlIO *file, const OP *o)
2760{
2761 UV seq;
2762 int contents = 0;
7918f24d
NC
2763
2764 PERL_ARGS_ASSERT_DO_OP_XMLDUMP;
2765
3b721df9
NC
2766 if (!o)
2767 return;
3b721df9
NC
2768 seq = sequence_num(o);
2769 Perl_xmldump_indent(aTHX_ level, file,
2770 "<op_%s seq=\"%"UVuf" -> ",
2771 OP_NAME(o),
2772 seq);
2773 level++;
2774 if (o->op_next)
2775 PerlIO_printf(file, seq ? "%"UVuf"\"" : "(%"UVuf")\"",
2776 sequence_num(o->op_next));
2777 else
2778 PerlIO_printf(file, "DONE\"");
2779
2780 if (o->op_targ) {
2781 if (o->op_type == OP_NULL)
2782 {
2783 PerlIO_printf(file, " was=\"%s\"", PL_op_name[o->op_targ]);
2784 if (o->op_targ == OP_NEXTSTATE)
2785 {
2786 if (CopLINE(cCOPo))
f5992bc4 2787 PerlIO_printf(file, " line=\"%"UVuf"\"",
3b721df9
NC
2788 (UV)CopLINE(cCOPo));
2789 if (CopSTASHPV(cCOPo))
2790 PerlIO_printf(file, " package=\"%s\"",
2791 CopSTASHPV(cCOPo));
4b65a919 2792 if (CopLABEL(cCOPo))
3b721df9 2793 PerlIO_printf(file, " label=\"%s\"",
4b65a919 2794 CopLABEL(cCOPo));
3b721df9
NC
2795 }
2796 }
2797 else
2798 PerlIO_printf(file, " targ=\"%ld\"", (long)o->op_targ);
2799 }
2800#ifdef DUMPADDR
2801 PerlIO_printf(file, " addr=\"0x%"UVxf" => 0x%"UVxf"\"", (UV)o, (UV)o->op_next);
2802#endif
2803 if (o->op_flags) {
76f68e9b 2804 SV * const tmpsv = newSVpvs("");
3b721df9
NC
2805 switch (o->op_flags & OPf_WANT) {
2806 case OPf_WANT_VOID:
2807 sv_catpv(tmpsv, ",VOID");
2808 break;
2809 case OPf_WANT_SCALAR:
2810 sv_catpv(tmpsv, ",SCALAR");
2811 break;
2812 case OPf_WANT_LIST:
2813 sv_catpv(tmpsv, ",LIST");
2814 break;
2815 default:
2816 sv_catpv(tmpsv, ",UNKNOWN");
2817 break;
2818 }
2819 if (o->op_flags & OPf_KIDS)
2820 sv_catpv(tmpsv, ",KIDS");
2821 if (o->op_flags & OPf_PARENS)
2822 sv_catpv(tmpsv, ",PARENS");
2823 if (o->op_flags & OPf_STACKED)
2824 sv_catpv(tmpsv, ",STACKED");
2825 if (o->op_flags & OPf_REF)
2826 sv_catpv(tmpsv, ",REF");
2827 if (o->op_flags & OPf_MOD)
2828 sv_catpv(tmpsv, ",MOD");
2829 if (o->op_flags & OPf_SPECIAL)
2830 sv_catpv(tmpsv, ",SPECIAL");
2831 PerlIO_printf(file, " flags=\"%s\"", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
2832 SvREFCNT_dec(tmpsv);
2833 }
2834 if (o->op_private) {
76f68e9b 2835 SV * const tmpsv = newSVpvs("");
3b721df9
NC
2836 if (PL_opargs[o->op_type] & OA_TARGLEX) {
2837 if (o->op_private & OPpTARGET_MY)
2838 sv_catpv(tmpsv, ",TARGET_MY");
2839 }
2840 else if (o->op_type == OP_LEAVESUB ||
2841 o->op_type == OP_LEAVE ||
2842 o->op_type == OP_LEAVESUBLV ||
2843 o->op_type == OP_LEAVEWRITE) {
2844 if (o->op_private & OPpREFCOUNTED)
2845 sv_catpv(tmpsv, ",REFCOUNTED");
2846 }
2847 else if (o->op_type == OP_AASSIGN) {
2848 if (o->op_private & OPpASSIGN_COMMON)
2849 sv_catpv(tmpsv, ",COMMON");
2850 }
2851 else if (o->op_type == OP_SASSIGN) {
2852 if (o->op_private & OPpASSIGN_BACKWARDS)
2853 sv_catpv(tmpsv, ",BACKWARDS");
2854 }
2855 else if (o->op_type == OP_TRANS) {
2856 if (o->op_private & OPpTRANS_SQUASH)
2857 sv_catpv(tmpsv, ",SQUASH");
2858 if (o->op_private & OPpTRANS_DELETE)
2859 sv_catpv(tmpsv, ",DELETE");
2860 if (o->op_private & OPpTRANS_COMPLEMENT)
2861 sv_catpv(tmpsv, ",COMPLEMENT");
2862 if (o->op_private & OPpTRANS_IDENTICAL)
2863 sv_catpv(tmpsv, ",IDENTICAL");
2864 if (o->op_private & OPpTRANS_GROWS)
2865 sv_catpv(tmpsv, ",GROWS");
2866 }
2867 else if (o->op_type == OP_REPEAT) {
2868 if (o->op_private & OPpREPEAT_DOLIST)
2869 sv_catpv(tmpsv, ",DOLIST");
2870 }
2871 else if (o->op_type == OP_ENTERSUB ||
2872 o->op_type == OP_RV2SV ||
2873 o->op_type == OP_GVSV ||
2874 o->op_type == OP_RV2AV ||
2875 o->op_type == OP_RV2HV ||
2876 o->op_type == OP_RV2GV ||
2877 o->op_type == OP_AELEM ||
2878 o->op_type == OP_HELEM )
2879 {
2880 if (o->op_type == OP_ENTERSUB) {
2881 if (o->op_private & OPpENTERSUB_AMPER)
2882 sv_catpv(tmpsv, ",AMPER");
2883 if (o->op_private & OPpENTERSUB_DB)
2884 sv_catpv(tmpsv, ",DB");
2885 if (o->op_private & OPpENTERSUB_HASTARG)
2886 sv_catpv(tmpsv, ",HASTARG");
2887 if (o->op_private & OPpENTERSUB_NOPAREN)
2888 sv_catpv(tmpsv, ",NOPAREN");
2889 if (o->op_private & OPpENTERSUB_INARGS)
2890 sv_catpv(tmpsv, ",INARGS");
3b721df9
NC
2891 }
2892 else {
2893 switch (o->op_private & OPpDEREF) {
2894 case OPpDEREF_SV:
2895 sv_catpv(tmpsv, ",SV");
2896 break;
2897 case OPpDEREF_AV:
2898 sv_catpv(tmpsv, ",AV");
2899 break;
2900 case OPpDEREF_HV:
2901 sv_catpv(tmpsv, ",HV");
2902 break;
2903 }
2904 if (o->op_private & OPpMAYBE_LVSUB)
2905 sv_catpv(tmpsv, ",MAYBE_LVSUB");
2906 }
2907 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
2908 if (o->op_private & OPpLVAL_DEFER)
2909 sv_catpv(tmpsv, ",LVAL_DEFER");
2910 }
2911 else {
2912 if (o->op_private & HINT_STRICT_REFS)
2913 sv_catpv(tmpsv, ",STRICT_REFS");
2914 if (o->op_private & OPpOUR_INTRO)
2915 sv_catpv(tmpsv, ",OUR_INTRO");
2916 }
2917 }
2918 else if (o->op_type == OP_CONST) {
2919 if (o->op_private & OPpCONST_BARE)
2920 sv_catpv(tmpsv, ",BARE");
2921 if (o->op_private & OPpCONST_STRICT)
2922 sv_catpv(tmpsv, ",STRICT");
3b721df9
NC
2923 if (o->op_private & OPpCONST_ENTERED)
2924 sv_catpv(tmpsv, ",ENTERED");
2925 }
2926 else if (o->op_type == OP_FLIP) {
2927 if (o->op_private & OPpFLIP_LINENUM)
2928 sv_catpv(tmpsv, ",LINENUM");
2929 }
2930 else if (o->op_type == OP_FLOP) {
2931 if (o->op_private & OPpFLIP_LINENUM)
2932 sv_catpv(tmpsv, ",LINENUM");
2933 }
2934 else if (o->op_type == OP_RV2CV) {
2935 if (o->op_private & OPpLVAL_INTRO)
2936 sv_catpv(tmpsv, ",INTRO");
2937 }
2938 else if (o->op_type == OP_GV) {
2939 if (o->op_private & OPpEARLY_CV)
2940 sv_catpv(tmpsv, ",EARLY_CV");
2941 }
2942 else if (o->op_type == OP_LIST) {
2943 if (o->op_private & OPpLIST_GUESSED)
2944 sv_catpv(tmpsv, ",GUESSED");
2945 }
2946 else if (o->op_type == OP_DELETE) {
2947 if (o->op_private & OPpSLICE)
2948 sv_catpv(tmpsv, ",SLICE");
2949 }
2950 else if (o->op_type == OP_EXISTS) {
2951 if (o->op_private & OPpEXISTS_SUB)
2952 sv_catpv(tmpsv, ",EXISTS_SUB");
2953 }
2954 else if (o->op_type == OP_SORT) {
2955 if (o->op_private & OPpSORT_NUMERIC)
2956 sv_catpv(tmpsv, ",NUMERIC");
2957 if (o->op_private & OPpSORT_INTEGER)
2958 sv_catpv(tmpsv, ",INTEGER");
2959 if (o->op_private & OPpSORT_REVERSE)
2960 sv_catpv(tmpsv, ",REVERSE");
2961 }
3b721df9
NC
2962 else if (o->op_type == OP_OPEN || o->op_type == OP_BACKTICK) {
2963 if (o->op_private & OPpOPEN_IN_RAW)
2964 sv_catpv(tmpsv, ",IN_RAW");
2965 if (o->op_private & OPpOPEN_IN_CRLF)
2966 sv_catpv(tmpsv, ",IN_CRLF");
2967 if (o->op_private & OPpOPEN_OUT_RAW)
2968 sv_catpv(tmpsv, ",OUT_RAW");
2969 if (o->op_private & OPpOPEN_OUT_CRLF)
2970 sv_catpv(tmpsv, ",OUT_CRLF");
2971 }
2972 else if (o->op_type == OP_EXIT) {
2973 if (o->op_private & OPpEXIT_VMSISH)
2974 sv_catpv(tmpsv, ",EXIT_VMSISH");
2975 if (o->op_private & OPpHUSH_VMSISH)
2976 sv_catpv(tmpsv, ",HUSH_VMSISH");
2977 }
2978 else if (o->op_type == OP_DIE) {
2979 if (o->op_private & OPpHUSH_VMSISH)
2980 sv_catpv(tmpsv, ",HUSH_VMSISH");
2981 }
ef69c8fc 2982 else if (PL_check[o->op_type] != Perl_ck_ftst) {
6ecf81d6 2983 if (OP_IS_FILETEST_ACCESS(o->op_type) && o->op_private & OPpFT_ACCESS)
3b721df9
NC
2984 sv_catpv(tmpsv, ",FT_ACCESS");
2985 if (o->op_private & OPpFT_STACKED)
2986 sv_catpv(tmpsv, ",FT_STACKED");
2987 }
2988 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
2989 sv_catpv(tmpsv, ",INTRO");
2990 if (SvCUR(tmpsv))
2991 S_xmldump_attr(aTHX_ level, file, "private=\"%s\"", SvPVX(tmpsv) + 1);
2992 SvREFCNT_dec(tmpsv);
2993 }
2994
2995 switch (o->op_type) {
2996 case OP_AELEMFAST:
2997 if (o->op_flags & OPf_SPECIAL) {
2998 break;
2999 }
3000 case OP_GVSV:
3001 case OP_GV:
3002#ifdef USE_ITHREADS
3003 S_xmldump_attr(aTHX_ level, file, "padix=\"%" IVdf "\"", (IV)cPADOPo->op_padix);
3004#else
3005 if (cSVOPo->op_sv) {
d914baab
NC
3006 SV * const tmpsv1 = newSVpvn_utf8(NULL, 0, TRUE);
3007 SV * const tmpsv2 = newSVpvn_utf8("", 0, TRUE);
3b721df9
NC
3008 char *s;
3009 STRLEN len;
3010 ENTER;
3011 SAVEFREESV(tmpsv1);
3012 SAVEFREESV(tmpsv2);
159b6efe 3013 gv_fullname3(tmpsv1, MUTABLE_GV(cSVOPo->op_sv), NULL);
3b721df9
NC
3014 s = SvPV(tmpsv1,len);
3015 sv_catxmlpvn(tmpsv2, s, len, 1);
3016 S_xmldump_attr(aTHX_ level, file, "gv=\"%s\"", SvPV(tmpsv2, len));
3017 LEAVE;
3018 }
3019 else
3020 S_xmldump_attr(aTHX_ level, file, "gv=\"NULL\"");
3021#endif
3022 break;
3023 case OP_CONST:
996c9baa 3024 case OP_HINTSEVAL:
3b721df9
NC
3025 case OP_METHOD_NAMED:
3026#ifndef USE_ITHREADS
3027 /* with ITHREADS, consts are stored in the pad, and the right pad
3028 * may not be active here, so skip */
3029 S_xmldump_attr(aTHX_ level, file, "%s", sv_xmlpeek(cSVOPo_sv));
3030#endif
3031 break;
3032 case OP_ANONCODE:
3033 if (!contents) {
3034 contents = 1;
3035 PerlIO_printf(file, ">\n");
3036 }
3037 do_op_xmldump(level+1, file, CvROOT(cSVOPo_sv));
3038 break;
3b721df9
NC
3039 case OP_NEXTSTATE:
3040 case OP_DBSTATE:
3041 if (CopLINE(cCOPo))
f5992bc4 3042 S_xmldump_attr(aTHX_ level, file, "line=\"%"UVuf"\"",
3b721df9
NC
3043 (UV)CopLINE(cCOPo));
3044 if (CopSTASHPV(cCOPo))
3045 S_xmldump_attr(aTHX_ level, file, "package=\"%s\"",
3046 CopSTASHPV(cCOPo));
4b65a919 3047 if (CopLABEL(cCOPo))
3b721df9 3048 S_xmldump_attr(aTHX_ level, file, "label=\"%s\"",
4b65a919 3049 CopLABEL(cCOPo));
3b721df9
NC
3050 break;
3051 case OP_ENTERLOOP:
3052 S_xmldump_attr(aTHX_ level, file, "redo=\"");
3053 if (cLOOPo->op_redoop)
3054 PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOOPo->op_redoop));
3055 else
3056 PerlIO_printf(file, "DONE\"");
3057 S_xmldump_attr(aTHX_ level, file, "next=\"");
3058 if (cLOOPo->op_nextop)
3059 PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOOPo->op_nextop));
3060 else
3061 PerlIO_printf(file, "DONE\"");
3062 S_xmldump_attr(aTHX_ level, file, "last=\"");
3063 if (cLOOPo->op_lastop)
3064 PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOOPo->op_lastop));
3065 else
3066 PerlIO_printf(file, "DONE\"");
3067 break;
3068 case OP_COND_EXPR:
3069 case OP_RANGE:
3070 case OP_MAPWHILE:
3071 case OP_GREPWHILE:
3072 case OP_OR:
3073 case OP_AND:
3074 S_xmldump_attr(aTHX_ level, file, "other=\"");
3075 if (cLOGOPo->op_other)
3076 PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOGOPo->op_other));
3077 else
3078 PerlIO_printf(file, "DONE\"");
3079 break;
3080 case OP_LEAVE:
3081 case OP_LEAVEEVAL:
3082 case OP_LEAVESUB:
3083 case OP_LEAVESUBLV:
3084 case OP_LEAVEWRITE:
3085 case OP_SCOPE:
3086 if (o->op_private & OPpREFCOUNTED)
3087 S_xmldump_attr(aTHX_ level, file, "refcnt=\"%"UVuf"\"", (UV)o->op_targ);
3088 break;
3089 default:
3090 break;
3091 }
3092
3093 if (PL_madskills && o->op_madprop) {
fb2b694a 3094 char prevkey = '\0';
d914baab 3095 SV * const tmpsv = newSVpvn_utf8("", 0, TRUE);
20f84293 3096 const MADPROP* mp = o->op_madprop;
61f9802b 3097
3b721df9
NC
3098 if (!contents) {
3099 contents = 1;
3100 PerlIO_printf(file, ">\n");
3101 }
3102 Perl_xmldump_indent(aTHX_ level, file, "<madprops>\n");
3103 level++;
3104 while (mp) {
3105 char tmp = mp->mad_key;
76f68e9b 3106 sv_setpvs(tmpsv,"\"");
3b721df9
NC
3107 if (tmp)
3108 sv_catxmlpvn(tmpsv, &tmp, 1, 0);
fb2b694a
GG
3109 if ((tmp == '_') || (tmp == '#')) /* '_' '#' whitespace belong to the previous token. */
3110 sv_catxmlpvn(tmpsv, &prevkey, 1, 0);
3111 else
3112 prevkey = tmp;
3b721df9
NC
3113 sv_catpv(tmpsv, "\"");
3114 switch (mp->mad_type) {
3115 case MAD_NULL:
3116 sv_catpv(tmpsv, "NULL");
3117 Perl_xmldump_indent(aTHX_ level, file, "<mad_null key=%s/>\n", SvPVX(tmpsv));
3118 break;
3119 case MAD_PV:
3120 sv_catpv(tmpsv, " val=\"");
3121 sv_catxmlpvn(tmpsv, (char*)mp->mad_val, mp->mad_vlen,1);
3122 sv_catpv(tmpsv, "\"");
3123 Perl_xmldump_indent(aTHX_ level, file, "<mad_pv key=%s/>\n", SvPVX(tmpsv));
3124 break;
3125 case MAD_SV:
3126 sv_catpv(tmpsv, " val=\"");
ad64d0ec 3127 sv_catxmlsv(tmpsv, MUTABLE_SV(mp->mad_val));
3b721df9
NC
3128 sv_catpv(tmpsv, "\"");
3129 Perl_xmldump_indent(aTHX_ level, file, "<mad_sv key=%s/>\n", SvPVX(tmpsv));
3130 break;
3131 case MAD_OP:
3132 if ((OP*)mp->mad_val) {
3133 Perl_xmldump_indent(aTHX_ level, file, "<mad_op key=%s>\n", SvPVX(tmpsv));
3134 do_op_xmldump(level+1, file, (OP*)mp->mad_val);
3135 Perl_xmldump_indent(aTHX_ level, file, "</mad_op>\n");
3136 }
3137 break;
3138 default:
3139 Perl_xmldump_indent(aTHX_ level, file, "<mad_unk key=%s/>\n", SvPVX(tmpsv));
3140 break;
3141 }
3142 mp = mp->mad_next;
3143 }
3144 level--;
3145 Perl_xmldump_indent(aTHX_ level, file, "</madprops>\n");
3146
3147 SvREFCNT_dec(tmpsv);
3148 }
3149
3150 switch (o->op_type) {
3151 case OP_PUSHRE:
3152 case OP_MATCH:
3153 case OP_QR:
3154 case OP_SUBST:
3155 if (!contents) {
3156 contents = 1;
3157 PerlIO_printf(file, ">\n");
3158 }
3159 do_pmop_xmldump(level, file, cPMOPo);
3160 break;
3161 default:
3162 break;
3163 }
3164
3165 if (o->op_flags & OPf_KIDS) {
3166 OP *kid;
3167 if (!contents) {
3168 contents = 1;
3169 PerlIO_printf(file, ">\n");
3170 }
3171 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
3172 do_op_xmldump(level, file, kid);
3173 }
3174
3175 if (contents)
3176 Perl_xmldump_indent(aTHX_ level-1, file, "</op_%s>\n", OP_NAME(o));
3177 else
3178 PerlIO_printf(file, " />\n");
3179}
3180
3181void
3182Perl_op_xmldump(pTHX_ const OP *o)
3183{
7918f24d
NC
3184 PERL_ARGS_ASSERT_OP_XMLDUMP;
3185
3b721df9
NC
3186 do_op_xmldump(0, PL_xmlfp, o);
3187}
3188#endif
3189
66610fdd
RGS
3190/*
3191 * Local variables:
3192 * c-indentation-style: bsd
3193 * c-basic-offset: 4
14d04a33 3194 * indent-tabs-mode: nil
66610fdd
RGS
3195 * End:
3196 *
14d04a33 3197 * ex: set ts=8 sts=4 sw=4 et:
37442d52 3198 */