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 if (op->op_flags & OPf_KNOW) {
135 if (op->op_flags & OPf_LIST)
136 (void)strcat(buf,"LIST,");
138 (void)strcat(buf,"SCALAR,");
141 (void)strcat(buf,"UNKNOWN,");
142 if (op->op_flags & OPf_KIDS)
143 (void)strcat(buf,"KIDS,");
144 if (op->op_flags & OPf_PARENS)
145 (void)strcat(buf,"PARENS,");
146 if (op->op_flags & OPf_STACKED)
147 (void)strcat(buf,"STACKED,");
148 if (op->op_flags & OPf_REF)
149 (void)strcat(buf,"REF,");
150 if (op->op_flags & OPf_MOD)
151 (void)strcat(buf,"MOD,");
152 if (op->op_flags & OPf_SPECIAL)
153 (void)strcat(buf,"SPECIAL,");
155 buf[strlen(buf)-1] = '\0';
156 dump("FLAGS = (%s)\n",buf);
158 if (op->op_private) {
160 if (op->op_type == OP_AASSIGN) {
161 if (op->op_private & OPpASSIGN_COMMON)
162 (void)strcat(buf,"COMMON,");
164 else if (op->op_type == OP_SASSIGN) {
165 if (op->op_private & OPpASSIGN_BACKWARDS)
166 (void)strcat(buf,"BACKWARDS,");
168 else if (op->op_type == OP_TRANS) {
169 if (op->op_private & OPpTRANS_SQUASH)
170 (void)strcat(buf,"SQUASH,");
171 if (op->op_private & OPpTRANS_DELETE)
172 (void)strcat(buf,"DELETE,");
173 if (op->op_private & OPpTRANS_COMPLEMENT)
174 (void)strcat(buf,"COMPLEMENT,");
176 else if (op->op_type == OP_REPEAT) {
177 if (op->op_private & OPpREPEAT_DOLIST)
178 (void)strcat(buf,"DOLIST,");
180 else if (op->op_type == OP_ENTERSUB ||
181 op->op_type == OP_RV2SV ||
182 op->op_type == OP_RV2AV ||
183 op->op_type == OP_RV2HV ||
184 op->op_type == OP_RV2GV ||
185 op->op_type == OP_AELEM ||
186 op->op_type == OP_HELEM )
188 if (op->op_type == OP_ENTERSUB) {
189 if (op->op_private & OPpENTERSUB_AMPER)
190 (void)strcat(buf,"AMPER,");
191 if (op->op_private & OPpENTERSUB_DB)
192 (void)strcat(buf,"DB,");
194 switch (op->op_private & OPpDEREF) {
196 (void)strcat(buf, "SV,");
199 (void)strcat(buf, "AV,");
202 (void)strcat(buf, "HV,");
205 if (op->op_type == OP_AELEM || op->op_type == OP_HELEM) {
206 if (op->op_private & OPpLVAL_DEFER)
207 (void)strcat(buf,"LVAL_DEFER,");
210 if (op->op_private & HINT_STRICT_REFS)
211 (void)strcat(buf,"STRICT_REFS,");
214 else if (op->op_type == OP_CONST) {
215 if (op->op_private & OPpCONST_BARE)
216 (void)strcat(buf,"BARE,");
218 else if (op->op_type == OP_FLIP) {
219 if (op->op_private & OPpFLIP_LINENUM)
220 (void)strcat(buf,"LINENUM,");
222 else if (op->op_type == OP_FLOP) {
223 if (op->op_private & OPpFLIP_LINENUM)
224 (void)strcat(buf,"LINENUM,");
226 if (op->op_flags & OPf_MOD && op->op_private & OPpLVAL_INTRO)
227 (void)strcat(buf,"INTRO,");
229 buf[strlen(buf)-1] = '\0';
230 dump("PRIVATE = (%s)\n",buf);
234 switch (op->op_type) {
241 gv_fullname3(tmpsv, cGVOP->op_gv, Nullch);
242 dump("GV = %s\n", SvPV(tmpsv, na));
249 dump("SV = %s\n", SvPEEK(cSVOP->op_sv));
254 dump("LINE = %d\n",cCOP->cop_line);
256 dump("LABEL = \"%s\"\n",cCOP->cop_label);
260 if (cLOOP->op_redoop)
261 PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_redoop->op_seq);
263 PerlIO_printf(Perl_debug_log, "DONE\n");
265 if (cLOOP->op_nextop)
266 PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_nextop->op_seq);
268 PerlIO_printf(Perl_debug_log, "DONE\n");
270 if (cLOOP->op_lastop)
271 PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_lastop->op_seq);
273 PerlIO_printf(Perl_debug_log, "DONE\n");
277 if (cCONDOP->op_true)
278 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOP->op_true->op_seq);
280 PerlIO_printf(Perl_debug_log, "DONE\n");
282 if (cCONDOP->op_false)
283 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOP->op_false->op_seq);
285 PerlIO_printf(Perl_debug_log, "DONE\n");
292 if (cLOGOP->op_other)
293 PerlIO_printf(Perl_debug_log, "%d\n", cLOGOP->op_other->op_seq);
295 PerlIO_printf(Perl_debug_log, "DONE\n");
305 if (op->op_flags & OPf_KIDS) {
307 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
321 PerlIO_printf(Perl_debug_log, "{}\n");
326 PerlIO_printf(Perl_debug_log, "{\n");
327 gv_fullname3(sv, gv, Nullch);
328 dump("GV_NAME = %s", SvPVX(sv));
329 if (gv != GvEGV(gv)) {
330 gv_efullname3(sv, GvEGV(gv), Nullch);
331 dump("-> %s", SvPVX(sv));
350 if (pm->op_pmflags & PMf_ONCE)
355 dump("PMf_PRE %c%s%c\n",ch,pm->op_pmregexp->precomp,ch);
356 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
358 dump_op(pm->op_pmreplroot);
360 if (pm->op_pmshort) {
361 dump("PMf_SHORT = %s\n",SvPEEK(pm->op_pmshort));
363 if (pm->op_pmflags) {
365 if (pm->op_pmflags & PMf_USED)
366 (void)strcat(buf,"USED,");
367 if (pm->op_pmflags & PMf_ONCE)
368 (void)strcat(buf,"ONCE,");
369 if (pm->op_pmflags & PMf_SCANFIRST)
370 (void)strcat(buf,"SCANFIRST,");
371 if (pm->op_pmflags & PMf_ALL)
372 (void)strcat(buf,"ALL,");
373 if (pm->op_pmflags & PMf_SKIPWHITE)
374 (void)strcat(buf,"SKIPWHITE,");
375 if (pm->op_pmflags & PMf_CONST)
376 (void)strcat(buf,"CONST,");
377 if (pm->op_pmflags & PMf_KEEP)
378 (void)strcat(buf,"KEEP,");
379 if (pm->op_pmflags & PMf_GLOBAL)
380 (void)strcat(buf,"GLOBAL,");
381 if (pm->op_pmflags & PMf_RUNTIME)
382 (void)strcat(buf,"RUNTIME,");
383 if (pm->op_pmflags & PMf_EVAL)
384 (void)strcat(buf,"EVAL,");
386 buf[strlen(buf)-1] = '\0';
387 dump("PMFLAGS = (%s)\n",buf);
395 #if !defined(I_STDARG) && !defined(I_VARARGS)
397 static void dump(arg1,arg2,arg3,arg4,arg5)
399 long arg2, arg3, arg4, arg5;
403 for (i = dumplvl*4; i; i--)
404 (void)PerlIO_putc(Perl_debug_log,' ');
405 PerlIO_printf(Perl_debug_log, arg1, arg2, arg3, arg4, arg5);
429 for (i = dumplvl*4; i; i--)
430 (void)PerlIO_putc(Perl_debug_log,' ');
431 PerlIO_vprintf(Perl_debug_log,pat,args);