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)));
110 PerlIO_printf(Perl_debug_log, "%-4d", op->op_seq);
112 PerlIO_printf(Perl_debug_log, " ");
113 dump("TYPE = %s ===> ", op_name[op->op_type]);
116 PerlIO_printf(Perl_debug_log, "%d\n", op->op_next->op_seq);
118 PerlIO_printf(Perl_debug_log, "(%d)\n", op->op_next->op_seq);
121 PerlIO_printf(Perl_debug_log, "DONE\n");
124 if (op->op_type == OP_NULL)
125 dump(" (was %s)\n", op_name[op->op_targ]);
127 dump("TARG = %d\n", op->op_targ);
130 dump("ADDR = 0x%lx => 0x%lx\n",op, op->op_next);
134 switch (op->op_flags & OPf_WANT) {
136 (void)strcat(buf,"VOID,");
138 case OPf_WANT_SCALAR:
139 (void)strcat(buf,"SCALAR,");
142 (void)strcat(buf,"LIST,");
145 (void)strcat(buf,"UNKNOWN,");
148 if (op->op_flags & OPf_KIDS)
149 (void)strcat(buf,"KIDS,");
150 if (op->op_flags & OPf_PARENS)
151 (void)strcat(buf,"PARENS,");
152 if (op->op_flags & OPf_STACKED)
153 (void)strcat(buf,"STACKED,");
154 if (op->op_flags & OPf_REF)
155 (void)strcat(buf,"REF,");
156 if (op->op_flags & OPf_MOD)
157 (void)strcat(buf,"MOD,");
158 if (op->op_flags & OPf_SPECIAL)
159 (void)strcat(buf,"SPECIAL,");
161 buf[strlen(buf)-1] = '\0';
162 dump("FLAGS = (%s)\n",buf);
164 if (op->op_private) {
166 if (op->op_type == OP_AASSIGN) {
167 if (op->op_private & OPpASSIGN_COMMON)
168 (void)strcat(buf,"COMMON,");
170 else if (op->op_type == OP_SASSIGN) {
171 if (op->op_private & OPpASSIGN_BACKWARDS)
172 (void)strcat(buf,"BACKWARDS,");
174 else if (op->op_type == OP_TRANS) {
175 if (op->op_private & OPpTRANS_SQUASH)
176 (void)strcat(buf,"SQUASH,");
177 if (op->op_private & OPpTRANS_DELETE)
178 (void)strcat(buf,"DELETE,");
179 if (op->op_private & OPpTRANS_COMPLEMENT)
180 (void)strcat(buf,"COMPLEMENT,");
182 else if (op->op_type == OP_REPEAT) {
183 if (op->op_private & OPpREPEAT_DOLIST)
184 (void)strcat(buf,"DOLIST,");
186 else if (op->op_type == OP_ENTERSUB ||
187 op->op_type == OP_RV2SV ||
188 op->op_type == OP_RV2AV ||
189 op->op_type == OP_RV2HV ||
190 op->op_type == OP_RV2GV ||
191 op->op_type == OP_AELEM ||
192 op->op_type == OP_HELEM )
194 if (op->op_type == OP_ENTERSUB) {
195 if (op->op_private & OPpENTERSUB_AMPER)
196 (void)strcat(buf,"AMPER,");
197 if (op->op_private & OPpENTERSUB_DB)
198 (void)strcat(buf,"DB,");
200 switch (op->op_private & OPpDEREF) {
202 (void)strcat(buf, "SV,");
205 (void)strcat(buf, "AV,");
208 (void)strcat(buf, "HV,");
211 if (op->op_type == OP_AELEM || op->op_type == OP_HELEM) {
212 if (op->op_private & OPpLVAL_DEFER)
213 (void)strcat(buf,"LVAL_DEFER,");
216 if (op->op_private & HINT_STRICT_REFS)
217 (void)strcat(buf,"STRICT_REFS,");
220 else if (op->op_type == OP_CONST) {
221 if (op->op_private & OPpCONST_BARE)
222 (void)strcat(buf,"BARE,");
224 else if (op->op_type == OP_FLIP) {
225 if (op->op_private & OPpFLIP_LINENUM)
226 (void)strcat(buf,"LINENUM,");
228 else if (op->op_type == OP_FLOP) {
229 if (op->op_private & OPpFLIP_LINENUM)
230 (void)strcat(buf,"LINENUM,");
232 if (op->op_flags & OPf_MOD && op->op_private & OPpLVAL_INTRO)
233 (void)strcat(buf,"INTRO,");
235 buf[strlen(buf)-1] = '\0';
236 dump("PRIVATE = (%s)\n",buf);
240 switch (op->op_type) {
247 gv_fullname3(tmpsv, cGVOP->op_gv, Nullch);
248 dump("GV = %s\n", SvPV(tmpsv, na));
255 dump("SV = %s\n", SvPEEK(cSVOP->op_sv));
260 dump("LINE = %d\n",cCOP->cop_line);
262 dump("LABEL = \"%s\"\n",cCOP->cop_label);
266 if (cLOOP->op_redoop)
267 PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_redoop->op_seq);
269 PerlIO_printf(Perl_debug_log, "DONE\n");
271 if (cLOOP->op_nextop)
272 PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_nextop->op_seq);
274 PerlIO_printf(Perl_debug_log, "DONE\n");
276 if (cLOOP->op_lastop)
277 PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_lastop->op_seq);
279 PerlIO_printf(Perl_debug_log, "DONE\n");
283 if (cCONDOP->op_true)
284 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOP->op_true->op_seq);
286 PerlIO_printf(Perl_debug_log, "DONE\n");
288 if (cCONDOP->op_false)
289 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOP->op_false->op_seq);
291 PerlIO_printf(Perl_debug_log, "DONE\n");
298 if (cLOGOP->op_other)
299 PerlIO_printf(Perl_debug_log, "%d\n", cLOGOP->op_other->op_seq);
301 PerlIO_printf(Perl_debug_log, "DONE\n");
311 if (op->op_flags & OPf_KIDS) {
313 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
327 PerlIO_printf(Perl_debug_log, "{}\n");
332 PerlIO_printf(Perl_debug_log, "{\n");
333 gv_fullname3(sv, gv, Nullch);
334 dump("GV_NAME = %s", SvPVX(sv));
335 if (gv != GvEGV(gv)) {
336 gv_efullname3(sv, GvEGV(gv), Nullch);
337 dump("-> %s", SvPVX(sv));
356 if (pm->op_pmflags & PMf_ONCE)
361 dump("PMf_PRE %c%s%c\n",ch,pm->op_pmregexp->precomp,ch);
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) {
371 if (pm->op_pmflags & PMf_USED)
372 (void)strcat(buf,"USED,");
373 if (pm->op_pmflags & PMf_ONCE)
374 (void)strcat(buf,"ONCE,");
375 if (pm->op_pmflags & PMf_SCANFIRST)
376 (void)strcat(buf,"SCANFIRST,");
377 if (pm->op_pmflags & PMf_ALL)
378 (void)strcat(buf,"ALL,");
379 if (pm->op_pmflags & PMf_SKIPWHITE)
380 (void)strcat(buf,"SKIPWHITE,");
381 if (pm->op_pmflags & PMf_CONST)
382 (void)strcat(buf,"CONST,");
383 if (pm->op_pmflags & PMf_KEEP)
384 (void)strcat(buf,"KEEP,");
385 if (pm->op_pmflags & PMf_GLOBAL)
386 (void)strcat(buf,"GLOBAL,");
387 if (pm->op_pmflags & PMf_RUNTIME)
388 (void)strcat(buf,"RUNTIME,");
389 if (pm->op_pmflags & PMf_EVAL)
390 (void)strcat(buf,"EVAL,");
392 buf[strlen(buf)-1] = '\0';
393 dump("PMFLAGS = (%s)\n",buf);
401 #if !defined(I_STDARG) && !defined(I_VARARGS)
403 static void dump(arg1,arg2,arg3,arg4,arg5)
405 long arg2, arg3, arg4, arg5;
409 for (i = dumplvl*4; i; i--)
410 (void)PerlIO_putc(Perl_debug_log,' ');
411 PerlIO_printf(Perl_debug_log, arg1, arg2, arg3, arg4, arg5);
435 for (i = dumplvl*4; i; i--)
436 (void)PerlIO_putc(Perl_debug_log,' ');
437 PerlIO_vprintf(Perl_debug_log,pat,args);