This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
sort.pm deserves a new version number
[perl5.git] / dump.c
CommitLineData
a0d0e21e 1/* dump.c
a687059c 2 *
4bb101f2 3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
1d325971 4 * 2000, 2001, 2002, 2003, 2004, 2005, by Larry Wall and others
a687059c 5 *
6e21c824
LW
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
8d063cd8 8 *
a0d0e21e
LW
9 */
10
11/*
12 * "'You have talked long in your sleep, Frodo,' said Gandalf gently, 'and
13 * it has not been hard for me to read your mind and memory.'"
8d063cd8
LW
14 */
15
166f8a29 16/* This file contains utility routines to dump the contents of SV and OP
61296642 17 * structures, as used by command-line options like -Dt and -Dx, and
166f8a29
DM
18 * by Devel::Peek.
19 *
20 * It also holds the debugging version of the runops function.
21 */
22
8d063cd8 23#include "EXTERN.h"
864dbfa3 24#define PERL_IN_DUMP_C
8d063cd8 25#include "perl.h"
f722798b 26#include "regcomp.h"
0bd48802
AL
27#include "proto.h"
28
8d063cd8 29
27da23d5 30#define Sequence PL_op_sequence
2814eb74 31
3967c732 32void
864dbfa3 33Perl_dump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
3967c732 34{
3967c732 35 va_list args;
3967c732 36 va_start(args, pat);
c5be433b 37 dump_vindent(level, file, pat, &args);
3967c732
JD
38 va_end(args);
39}
8adcabd8
LW
40
41void
c5be433b
GS
42Perl_dump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args)
43{
c8db6e60 44 PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), "");
c5be433b
GS
45 PerlIO_vprintf(file, pat, *args);
46}
47
48void
864dbfa3 49Perl_dump_all(pTHX)
79072805 50{
760ac839 51 PerlIO_setlinebuf(Perl_debug_log);
3280af22 52 if (PL_main_root)
3967c732 53 op_dump(PL_main_root);
3280af22 54 dump_packsubs(PL_defstash);
463ee0b2
LW
55}
56
57void
e1ec3a88 58Perl_dump_packsubs(pTHX_ const HV *stash)
463ee0b2 59{
a0d0e21e 60 I32 i;
463ee0b2 61
8990e307
LW
62 if (!HvARRAY(stash))
63 return;
a0d0e21e 64 for (i = 0; i <= (I32) HvMAX(stash); i++) {
e1ec3a88 65 const HE *entry;
4db58590 66 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
e1ec3a88
AL
67 const GV *gv = (GV*)HeVAL(entry);
68 const HV *hv;
e29cdcb3
GS
69 if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
70 continue;
8ebc5c01 71 if (GvCVu(gv))
463ee0b2 72 dump_sub(gv);
85e6fe83
LW
73 if (GvFORM(gv))
74 dump_form(gv);
6676db26
AMS
75 if (HeKEY(entry)[HeKLEN(entry)-1] == ':'
76 && (hv = GvHV(gv)) && hv != PL_defstash)
463ee0b2
LW
77 dump_packsubs(hv); /* nested package */
78 }
79072805
LW
79 }
80}
81
82void
e1ec3a88 83Perl_dump_sub(pTHX_ const GV *gv)
a687059c 84{
b464bac0 85 SV * const sv = sv_newmortal();
85e6fe83 86
f6aff53a 87 gv_fullname3(sv, gv, Nullch);
b15aece3 88 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ", SvPVX_const(sv));
a0d0e21e 89 if (CvXSUB(GvCV(gv)))
91f3b821
GS
90 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "(xsub 0x%"UVxf" %d)\n",
91 PTR2UV(CvXSUB(GvCV(gv))),
894356b3 92 (int)CvXSUBANY(GvCV(gv)).any_i32);
85e6fe83 93 else if (CvROOT(GvCV(gv)))
3967c732 94 op_dump(CvROOT(GvCV(gv)));
85e6fe83 95 else
cea2e8a9 96 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
85e6fe83
LW
97}
98
99void
e1ec3a88 100Perl_dump_form(pTHX_ const GV *gv)
85e6fe83 101{
b464bac0 102 SV * const sv = sv_newmortal();
85e6fe83 103
f6aff53a 104 gv_fullname3(sv, gv, Nullch);
b15aece3 105 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nFORMAT %s = ", SvPVX_const(sv));
85e6fe83 106 if (CvROOT(GvFORM(gv)))
3967c732 107 op_dump(CvROOT(GvFORM(gv)));
85e6fe83 108 else
cea2e8a9 109 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
a687059c
LW
110}
111
8adcabd8 112void
864dbfa3 113Perl_dump_eval(pTHX)
8d063cd8 114{
3967c732
JD
115 op_dump(PL_eval_root);
116}
117
118char *
e1ec3a88 119Perl_pv_display(pTHX_ SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
3967c732 120{
e1ec3a88
AL
121 const bool nul_terminated = len > cur && pv[cur] == '\0';
122 bool truncated = 0;
3967c732 123
e6abe6d8 124 sv_setpvn(dsv, "\"", 1);
3967c732 125 for (; cur--; pv++) {
e6abe6d8 126 if (pvlim && SvCUR(dsv) >= pvlim) {
e1ec3a88 127 truncated = 1;
3967c732
JD
128 break;
129 }
46316b0a
DM
130 switch (*pv) {
131 case '\t': sv_catpvn(dsv, "\\t", 2); break;
132 case '\n': sv_catpvn(dsv, "\\n", 2); break;
133 case '\r': sv_catpvn(dsv, "\\r", 2); break;
134 case '\f': sv_catpvn(dsv, "\\f", 2); break;
135 case '"': sv_catpvn(dsv, "\\\"", 2); break;
136 case '\\': sv_catpvn(dsv, "\\\\", 2); break;
137 default:
138 if (isPRINT(*pv))
139 sv_catpvn(dsv, pv, 1);
140 else if (cur && isDIGIT(*(pv+1)))
e6abe6d8 141 Perl_sv_catpvf(aTHX_ dsv, "\\%03o", (U8)*pv);
3967c732 142 else
e6abe6d8 143 Perl_sv_catpvf(aTHX_ dsv, "\\%o", (U8)*pv);
3967c732
JD
144 }
145 }
e6abe6d8 146 sv_catpvn(dsv, "\"", 1);
3967c732 147 if (truncated)
e6abe6d8 148 sv_catpvn(dsv, "...", 3);
3967c732 149 if (nul_terminated)
e6abe6d8 150 sv_catpvn(dsv, "\\0", 2);
3967c732 151
e6abe6d8
JH
152 return SvPVX(dsv);
153}
154
155char *
864dbfa3 156Perl_sv_peek(pTHX_ SV *sv)
3967c732 157{
27da23d5 158 dVAR;
aec46f14 159 SV * const t = sv_newmortal();
3967c732
JD
160 int unref = 0;
161
162 sv_setpvn(t, "", 0);
163 retry:
164 if (!sv) {
165 sv_catpv(t, "VOID");
166 goto finish;
167 }
168 else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') {
169 sv_catpv(t, "WILD");
170 goto finish;
171 }
7996736c 172 else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) {
3967c732
JD
173 if (sv == &PL_sv_undef) {
174 sv_catpv(t, "SV_UNDEF");
175 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
176 SVs_GMG|SVs_SMG|SVs_RMG)) &&
177 SvREADONLY(sv))
178 goto finish;
179 }
180 else if (sv == &PL_sv_no) {
181 sv_catpv(t, "SV_NO");
182 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
183 SVs_GMG|SVs_SMG|SVs_RMG)) &&
184 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
185 SVp_POK|SVp_NOK)) &&
186 SvCUR(sv) == 0 &&
187 SvNVX(sv) == 0.0)
188 goto finish;
189 }
7996736c 190 else if (sv == &PL_sv_yes) {
3967c732
JD
191 sv_catpv(t, "SV_YES");
192 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
193 SVs_GMG|SVs_SMG|SVs_RMG)) &&
194 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
195 SVp_POK|SVp_NOK)) &&
196 SvCUR(sv) == 1 &&
b15aece3 197 SvPVX_const(sv) && *SvPVX_const(sv) == '1' &&
3967c732
JD
198 SvNVX(sv) == 1.0)
199 goto finish;
7996736c
MHM
200 }
201 else {
202 sv_catpv(t, "SV_PLACEHOLDER");
203 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
204 SVs_GMG|SVs_SMG|SVs_RMG)) &&
205 SvREADONLY(sv))
206 goto finish;
3967c732
JD
207 }
208 sv_catpv(t, ":");
209 }
210 else if (SvREFCNT(sv) == 0) {
211 sv_catpv(t, "(");
212 unref++;
213 }
a3b4c9c6
DM
214 else if (DEBUG_R_TEST_) {
215 int is_tmp = 0;
216 I32 ix;
217 /* is this SV on the tmps stack? */
218 for (ix=PL_tmps_ix; ix>=0; ix--) {
219 if (PL_tmps_stack[ix] == sv) {
220 is_tmp = 1;
221 break;
222 }
223 }
224 if (SvREFCNT(sv) > 1)
225 Perl_sv_catpvf(aTHX_ t, "<%"UVuf"%s>", (UV)SvREFCNT(sv),
226 is_tmp ? "T" : "");
227 else if (is_tmp)
228 sv_catpv(t, "<T>");
04932ac8
DM
229 }
230
3967c732
JD
231 if (SvROK(sv)) {
232 sv_catpv(t, "\\");
233 if (SvCUR(t) + unref > 10) {
b162af07 234 SvCUR_set(t, unref + 3);
3967c732
JD
235 *SvEND(t) = '\0';
236 sv_catpv(t, "...");
237 goto finish;
238 }
239 sv = (SV*)SvRV(sv);
240 goto retry;
241 }
242 switch (SvTYPE(sv)) {
243 default:
244 sv_catpv(t, "FREED");
245 goto finish;
246
247 case SVt_NULL:
248 sv_catpv(t, "UNDEF");
249 goto finish;
250 case SVt_IV:
251 sv_catpv(t, "IV");
252 break;
253 case SVt_NV:
254 sv_catpv(t, "NV");
255 break;
256 case SVt_RV:
257 sv_catpv(t, "RV");
258 break;
259 case SVt_PV:
260 sv_catpv(t, "PV");
261 break;
262 case SVt_PVIV:
263 sv_catpv(t, "PVIV");
264 break;
265 case SVt_PVNV:
266 sv_catpv(t, "PVNV");
267 break;
268 case SVt_PVMG:
269 sv_catpv(t, "PVMG");
270 break;
271 case SVt_PVLV:
272 sv_catpv(t, "PVLV");
273 break;
274 case SVt_PVAV:
275 sv_catpv(t, "AV");
276 break;
277 case SVt_PVHV:
278 sv_catpv(t, "HV");
279 break;
280 case SVt_PVCV:
281 if (CvGV(sv))
cea2e8a9 282 Perl_sv_catpvf(aTHX_ t, "CV(%s)", GvNAME(CvGV(sv)));
3967c732
JD
283 else
284 sv_catpv(t, "CV()");
285 goto finish;
286 case SVt_PVGV:
287 sv_catpv(t, "GV");
288 break;
289 case SVt_PVBM:
290 sv_catpv(t, "BM");
291 break;
292 case SVt_PVFM:
293 sv_catpv(t, "FM");
294 break;
295 case SVt_PVIO:
296 sv_catpv(t, "IO");
297 break;
298 }
299
300 if (SvPOKp(sv)) {
b15aece3 301 if (!SvPVX_const(sv))
3967c732
JD
302 sv_catpv(t, "(null)");
303 else {
79cb57f6 304 SV *tmp = newSVpvn("", 0);
3967c732
JD
305 sv_catpv(t, "(");
306 if (SvOOK(sv))
b15aece3
SP
307 Perl_sv_catpvf(aTHX_ t, "[%s]", pv_display(tmp, SvPVX_const(sv)-SvIVX(sv), SvIVX(sv), 0, 127));
308 Perl_sv_catpvf(aTHX_ t, "%s)", pv_display(tmp, SvPVX_const(sv), SvCUR(sv), SvLEN(sv), 127));
32639b87 309 if (SvUTF8(sv))
b2ff9928 310 Perl_sv_catpvf(aTHX_ t, " [UTF8 \"%s\"]",
c728cb41
JH
311 sv_uni_display(tmp, sv, 8 * sv_len_utf8(sv),
312 UNI_DISPLAY_QQ));
3967c732
JD
313 SvREFCNT_dec(tmp);
314 }
315 }
316 else if (SvNOKp(sv)) {
e54dc35b 317 STORE_NUMERIC_LOCAL_SET_STANDARD();
1779d84d 318 Perl_sv_catpvf(aTHX_ t, "(%"NVgf")",SvNVX(sv));
e54dc35b 319 RESTORE_NUMERIC_LOCAL();
3967c732 320 }
57def98f 321 else if (SvIOKp(sv)) {
cf2093f6 322 if (SvIsUV(sv))
57def98f 323 Perl_sv_catpvf(aTHX_ t, "(%"UVuf")", (UV)SvUVX(sv));
cf2093f6 324 else
57def98f 325 Perl_sv_catpvf(aTHX_ t, "(%"IVdf")", (IV)SvIVX(sv));
25da4f38 326 }
3967c732
JD
327 else
328 sv_catpv(t, "()");
2ef28da1 329
3967c732
JD
330 finish:
331 if (unref) {
332 while (unref--)
333 sv_catpv(t, ")");
334 }
8b6b16e7 335 return SvPV_nolen(t);
3967c732
JD
336}
337
338void
6867be6d 339Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, const PMOP *pm)
3967c732
JD
340{
341 char ch;
342
343 if (!pm) {
cea2e8a9 344 Perl_dump_indent(aTHX_ level, file, "{}\n");
3967c732
JD
345 return;
346 }
cea2e8a9 347 Perl_dump_indent(aTHX_ level, file, "{\n");
3967c732
JD
348 level++;
349 if (pm->op_pmflags & PMf_ONCE)
350 ch = '?';
351 else
352 ch = '/';
aaa362c4 353 if (PM_GETRE(pm))
cea2e8a9 354 Perl_dump_indent(aTHX_ level, file, "PMf_PRE %c%s%c%s\n",
aaa362c4 355 ch, PM_GETRE(pm)->precomp, ch,
3967c732
JD
356 (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
357 else
cea2e8a9 358 Perl_dump_indent(aTHX_ level, file, "PMf_PRE (RUNTIME)\n");
3967c732 359 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
cea2e8a9 360 Perl_dump_indent(aTHX_ level, file, "PMf_REPL = ");
3967c732
JD
361 op_dump(pm->op_pmreplroot);
362 }
aaa362c4 363 if (pm->op_pmflags || (PM_GETRE(pm) && PM_GETRE(pm)->check_substr)) {
79cb57f6 364 SV *tmpsv = newSVpvn("", 0);
3967c732
JD
365 if (pm->op_pmdynflags & PMdf_USED)
366 sv_catpv(tmpsv, ",USED");
367 if (pm->op_pmdynflags & PMdf_TAINTED)
368 sv_catpv(tmpsv, ",TAINTED");
369 if (pm->op_pmflags & PMf_ONCE)
370 sv_catpv(tmpsv, ",ONCE");
aaa362c4
RS
371 if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr
372 && !(PM_GETRE(pm)->reganch & ROPT_NOSCAN))
3967c732 373 sv_catpv(tmpsv, ",SCANFIRST");
aaa362c4
RS
374 if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr
375 && PM_GETRE(pm)->reganch & ROPT_CHECK_ALL)
3967c732
JD
376 sv_catpv(tmpsv, ",ALL");
377 if (pm->op_pmflags & PMf_SKIPWHITE)
378 sv_catpv(tmpsv, ",SKIPWHITE");
379 if (pm->op_pmflags & PMf_CONST)
380 sv_catpv(tmpsv, ",CONST");
381 if (pm->op_pmflags & PMf_KEEP)
382 sv_catpv(tmpsv, ",KEEP");
383 if (pm->op_pmflags & PMf_GLOBAL)
384 sv_catpv(tmpsv, ",GLOBAL");
385 if (pm->op_pmflags & PMf_CONTINUE)
386 sv_catpv(tmpsv, ",CONTINUE");
387 if (pm->op_pmflags & PMf_RETAINT)
388 sv_catpv(tmpsv, ",RETAINT");
389 if (pm->op_pmflags & PMf_EVAL)
390 sv_catpv(tmpsv, ",EVAL");
b15aece3 391 Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
3967c732
JD
392 SvREFCNT_dec(tmpsv);
393 }
394
cea2e8a9 395 Perl_dump_indent(aTHX_ level-1, file, "}\n");
3967c732
JD
396}
397
398void
864dbfa3 399Perl_pmop_dump(pTHX_ PMOP *pm)
3967c732
JD
400{
401 do_pmop_dump(0, Perl_debug_log, pm);
79072805
LW
402}
403
2814eb74
PJ
404/* An op sequencer. We visit the ops in the order they're to execute. */
405
406STATIC void
0bd48802 407S_sequence(pTHX_ register const OP *o)
2814eb74 408{
27da23d5 409 dVAR;
2814eb74 410 SV *op;
93524f2b 411 const char *key;
2814eb74 412 STRLEN len;
6867be6d
AL
413 const OP *oldop = 0;
414 OP *l;
2814eb74 415
2814eb74
PJ
416 if (!o)
417 return;
418
724e67cb
RGS
419 if (!Sequence)
420 Sequence = newHV();
2814eb74
PJ
421
422 for (; o; o = o->op_next) {
c0fd1b42 423 op = newSVuv(PTR2UV(o));
93524f2b 424 key = SvPV_const(op, len);
2814eb74
PJ
425 if (hv_exists(Sequence, key, len))
426 break;
427
428 switch (o->op_type) {
429 case OP_STUB:
430 if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) {
27da23d5 431 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
2814eb74
PJ
432 break;
433 }
434 goto nothin;
435 case OP_NULL:
436 if (oldop && o->op_next)
437 continue;
438 break;
439 case OP_SCALAR:
440 case OP_LINESEQ:
441 case OP_SCOPE:
442 nothin:
443 if (oldop && o->op_next)
444 continue;
27da23d5 445 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
2814eb74
PJ
446 break;
447
448 case OP_MAPWHILE:
449 case OP_GREPWHILE:
450 case OP_AND:
451 case OP_OR:
452 case OP_DOR:
453 case OP_ANDASSIGN:
454 case OP_ORASSIGN:
455 case OP_DORASSIGN:
456 case OP_COND_EXPR:
457 case OP_RANGE:
27da23d5 458 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
5411ce9f 459 for (l = cLOGOPo->op_other; l && l->op_type == OP_NULL; l = l->op_next)
2814eb74 460 ;
0bd48802 461 sequence(l);
2814eb74
PJ
462 break;
463
464 case OP_ENTERLOOP:
465 case OP_ENTERITER:
27da23d5 466 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
5411ce9f 467 for (l = cLOOPo->op_redoop; l && l->op_type == OP_NULL; l = l->op_next)
2814eb74 468 ;
0bd48802 469 sequence(l);
5411ce9f 470 for (l = cLOOPo->op_nextop; l && l->op_type == OP_NULL; l = l->op_next)
2814eb74 471 ;
0bd48802 472 sequence(l);
5411ce9f 473 for (l = cLOOPo->op_lastop; l && l->op_type == OP_NULL; l = l->op_next)
2814eb74 474 ;
0bd48802 475 sequence(l);
2814eb74
PJ
476 break;
477
478 case OP_QR:
479 case OP_MATCH:
480 case OP_SUBST:
27da23d5 481 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
5411ce9f 482 for (l = cPMOPo->op_pmreplstart; l && l->op_type == OP_NULL; l = l->op_next)
2814eb74 483 ;
0bd48802 484 sequence(l);
2814eb74
PJ
485 break;
486
487 case OP_HELEM:
488 break;
489
490 default:
27da23d5 491 hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0);
2814eb74
PJ
492 break;
493 }
494 oldop = o;
495 }
496}
497
498STATIC UV
0bd48802 499S_sequence_num(pTHX_ const OP *o)
2814eb74 500{
27da23d5 501 dVAR;
2814eb74
PJ
502 SV *op,
503 **seq;
93524f2b 504 const char *key;
2814eb74
PJ
505 STRLEN len;
506 if (!o) return 0;
c0fd1b42 507 op = newSVuv(PTR2UV(o));
93524f2b 508 key = SvPV_const(op, len);
2814eb74
PJ
509 seq = hv_fetch(Sequence, key, len, 0);
510 return seq ? SvUV(*seq): 0;
511}
512
79072805 513void
6867be6d 514Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
79072805 515{
27da23d5 516 dVAR;
2814eb74 517 UV seq;
0bd48802 518 sequence(o);
cea2e8a9 519 Perl_dump_indent(aTHX_ level, file, "{\n");
3967c732 520 level++;
0bd48802 521 seq = sequence_num(o);
2814eb74 522 if (seq)
c0fd1b42 523 PerlIO_printf(file, "%-4"UVf, seq);
93a17b20 524 else
3967c732 525 PerlIO_printf(file, " ");
c8db6e60
JH
526 PerlIO_printf(file,
527 "%*sTYPE = %s ===> ",
53e06cf0 528 (int)(PL_dumpindent*level-4), "", OP_NAME(o));
2814eb74 529 if (o->op_next)
c0fd1b42 530 PerlIO_printf(file, seq ? "%"UVf"\n" : "(%"UVf")\n",
0bd48802 531 sequence_num(o->op_next));
79072805 532 else
3967c732 533 PerlIO_printf(file, "DONE\n");
11343788 534 if (o->op_targ) {
acb36ea4 535 if (o->op_type == OP_NULL)
ae7d165c 536 {
cea2e8a9 537 Perl_dump_indent(aTHX_ level, file, " (was %s)\n", PL_op_name[o->op_targ]);
ae7d165c
PJ
538 if (o->op_targ == OP_NEXTSTATE)
539 {
540 if (CopLINE(cCOPo))
9d98dee5
RB
541 Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n",
542 (UV)CopLINE(cCOPo));
ae7d165c
PJ
543 if (CopSTASHPV(cCOPo))
544 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
545 CopSTASHPV(cCOPo));
546 if (cCOPo->cop_label)
547 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
548 cCOPo->cop_label);
549 }
550 }
8990e307 551 else
894356b3 552 Perl_dump_indent(aTHX_ level, file, "TARG = %ld\n", (long)o->op_targ);
8990e307 553 }
748a9306 554#ifdef DUMPADDR
57def98f 555 Perl_dump_indent(aTHX_ level, file, "ADDR = 0x%"UVxf" => 0x%"UVxf"\n", (UV)o, (UV)o->op_next);
79072805 556#endif
11343788 557 if (o->op_flags) {
79cb57f6 558 SV *tmpsv = newSVpvn("", 0);
5dc0d613 559 switch (o->op_flags & OPf_WANT) {
54310121 560 case OPf_WANT_VOID:
46fc3d4c 561 sv_catpv(tmpsv, ",VOID");
54310121
PP
562 break;
563 case OPf_WANT_SCALAR:
46fc3d4c 564 sv_catpv(tmpsv, ",SCALAR");
54310121
PP
565 break;
566 case OPf_WANT_LIST:
46fc3d4c 567 sv_catpv(tmpsv, ",LIST");
54310121
PP
568 break;
569 default:
46fc3d4c 570 sv_catpv(tmpsv, ",UNKNOWN");
54310121
PP
571 break;
572 }
11343788 573 if (o->op_flags & OPf_KIDS)
46fc3d4c 574 sv_catpv(tmpsv, ",KIDS");
11343788 575 if (o->op_flags & OPf_PARENS)
46fc3d4c 576 sv_catpv(tmpsv, ",PARENS");
11343788 577 if (o->op_flags & OPf_STACKED)
46fc3d4c 578 sv_catpv(tmpsv, ",STACKED");
11343788 579 if (o->op_flags & OPf_REF)
46fc3d4c 580 sv_catpv(tmpsv, ",REF");
11343788 581 if (o->op_flags & OPf_MOD)
46fc3d4c 582 sv_catpv(tmpsv, ",MOD");
11343788 583 if (o->op_flags & OPf_SPECIAL)
46fc3d4c 584 sv_catpv(tmpsv, ",SPECIAL");
b15aece3 585 Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
46fc3d4c 586 SvREFCNT_dec(tmpsv);
79072805 587 }
11343788 588 if (o->op_private) {
79cb57f6 589 SV *tmpsv = newSVpvn("", 0);
07447971
GS
590 if (PL_opargs[o->op_type] & OA_TARGLEX) {
591 if (o->op_private & OPpTARGET_MY)
592 sv_catpv(tmpsv, ",TARGET_MY");
593 }
bf91b999
SC
594 else if (o->op_type == OP_LEAVESUB ||
595 o->op_type == OP_LEAVE ||
596 o->op_type == OP_LEAVESUBLV ||
597 o->op_type == OP_LEAVEWRITE) {
598 if (o->op_private & OPpREFCOUNTED)
599 sv_catpv(tmpsv, ",REFCOUNTED");
600 }
601 else if (o->op_type == OP_AASSIGN) {
11343788 602 if (o->op_private & OPpASSIGN_COMMON)
46fc3d4c 603 sv_catpv(tmpsv, ",COMMON");
8d063cd8 604 }
11343788
MB
605 else if (o->op_type == OP_SASSIGN) {
606 if (o->op_private & OPpASSIGN_BACKWARDS)
46fc3d4c 607 sv_catpv(tmpsv, ",BACKWARDS");
a0d0e21e 608 }
11343788
MB
609 else if (o->op_type == OP_TRANS) {
610 if (o->op_private & OPpTRANS_SQUASH)
46fc3d4c 611 sv_catpv(tmpsv, ",SQUASH");
11343788 612 if (o->op_private & OPpTRANS_DELETE)
46fc3d4c 613 sv_catpv(tmpsv, ",DELETE");
11343788 614 if (o->op_private & OPpTRANS_COMPLEMENT)
46fc3d4c 615 sv_catpv(tmpsv, ",COMPLEMENT");
bf91b999
SC
616 if (o->op_private & OPpTRANS_IDENTICAL)
617 sv_catpv(tmpsv, ",IDENTICAL");
618 if (o->op_private & OPpTRANS_GROWS)
619 sv_catpv(tmpsv, ",GROWS");
8d063cd8 620 }
11343788
MB
621 else if (o->op_type == OP_REPEAT) {
622 if (o->op_private & OPpREPEAT_DOLIST)
46fc3d4c 623 sv_catpv(tmpsv, ",DOLIST");
8d063cd8 624 }
11343788
MB
625 else if (o->op_type == OP_ENTERSUB ||
626 o->op_type == OP_RV2SV ||
23f1ca44 627 o->op_type == OP_GVSV ||
11343788
MB
628 o->op_type == OP_RV2AV ||
629 o->op_type == OP_RV2HV ||
630 o->op_type == OP_RV2GV ||
631 o->op_type == OP_AELEM ||
632 o->op_type == OP_HELEM )
85e6fe83 633 {
5dc0d613
MB
634 if (o->op_type == OP_ENTERSUB) {
635 if (o->op_private & OPpENTERSUB_AMPER)
46fc3d4c 636 sv_catpv(tmpsv, ",AMPER");
5dc0d613 637 if (o->op_private & OPpENTERSUB_DB)
46fc3d4c 638 sv_catpv(tmpsv, ",DB");
d3011074
IZ
639 if (o->op_private & OPpENTERSUB_HASTARG)
640 sv_catpv(tmpsv, ",HASTARG");
bf91b999
SC
641 if (o->op_private & OPpENTERSUB_NOPAREN)
642 sv_catpv(tmpsv, ",NOPAREN");
643 if (o->op_private & OPpENTERSUB_INARGS)
644 sv_catpv(tmpsv, ",INARGS");
95f0a2f1
SB
645 if (o->op_private & OPpENTERSUB_NOMOD)
646 sv_catpv(tmpsv, ",NOMOD");
68dc0745 647 }
bf91b999 648 else {
d3011074 649 switch (o->op_private & OPpDEREF) {
5f05dabc 650 case OPpDEREF_SV:
46fc3d4c 651 sv_catpv(tmpsv, ",SV");
5f05dabc
PP
652 break;
653 case OPpDEREF_AV:
46fc3d4c 654 sv_catpv(tmpsv, ",AV");
5f05dabc
PP
655 break;
656 case OPpDEREF_HV:
46fc3d4c 657 sv_catpv(tmpsv, ",HV");
5f05dabc
PP
658 break;
659 }
bf91b999
SC
660 if (o->op_private & OPpMAYBE_LVSUB)
661 sv_catpv(tmpsv, ",MAYBE_LVSUB");
662 }
5dc0d613
MB
663 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
664 if (o->op_private & OPpLVAL_DEFER)
46fc3d4c 665 sv_catpv(tmpsv, ",LVAL_DEFER");
68dc0745
PP
666 }
667 else {
5dc0d613 668 if (o->op_private & HINT_STRICT_REFS)
46fc3d4c 669 sv_catpv(tmpsv, ",STRICT_REFS");
192587c2
GS
670 if (o->op_private & OPpOUR_INTRO)
671 sv_catpv(tmpsv, ",OUR_INTRO");
68dc0745 672 }
8d063cd8 673 }
11343788
MB
674 else if (o->op_type == OP_CONST) {
675 if (o->op_private & OPpCONST_BARE)
46fc3d4c 676 sv_catpv(tmpsv, ",BARE");
7a52d87a
GS
677 if (o->op_private & OPpCONST_STRICT)
678 sv_catpv(tmpsv, ",STRICT");
bf91b999
SC
679 if (o->op_private & OPpCONST_ARYBASE)
680 sv_catpv(tmpsv, ",ARYBASE");
681 if (o->op_private & OPpCONST_WARNING)
682 sv_catpv(tmpsv, ",WARNING");
683 if (o->op_private & OPpCONST_ENTERED)
684 sv_catpv(tmpsv, ",ENTERED");
79072805 685 }
11343788
MB
686 else if (o->op_type == OP_FLIP) {
687 if (o->op_private & OPpFLIP_LINENUM)
46fc3d4c 688 sv_catpv(tmpsv, ",LINENUM");
79072805 689 }
11343788
MB
690 else if (o->op_type == OP_FLOP) {
691 if (o->op_private & OPpFLIP_LINENUM)
46fc3d4c 692 sv_catpv(tmpsv, ",LINENUM");
95f0a2f1
SB
693 }
694 else if (o->op_type == OP_RV2CV) {
cd06dffe
GS
695 if (o->op_private & OPpLVAL_INTRO)
696 sv_catpv(tmpsv, ",INTRO");
79072805 697 }
bf91b999
SC
698 else if (o->op_type == OP_GV) {
699 if (o->op_private & OPpEARLY_CV)
700 sv_catpv(tmpsv, ",EARLY_CV");
701 }
702 else if (o->op_type == OP_LIST) {
703 if (o->op_private & OPpLIST_GUESSED)
704 sv_catpv(tmpsv, ",GUESSED");
705 }
706 else if (o->op_type == OP_DELETE) {
707 if (o->op_private & OPpSLICE)
708 sv_catpv(tmpsv, ",SLICE");
709 }
710 else if (o->op_type == OP_EXISTS) {
711 if (o->op_private & OPpEXISTS_SUB)
712 sv_catpv(tmpsv, ",EXISTS_SUB");
713 }
714 else if (o->op_type == OP_SORT) {
715 if (o->op_private & OPpSORT_NUMERIC)
716 sv_catpv(tmpsv, ",NUMERIC");
717 if (o->op_private & OPpSORT_INTEGER)
718 sv_catpv(tmpsv, ",INTEGER");
719 if (o->op_private & OPpSORT_REVERSE)
720 sv_catpv(tmpsv, ",REVERSE");
721 }
722 else if (o->op_type == OP_THREADSV) {
723 if (o->op_private & OPpDONE_SVREF)
724 sv_catpv(tmpsv, ",SVREF");
725 }
726 else if (o->op_type == OP_OPEN || o->op_type == OP_BACKTICK) {
727 if (o->op_private & OPpOPEN_IN_RAW)
728 sv_catpv(tmpsv, ",IN_RAW");
729 if (o->op_private & OPpOPEN_IN_CRLF)
730 sv_catpv(tmpsv, ",IN_CRLF");
731 if (o->op_private & OPpOPEN_OUT_RAW)
732 sv_catpv(tmpsv, ",OUT_RAW");
733 if (o->op_private & OPpOPEN_OUT_CRLF)
734 sv_catpv(tmpsv, ",OUT_CRLF");
735 }
736 else if (o->op_type == OP_EXIT) {
737 if (o->op_private & OPpEXIT_VMSISH)
96e176bf
CL
738 sv_catpv(tmpsv, ",EXIT_VMSISH");
739 if (o->op_private & OPpHUSH_VMSISH)
740 sv_catpv(tmpsv, ",HUSH_VMSISH");
741 }
742 else if (o->op_type == OP_DIE) {
743 if (o->op_private & OPpHUSH_VMSISH)
744 sv_catpv(tmpsv, ",HUSH_VMSISH");
bf91b999 745 }
fbb0b3b3
RGS
746 else if (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)) {
747 if (OP_IS_FILETEST_ACCESS(o) && o->op_private & OPpFT_ACCESS)
748 sv_catpv(tmpsv, ",FT_ACCESS");
749 if (o->op_private & OPpFT_STACKED)
750 sv_catpv(tmpsv, ",FT_STACKED");
1af34c76 751 }
11343788 752 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
46fc3d4c
PP
753 sv_catpv(tmpsv, ",INTRO");
754 if (SvCUR(tmpsv))
b15aece3 755 Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX_const(tmpsv) + 1);
46fc3d4c 756 SvREFCNT_dec(tmpsv);
8d063cd8 757 }
8d063cd8 758
11343788 759 switch (o->op_type) {
971a9dd3 760 case OP_AELEMFAST:
93a17b20 761 case OP_GVSV:
79072805 762 case OP_GV:
971a9dd3 763#ifdef USE_ITHREADS
c803eecc 764 Perl_dump_indent(aTHX_ level, file, "PADIX = %" IVdf "\n", (IV)cPADOPo->op_padix);
971a9dd3 765#else
38c076c7
DM
766 if ( ! PL_op->op_flags & OPf_SPECIAL) { /* not lexical */
767 if (cSVOPo->op_sv) {
768 SV *tmpsv = NEWSV(0,0);
38c076c7
DM
769 ENTER;
770 SAVEFREESV(tmpsv);
771 gv_fullname3(tmpsv, (GV*)cSVOPo->op_sv, Nullch);
8b6b16e7 772 Perl_dump_indent(aTHX_ level, file, "GV = %s\n",
d5263905 773 SvPV_nolen_const(tmpsv));
38c076c7
DM
774 LEAVE;
775 }
776 else
777 Perl_dump_indent(aTHX_ level, file, "GV = NULL\n");
378cc40b 778 }
971a9dd3 779#endif
79072805
LW
780 break;
781 case OP_CONST:
f5d5a27c 782 case OP_METHOD_NAMED:
b6a15bc5
DM
783#ifndef USE_ITHREADS
784 /* with ITHREADS, consts are stored in the pad, and the right pad
785 * may not be active here, so skip */
3848b962 786 Perl_dump_indent(aTHX_ level, file, "SV = %s\n", SvPEEK(cSVOPo_sv));
b6a15bc5 787#endif
79072805 788 break;
7399586d 789 case OP_SETSTATE:
93a17b20
LW
790 case OP_NEXTSTATE:
791 case OP_DBSTATE:
57843af0 792 if (CopLINE(cCOPo))
9d98dee5
RB
793 Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n",
794 (UV)CopLINE(cCOPo));
ed094faf
GS
795 if (CopSTASHPV(cCOPo))
796 Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
797 CopSTASHPV(cCOPo));
11343788 798 if (cCOPo->cop_label)
ed094faf
GS
799 Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
800 cCOPo->cop_label);
79072805
LW
801 break;
802 case OP_ENTERLOOP:
cea2e8a9 803 Perl_dump_indent(aTHX_ level, file, "REDO ===> ");
11343788 804 if (cLOOPo->op_redoop)
0bd48802 805 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_redoop));
79072805 806 else
3967c732 807 PerlIO_printf(file, "DONE\n");
cea2e8a9 808 Perl_dump_indent(aTHX_ level, file, "NEXT ===> ");
11343788 809 if (cLOOPo->op_nextop)
0bd48802 810 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_nextop));
79072805 811 else
3967c732 812 PerlIO_printf(file, "DONE\n");
cea2e8a9 813 Perl_dump_indent(aTHX_ level, file, "LAST ===> ");
11343788 814 if (cLOOPo->op_lastop)
0bd48802 815 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_lastop));
79072805 816 else
3967c732 817 PerlIO_printf(file, "DONE\n");
79072805
LW
818 break;
819 case OP_COND_EXPR:
1a67a97c 820 case OP_RANGE:
a0d0e21e 821 case OP_MAPWHILE:
79072805
LW
822 case OP_GREPWHILE:
823 case OP_OR:
824 case OP_AND:
cea2e8a9 825 Perl_dump_indent(aTHX_ level, file, "OTHER ===> ");
11343788 826 if (cLOGOPo->op_other)
0bd48802 827 PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOGOPo->op_other));
79072805 828 else
3967c732 829 PerlIO_printf(file, "DONE\n");
79072805
LW
830 break;
831 case OP_PUSHRE:
832 case OP_MATCH:
8782bef2 833 case OP_QR:
79072805 834 case OP_SUBST:
3967c732 835 do_pmop_dump(level, file, cPMOPo);
79072805 836 break;
7934575e
GS
837 case OP_LEAVE:
838 case OP_LEAVEEVAL:
839 case OP_LEAVESUB:
840 case OP_LEAVESUBLV:
841 case OP_LEAVEWRITE:
842 case OP_SCOPE:
843 if (o->op_private & OPpREFCOUNTED)
844 Perl_dump_indent(aTHX_ level, file, "REFCNT = %"UVuf"\n", (UV)o->op_targ);
845 break;
a0d0e21e
LW
846 default:
847 break;
79072805 848 }
11343788 849 if (o->op_flags & OPf_KIDS) {
79072805 850 OP *kid;
11343788 851 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
3967c732 852 do_op_dump(level, file, kid);
8d063cd8 853 }
cea2e8a9 854 Perl_dump_indent(aTHX_ level-1, file, "}\n");
3967c732
JD
855}
856
857void
6867be6d 858Perl_op_dump(pTHX_ const OP *o)
3967c732
JD
859{
860 do_op_dump(0, Perl_debug_log, o);
8d063cd8
LW
861}
862
8adcabd8 863void
864dbfa3 864Perl_gv_dump(pTHX_ GV *gv)
378cc40b 865{
79072805 866 SV *sv;
378cc40b 867
79072805 868 if (!gv) {
760ac839 869 PerlIO_printf(Perl_debug_log, "{}\n");
378cc40b
LW
870 return;
871 }
8990e307 872 sv = sv_newmortal();
760ac839 873 PerlIO_printf(Perl_debug_log, "{\n");
f6aff53a 874 gv_fullname3(sv, gv, Nullch);
b15aece3 875 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s", SvPVX_const(sv));
79072805 876 if (gv != GvEGV(gv)) {
f6aff53a 877 gv_efullname3(sv, GvEGV(gv), Nullch);
b15aece3 878 Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s", SvPVX_const(sv));
8adcabd8 879 }
3967c732 880 PerlIO_putc(Perl_debug_log, '\n');
cea2e8a9 881 Perl_dump_indent(aTHX_ 0, Perl_debug_log, "}\n");
8d063cd8
LW
882}
883
14befaf4 884
afe38520 885/* map magic types to the symbolic names
14befaf4
DM
886 * (with the PERL_MAGIC_ prefixed stripped)
887 */
888
27da23d5 889static const struct { const char type; const char *name; } magic_names[] = {
516a5887
JH
890 { PERL_MAGIC_sv, "sv(\\0)" },
891 { PERL_MAGIC_arylen, "arylen(#)" },
ca732855 892 { PERL_MAGIC_rhash, "rhash(%)" },
516a5887
JH
893 { PERL_MAGIC_glob, "glob(*)" },
894 { PERL_MAGIC_pos, "pos(.)" },
8d2f4536 895 { PERL_MAGIC_symtab, "symtab(:)" },
516a5887 896 { PERL_MAGIC_backref, "backref(<)" },
a3874608 897 { PERL_MAGIC_arylen_p, "arylen_p(@)" },
516a5887
JH
898 { PERL_MAGIC_overload, "overload(A)" },
899 { PERL_MAGIC_bm, "bm(B)" },
900 { PERL_MAGIC_regdata, "regdata(D)" },
901 { PERL_MAGIC_env, "env(E)" },
902 { PERL_MAGIC_isa, "isa(I)" },
903 { PERL_MAGIC_dbfile, "dbfile(L)" },
afe38520 904 { PERL_MAGIC_shared, "shared(N)" },
516a5887
JH
905 { PERL_MAGIC_tied, "tied(P)" },
906 { PERL_MAGIC_sig, "sig(S)" },
907 { PERL_MAGIC_uvar, "uvar(U)" },
908 { PERL_MAGIC_overload_elem, "overload_elem(a)" },
909 { PERL_MAGIC_overload_table, "overload_table(c)" },
910 { PERL_MAGIC_regdatum, "regdatum(d)" },
911 { PERL_MAGIC_envelem, "envelem(e)" },
912 { PERL_MAGIC_fm, "fm(f)" },
913 { PERL_MAGIC_regex_global, "regex_global(g)" },
914 { PERL_MAGIC_isaelem, "isaelem(i)" },
915 { PERL_MAGIC_nkeys, "nkeys(k)" },
916 { PERL_MAGIC_dbline, "dbline(l)" },
917 { PERL_MAGIC_mutex, "mutex(m)" },
afe38520 918 { PERL_MAGIC_shared_scalar, "shared_scalar(n)" },
516a5887
JH
919 { PERL_MAGIC_collxfrm, "collxfrm(o)" },
920 { PERL_MAGIC_tiedelem, "tiedelem(p)" },
921 { PERL_MAGIC_tiedscalar, "tiedscalar(q)" },
922 { PERL_MAGIC_qr, "qr(r)" },
923 { PERL_MAGIC_sigelem, "sigelem(s)" },
924 { PERL_MAGIC_taint, "taint(t)" },
afe38520 925 { PERL_MAGIC_uvar_elem, "uvar_elem(v)" },
516a5887 926 { PERL_MAGIC_vec, "vec(v)" },
cb50f42d 927 { PERL_MAGIC_vstring, "vstring(V)" },
7e8c5dac 928 { PERL_MAGIC_utf8, "utf8(w)" },
516a5887
JH
929 { PERL_MAGIC_substr, "substr(x)" },
930 { PERL_MAGIC_defelem, "defelem(y)" },
931 { PERL_MAGIC_ext, "ext(~)" },
932 /* this null string terminates the list */
933 { 0, 0 },
14befaf4
DM
934};
935
8adcabd8 936void
6867be6d 937Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, const MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
8d063cd8 938{
3967c732 939 for (; mg; mg = mg->mg_moremagic) {
b900a521
JH
940 Perl_dump_indent(aTHX_ level, file,
941 " MAGIC = 0x%"UVxf"\n", PTR2UV(mg));
3967c732 942 if (mg->mg_virtual) {
bfed75c6
AL
943 const MGVTBL * const v = mg->mg_virtual;
944 const char *s = 0;
3967c732
JD
945 if (v == &PL_vtbl_sv) s = "sv";
946 else if (v == &PL_vtbl_env) s = "env";
947 else if (v == &PL_vtbl_envelem) s = "envelem";
948 else if (v == &PL_vtbl_sig) s = "sig";
949 else if (v == &PL_vtbl_sigelem) s = "sigelem";
950 else if (v == &PL_vtbl_pack) s = "pack";
951 else if (v == &PL_vtbl_packelem) s = "packelem";
952 else if (v == &PL_vtbl_dbline) s = "dbline";
953 else if (v == &PL_vtbl_isa) s = "isa";
954 else if (v == &PL_vtbl_arylen) s = "arylen";
955 else if (v == &PL_vtbl_glob) s = "glob";
956 else if (v == &PL_vtbl_mglob) s = "mglob";
957 else if (v == &PL_vtbl_nkeys) s = "nkeys";
958 else if (v == &PL_vtbl_taint) s = "taint";
959 else if (v == &PL_vtbl_substr) s = "substr";
960 else if (v == &PL_vtbl_vec) s = "vec";
961 else if (v == &PL_vtbl_pos) s = "pos";
962 else if (v == &PL_vtbl_bm) s = "bm";
963 else if (v == &PL_vtbl_fm) s = "fm";
964 else if (v == &PL_vtbl_uvar) s = "uvar";
965 else if (v == &PL_vtbl_defelem) s = "defelem";
966#ifdef USE_LOCALE_COLLATE
967 else if (v == &PL_vtbl_collxfrm) s = "collxfrm";
968#endif
3967c732
JD
969 else if (v == &PL_vtbl_amagic) s = "amagic";
970 else if (v == &PL_vtbl_amagicelem) s = "amagicelem";
810b8aa5 971 else if (v == &PL_vtbl_backref) s = "backref";
7e8c5dac 972 else if (v == &PL_vtbl_utf8) s = "utf8";
83bf042f 973 else if (v == &PL_vtbl_arylen_p) s = "arylen_p";
3967c732 974 if (s)
cea2e8a9 975 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", s);
3967c732 976 else
b900a521 977 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0x%"UVxf"\n", PTR2UV(v));
3967c732
JD
978 }
979 else
cea2e8a9 980 Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0\n");
8d063cd8 981
3967c732 982 if (mg->mg_private)
cea2e8a9 983 Perl_dump_indent(aTHX_ level, file, " MG_PRIVATE = %d\n", mg->mg_private);
3967c732 984
14befaf4
DM
985 {
986 int n;
e1ec3a88 987 const char *name = 0;
27da23d5 988 for (n = 0; magic_names[n].name; n++) {
14befaf4
DM
989 if (mg->mg_type == magic_names[n].type) {
990 name = magic_names[n].name;
991 break;
992 }
993 }
994 if (name)
995 Perl_dump_indent(aTHX_ level, file,
996 " MG_TYPE = PERL_MAGIC_%s\n", name);
997 else
998 Perl_dump_indent(aTHX_ level, file,
999 " MG_TYPE = UNKNOWN(\\%o)\n", mg->mg_type);
1000 }
3967c732
JD
1001
1002 if (mg->mg_flags) {
cea2e8a9 1003 Perl_dump_indent(aTHX_ level, file, " MG_FLAGS = 0x%02X\n", mg->mg_flags);
cb50f42d
YST
1004 if (mg->mg_type == PERL_MAGIC_envelem &&
1005 mg->mg_flags & MGf_TAINTEDDIR)
cea2e8a9 1006 Perl_dump_indent(aTHX_ level, file, " TAINTEDDIR\n");
3967c732 1007 if (mg->mg_flags & MGf_REFCOUNTED)
cea2e8a9 1008 Perl_dump_indent(aTHX_ level, file, " REFCOUNTED\n");
3967c732 1009 if (mg->mg_flags & MGf_GSKIP)
cea2e8a9 1010 Perl_dump_indent(aTHX_ level, file, " GSKIP\n");
cb50f42d
YST
1011 if (mg->mg_type == PERL_MAGIC_regex_global &&
1012 mg->mg_flags & MGf_MINMATCH)
cea2e8a9 1013 Perl_dump_indent(aTHX_ level, file, " MINMATCH\n");
3967c732
JD
1014 }
1015 if (mg->mg_obj) {
b900a521 1016 Perl_dump_indent(aTHX_ level, file, " MG_OBJ = 0x%"UVxf"\n", PTR2UV(mg->mg_obj));
3967c732
JD
1017 if (mg->mg_flags & MGf_REFCOUNTED)
1018 do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
1019 }
1020 if (mg->mg_len)
894356b3 1021 Perl_dump_indent(aTHX_ level, file, " MG_LEN = %ld\n", (long)mg->mg_len);
3967c732 1022 if (mg->mg_ptr) {
b900a521 1023 Perl_dump_indent(aTHX_ level, file, " MG_PTR = 0x%"UVxf, PTR2UV(mg->mg_ptr));
3967c732 1024 if (mg->mg_len >= 0) {
7e8c5dac
HS
1025 if (mg->mg_type != PERL_MAGIC_utf8) {
1026 SV *sv = newSVpvn("", 0);
1027 PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim));
1028 SvREFCNT_dec(sv);
1029 }
3967c732
JD
1030 }
1031 else if (mg->mg_len == HEf_SVKEY) {
1032 PerlIO_puts(file, " => HEf_SVKEY\n");
1033 do_sv_dump(level+2, file, (SV*)((mg)->mg_ptr), nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
1034 continue;
1035 }
1036 else
1037 PerlIO_puts(file, " ???? - please notify IZ");
1038 PerlIO_putc(file, '\n');
1039 }
7e8c5dac
HS
1040 if (mg->mg_type == PERL_MAGIC_utf8) {
1041 STRLEN *cache = (STRLEN *) mg->mg_ptr;
1042 if (cache) {
1043 IV i;
1044 for (i = 0; i < PERL_MAGIC_UTF8_CACHESIZE; i++)
1045 Perl_dump_indent(aTHX_ level, file,
1046 " %2"IVdf": %"UVuf" -> %"UVuf"\n",
1047 i,
1048 (UV)cache[i * 2],
1049 (UV)cache[i * 2 + 1]);
1050 }
1051 }
378cc40b 1052 }
3967c732
JD
1053}
1054
1055void
6867be6d 1056Perl_magic_dump(pTHX_ const MAGIC *mg)
3967c732
JD
1057{
1058 do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0);
1059}
1060
1061void
e1ec3a88 1062Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, const char *name, HV *sv)
3967c732 1063{
bfcb3514 1064 const char *hvname;
b900a521 1065 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
bfcb3514
NC
1066 if (sv && (hvname = HvNAME_get(sv)))
1067 PerlIO_printf(file, "\t\"%s\"\n", hvname);
79072805 1068 else
3967c732
JD
1069 PerlIO_putc(file, '\n');
1070}
1071
1072void
e1ec3a88 1073Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
3967c732 1074{
b900a521 1075 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
3967c732
JD
1076 if (sv && GvNAME(sv))
1077 PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv));
c90c0ff4 1078 else
3967c732
JD
1079 PerlIO_putc(file, '\n');
1080}
1081
1082void
e1ec3a88 1083Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
3967c732 1084{
b900a521 1085 Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
3967c732 1086 if (sv && GvNAME(sv)) {
bfcb3514 1087 const char *hvname;
3967c732 1088 PerlIO_printf(file, "\t\"");
bfcb3514
NC
1089 if (GvSTASH(sv) && (hvname = HvNAME_get(GvSTASH(sv))))
1090 PerlIO_printf(file, "%s\" :: \"", hvname);
3967c732 1091 PerlIO_printf(file, "%s\"\n", GvNAME(sv));
8d063cd8 1092 }
3967c732
JD
1093 else
1094 PerlIO_putc(file, '\n');
1095}
1096
1097void
864dbfa3 1098Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
3967c732 1099{
cea89e20 1100 SV *d;
e1ec3a88 1101 const char *s;
3967c732
JD
1102 U32 flags;
1103 U32 type;
1104
1105 if (!sv) {
cea2e8a9 1106 Perl_dump_indent(aTHX_ level, file, "SV = 0\n");
3967c732 1107 return;
378cc40b 1108 }
2ef28da1 1109
3967c732
JD
1110 flags = SvFLAGS(sv);
1111 type = SvTYPE(sv);
79072805 1112
cea89e20 1113 d = Perl_newSVpvf(aTHX_
57def98f 1114 "(0x%"UVxf") at 0x%"UVxf"\n%*s REFCNT = %"IVdf"\n%*s FLAGS = (",
56431972 1115 PTR2UV(SvANY(sv)), PTR2UV(sv),
894356b3
GS
1116 (int)(PL_dumpindent*level), "", (IV)SvREFCNT(sv),
1117 (int)(PL_dumpindent*level), "");
8d063cd8 1118
d9d18af6 1119 if (flags & SVs_PADSTALE) sv_catpv(d, "PADSTALE,");
3967c732
JD
1120 if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,");
1121 if (flags & SVs_PADMY) sv_catpv(d, "PADMY,");
1122 if (flags & SVs_TEMP) sv_catpv(d, "TEMP,");
1123 if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,");
1124 if (flags & SVs_GMG) sv_catpv(d, "GMG,");
1125 if (flags & SVs_SMG) sv_catpv(d, "SMG,");
1126 if (flags & SVs_RMG) sv_catpv(d, "RMG,");
4db58590 1127
3967c732
JD
1128 if (flags & SVf_IOK) sv_catpv(d, "IOK,");
1129 if (flags & SVf_NOK) sv_catpv(d, "NOK,");
1130 if (flags & SVf_POK) sv_catpv(d, "POK,");
810b8aa5
GS
1131 if (flags & SVf_ROK) {
1132 sv_catpv(d, "ROK,");
1133 if (SvWEAKREF(sv)) sv_catpv(d, "WEAKREF,");
1134 }
3967c732
JD
1135 if (flags & SVf_OOK) sv_catpv(d, "OOK,");
1136 if (flags & SVf_FAKE) sv_catpv(d, "FAKE,");
1137 if (flags & SVf_READONLY) sv_catpv(d, "READONLY,");
4db58590 1138
afce8e55
NC
1139 if (flags & SVf_AMAGIC && type != SVt_PVHV)
1140 sv_catpv(d, "OVERLOAD,");
3967c732
JD
1141 if (flags & SVp_IOK) sv_catpv(d, "pIOK,");
1142 if (flags & SVp_NOK) sv_catpv(d, "pNOK,");
1143 if (flags & SVp_POK) sv_catpv(d, "pPOK,");
9660f481
DM
1144 if (flags & SVp_SCREAM && type != SVt_PVHV)
1145 sv_catpv(d, "SCREAM,");
3967c732
JD
1146
1147 switch (type) {
1148 case SVt_PVCV:
1149 case SVt_PVFM:
1150 if (CvANON(sv)) sv_catpv(d, "ANON,");
1151 if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
1152 if (CvCLONE(sv)) sv_catpv(d, "CLONE,");
1153 if (CvCLONED(sv)) sv_catpv(d, "CLONED,");
de3f1649 1154 if (CvCONST(sv)) sv_catpv(d, "CONST,");
3967c732 1155 if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,");
25da4f38 1156 if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,");
18f7acf9
TJ
1157 if (CvLVALUE(sv)) sv_catpv(d, "LVALUE,");
1158 if (CvMETHOD(sv)) sv_catpv(d, "METHOD,");
662a8415 1159 if (CvLOCKED(sv)) sv_catpv(d, "LOCKED,");
7dafbf52 1160 if (CvWEAKOUTSIDE(sv)) sv_catpv(d, "WEAKOUTSIDE,");
06492da6 1161 if (CvASSERTION(sv)) sv_catpv(d, "ASSERTION,");
3967c732
JD
1162 break;
1163 case SVt_PVHV:
1164 if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,");
1165 if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,");
19692e8d 1166 if (HvHASKFLAGS(sv)) sv_catpv(d, "HASKFLAGS,");
afce8e55 1167 if (HvREHASH(sv)) sv_catpv(d, "REHASH,");
9660f481 1168 if (flags & SVphv_CLONEABLE) sv_catpv(d, "CLONEABLE,");
3967c732 1169 break;
4ce457a6 1170 case SVt_PVGV: case SVt_PVLV:
3967c732
JD
1171 if (GvINTRO(sv)) sv_catpv(d, "INTRO,");
1172 if (GvMULTI(sv)) sv_catpv(d, "MULTI,");
7fb37951 1173 if (GvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
3967c732 1174 if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,");
12c18039 1175 if (GvIN_PAD(sv)) sv_catpv(d, "IN_PAD,");
addd1794 1176 if (flags & SVpad_OUR) sv_catpv(d, "OUR,");
3967c732
JD
1177 if (GvIMPORTED(sv)) {
1178 sv_catpv(d, "IMPORT");
1179 if (GvIMPORTED(sv) == GVf_IMPORTED)
1180 sv_catpv(d, "ALL,");
1181 else {
1182 sv_catpv(d, "(");
1183 if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV");
1184 if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV");
1185 if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV");
1186 if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV");
1187 sv_catpv(d, " ),");
1188 }
1189 }
addd1794 1190 /* FALL THROUGH */
25da4f38
IZ
1191 default:
1192 if (SvEVALED(sv)) sv_catpv(d, "EVALED,");
69c678eb 1193 if (SvIsUV(sv) && !(flags & SVf_ROK)) sv_catpv(d, "IsUV,");
25da4f38 1194 break;
3967c732
JD
1195 case SVt_PVBM:
1196 if (SvTAIL(sv)) sv_catpv(d, "TAIL,");
25da4f38 1197 if (SvVALID(sv)) sv_catpv(d, "VALID,");
3967c732 1198 break;
addd1794
AMS
1199 case SVt_PVMG:
1200 if (flags & SVpad_TYPED)
1201 sv_catpv(d, "TYPED,");
1202 break;
11ca45c0
NC
1203 case SVt_PVAV:
1204 break;
3967c732 1205 }
86f0d186
NC
1206 /* SVphv_SHAREKEYS is also 0x20000000 */
1207 if ((type != SVt_PVHV) && SvUTF8(sv))
9fe74ede 1208 sv_catpv(d, "UTF8");
3967c732 1209
b162af07
SP
1210 if (*(SvEND(d) - 1) == ',') {
1211 SvCUR_set(d, SvCUR(d) - 1);
1212 SvPVX(d)[SvCUR(d)] = '\0';
1213 }
3967c732 1214 sv_catpv(d, ")");
b15aece3 1215 s = SvPVX_const(d);
3967c732 1216
fd0854ff
DM
1217#ifdef DEBUG_LEAKING_SCALARS
1218 Perl_dump_indent(aTHX_ level, file, "ALLOCATED at %s:%d %s %s%s\n",
1219 sv->sv_debug_file ? sv->sv_debug_file : "(unknown)",
1220 sv->sv_debug_line,
1221 sv->sv_debug_inpad ? "for" : "by",
1222 sv->sv_debug_optype ? PL_op_name[sv->sv_debug_optype]: "(none)",
1223 sv->sv_debug_cloned ? " (cloned)" : "");
1224#endif
cea2e8a9 1225 Perl_dump_indent(aTHX_ level, file, "SV = ");
3967c732
JD
1226 switch (type) {
1227 case SVt_NULL:
1228 PerlIO_printf(file, "NULL%s\n", s);
cea89e20 1229 SvREFCNT_dec(d);
3967c732
JD
1230 return;
1231 case SVt_IV:
1232 PerlIO_printf(file, "IV%s\n", s);
1233 break;
1234 case SVt_NV:
1235 PerlIO_printf(file, "NV%s\n", s);
1236 break;
1237 case SVt_RV:
1238 PerlIO_printf(file, "RV%s\n", s);
1239 break;
1240 case SVt_PV:
1241 PerlIO_printf(file, "PV%s\n", s);
1242 break;
1243 case SVt_PVIV:
1244 PerlIO_printf(file, "PVIV%s\n", s);
1245 break;
1246 case SVt_PVNV:
1247 PerlIO_printf(file, "PVNV%s\n", s);
1248 break;
1249 case SVt_PVBM:
1250 PerlIO_printf(file, "PVBM%s\n", s);
1251 break;
1252 case SVt_PVMG:
1253 PerlIO_printf(file, "PVMG%s\n", s);
1254 break;
1255 case SVt_PVLV:
1256 PerlIO_printf(file, "PVLV%s\n", s);
1257 break;
1258 case SVt_PVAV:
1259 PerlIO_printf(file, "PVAV%s\n", s);
1260 break;
1261 case SVt_PVHV:
1262 PerlIO_printf(file, "PVHV%s\n", s);
1263 break;
1264 case SVt_PVCV:
1265 PerlIO_printf(file, "PVCV%s\n", s);
1266 break;
1267 case SVt_PVGV:
1268 PerlIO_printf(file, "PVGV%s\n", s);
1269 break;
1270 case SVt_PVFM:
1271 PerlIO_printf(file, "PVFM%s\n", s);
1272 break;
1273 case SVt_PVIO:
1274 PerlIO_printf(file, "PVIO%s\n", s);
1275 break;
1276 default:
faccc32b 1277 PerlIO_printf(file, "UNKNOWN(0x%"UVxf") %s\n", (UV)type, s);
cea89e20 1278 SvREFCNT_dec(d);
3967c732
JD
1279 return;
1280 }
e4305a63
NC
1281 if ((type >= SVt_PVIV && type != SVt_PVAV && type != SVt_PVHV)
1282 || type == SVt_IV) {
765f542d 1283 if (SvIsUV(sv)
f8c7b90f 1284#ifdef PERL_OLD_COPY_ON_WRITE
765f542d
NC
1285 || SvIsCOW(sv)
1286#endif
1287 )
57def98f 1288 Perl_dump_indent(aTHX_ level, file, " UV = %"UVuf, (UV)SvUVX(sv));
cf2093f6 1289 else
57def98f 1290 Perl_dump_indent(aTHX_ level, file, " IV = %"IVdf, (IV)SvIVX(sv));
3967c732
JD
1291 if (SvOOK(sv))
1292 PerlIO_printf(file, " (OFFSET)");
f8c7b90f 1293#ifdef PERL_OLD_COPY_ON_WRITE
765f542d
NC
1294 if (SvIsCOW_shared_hash(sv))
1295 PerlIO_printf(file, " (HASH)");
1296 else if (SvIsCOW_normal(sv))
1297 PerlIO_printf(file, " (COW from 0x%"UVxf")", (UV)SvUVX(sv));
1298#endif
3967c732
JD
1299 PerlIO_putc(file, '\n');
1300 }
e4305a63
NC
1301 if ((type >= SVt_PVNV && type != SVt_PVAV && type != SVt_PVHV)
1302 || type == SVt_NV) {
e54dc35b 1303 STORE_NUMERIC_LOCAL_SET_STANDARD();
57def98f 1304 /* %Vg doesn't work? --jhi */
cf2093f6 1305#ifdef USE_LONG_DOUBLE
2d4389e4 1306 Perl_dump_indent(aTHX_ level, file, " NV = %.*" PERL_PRIgldbl "\n", LDBL_DIG, SvNVX(sv));
cf2093f6 1307#else
cea2e8a9 1308 Perl_dump_indent(aTHX_ level, file, " NV = %.*g\n", DBL_DIG, SvNVX(sv));
cf2093f6 1309#endif
e54dc35b 1310 RESTORE_NUMERIC_LOCAL();
3967c732
JD
1311 }
1312 if (SvROK(sv)) {
57def98f 1313 Perl_dump_indent(aTHX_ level, file, " RV = 0x%"UVxf"\n", PTR2UV(SvRV(sv)));
3967c732
JD
1314 if (nest < maxnest)
1315 do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim);
3967c732 1316 }
cea89e20
JH
1317 if (type < SVt_PV) {
1318 SvREFCNT_dec(d);
3967c732 1319 return;
cea89e20 1320 }
4ce457a6 1321 if (type <= SVt_PVLV && type != SVt_PVGV) {
b15aece3
SP
1322 if (SvPVX_const(sv)) {
1323 Perl_dump_indent(aTHX_ level, file," PV = 0x%"UVxf" ", PTR2UV(SvPVX_const(sv)));
3967c732 1324 if (SvOOK(sv))
b15aece3
SP
1325 PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX_const(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim));
1326 PerlIO_printf(file, "%s", pv_display(d, SvPVX_const(sv), SvCUR(sv), SvLEN(sv), pvlim));
e6abe6d8 1327 if (SvUTF8(sv)) /* the 8? \x{....} */
c728cb41 1328 PerlIO_printf(file, " [UTF8 \"%s\"]", sv_uni_display(d, sv, 8 * sv_len_utf8(sv), UNI_DISPLAY_QQ));
e6abe6d8 1329 PerlIO_printf(file, "\n");
57def98f
JH
1330 Perl_dump_indent(aTHX_ level, file, " CUR = %"IVdf"\n", (IV)SvCUR(sv));
1331 Perl_dump_indent(aTHX_ level, file, " LEN = %"IVdf"\n", (IV)SvLEN(sv));
3967c732
JD
1332 }
1333 else
cea2e8a9 1334 Perl_dump_indent(aTHX_ level, file, " PV = 0\n");
3967c732
JD
1335 }
1336 if (type >= SVt_PVMG) {
1337 if (SvMAGIC(sv))
1338 do_magic_dump(level, file, SvMAGIC(sv), nest, maxnest, dumpops, pvlim);
1339 if (SvSTASH(sv))
1340 do_hv_dump(level, file, " STASH", SvSTASH(sv));
1341 }
1342 switch (type) {
3967c732 1343 case SVt_PVAV:
57def98f 1344 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(AvARRAY(sv)));
3967c732 1345 if (AvARRAY(sv) != AvALLOC(sv)) {
57def98f
JH
1346 PerlIO_printf(file, " (offset=%"IVdf")\n", (IV)(AvARRAY(sv) - AvALLOC(sv)));
1347 Perl_dump_indent(aTHX_ level, file, " ALLOC = 0x%"UVxf"\n", PTR2UV(AvALLOC(sv)));
3967c732
JD
1348 }
1349 else
1350 PerlIO_putc(file, '\n');
57def98f
JH
1351 Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)AvFILLp(sv));
1352 Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)AvMAX(sv));
a3874608 1353 Perl_dump_indent(aTHX_ level, file, " ARYLEN = 0x%"UVxf"\n", SvMAGIC(sv) ? PTR2UV(AvARYLEN(sv)) : 0);
c69006e4 1354 sv_setpvn(d, "", 0);
11ca45c0
NC
1355 if (AvREAL(sv)) sv_catpv(d, ",REAL");
1356 if (AvREIFY(sv)) sv_catpv(d, ",REIFY");
b15aece3
SP
1357 Perl_dump_indent(aTHX_ level, file, " FLAGS = (%s)\n",
1358 SvCUR(d) ? SvPVX_const(d) + 1 : "");
3967c732
JD
1359 if (nest < maxnest && av_len((AV*)sv) >= 0) {
1360 int count;
1361 for (count = 0; count <= av_len((AV*)sv) && count < maxnest; count++) {
1362 SV** elt = av_fetch((AV*)sv,count,0);
1363
57def98f 1364 Perl_dump_indent(aTHX_ level + 1, file, "Elt No. %"IVdf"\n", (IV)count);
2ef28da1 1365 if (elt)
3967c732
JD
1366 do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim);
1367 }
1368 }
1369 break;
1370 case SVt_PVHV:
57def98f 1371 Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv)));
3967c732
JD
1372 if (HvARRAY(sv) && HvKEYS(sv)) {
1373 /* Show distribution of HEs in the ARRAY */
1374 int freq[200];
1375#define FREQ_MAX (sizeof freq / sizeof freq[0] - 1)
1376 int i;
1377 int max = 0;
1378 U32 pow2 = 2, keys = HvKEYS(sv);
65202027 1379 NV theoret, sum = 0;
3967c732
JD
1380
1381 PerlIO_printf(file, " (");
1382 Zero(freq, FREQ_MAX + 1, int);
eb160463 1383 for (i = 0; (STRLEN)i <= HvMAX(sv); i++) {
3967c732
JD
1384 HE* h; int count = 0;
1385 for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h))
1386 count++;
1387 if (count > FREQ_MAX)
1388 count = FREQ_MAX;
1389 freq[count]++;
1390 if (max < count)
1391 max = count;
1392 }
1393 for (i = 0; i <= max; i++) {
1394 if (freq[i]) {
1395 PerlIO_printf(file, "%d%s:%d", i,
1396 (i == FREQ_MAX) ? "+" : "",
1397 freq[i]);
1398 if (i != max)
1399 PerlIO_printf(file, ", ");
1400 }
1401 }
1402 PerlIO_putc(file, ')');
b8fa94d8
MG
1403 /* The "quality" of a hash is defined as the total number of
1404 comparisons needed to access every element once, relative
1405 to the expected number needed for a random hash.
1406
1407 The total number of comparisons is equal to the sum of
e76cd0fa
AMS
1408 the squares of the number of entries in each bucket.
1409 For a random hash of n keys into k buckets, the expected
b8fa94d8
MG
1410 value is
1411 n + n(n-1)/2k
1412 */
1413
3967c732
JD
1414 for (i = max; i > 0; i--) { /* Precision: count down. */
1415 sum += freq[i] * i * i;
1416 }
155aba94 1417 while ((keys = keys >> 1))
3967c732 1418 pow2 = pow2 << 1;
3967c732 1419 theoret = HvKEYS(sv);
b8fa94d8 1420 theoret += theoret * (theoret-1)/pow2;
3967c732 1421 PerlIO_putc(file, '\n');
6b4667fc 1422 Perl_dump_indent(aTHX_ level, file, " hash quality = %.1"NVff"%%", theoret/sum*100);
3967c732
JD
1423 }
1424 PerlIO_putc(file, '\n');
57def98f
JH
1425 Perl_dump_indent(aTHX_ level, file, " KEYS = %"IVdf"\n", (IV)HvKEYS(sv));
1426 Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)HvFILL(sv));
1427 Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)HvMAX(sv));
bfcb3514
NC
1428 Perl_dump_indent(aTHX_ level, file, " RITER = %"IVdf"\n", (IV)HvRITER_get(sv));
1429 Perl_dump_indent(aTHX_ level, file, " EITER = 0x%"UVxf"\n", PTR2UV(HvEITER_get(sv)));
8d2f4536
NC
1430 {
1431 MAGIC *mg = mg_find(sv, PERL_MAGIC_symtab);
1432 if (mg && mg->mg_obj) {
1433 Perl_dump_indent(aTHX_ level, file, " PMROOT = 0x%"UVxf"\n", PTR2UV(mg->mg_obj));
1434 }
1435 }
bfcb3514
NC
1436 {
1437 const char *hvname = HvNAME_get(sv);
1438 if (hvname)
1439 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", hvname);
1440 }
1441 if (nest < maxnest && !HvEITER_get(sv)) { /* Try to preserve iterator */
3967c732
JD
1442 HE *he;
1443 HV *hv = (HV*)sv;
1444 int count = maxnest - nest;
1445
1446 hv_iterinit(hv);
e16e2ff8
NC
1447 while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS))
1448 && count--) {
98c991d1 1449 SV *elt, *keysv;
e1ec3a88 1450 const char *keypv;
98c991d1 1451 STRLEN len;
3967c732
JD
1452 U32 hash = HeHASH(he);
1453
98c991d1 1454 keysv = hv_iterkeysv(he);
93524f2b 1455 keypv = SvPV_const(keysv, len);
3967c732 1456 elt = hv_iterval(hv, he);
98c991d1
JH
1457 Perl_dump_indent(aTHX_ level+1, file, "Elt %s ", pv_display(d, keypv, len, 0, pvlim));
1458 if (SvUTF8(keysv))
c728cb41 1459 PerlIO_printf(file, "[UTF8 \"%s\"] ", sv_uni_display(d, keysv, 8 * sv_len_utf8(keysv), UNI_DISPLAY_QQ));
afce8e55
NC
1460 if (HeKREHASH(he))
1461 PerlIO_printf(file, "[REHASH] ");
98c991d1 1462 PerlIO_printf(file, "HASH = 0x%"UVxf"\n", (UV)hash);
3967c732
JD
1463 do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim);
1464 }
1465 hv_iterinit(hv); /* Return to status quo */
1466 }
1467 break;
1468 case SVt_PVCV:
1469 if (SvPOK(sv))
93524f2b 1470 Perl_dump_indent(aTHX_ level, file, " PROTOTYPE = \"%s\"\n", SvPV_nolen_const(sv));
3967c732
JD
1471 /* FALL THROUGH */
1472 case SVt_PVFM:
1473 do_hv_dump(level, file, " COMP_STASH", CvSTASH(sv));
1474 if (CvSTART(sv))
0bd48802 1475 Perl_dump_indent(aTHX_ level, file, " START = 0x%"UVxf" ===> %"IVdf"\n", PTR2UV(CvSTART(sv)), (IV)sequence_num(CvSTART(sv)));
57def98f 1476 Perl_dump_indent(aTHX_ level, file, " ROOT = 0x%"UVxf"\n", PTR2UV(CvROOT(sv)));
3967c732
JD
1477 if (CvROOT(sv) && dumpops)
1478 do_op_dump(level+1, file, CvROOT(sv));
57def98f
JH
1479 Perl_dump_indent(aTHX_ level, file, " XSUB = 0x%"UVxf"\n", PTR2UV(CvXSUB(sv)));
1480 Perl_dump_indent(aTHX_ level, file, " XSUBANY = %"IVdf"\n", (IV)CvXSUBANY(sv).any_i32);
3967c732 1481 do_gvgv_dump(level, file, " GVGV::GV", CvGV(sv));
57843af0 1482 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", CvFILE(sv));
57def98f 1483 Perl_dump_indent(aTHX_ level, file, " DEPTH = %"IVdf"\n", (IV)CvDEPTH(sv));
894356b3 1484 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)CvFLAGS(sv));
a3985cdc 1485 Perl_dump_indent(aTHX_ level, file, " OUTSIDE_SEQ = %"UVuf"\n", (UV)CvOUTSIDE_SEQ(sv));
3967c732 1486 if (type == SVt_PVFM)
57def98f
JH
1487 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)FmLINES(sv));
1488 Perl_dump_indent(aTHX_ level, file, " PADLIST = 0x%"UVxf"\n", PTR2UV(CvPADLIST(sv)));
dd2155a4
DM
1489 if (nest < maxnest) {
1490 do_dump_pad(level+1, file, CvPADLIST(sv), 0);
3967c732
JD
1491 }
1492 {
e1ec3a88 1493 const CV *outside = CvOUTSIDE(sv);
2ef28da1 1494 Perl_dump_indent(aTHX_ level, file, " OUTSIDE = 0x%"UVxf" (%s)\n",
57def98f 1495 PTR2UV(outside),
cf2093f6
JH
1496 (!outside ? "null"
1497 : CvANON(outside) ? "ANON"
1498 : (outside == PL_main_cv) ? "MAIN"
1499 : CvUNIQUE(outside) ? "UNIQUE"
1500 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
3967c732
JD
1501 }
1502 if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv)))
1503 do_sv_dump(level+1, file, (SV*)CvOUTSIDE(sv), nest+1, maxnest, dumpops, pvlim);
1504 break;
4ce457a6
TP
1505 case SVt_PVGV: case SVt_PVLV:
1506 if (type == SVt_PVLV) {
1507 Perl_dump_indent(aTHX_ level, file, " TYPE = %c\n", LvTYPE(sv));
1508 Perl_dump_indent(aTHX_ level, file, " TARGOFF = %"IVdf"\n", (IV)LvTARGOFF(sv));
1509 Perl_dump_indent(aTHX_ level, file, " TARGLEN = %"IVdf"\n", (IV)LvTARGLEN(sv));
1510 Perl_dump_indent(aTHX_ level, file, " TARG = 0x%"UVxf"\n", PTR2UV(LvTARG(sv)));
1511 if (LvTYPE(sv) != 't' && LvTYPE(sv) != 'T')
1512 do_sv_dump(level+1, file, LvTARG(sv), nest+1, maxnest,
1513 dumpops, pvlim);
1514 }
cea2e8a9 1515 Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", GvNAME(sv));
57def98f 1516 Perl_dump_indent(aTHX_ level, file, " NAMELEN = %"IVdf"\n", (IV)GvNAMELEN(sv));
3967c732 1517 do_hv_dump (level, file, " GvSTASH", GvSTASH(sv));
57def98f 1518 Perl_dump_indent(aTHX_ level, file, " GP = 0x%"UVxf"\n", PTR2UV(GvGP(sv)));
f472eb5c
GS
1519 if (!GvGP(sv))
1520 break;
57def98f
JH
1521 Perl_dump_indent(aTHX_ level, file, " SV = 0x%"UVxf"\n", PTR2UV(GvSV(sv)));
1522 Perl_dump_indent(aTHX_ level, file, " REFCNT = %"IVdf"\n", (IV)GvREFCNT(sv));
1523 Perl_dump_indent(aTHX_ level, file, " IO = 0x%"UVxf"\n", PTR2UV(GvIOp(sv)));
1524 Perl_dump_indent(aTHX_ level, file, " FORM = 0x%"UVxf" \n", PTR2UV(GvFORM(sv)));
1525 Perl_dump_indent(aTHX_ level, file, " AV = 0x%"UVxf"\n", PTR2UV(GvAV(sv)));
1526 Perl_dump_indent(aTHX_ level, file, " HV = 0x%"UVxf"\n", PTR2UV(GvHV(sv)));
1527 Perl_dump_indent(aTHX_ level, file, " CV = 0x%"UVxf"\n", PTR2UV(GvCV(sv)));
1528 Perl_dump_indent(aTHX_ level, file, " CVGEN = 0x%"UVxf"\n", (UV)GvCVGEN(sv));
57def98f 1529 Perl_dump_indent(aTHX_ level, file, " LINE = %"IVdf"\n", (IV)GvLINE(sv));
b195d487 1530 Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", GvFILE(sv));
e39917cc 1531 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)GvFLAGS(sv));
3967c732
JD
1532 do_gv_dump (level, file, " EGV", GvEGV(sv));
1533 break;
1534 case SVt_PVIO:
57def98f
JH
1535 Perl_dump_indent(aTHX_ level, file, " IFP = 0x%"UVxf"\n", PTR2UV(IoIFP(sv)));
1536 Perl_dump_indent(aTHX_ level, file, " OFP = 0x%"UVxf"\n", PTR2UV(IoOFP(sv)));
1537 Perl_dump_indent(aTHX_ level, file, " DIRP = 0x%"UVxf"\n", PTR2UV(IoDIRP(sv)));
1538 Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)IoLINES(sv));
1539 Perl_dump_indent(aTHX_ level, file, " PAGE = %"IVdf"\n", (IV)IoPAGE(sv));
1540 Perl_dump_indent(aTHX_ level, file, " PAGE_LEN = %"IVdf"\n", (IV)IoPAGE_LEN(sv));
1541 Perl_dump_indent(aTHX_ level, file, " LINES_LEFT = %"IVdf"\n", (IV)IoLINES_LEFT(sv));
27533608 1542 if (IoTOP_NAME(sv))
cea2e8a9 1543 Perl_dump_indent(aTHX_ level, file, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
3967c732 1544 do_gv_dump (level, file, " TOP_GV", IoTOP_GV(sv));
27533608 1545 if (IoFMT_NAME(sv))
cea2e8a9 1546 Perl_dump_indent(aTHX_ level, file, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
3967c732 1547 do_gv_dump (level, file, " FMT_GV", IoFMT_GV(sv));
27533608 1548 if (IoBOTTOM_NAME(sv))
cea2e8a9 1549 Perl_dump_indent(aTHX_ level, file, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
3967c732 1550 do_gv_dump (level, file, " BOTTOM_GV", IoBOTTOM_GV(sv));
57def98f 1551 Perl_dump_indent(aTHX_ level, file, " SUBPROCESS = %"IVdf"\n", (IV)IoSUBPROCESS(sv));
27533608 1552 if (isPRINT(IoTYPE(sv)))
cea2e8a9 1553 Perl_dump_indent(aTHX_ level, file, " TYPE = '%c'\n", IoTYPE(sv));
27533608 1554 else
cea2e8a9 1555 Perl_dump_indent(aTHX_ level, file, " TYPE = '\\%o'\n", IoTYPE(sv));
57def98f 1556 Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)IoFLAGS(sv));
3967c732
JD
1557 break;
1558 }
cea89e20 1559 SvREFCNT_dec(d);
3967c732
JD
1560}
1561
1562void
864dbfa3 1563Perl_sv_dump(pTHX_ SV *sv)
3967c732
JD
1564{
1565 do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0);
8d063cd8 1566}
bd16a5f0
IZ
1567
1568int
1569Perl_runops_debug(pTHX)
1570{
1571 if (!PL_op) {
1572 if (ckWARN_d(WARN_DEBUGGING))
9014280d 1573 Perl_warner(aTHX_ packWARN(WARN_DEBUGGING), "NULL OP IN RUN");
bd16a5f0
IZ
1574 return 0;
1575 }
1576
9f3673fb 1577 DEBUG_l(Perl_deb(aTHX_ "Entering new RUNOPS level\n"));
bd16a5f0
IZ
1578 do {
1579 PERL_ASYNC_CHECK();
1580 if (PL_debug) {
1581 if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok)
1582 PerlIO_printf(Perl_debug_log,
1583 "WARNING: %"UVxf" changed from %"UVxf" to %"UVxf"\n",
1584 PTR2UV(PL_watchaddr), PTR2UV(PL_watchok),
1585 PTR2UV(*PL_watchaddr));
d6721266
DM
1586 if (DEBUG_s_TEST_) {
1587 if (DEBUG_v_TEST_) {
1588 PerlIO_printf(Perl_debug_log, "\n");
1589 deb_stack_all();
1590 }
1591 else
1592 debstack();
1593 }
1594
1595
bd16a5f0
IZ
1596 if (DEBUG_t_TEST_) debop(PL_op);
1597 if (DEBUG_P_TEST_) debprof(PL_op);
1598 }
1599 } while ((PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX)));
9f3673fb 1600 DEBUG_l(Perl_deb(aTHX_ "leaving RUNOPS level\n"));
bd16a5f0
IZ
1601
1602 TAINT_NOT;
1603 return 0;
1604}
1605
1606I32
6867be6d 1607Perl_debop(pTHX_ const OP *o)
bd16a5f0 1608{
1045810a
IZ
1609 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
1610 return 0;
1611
bd16a5f0
IZ
1612 Perl_deb(aTHX_ "%s", OP_NAME(o));
1613 switch (o->op_type) {
1614 case OP_CONST:
1615 PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo_sv));
1616 break;
1617 case OP_GVSV:
1618 case OP_GV:
1619 if (cGVOPo_gv) {
a3b680e6 1620 SV *sv = NEWSV(0,0);
bd16a5f0 1621 gv_fullname3(sv, cGVOPo_gv, Nullch);
93524f2b 1622 PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv));
bd16a5f0
IZ
1623 SvREFCNT_dec(sv);
1624 }
1625 else
1626 PerlIO_printf(Perl_debug_log, "(NULL)");
1627 break;
1628 case OP_PADSV:
1629 case OP_PADAV:
1630 case OP_PADHV:
a3b680e6 1631 {
bd16a5f0 1632 /* print the lexical's name */
a3b680e6
AL
1633 CV *cv = deb_curcv(cxstack_ix);
1634 SV *sv;
bd16a5f0 1635 if (cv) {
b464bac0
AL
1636 AV * const padlist = CvPADLIST(cv);
1637 AV * const comppad = (AV*)(*av_fetch(padlist, 0, FALSE));
bd16a5f0
IZ
1638 sv = *av_fetch(comppad, o->op_targ, FALSE);
1639 } else
1640 sv = Nullsv;
1641 if (sv)
93524f2b 1642 PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv));
bd16a5f0
IZ
1643 else
1644 PerlIO_printf(Perl_debug_log, "[%"UVuf"]", (UV)o->op_targ);
a3b680e6 1645 }
bd16a5f0
IZ
1646 break;
1647 default:
091ab601 1648 break;
bd16a5f0
IZ
1649 }
1650 PerlIO_printf(Perl_debug_log, "\n");
1651 return 0;
1652}
1653
1654STATIC CV*
1655S_deb_curcv(pTHX_ I32 ix)
1656{
e1ec3a88 1657 const PERL_CONTEXT *cx = &cxstack[ix];
bd16a5f0
IZ
1658 if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT)
1659 return cx->blk_sub.cv;
1660 else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx))
1661 return PL_compcv;
1662 else if (ix == 0 && PL_curstackinfo->si_type == PERLSI_MAIN)
1663 return PL_main_cv;
1664 else if (ix <= 0)
1665 return Nullcv;
1666 else
1667 return deb_curcv(ix - 1);
1668}
1669
1670void
1671Perl_watch(pTHX_ char **addr)
1672{
1673 PL_watchaddr = addr;
1674 PL_watchok = *addr;
1675 PerlIO_printf(Perl_debug_log, "WATCHING, %"UVxf" is currently %"UVxf"\n",
1676 PTR2UV(PL_watchaddr), PTR2UV(PL_watchok));
1677}
1678
1679STATIC void
e1ec3a88 1680S_debprof(pTHX_ const OP *o)
bd16a5f0 1681{
1045810a
IZ
1682 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
1683 return;
bd16a5f0 1684 if (!PL_profiledata)
a02a5408 1685 Newxz(PL_profiledata, MAXO, U32);
bd16a5f0
IZ
1686 ++PL_profiledata[o->op_type];
1687}
1688
1689void
1690Perl_debprofdump(pTHX)
1691{
1692 unsigned i;
1693 if (!PL_profiledata)
1694 return;
1695 for (i = 0; i < MAXO; i++) {
1696 if (PL_profiledata[i])
1697 PerlIO_printf(Perl_debug_log,
1698 "%5lu %s\n", (unsigned long)PL_profiledata[i],
1699 PL_op_name[i]);
1700 }
1701}
66610fdd
RGS
1702
1703/*
1704 * Local variables:
1705 * c-indentation-style: bsd
1706 * c-basic-offset: 4
1707 * indent-tabs-mode: t
1708 * End:
1709 *
37442d52
RGS
1710 * ex: set ts=8 sts=4 sw=4 noet:
1711 */