3 * Copyright (c) 1991-1997, Larry Wall
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.
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.'"
23 #else /* Rest of file is for DEBUGGING */
26 static void dump(char *pat, ...);
34 PerlIO_setlinebuf(Perl_debug_log);
37 dump_packsubs(defstash);
49 for (i = 0; i <= (I32) HvMAX(stash); i++) {
50 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
51 GV *gv = (GV*)HeVAL(entry);
57 if (HeKEY(entry)[HeKLEN(entry)-1] == ':' &&
58 (hv = GvHV(gv)) && HvNAME(hv) && hv != defstash)
59 dump_packsubs(hv); /* nested package */
68 SV *sv = sv_newmortal();
70 gv_fullname3(sv, gv, Nullch);
71 dump("\nSUB %s = ", SvPVX(sv));
73 dump("(xsub 0x%x %d)\n",
74 (long)CvXSUB(GvCV(gv)),
75 CvXSUBANY(GvCV(gv)).any_i32);
76 else if (CvROOT(GvCV(gv)))
77 dump_op(CvROOT(GvCV(gv)));
86 SV *sv = sv_newmortal();
88 gv_fullname3(sv, gv, Nullch);
89 dump("\nFORMAT %s = ", SvPVX(sv));
90 if (CvROOT(GvFORM(gv)))
91 dump_op(CvROOT(GvFORM(gv)));
108 PerlIO_printf(Perl_debug_log, "%-4d", op->op_seq);
110 PerlIO_printf(Perl_debug_log, " ");
111 dump("TYPE = %s ===> ", op_name[op->op_type]);
114 PerlIO_printf(Perl_debug_log, "%d\n", op->op_next->op_seq);
116 PerlIO_printf(Perl_debug_log, "(%d)\n", op->op_next->op_seq);
119 PerlIO_printf(Perl_debug_log, "DONE\n");
122 if (op->op_type == OP_NULL)
123 dump(" (was %s)\n", op_name[op->op_targ]);
125 dump("TARG = %d\n", op->op_targ);
128 dump("ADDR = 0x%lx => 0x%lx\n",op, op->op_next);
131 SV *tmpsv = newSVpv("", 0);
132 switch (op->op_flags & OPf_WANT) {
134 sv_catpv(tmpsv, ",VOID");
136 case OPf_WANT_SCALAR:
137 sv_catpv(tmpsv, ",SCALAR");
140 sv_catpv(tmpsv, ",LIST");
143 sv_catpv(tmpsv, ",UNKNOWN");
146 if (op->op_flags & OPf_KIDS)
147 sv_catpv(tmpsv, ",KIDS");
148 if (op->op_flags & OPf_PARENS)
149 sv_catpv(tmpsv, ",PARENS");
150 if (op->op_flags & OPf_STACKED)
151 sv_catpv(tmpsv, ",STACKED");
152 if (op->op_flags & OPf_REF)
153 sv_catpv(tmpsv, ",REF");
154 if (op->op_flags & OPf_MOD)
155 sv_catpv(tmpsv, ",MOD");
156 if (op->op_flags & OPf_SPECIAL)
157 sv_catpv(tmpsv, ",SPECIAL");
158 dump("FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
161 if (op->op_private) {
162 SV *tmpsv = newSVpv("", 0);
163 if (op->op_type == OP_AASSIGN) {
164 if (op->op_private & OPpASSIGN_COMMON)
165 sv_catpv(tmpsv, ",COMMON");
167 else if (op->op_type == OP_SASSIGN) {
168 if (op->op_private & OPpASSIGN_BACKWARDS)
169 sv_catpv(tmpsv, ",BACKWARDS");
171 else if (op->op_type == OP_TRANS) {
172 if (op->op_private & OPpTRANS_SQUASH)
173 sv_catpv(tmpsv, ",SQUASH");
174 if (op->op_private & OPpTRANS_DELETE)
175 sv_catpv(tmpsv, ",DELETE");
176 if (op->op_private & OPpTRANS_COMPLEMENT)
177 sv_catpv(tmpsv, ",COMPLEMENT");
179 else if (op->op_type == OP_REPEAT) {
180 if (op->op_private & OPpREPEAT_DOLIST)
181 sv_catpv(tmpsv, ",DOLIST");
183 else if (op->op_type == OP_ENTERSUB ||
184 op->op_type == OP_RV2SV ||
185 op->op_type == OP_RV2AV ||
186 op->op_type == OP_RV2HV ||
187 op->op_type == OP_RV2GV ||
188 op->op_type == OP_AELEM ||
189 op->op_type == OP_HELEM )
191 if (op->op_type == OP_ENTERSUB) {
192 if (op->op_private & OPpENTERSUB_AMPER)
193 sv_catpv(tmpsv, ",AMPER");
194 if (op->op_private & OPpENTERSUB_DB)
195 sv_catpv(tmpsv, ",DB");
197 switch (op->op_private & OPpDEREF) {
199 sv_catpv(tmpsv, ",SV");
202 sv_catpv(tmpsv, ",AV");
205 sv_catpv(tmpsv, ",HV");
208 if (op->op_type == OP_AELEM || op->op_type == OP_HELEM) {
209 if (op->op_private & OPpLVAL_DEFER)
210 sv_catpv(tmpsv, ",LVAL_DEFER");
213 if (op->op_private & HINT_STRICT_REFS)
214 sv_catpv(tmpsv, ",STRICT_REFS");
217 else if (op->op_type == OP_CONST) {
218 if (op->op_private & OPpCONST_BARE)
219 sv_catpv(tmpsv, ",BARE");
221 else if (op->op_type == OP_FLIP) {
222 if (op->op_private & OPpFLIP_LINENUM)
223 sv_catpv(tmpsv, ",LINENUM");
225 else if (op->op_type == OP_FLOP) {
226 if (op->op_private & OPpFLIP_LINENUM)
227 sv_catpv(tmpsv, ",LINENUM");
229 if (op->op_flags & OPf_MOD && op->op_private & OPpLVAL_INTRO)
230 sv_catpv(tmpsv, ",INTRO");
232 dump("PRIVATE = (%s)\n", SvPVX(tmpsv) + 1);
236 switch (op->op_type) {
240 SV *tmpsv = NEWSV(0,0);
243 gv_fullname3(tmpsv, cGVOP->op_gv, Nullch);
244 dump("GV = %s\n", SvPV(tmpsv, na));
251 dump("SV = %s\n", SvPEEK(cSVOP->op_sv));
256 dump("LINE = %d\n",cCOP->cop_line);
258 dump("LABEL = \"%s\"\n",cCOP->cop_label);
262 if (cLOOP->op_redoop)
263 PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_redoop->op_seq);
265 PerlIO_printf(Perl_debug_log, "DONE\n");
267 if (cLOOP->op_nextop)
268 PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_nextop->op_seq);
270 PerlIO_printf(Perl_debug_log, "DONE\n");
272 if (cLOOP->op_lastop)
273 PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_lastop->op_seq);
275 PerlIO_printf(Perl_debug_log, "DONE\n");
279 if (cCONDOP->op_true)
280 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOP->op_true->op_seq);
282 PerlIO_printf(Perl_debug_log, "DONE\n");
284 if (cCONDOP->op_false)
285 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOP->op_false->op_seq);
287 PerlIO_printf(Perl_debug_log, "DONE\n");
294 if (cLOGOP->op_other)
295 PerlIO_printf(Perl_debug_log, "%d\n", cLOGOP->op_other->op_seq);
297 PerlIO_printf(Perl_debug_log, "DONE\n");
307 if (op->op_flags & OPf_KIDS) {
309 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
323 PerlIO_printf(Perl_debug_log, "{}\n");
328 PerlIO_printf(Perl_debug_log, "{\n");
329 gv_fullname3(sv, gv, Nullch);
330 dump("GV_NAME = %s", SvPVX(sv));
331 if (gv != GvEGV(gv)) {
332 gv_efullname3(sv, GvEGV(gv), Nullch);
333 dump("-> %s", SvPVX(sv));
352 if (pm->op_pmflags & PMf_ONCE)
357 dump("PMf_PRE %c%s%c%s\n",
358 ch, pm->op_pmregexp->precomp, ch,
359 (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
361 dump("PMf_PRE (RUNTIME)\n");
362 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
364 dump_op(pm->op_pmreplroot);
366 if (pm->op_pmshort) {
367 dump("PMf_SHORT = %s\n",SvPEEK(pm->op_pmshort));
369 if (pm->op_pmflags) {
370 SV *tmpsv = newSVpv("", 0);
371 if (pm->op_pmflags & PMf_USED)
372 sv_catpv(tmpsv, ",USED");
373 if (pm->op_pmflags & PMf_ONCE)
374 sv_catpv(tmpsv, ",ONCE");
375 if (pm->op_pmflags & PMf_SCANFIRST)
376 sv_catpv(tmpsv, ",SCANFIRST");
377 if (pm->op_pmflags & PMf_ALL)
378 sv_catpv(tmpsv, ",ALL");
379 if (pm->op_pmflags & PMf_SKIPWHITE)
380 sv_catpv(tmpsv, ",SKIPWHITE");
381 if (pm->op_pmflags & PMf_CONST)
382 sv_catpv(tmpsv, ",CONST");
383 if (pm->op_pmflags & PMf_KEEP)
384 sv_catpv(tmpsv, ",KEEP");
385 if (pm->op_pmflags & PMf_GLOBAL)
386 sv_catpv(tmpsv, ",GLOBAL");
387 if (pm->op_pmflags & PMf_CONTINUE)
388 sv_catpv(tmpsv, ",CONTINUE");
389 if (pm->op_pmflags & PMf_EVAL)
390 sv_catpv(tmpsv, ",EVAL");
391 dump("PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
400 #if !defined(I_STDARG) && !defined(I_VARARGS)
402 static void dump(arg1,arg2,arg3,arg4,arg5)
404 long arg2, arg3, arg4, arg5;
408 for (i = dumplvl*4; i; i--)
409 (void)PerlIO_putc(Perl_debug_log,' ');
410 PerlIO_printf(Perl_debug_log, arg1, arg2, arg3, arg4, arg5);
434 for (i = dumplvl*4; i; i--)
435 (void)PerlIO_putc(Perl_debug_log,' ');
436 PerlIO_vprintf(Perl_debug_log,pat,args);