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