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