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