This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
missed a file
[perl5.git] / dump.c
CommitLineData
a0d0e21e 1/* dump.c
a687059c 2 *
4eb8286e 3 * Copyright (c) 1991-1999, Larry Wall
a687059c 4 *
6e21c824
LW
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
8d063cd8 7 *
a0d0e21e
LW
8 */
9
10/*
11 * "'You have talked long in your sleep, Frodo,' said Gandalf gently, 'and
12 * it has not been hard for me to read your mind and memory.'"
8d063cd8
LW
13 */
14
8d063cd8 15#include "EXTERN.h"
864dbfa3 16#define PERL_IN_DUMP_C
8d063cd8
LW
17#include "perl.h"
18
3967c732
JD
19#ifndef DBL_DIG
20#define DBL_DIG 15 /* A guess that works lots of places */
21#endif
22
23void
864dbfa3 24Perl_dump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
3967c732
JD
25{
26 dTHR;
27 va_list args;
28
29 va_start(args, pat);
30 PerlIO_printf(file, "%*s", level*PL_dumpindent, "");
31 PerlIO_vprintf(file, pat, args);
32 va_end(args);
33}
8adcabd8
LW
34
35void
864dbfa3 36Perl_dump_all(pTHX)
79072805 37{
11343788 38 dTHR;
760ac839 39 PerlIO_setlinebuf(Perl_debug_log);
3280af22 40 if (PL_main_root)
3967c732 41 op_dump(PL_main_root);
3280af22 42 dump_packsubs(PL_defstash);
463ee0b2
LW
43}
44
45void
864dbfa3 46Perl_dump_packsubs(pTHX_ HV *stash)
463ee0b2 47{
11343788 48 dTHR;
a0d0e21e 49 I32 i;
463ee0b2
LW
50 HE *entry;
51
8990e307
LW
52 if (!HvARRAY(stash))
53 return;
a0d0e21e 54 for (i = 0; i <= (I32) HvMAX(stash); i++) {
4db58590
PP
55 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
56 GV *gv = (GV*)HeVAL(entry);
463ee0b2 57 HV *hv;
e29cdcb3
GS
58 if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
59 continue;
8ebc5c01 60 if (GvCVu(gv))
463ee0b2 61 dump_sub(gv);
85e6fe83
LW
62 if (GvFORM(gv))
63 dump_form(gv);
4db58590 64 if (HeKEY(entry)[HeKLEN(entry)-1] == ':' &&
3280af22 65 (hv = GvHV(gv)) && HvNAME(hv) && hv != PL_defstash)
463ee0b2
LW
66 dump_packsubs(hv); /* nested package */
67 }
79072805
LW
68 }
69}
70
71void
864dbfa3 72Perl_dump_sub(pTHX_ GV *gv)
a687059c 73{
8990e307 74 SV *sv = sv_newmortal();
85e6fe83 75
f6aff53a 76 gv_fullname3(sv, gv, Nullch);
3967c732 77 dump_indent(0, Perl_debug_log, "\nSUB %s = ", SvPVX(sv));
a0d0e21e 78 if (CvXSUB(GvCV(gv)))
3967c732 79 dump_indent(0, Perl_debug_log, "(xsub 0x%x %d)\n",
a0d0e21e
LW
80 (long)CvXSUB(GvCV(gv)),
81 CvXSUBANY(GvCV(gv)).any_i32);
85e6fe83 82 else if (CvROOT(GvCV(gv)))
3967c732 83 op_dump(CvROOT(GvCV(gv)));
85e6fe83 84 else
3967c732 85 dump_indent(0, Perl_debug_log, "<undef>\n");
85e6fe83
LW
86}
87
88void
864dbfa3 89Perl_dump_form(pTHX_ GV *gv)
85e6fe83
LW
90{
91 SV *sv = sv_newmortal();
92
f6aff53a 93 gv_fullname3(sv, gv, Nullch);
3967c732 94 dump_indent(0, Perl_debug_log, "\nFORMAT %s = ", SvPVX(sv));
85e6fe83 95 if (CvROOT(GvFORM(gv)))
3967c732 96 op_dump(CvROOT(GvFORM(gv)));
85e6fe83 97 else
3967c732 98 dump_indent(0, Perl_debug_log, "<undef>\n");
a687059c
LW
99}
100
8adcabd8 101void
864dbfa3 102Perl_dump_eval(pTHX)
8d063cd8 103{
3967c732
JD
104 op_dump(PL_eval_root);
105}
106
107char *
864dbfa3 108Perl_pv_display(pTHX_ SV *sv, char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
3967c732
JD
109{
110 int truncated = 0;
111 int nul_terminated = len > cur && pv[cur] == '\0';
112
113 sv_setpvn(sv, "\"", 1);
114 for (; cur--; pv++) {
115 if (pvlim && SvCUR(sv) >= pvlim) {
116 truncated++;
117 break;
118 }
119 if (isPRINT(*pv)) {
120 switch (*pv) {
121 case '\t': sv_catpvn(sv, "\\t", 2); break;
122 case '\n': sv_catpvn(sv, "\\n", 2); break;
123 case '\r': sv_catpvn(sv, "\\r", 2); break;
124 case '\f': sv_catpvn(sv, "\\f", 2); break;
125 case '"': sv_catpvn(sv, "\\\"", 2); break;
126 case '\\': sv_catpvn(sv, "\\\\", 2); break;
127 default: sv_catpvn(sv, pv, 1); break;
128 }
129 }
130 else {
131 if (cur && isDIGIT(*(pv+1)))
132 sv_catpvf(sv, "\\%03o", *pv);
133 else
134 sv_catpvf(sv, "\\%o", *pv);
135 }
136 }
137 sv_catpvn(sv, "\"", 1);
138 if (truncated)
139 sv_catpvn(sv, "...", 3);
140 if (nul_terminated)
141 sv_catpvn(sv, "\\0", 2);
142
143 return SvPVX(sv);
144}
145
146char *
864dbfa3 147Perl_sv_peek(pTHX_ SV *sv)
3967c732
JD
148{
149 SV *t = sv_newmortal();
2d8e6c8d 150 STRLEN n_a;
3967c732
JD
151 int unref = 0;
152
153 sv_setpvn(t, "", 0);
154 retry:
155 if (!sv) {
156 sv_catpv(t, "VOID");
157 goto finish;
158 }
159 else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') {
160 sv_catpv(t, "WILD");
161 goto finish;
162 }
163 else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes) {
164 if (sv == &PL_sv_undef) {
165 sv_catpv(t, "SV_UNDEF");
166 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
167 SVs_GMG|SVs_SMG|SVs_RMG)) &&
168 SvREADONLY(sv))
169 goto finish;
170 }
171 else if (sv == &PL_sv_no) {
172 sv_catpv(t, "SV_NO");
173 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
174 SVs_GMG|SVs_SMG|SVs_RMG)) &&
175 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
176 SVp_POK|SVp_NOK)) &&
177 SvCUR(sv) == 0 &&
178 SvNVX(sv) == 0.0)
179 goto finish;
180 }
181 else {
182 sv_catpv(t, "SV_YES");
183 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
184 SVs_GMG|SVs_SMG|SVs_RMG)) &&
185 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
186 SVp_POK|SVp_NOK)) &&
187 SvCUR(sv) == 1 &&
188 SvPVX(sv) && *SvPVX(sv) == '1' &&
189 SvNVX(sv) == 1.0)
190 goto finish;
191 }
192 sv_catpv(t, ":");
193 }
194 else if (SvREFCNT(sv) == 0) {
195 sv_catpv(t, "(");
196 unref++;
197 }
198 if (SvROK(sv)) {
199 sv_catpv(t, "\\");
200 if (SvCUR(t) + unref > 10) {
201 SvCUR(t) = unref + 3;
202 *SvEND(t) = '\0';
203 sv_catpv(t, "...");
204 goto finish;
205 }
206 sv = (SV*)SvRV(sv);
207 goto retry;
208 }
209 switch (SvTYPE(sv)) {
210 default:
211 sv_catpv(t, "FREED");
212 goto finish;
213
214 case SVt_NULL:
215 sv_catpv(t, "UNDEF");
216 goto finish;
217 case SVt_IV:
218 sv_catpv(t, "IV");
219 break;
220 case SVt_NV:
221 sv_catpv(t, "NV");
222 break;
223 case SVt_RV:
224 sv_catpv(t, "RV");
225 break;
226 case SVt_PV:
227 sv_catpv(t, "PV");
228 break;
229 case SVt_PVIV:
230 sv_catpv(t, "PVIV");
231 break;
232 case SVt_PVNV:
233 sv_catpv(t, "PVNV");
234 break;
235 case SVt_PVMG:
236 sv_catpv(t, "PVMG");
237 break;
238 case SVt_PVLV:
239 sv_catpv(t, "PVLV");
240 break;
241 case SVt_PVAV:
242 sv_catpv(t, "AV");
243 break;
244 case SVt_PVHV:
245 sv_catpv(t, "HV");
246 break;
247 case SVt_PVCV:
248 if (CvGV(sv))
249 sv_catpvf(t, "CV(%s)", GvNAME(CvGV(sv)));
250 else
251 sv_catpv(t, "CV()");
252 goto finish;
253 case SVt_PVGV:
254 sv_catpv(t, "GV");
255 break;
256 case SVt_PVBM:
257 sv_catpv(t, "BM");
258 break;
259 case SVt_PVFM:
260 sv_catpv(t, "FM");
261 break;
262 case SVt_PVIO:
263 sv_catpv(t, "IO");
264 break;
265 }
266
267 if (SvPOKp(sv)) {
268 if (!SvPVX(sv))
269 sv_catpv(t, "(null)");
270 else {
79cb57f6 271 SV *tmp = newSVpvn("", 0);
3967c732
JD
272 sv_catpv(t, "(");
273 if (SvOOK(sv))
274 sv_catpvf(t, "[%s]", pv_display(tmp, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, 127));
275 sv_catpvf(t, "%s)", pv_display(tmp, SvPVX(sv), SvCUR(sv), SvLEN(sv), 127));
276 SvREFCNT_dec(tmp);
277 }
278 }
279 else if (SvNOKp(sv)) {
280 SET_NUMERIC_STANDARD();
281 sv_catpvf(t, "(%g)",SvNVX(sv));
282 }
25da4f38
IZ
283 else if (SvIOKp(sv)) { /* XXXX: IV, UV? */
284 if (SvIsUV(sv))
285 sv_catpvf(t, "(%lu)",(unsigned long)SvUVX(sv));
286 else
287 sv_catpvf(t, "(%ld)",(long)SvIVX(sv));
288 }
3967c732
JD
289 else
290 sv_catpv(t, "()");
291
292 finish:
293 if (unref) {
294 while (unref--)
295 sv_catpv(t, ")");
296 }
2d8e6c8d 297 return SvPV(t, n_a);
3967c732
JD
298}
299
300void
864dbfa3 301Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, PMOP *pm)
3967c732
JD
302{
303 char ch;
304
305 if (!pm) {
306 dump_indent(level, file, "{}\n");
307 return;
308 }
309 dump_indent(level, file, "{\n");
310 level++;
311 if (pm->op_pmflags & PMf_ONCE)
312 ch = '?';
313 else
314 ch = '/';
315 if (pm->op_pmregexp)
316 dump_indent(level, file, "PMf_PRE %c%s%c%s\n",
317 ch, pm->op_pmregexp->precomp, ch,
318 (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
319 else
320 dump_indent(level, file, "PMf_PRE (RUNTIME)\n");
321 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
322 dump_indent(level, file, "PMf_REPL = ");
323 op_dump(pm->op_pmreplroot);
324 }
325 if (pm->op_pmflags || (pm->op_pmregexp && pm->op_pmregexp->check_substr)) {
79cb57f6 326 SV *tmpsv = newSVpvn("", 0);
3967c732
JD
327 if (pm->op_pmdynflags & PMdf_USED)
328 sv_catpv(tmpsv, ",USED");
329 if (pm->op_pmdynflags & PMdf_TAINTED)
330 sv_catpv(tmpsv, ",TAINTED");
331 if (pm->op_pmflags & PMf_ONCE)
332 sv_catpv(tmpsv, ",ONCE");
333 if (pm->op_pmregexp && pm->op_pmregexp->check_substr
334 && !(pm->op_pmregexp->reganch & ROPT_NOSCAN))
335 sv_catpv(tmpsv, ",SCANFIRST");
336 if (pm->op_pmregexp && pm->op_pmregexp->check_substr
337 && pm->op_pmregexp->reganch & ROPT_CHECK_ALL)
338 sv_catpv(tmpsv, ",ALL");
339 if (pm->op_pmflags & PMf_SKIPWHITE)
340 sv_catpv(tmpsv, ",SKIPWHITE");
341 if (pm->op_pmflags & PMf_CONST)
342 sv_catpv(tmpsv, ",CONST");
343 if (pm->op_pmflags & PMf_KEEP)
344 sv_catpv(tmpsv, ",KEEP");
345 if (pm->op_pmflags & PMf_GLOBAL)
346 sv_catpv(tmpsv, ",GLOBAL");
347 if (pm->op_pmflags & PMf_CONTINUE)
348 sv_catpv(tmpsv, ",CONTINUE");
349 if (pm->op_pmflags & PMf_RETAINT)
350 sv_catpv(tmpsv, ",RETAINT");
351 if (pm->op_pmflags & PMf_EVAL)
352 sv_catpv(tmpsv, ",EVAL");
353 dump_indent(level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
354 SvREFCNT_dec(tmpsv);
355 }
356
357 dump_indent(level-1, file, "}\n");
358}
359
360void
864dbfa3 361Perl_pmop_dump(pTHX_ PMOP *pm)
3967c732
JD
362{
363 do_pmop_dump(0, Perl_debug_log, pm);
79072805
LW
364}
365
366void
864dbfa3 367Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, OP *o)
79072805 368{
3967c732 369 dTHR;
2d8e6c8d 370 STRLEN n_a;
3967c732
JD
371 dump_indent(level, file, "{\n");
372 level++;
11343788 373 if (o->op_seq)
3967c732 374 PerlIO_printf(file, "%-4d", o->op_seq);
93a17b20 375 else
3967c732
JD
376 PerlIO_printf(file, " ");
377 PerlIO_printf(file, "%*sTYPE = %s ===> ", PL_dumpindent*level-4, "", PL_op_name[o->op_type]);
11343788
MB
378 if (o->op_next) {
379 if (o->op_seq)
3967c732 380 PerlIO_printf(file, "%d\n", o->op_next->op_seq);
93a17b20 381 else
3967c732 382 PerlIO_printf(file, "(%d)\n", o->op_next->op_seq);
93a17b20 383 }
79072805 384 else
3967c732 385 PerlIO_printf(file, "DONE\n");
11343788
MB
386 if (o->op_targ) {
387 if (o->op_type == OP_NULL)
3967c732 388 dump_indent(level, file, " (was %s)\n", PL_op_name[o->op_targ]);
8990e307 389 else
3967c732 390 dump_indent(level, file, "TARG = %d\n", o->op_targ);
8990e307 391 }
748a9306 392#ifdef DUMPADDR
3967c732 393 dump_indent(level, file, "ADDR = 0x%lx => 0x%lx\n",o, o->op_next);
79072805 394#endif
11343788 395 if (o->op_flags) {
79cb57f6 396 SV *tmpsv = newSVpvn("", 0);
5dc0d613 397 switch (o->op_flags & OPf_WANT) {
54310121 398 case OPf_WANT_VOID:
46fc3d4c 399 sv_catpv(tmpsv, ",VOID");
54310121
PP
400 break;
401 case OPf_WANT_SCALAR:
46fc3d4c 402 sv_catpv(tmpsv, ",SCALAR");
54310121
PP
403 break;
404 case OPf_WANT_LIST:
46fc3d4c 405 sv_catpv(tmpsv, ",LIST");
54310121
PP
406 break;
407 default:
46fc3d4c 408 sv_catpv(tmpsv, ",UNKNOWN");
54310121
PP
409 break;
410 }
11343788 411 if (o->op_flags & OPf_KIDS)
46fc3d4c 412 sv_catpv(tmpsv, ",KIDS");
11343788 413 if (o->op_flags & OPf_PARENS)
46fc3d4c 414 sv_catpv(tmpsv, ",PARENS");
11343788 415 if (o->op_flags & OPf_STACKED)
46fc3d4c 416 sv_catpv(tmpsv, ",STACKED");
11343788 417 if (o->op_flags & OPf_REF)
46fc3d4c 418 sv_catpv(tmpsv, ",REF");
11343788 419 if (o->op_flags & OPf_MOD)
46fc3d4c 420 sv_catpv(tmpsv, ",MOD");
11343788 421 if (o->op_flags & OPf_SPECIAL)
46fc3d4c 422 sv_catpv(tmpsv, ",SPECIAL");
3967c732 423 dump_indent(level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
46fc3d4c 424 SvREFCNT_dec(tmpsv);
79072805 425 }
11343788 426 if (o->op_private) {
79cb57f6 427 SV *tmpsv = newSVpvn("", 0);
11343788
MB
428 if (o->op_type == OP_AASSIGN) {
429 if (o->op_private & OPpASSIGN_COMMON)
46fc3d4c 430 sv_catpv(tmpsv, ",COMMON");
8d063cd8 431 }
11343788
MB
432 else if (o->op_type == OP_SASSIGN) {
433 if (o->op_private & OPpASSIGN_BACKWARDS)
46fc3d4c 434 sv_catpv(tmpsv, ",BACKWARDS");
a0d0e21e 435 }
11343788
MB
436 else if (o->op_type == OP_TRANS) {
437 if (o->op_private & OPpTRANS_SQUASH)
46fc3d4c 438 sv_catpv(tmpsv, ",SQUASH");
11343788 439 if (o->op_private & OPpTRANS_DELETE)
46fc3d4c 440 sv_catpv(tmpsv, ",DELETE");
11343788 441 if (o->op_private & OPpTRANS_COMPLEMENT)
46fc3d4c 442 sv_catpv(tmpsv, ",COMPLEMENT");
8d063cd8 443 }
11343788
MB
444 else if (o->op_type == OP_REPEAT) {
445 if (o->op_private & OPpREPEAT_DOLIST)
46fc3d4c 446 sv_catpv(tmpsv, ",DOLIST");
8d063cd8 447 }
11343788
MB
448 else if (o->op_type == OP_ENTERSUB ||
449 o->op_type == OP_RV2SV ||
450 o->op_type == OP_RV2AV ||
451 o->op_type == OP_RV2HV ||
452 o->op_type == OP_RV2GV ||
453 o->op_type == OP_AELEM ||
454 o->op_type == OP_HELEM )
85e6fe83 455 {
5dc0d613
MB
456 if (o->op_type == OP_ENTERSUB) {
457 if (o->op_private & OPpENTERSUB_AMPER)
46fc3d4c 458 sv_catpv(tmpsv, ",AMPER");
5dc0d613 459 if (o->op_private & OPpENTERSUB_DB)
46fc3d4c 460 sv_catpv(tmpsv, ",DB");
68dc0745 461 }
5dc0d613 462 switch (o->op_private & OPpDEREF) {
5f05dabc 463 case OPpDEREF_SV:
46fc3d4c 464 sv_catpv(tmpsv, ",SV");
5f05dabc
PP
465 break;
466 case OPpDEREF_AV:
46fc3d4c 467 sv_catpv(tmpsv, ",AV");
5f05dabc
PP
468 break;
469 case OPpDEREF_HV:
46fc3d4c 470 sv_catpv(tmpsv, ",HV");
5f05dabc
PP
471 break;
472 }
5dc0d613
MB
473 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
474 if (o->op_private & OPpLVAL_DEFER)
46fc3d4c 475 sv_catpv(tmpsv, ",LVAL_DEFER");
68dc0745
PP
476 }
477 else {
5dc0d613 478 if (o->op_private & HINT_STRICT_REFS)
46fc3d4c 479 sv_catpv(tmpsv, ",STRICT_REFS");
68dc0745 480 }
8d063cd8 481 }
11343788
MB
482 else if (o->op_type == OP_CONST) {
483 if (o->op_private & OPpCONST_BARE)
46fc3d4c 484 sv_catpv(tmpsv, ",BARE");
7a52d87a
GS
485 if (o->op_private & OPpCONST_STRICT)
486 sv_catpv(tmpsv, ",STRICT");
79072805 487 }
11343788
MB
488 else if (o->op_type == OP_FLIP) {
489 if (o->op_private & OPpFLIP_LINENUM)
46fc3d4c 490 sv_catpv(tmpsv, ",LINENUM");
79072805 491 }
11343788
MB
492 else if (o->op_type == OP_FLOP) {
493 if (o->op_private & OPpFLIP_LINENUM)
46fc3d4c 494 sv_catpv(tmpsv, ",LINENUM");
79072805 495 }
11343788 496 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
46fc3d4c
PP
497 sv_catpv(tmpsv, ",INTRO");
498 if (SvCUR(tmpsv))
3967c732 499 dump_indent(level, file, "PRIVATE = (%s)\n", SvPVX(tmpsv) + 1);
46fc3d4c 500 SvREFCNT_dec(tmpsv);
8d063cd8 501 }
8d063cd8 502
11343788 503 switch (o->op_type) {
93a17b20 504 case OP_GVSV:
79072805 505 case OP_GV:
11343788 506 if (cGVOPo->op_gv) {
46fc3d4c 507 SV *tmpsv = NEWSV(0,0);
8990e307 508 ENTER;
8990e307 509 SAVEFREESV(tmpsv);
5dc0d613 510 gv_fullname3(tmpsv, cGVOPo->op_gv, Nullch);
2d8e6c8d 511 dump_indent(level, file, "GV = %s\n", SvPV(tmpsv, n_a));
8990e307 512 LEAVE;
378cc40b 513 }
79072805 514 else
3967c732 515 dump_indent(level, file, "GV = NULL\n");
79072805
LW
516 break;
517 case OP_CONST:
3967c732 518 dump_indent(level, file, "SV = %s\n", SvPEEK(cSVOPo->op_sv));
79072805 519 break;
93a17b20
LW
520 case OP_NEXTSTATE:
521 case OP_DBSTATE:
11343788 522 if (cCOPo->cop_line)
3967c732 523 dump_indent(level, file, "LINE = %d\n",cCOPo->cop_line);
11343788 524 if (cCOPo->cop_label)
3967c732 525 dump_indent(level, file, "LABEL = \"%s\"\n",cCOPo->cop_label);
79072805
LW
526 break;
527 case OP_ENTERLOOP:
3967c732 528 dump_indent(level, file, "REDO ===> ");
11343788 529 if (cLOOPo->op_redoop)
3967c732 530 PerlIO_printf(file, "%d\n", cLOOPo->op_redoop->op_seq);
79072805 531 else
3967c732
JD
532 PerlIO_printf(file, "DONE\n");
533 dump_indent(level, file, "NEXT ===> ");
11343788 534 if (cLOOPo->op_nextop)
3967c732 535 PerlIO_printf(file, "%d\n", cLOOPo->op_nextop->op_seq);
79072805 536 else
3967c732
JD
537 PerlIO_printf(file, "DONE\n");
538 dump_indent(level, file, "LAST ===> ");
11343788 539 if (cLOOPo->op_lastop)
3967c732 540 PerlIO_printf(file, "%d\n", cLOOPo->op_lastop->op_seq);
79072805 541 else
3967c732 542 PerlIO_printf(file, "DONE\n");
79072805
LW
543 break;
544 case OP_COND_EXPR:
3967c732 545 dump_indent(level, file, "TRUE ===> ");
11343788 546 if (cCONDOPo->op_true)
3967c732 547 PerlIO_printf(file, "%d\n", cCONDOPo->op_true->op_seq);
79072805 548 else
3967c732
JD
549 PerlIO_printf(file, "DONE\n");
550 dump_indent(level, file, "FALSE ===> ");
11343788 551 if (cCONDOPo->op_false)
3967c732 552 PerlIO_printf(file, "%d\n", cCONDOPo->op_false->op_seq);
79072805 553 else
3967c732 554 PerlIO_printf(file, "DONE\n");
79072805 555 break;
a0d0e21e 556 case OP_MAPWHILE:
79072805
LW
557 case OP_GREPWHILE:
558 case OP_OR:
559 case OP_AND:
3967c732 560 dump_indent(level, file, "OTHER ===> ");
11343788 561 if (cLOGOPo->op_other)
3967c732 562 PerlIO_printf(file, "%d\n", cLOGOPo->op_other->op_seq);
79072805 563 else
3967c732 564 PerlIO_printf(file, "DONE\n");
79072805
LW
565 break;
566 case OP_PUSHRE:
567 case OP_MATCH:
8782bef2 568 case OP_QR:
79072805 569 case OP_SUBST:
3967c732 570 do_pmop_dump(level, file, cPMOPo);
79072805 571 break;
a0d0e21e
LW
572 default:
573 break;
79072805 574 }
11343788 575 if (o->op_flags & OPf_KIDS) {
79072805 576 OP *kid;
11343788 577 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
3967c732 578 do_op_dump(level, file, kid);
8d063cd8 579 }
3967c732
JD
580 dump_indent(level-1, file, "}\n");
581}
582
583void
864dbfa3 584Perl_op_dump(pTHX_ OP *o)
3967c732
JD
585{
586 do_op_dump(0, Perl_debug_log, o);
8d063cd8
LW
587}
588
8adcabd8 589void
864dbfa3 590Perl_gv_dump(pTHX_ GV *gv)
378cc40b 591{
79072805 592 SV *sv;
378cc40b 593
79072805 594 if (!gv) {
760ac839 595 PerlIO_printf(Perl_debug_log, "{}\n");
378cc40b
LW
596 return;
597 }
8990e307 598 sv = sv_newmortal();
760ac839 599 PerlIO_printf(Perl_debug_log, "{\n");
f6aff53a 600 gv_fullname3(sv, gv, Nullch);
3967c732 601 dump_indent(1, Perl_debug_log, "GV_NAME = %s", SvPVX(sv));
79072805 602 if (gv != GvEGV(gv)) {
f6aff53a 603 gv_efullname3(sv, GvEGV(gv), Nullch);
3967c732 604 dump_indent(1, Perl_debug_log, "-> %s", SvPVX(sv));
8adcabd8 605 }
3967c732
JD
606 PerlIO_putc(Perl_debug_log, '\n');
607 dump_indent(0, Perl_debug_log, "}\n");
8d063cd8
LW
608}
609
8adcabd8 610void
864dbfa3 611Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
8d063cd8 612{
3967c732
JD
613 for (; mg; mg = mg->mg_moremagic) {
614 dump_indent(level, file, " MAGIC = 0x%lx\n", (long)mg);
615 if (mg->mg_virtual) {
616 MGVTBL *v = mg->mg_virtual;
617 char *s = 0;
618 if (v == &PL_vtbl_sv) s = "sv";
619 else if (v == &PL_vtbl_env) s = "env";
620 else if (v == &PL_vtbl_envelem) s = "envelem";
621 else if (v == &PL_vtbl_sig) s = "sig";
622 else if (v == &PL_vtbl_sigelem) s = "sigelem";
623 else if (v == &PL_vtbl_pack) s = "pack";
624 else if (v == &PL_vtbl_packelem) s = "packelem";
625 else if (v == &PL_vtbl_dbline) s = "dbline";
626 else if (v == &PL_vtbl_isa) s = "isa";
627 else if (v == &PL_vtbl_arylen) s = "arylen";
628 else if (v == &PL_vtbl_glob) s = "glob";
629 else if (v == &PL_vtbl_mglob) s = "mglob";
630 else if (v == &PL_vtbl_nkeys) s = "nkeys";
631 else if (v == &PL_vtbl_taint) s = "taint";
632 else if (v == &PL_vtbl_substr) s = "substr";
633 else if (v == &PL_vtbl_vec) s = "vec";
634 else if (v == &PL_vtbl_pos) s = "pos";
635 else if (v == &PL_vtbl_bm) s = "bm";
636 else if (v == &PL_vtbl_fm) s = "fm";
637 else if (v == &PL_vtbl_uvar) s = "uvar";
638 else if (v == &PL_vtbl_defelem) s = "defelem";
639#ifdef USE_LOCALE_COLLATE
640 else if (v == &PL_vtbl_collxfrm) s = "collxfrm";
641#endif
3967c732
JD
642 else if (v == &PL_vtbl_amagic) s = "amagic";
643 else if (v == &PL_vtbl_amagicelem) s = "amagicelem";
810b8aa5 644 else if (v == &PL_vtbl_backref) s = "backref";
3967c732
JD
645 if (s)
646 dump_indent(level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", s);
647 else
648 dump_indent(level, file, " MG_VIRTUAL = 0x%lx\n", (long)v);
649 }
650 else
651 dump_indent(level, file, " MG_VIRTUAL = 0\n");
8d063cd8 652
3967c732
JD
653 if (mg->mg_private)
654 dump_indent(level, file, " MG_PRIVATE = %d\n", mg->mg_private);
655
656 if (isPRINT(mg->mg_type))
657 dump_indent(level, file, " MG_TYPE = '%c'\n", mg->mg_type);
658 else
659 dump_indent(level, file, " MG_TYPE = '\\%o'\n", mg->mg_type);
660
661 if (mg->mg_flags) {
662 dump_indent(level, file, " MG_FLAGS = 0x%02X\n", mg->mg_flags);
663 if (mg->mg_flags & MGf_TAINTEDDIR)
664 dump_indent(level, file, " TAINTEDDIR\n");
665 if (mg->mg_flags & MGf_REFCOUNTED)
666 dump_indent(level, file, " REFCOUNTED\n");
667 if (mg->mg_flags & MGf_GSKIP)
668 dump_indent(level, file, " GSKIP\n");
669 if (mg->mg_flags & MGf_MINMATCH)
670 dump_indent(level, file, " MINMATCH\n");
671 }
672 if (mg->mg_obj) {
673 dump_indent(level, file, " MG_OBJ = 0x%lx\n", (long)mg->mg_obj);
674 if (mg->mg_flags & MGf_REFCOUNTED)
675 do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
676 }
677 if (mg->mg_len)
678 dump_indent(level, file, " MG_LEN = %d\n", mg->mg_len);
679 if (mg->mg_ptr) {
680 dump_indent(level, file, " MG_PTR = 0x%lx", (long)mg->mg_ptr);
681 if (mg->mg_len >= 0) {
79cb57f6 682 SV *sv = newSVpvn("", 0);
3967c732
JD
683 PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim));
684 SvREFCNT_dec(sv);
685 }
686 else if (mg->mg_len == HEf_SVKEY) {
687 PerlIO_puts(file, " => HEf_SVKEY\n");
688 do_sv_dump(level+2, file, (SV*)((mg)->mg_ptr), nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */
689 continue;
690 }
691 else
692 PerlIO_puts(file, " ???? - please notify IZ");
693 PerlIO_putc(file, '\n');
694 }
378cc40b 695 }
3967c732
JD
696}
697
698void
864dbfa3 699Perl_magic_dump(pTHX_ MAGIC *mg)
3967c732
JD
700{
701 do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0);
702}
703
704void
864dbfa3 705Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, char *name, HV *sv)
3967c732
JD
706{
707 dump_indent(level, file, "%s = 0x%lx", name, (long)sv);
708 if (sv && HvNAME(sv))
709 PerlIO_printf(file, "\t\"%s\"\n", HvNAME(sv));
79072805 710 else
3967c732
JD
711 PerlIO_putc(file, '\n');
712}
713
714void
864dbfa3 715Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv)
3967c732
JD
716{
717 dump_indent(level, file, "%s = 0x%lx", name, (long)sv);
718 if (sv && GvNAME(sv))
719 PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv));
c90c0ff4 720 else
3967c732
JD
721 PerlIO_putc(file, '\n');
722}
723
724void
864dbfa3 725Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, char *name, GV *sv)
3967c732
JD
726{
727 dump_indent(level, file, "%s = 0x%lx", name, (long)sv);
728 if (sv && GvNAME(sv)) {
729 PerlIO_printf(file, "\t\"");
730 if (GvSTASH(sv) && HvNAME(GvSTASH(sv)))
731 PerlIO_printf(file, "%s\" :: \"", HvNAME(GvSTASH(sv)));
732 PerlIO_printf(file, "%s\"\n", GvNAME(sv));
8d063cd8 733 }
3967c732
JD
734 else
735 PerlIO_putc(file, '\n');
736}
737
738void
864dbfa3 739Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
3967c732
JD
740{
741 dTHR;
742 SV *d = sv_newmortal();
743 char *s;
744 U32 flags;
745 U32 type;
2d8e6c8d 746 STRLEN n_a;
3967c732
JD
747
748 if (!sv) {
749 dump_indent(level, file, "SV = 0\n");
750 return;
378cc40b 751 }
3967c732
JD
752
753 flags = SvFLAGS(sv);
754 type = SvTYPE(sv);
79072805 755
3967c732
JD
756 sv_setpvf(d, "(0x%lx) at 0x%lx\n%*s REFCNT = %ld\n%*s FLAGS = (",
757 (unsigned long)SvANY(sv), (unsigned long)sv,
758 PL_dumpindent*level, "", (long)SvREFCNT(sv),
759 PL_dumpindent*level, "");
8d063cd8 760
3967c732
JD
761 if (flags & SVs_PADBUSY) sv_catpv(d, "PADBUSY,");
762 if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,");
763 if (flags & SVs_PADMY) sv_catpv(d, "PADMY,");
764 if (flags & SVs_TEMP) sv_catpv(d, "TEMP,");
765 if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,");
766 if (flags & SVs_GMG) sv_catpv(d, "GMG,");
767 if (flags & SVs_SMG) sv_catpv(d, "SMG,");
768 if (flags & SVs_RMG) sv_catpv(d, "RMG,");
4db58590 769
3967c732
JD
770 if (flags & SVf_IOK) sv_catpv(d, "IOK,");
771 if (flags & SVf_NOK) sv_catpv(d, "NOK,");
772 if (flags & SVf_POK) sv_catpv(d, "POK,");
810b8aa5
GS
773 if (flags & SVf_ROK) {
774 sv_catpv(d, "ROK,");
775 if (SvWEAKREF(sv)) sv_catpv(d, "WEAKREF,");
776 }
3967c732
JD
777 if (flags & SVf_OOK) sv_catpv(d, "OOK,");
778 if (flags & SVf_FAKE) sv_catpv(d, "FAKE,");
779 if (flags & SVf_READONLY) sv_catpv(d, "READONLY,");
4db58590 780
3967c732 781 if (flags & SVf_AMAGIC) sv_catpv(d, "OVERLOAD,");
3967c732
JD
782 if (flags & SVp_IOK) sv_catpv(d, "pIOK,");
783 if (flags & SVp_NOK) sv_catpv(d, "pNOK,");
784 if (flags & SVp_POK) sv_catpv(d, "pPOK,");
785 if (flags & SVp_SCREAM) sv_catpv(d, "SCREAM,");
786
787 switch (type) {
788 case SVt_PVCV:
789 case SVt_PVFM:
790 if (CvANON(sv)) sv_catpv(d, "ANON,");
791 if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
792 if (CvCLONE(sv)) sv_catpv(d, "CLONE,");
793 if (CvCLONED(sv)) sv_catpv(d, "CLONED,");
794 if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,");
25da4f38 795 if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,");
3967c732
JD
796 break;
797 case SVt_PVHV:
798 if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,");
799 if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,");
800 break;
801 case SVt_PVGV:
802 if (GvINTRO(sv)) sv_catpv(d, "INTRO,");
803 if (GvMULTI(sv)) sv_catpv(d, "MULTI,");
804 if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,");
805 if (GvIMPORTED(sv)) {
806 sv_catpv(d, "IMPORT");
807 if (GvIMPORTED(sv) == GVf_IMPORTED)
808 sv_catpv(d, "ALL,");
809 else {
810 sv_catpv(d, "(");
811 if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV");
812 if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV");
813 if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV");
814 if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV");
815 sv_catpv(d, " ),");
816 }
817 }
25da4f38
IZ
818 /* FALL THROGH */
819 default:
820 if (SvEVALED(sv)) sv_catpv(d, "EVALED,");
821 if (SvIsUV(sv)) sv_catpv(d, "IsUV,");
822 break;
3967c732
JD
823 case SVt_PVBM:
824 if (SvTAIL(sv)) sv_catpv(d, "TAIL,");
25da4f38 825 if (SvVALID(sv)) sv_catpv(d, "VALID,");
3967c732
JD
826 break;
827 }
828
829 if (*(SvEND(d) - 1) == ',')
830 SvPVX(d)[--SvCUR(d)] = '\0';
831 sv_catpv(d, ")");
832 s = SvPVX(d);
833
834 dump_indent(level, file, "SV = ");
835 switch (type) {
836 case SVt_NULL:
837 PerlIO_printf(file, "NULL%s\n", s);
838 return;
839 case SVt_IV:
840 PerlIO_printf(file, "IV%s\n", s);
841 break;
842 case SVt_NV:
843 PerlIO_printf(file, "NV%s\n", s);
844 break;
845 case SVt_RV:
846 PerlIO_printf(file, "RV%s\n", s);
847 break;
848 case SVt_PV:
849 PerlIO_printf(file, "PV%s\n", s);
850 break;
851 case SVt_PVIV:
852 PerlIO_printf(file, "PVIV%s\n", s);
853 break;
854 case SVt_PVNV:
855 PerlIO_printf(file, "PVNV%s\n", s);
856 break;
857 case SVt_PVBM:
858 PerlIO_printf(file, "PVBM%s\n", s);
859 break;
860 case SVt_PVMG:
861 PerlIO_printf(file, "PVMG%s\n", s);
862 break;
863 case SVt_PVLV:
864 PerlIO_printf(file, "PVLV%s\n", s);
865 break;
866 case SVt_PVAV:
867 PerlIO_printf(file, "PVAV%s\n", s);
868 break;
869 case SVt_PVHV:
870 PerlIO_printf(file, "PVHV%s\n", s);
871 break;
872 case SVt_PVCV:
873 PerlIO_printf(file, "PVCV%s\n", s);
874 break;
875 case SVt_PVGV:
876 PerlIO_printf(file, "PVGV%s\n", s);
877 break;
878 case SVt_PVFM:
879 PerlIO_printf(file, "PVFM%s\n", s);
880 break;
881 case SVt_PVIO:
882 PerlIO_printf(file, "PVIO%s\n", s);
883 break;
884 default:
885 PerlIO_printf(file, "UNKNOWN(0x%x) %s\n", type, s);
886 return;
887 }
888 if (type >= SVt_PVIV || type == SVt_IV) {
25da4f38
IZ
889 if (SvIsUV(sv))
890 dump_indent(level, file, " UV = %lu", (unsigned long)SvUVX(sv));
891 else
892 dump_indent(level, file, " IV = %ld", (long)SvIVX(sv));
3967c732
JD
893 if (SvOOK(sv))
894 PerlIO_printf(file, " (OFFSET)");
895 PerlIO_putc(file, '\n');
896 }
897 if (type >= SVt_PVNV || type == SVt_NV) {
898 SET_NUMERIC_STANDARD();
899 dump_indent(level, file, " NV = %.*g\n", DBL_DIG, SvNVX(sv));
900 }
901 if (SvROK(sv)) {
902 dump_indent(level, file, " RV = 0x%lx\n", (long)SvRV(sv));
903 if (nest < maxnest)
904 do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim);
905 return;
906 }
907 if (type < SVt_PV)
908 return;
909 if (type <= SVt_PVLV) {
910 if (SvPVX(sv)) {
911 dump_indent(level, file," PV = 0x%lx ", (long)SvPVX(sv));
912 if (SvOOK(sv))
913 PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim));
914 PerlIO_printf(file, "%s\n", pv_display(d, SvPVX(sv), SvCUR(sv), SvLEN(sv), pvlim));
52a3d2a9
JD
915 dump_indent(level, file, " CUR = %ld\n", (long)SvCUR(sv));
916 dump_indent(level, file, " LEN = %ld\n", (long)SvLEN(sv));
3967c732
JD
917 }
918 else
919 dump_indent(level, file, " PV = 0\n");
920 }
921 if (type >= SVt_PVMG) {
922 if (SvMAGIC(sv))
923 do_magic_dump(level, file, SvMAGIC(sv), nest, maxnest, dumpops, pvlim);
924 if (SvSTASH(sv))
925 do_hv_dump(level, file, " STASH", SvSTASH(sv));
926 }
927 switch (type) {
928 case SVt_PVLV:
929 dump_indent(level, file, " TYPE = %c\n", LvTYPE(sv));
930 dump_indent(level, file, " TARGOFF = %ld\n", (long)LvTARGOFF(sv));
931 dump_indent(level, file, " TARGLEN = %ld\n", (long)LvTARGLEN(sv));
932 dump_indent(level, file, " TARG = 0x%lx\n", (long)LvTARG(sv));
933 /* XXX level+1 ??? */
934 do_sv_dump(level, file, LvTARG(sv), nest+1, maxnest, dumpops, pvlim);
935 break;
936 case SVt_PVAV:
937 dump_indent(level, file, " ARRAY = 0x%lx", (long)AvARRAY(sv));
938 if (AvARRAY(sv) != AvALLOC(sv)) {
939 PerlIO_printf(file, " (offset=%d)\n", (AvARRAY(sv) - AvALLOC(sv)));
940 dump_indent(level, file, " ALLOC = 0x%lx\n", (long)AvALLOC(sv));
941 }
942 else
943 PerlIO_putc(file, '\n');
944 dump_indent(level, file, " FILL = %ld\n", (long)AvFILLp(sv));
945 dump_indent(level, file, " MAX = %ld\n", (long)AvMAX(sv));
946 dump_indent(level, file, " ARYLEN = 0x%lx\n", (long)AvARYLEN(sv));
947 flags = AvFLAGS(sv);
948 sv_setpv(d, "");
949 if (flags & AVf_REAL) sv_catpv(d, ",REAL");
950 if (flags & AVf_REIFY) sv_catpv(d, ",REIFY");
951 if (flags & AVf_REUSED) sv_catpv(d, ",REUSED");
952 dump_indent(level, file, " FLAGS = (%s)\n", SvCUR(d) ? SvPVX(d) + 1 : "");
953 if (nest < maxnest && av_len((AV*)sv) >= 0) {
954 int count;
955 for (count = 0; count <= av_len((AV*)sv) && count < maxnest; count++) {
956 SV** elt = av_fetch((AV*)sv,count,0);
957
958 dump_indent(level + 1, file, "Elt No. %ld\n", (long)count);
959 if (elt)
960 do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim);
961 }
962 }
963 break;
964 case SVt_PVHV:
965 dump_indent(level, file, " ARRAY = 0x%lx",(long)HvARRAY(sv));
966 if (HvARRAY(sv) && HvKEYS(sv)) {
967 /* Show distribution of HEs in the ARRAY */
968 int freq[200];
969#define FREQ_MAX (sizeof freq / sizeof freq[0] - 1)
970 int i;
971 int max = 0;
972 U32 pow2 = 2, keys = HvKEYS(sv);
973 double theoret, sum = 0;
974
975 PerlIO_printf(file, " (");
976 Zero(freq, FREQ_MAX + 1, int);
977 for (i = 0; i <= HvMAX(sv); i++) {
978 HE* h; int count = 0;
979 for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h))
980 count++;
981 if (count > FREQ_MAX)
982 count = FREQ_MAX;
983 freq[count]++;
984 if (max < count)
985 max = count;
986 }
987 for (i = 0; i <= max; i++) {
988 if (freq[i]) {
989 PerlIO_printf(file, "%d%s:%d", i,
990 (i == FREQ_MAX) ? "+" : "",
991 freq[i]);
992 if (i != max)
993 PerlIO_printf(file, ", ");
994 }
995 }
996 PerlIO_putc(file, ')');
997 /* Now calculate quality wrt theoretical value */
998 for (i = max; i > 0; i--) { /* Precision: count down. */
999 sum += freq[i] * i * i;
1000 }
1001 while (keys = keys >> 1)
1002 pow2 = pow2 << 1;
1003 /* Approximate by Poisson distribution */
1004 theoret = HvKEYS(sv);
1005 theoret += theoret * theoret/pow2;
1006 PerlIO_putc(file, '\n');
1007 dump_indent(level, file, " hash quality = %.1f%%", theoret/sum*100);
1008 }
1009 PerlIO_putc(file, '\n');
1010 dump_indent(level, file, " KEYS = %ld\n", (long)HvKEYS(sv));
1011 dump_indent(level, file, " FILL = %ld\n", (long)HvFILL(sv));
1012 dump_indent(level, file, " MAX = %ld\n", (long)HvMAX(sv));
1013 dump_indent(level, file, " RITER = %ld\n", (long)HvRITER(sv));
1014 dump_indent(level, file, " EITER = 0x%lx\n",(long) HvEITER(sv));
1015 if (HvPMROOT(sv))
1016 dump_indent(level, file, " PMROOT = 0x%lx\n",(long)HvPMROOT(sv));
1017 if (HvNAME(sv))
1018 dump_indent(level, file, " NAME = \"%s\"\n", HvNAME(sv));
1019 if (nest < maxnest && !HvEITER(sv)) { /* Try to preserve iterator */
1020 HE *he;
1021 HV *hv = (HV*)sv;
1022 int count = maxnest - nest;
1023
1024 hv_iterinit(hv);
1025 while ((he = hv_iternext(hv)) && count--) {
1026 SV *elt;
1027 char *key;
1028 I32 len;
1029 U32 hash = HeHASH(he);
1030
1031 key = hv_iterkey(he, &len);
1032 elt = hv_iterval(hv, he);
1033 dump_indent(level+1, file, "Elt %s HASH = 0x%lx\n", pv_display(d, key, len, 0, pvlim), hash);
1034 do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim);
1035 }
1036 hv_iterinit(hv); /* Return to status quo */
1037 }
1038 break;
1039 case SVt_PVCV:
1040 if (SvPOK(sv))
2d8e6c8d 1041 dump_indent(level, file, " PROTOTYPE = \"%s\"\n", SvPV(sv,n_a));
3967c732
JD
1042 /* FALL THROUGH */
1043 case SVt_PVFM:
1044 do_hv_dump(level, file, " COMP_STASH", CvSTASH(sv));
1045 if (CvSTART(sv))
1046 dump_indent(level, file, " START = 0x%lx ===> %d\n", (long)CvSTART(sv), CvSTART(sv)->op_seq);
1047 dump_indent(level, file, " ROOT = 0x%lx\n", (long)CvROOT(sv));
1048 if (CvROOT(sv) && dumpops)
1049 do_op_dump(level+1, file, CvROOT(sv));
1050 dump_indent (level, file, " XSUB = 0x%lx\n", (long)CvXSUB(sv));
1051 dump_indent (level, file, " XSUBANY = %ld\n", (long)CvXSUBANY(sv).any_i32);
1052 do_gvgv_dump(level, file, " GVGV::GV", CvGV(sv));
1053 do_gv_dump (level, file, " FILEGV", CvFILEGV(sv));
1054 dump_indent (level, file, " DEPTH = %ld\n", (long)CvDEPTH(sv));
1055#ifdef USE_THREADS
1056 dump_indent (level, file, " MUTEXP = 0x%lx\n", (long)CvMUTEXP(sv));
1057 dump_indent (level, file, " OWNER = 0x%lx\n", (long)CvOWNER(sv));
1058#endif /* USE_THREADS */
1059 dump_indent (level, file, " FLAGS = 0x%lx\n", (unsigned long)CvFLAGS(sv));
1060 if (type == SVt_PVFM)
1061 dump_indent(level, file, " LINES = %ld\n", (long)FmLINES(sv));
1062 dump_indent(level, file, " PADLIST = 0x%lx\n", (long)CvPADLIST(sv));
1063 if (nest < maxnest && CvPADLIST(sv)) {
1064 AV* padlist = CvPADLIST(sv);
1065 AV* pad_name = (AV*)*av_fetch(padlist, 0, FALSE);
1066 AV* pad = (AV*)*av_fetch(padlist, 1, FALSE);
1067 SV** pname = AvARRAY(pad_name);
1068 SV** ppad = AvARRAY(pad);
1069 I32 ix;
1070
1071 for (ix = 1; ix <= AvFILL(pad_name); ix++) {
1072 if (SvPOK(pname[ix]))
1073 dump_indent(level, /* %5d below is enough whitespace. */
1074 file,
1075 "%5d. 0x%lx (%s\"%s\" %ld-%ld)\n",
1076 ix, ppad[ix],
1077 SvFAKE(pname[ix]) ? "FAKE " : "",
1078 SvPVX(pname[ix]),
1079 (long)I_32(SvNVX(pname[ix])),
1080 (long)SvIVX(pname[ix]));
1081 }
1082 }
1083 {
1084 CV *outside = CvOUTSIDE(sv);
1085 dump_indent(level, file, " OUTSIDE = 0x%lx (%s)\n",
1086 (long)outside,
1087 (!outside ? "null"
1088 : CvANON(outside) ? "ANON"
1089 : (outside == PL_main_cv) ? "MAIN"
1090 : CvUNIQUE(outside) ? "UNIQUE"
1091 : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
1092 }
1093 if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv)))
1094 do_sv_dump(level+1, file, (SV*)CvOUTSIDE(sv), nest+1, maxnest, dumpops, pvlim);
1095 break;
1096 case SVt_PVGV:
1097 dump_indent(level, file, " NAME = \"%s\"\n", GvNAME(sv));
1098 dump_indent(level, file, " NAMELEN = %ld\n", (long)GvNAMELEN(sv));
1099 do_hv_dump (level, file, " GvSTASH", GvSTASH(sv));
1100 dump_indent(level, file, " GP = 0x%lx\n", (long)GvGP(sv));
1101 dump_indent(level, file, " SV = 0x%lx\n", (long)GvSV(sv));
1102 dump_indent(level, file, " REFCNT = %ld\n", (long)GvREFCNT(sv));
1103 dump_indent(level, file, " IO = 0x%lx\n", (long)GvIOp(sv));
1104 dump_indent(level, file, " FORM = 0x%lx\n", (long)GvFORM(sv));
1105 dump_indent(level, file, " AV = 0x%lx\n", (long)GvAV(sv));
1106 dump_indent(level, file, " HV = 0x%lx\n", (long)GvHV(sv));
1107 dump_indent(level, file, " CV = 0x%lx\n", (long)GvCV(sv));
1108 dump_indent(level, file, " CVGEN = 0x%lx\n", (long)GvCVGEN(sv));
1109 dump_indent(level, file, " LASTEXPR = %ld\n", (long)GvLASTEXPR(sv));
1110 dump_indent(level, file, " LINE = %ld\n", (long)GvLINE(sv));
1111 dump_indent(level, file, " FLAGS = 0x%x\n", (int)GvFLAGS(sv));
1112 do_gv_dump (level, file, " FILEGV", GvFILEGV(sv));
1113 do_gv_dump (level, file, " EGV", GvEGV(sv));
1114 break;
1115 case SVt_PVIO:
1116 dump_indent(level, file, " IFP = 0x%lx\n", (long)IoIFP(sv));
1117 dump_indent(level, file, " OFP = 0x%lx\n", (long)IoOFP(sv));
1118 dump_indent(level, file, " DIRP = 0x%lx\n", (long)IoDIRP(sv));
1119 dump_indent(level, file, " LINES = %ld\n", (long)IoLINES(sv));
1120 dump_indent(level, file, " PAGE = %ld\n", (long)IoPAGE(sv));
1121 dump_indent(level, file, " PAGE_LEN = %ld\n", (long)IoPAGE_LEN(sv));
1122 dump_indent(level, file, " LINES_LEFT = %ld\n", (long)IoLINES_LEFT(sv));
27533608
AD
1123 if (IoTOP_NAME(sv))
1124 dump_indent(level, file, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
3967c732 1125 do_gv_dump (level, file, " TOP_GV", IoTOP_GV(sv));
27533608
AD
1126 if (IoFMT_NAME(sv))
1127 dump_indent(level, file, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
3967c732 1128 do_gv_dump (level, file, " FMT_GV", IoFMT_GV(sv));
27533608
AD
1129 if (IoBOTTOM_NAME(sv))
1130 dump_indent(level, file, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
3967c732
JD
1131 do_gv_dump (level, file, " BOTTOM_GV", IoBOTTOM_GV(sv));
1132 dump_indent(level, file, " SUBPROCESS = %ld\n", (long)IoSUBPROCESS(sv));
27533608
AD
1133 if (isPRINT(IoTYPE(sv)))
1134 dump_indent(level, file, " TYPE = '%c'\n", IoTYPE(sv));
1135 else
1136 dump_indent(level, file, " TYPE = '\\%o'\n", IoTYPE(sv));
3967c732
JD
1137 dump_indent(level, file, " FLAGS = 0x%lx\n", (long)IoFLAGS(sv));
1138 break;
1139 }
1140}
1141
1142void
864dbfa3 1143Perl_sv_dump(pTHX_ SV *sv)
3967c732
JD
1144{
1145 do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0);
8d063cd8 1146}