3 * Copyright (c) 1991-1994, 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_fullname(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_fullname(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_private & OPpENTERSUB_AMPER)
189 (void)strcat(buf,"AMPER,");
190 if (op->op_private & OPpENTERSUB_DB)
191 (void)strcat(buf,"DB,");
192 if (op->op_private & OPpDEREF_AV)
193 (void)strcat(buf,"AV,");
194 if (op->op_private & OPpDEREF_HV)
195 (void)strcat(buf,"HV,");
196 if (op->op_private & HINT_STRICT_REFS)
197 (void)strcat(buf,"STRICT_REFS,");
199 else if (op->op_type == OP_CONST) {
200 if (op->op_private & OPpCONST_BARE)
201 (void)strcat(buf,"BARE,");
203 else if (op->op_type == OP_FLIP) {
204 if (op->op_private & OPpFLIP_LINENUM)
205 (void)strcat(buf,"LINENUM,");
207 else if (op->op_type == OP_FLOP) {
208 if (op->op_private & OPpFLIP_LINENUM)
209 (void)strcat(buf,"LINENUM,");
211 if (op->op_flags & OPf_MOD && op->op_private & OPpLVAL_INTRO)
212 (void)strcat(buf,"INTRO,");
214 buf[strlen(buf)-1] = '\0';
215 dump("PRIVATE = (%s)\n",buf);
219 switch (op->op_type) {
226 gv_fullname(tmpsv, cGVOP->op_gv, Nullch);
227 dump("GV = %s\n", SvPV(tmpsv, na));
234 dump("SV = %s\n", SvPEEK(cSVOP->op_sv));
239 dump("LINE = %d\n",cCOP->cop_line);
241 dump("LABEL = \"%s\"\n",cCOP->cop_label);
245 if (cLOOP->op_redoop)
246 PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_redoop->op_seq);
248 PerlIO_printf(Perl_debug_log, "DONE\n");
250 if (cLOOP->op_nextop)
251 PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_nextop->op_seq);
253 PerlIO_printf(Perl_debug_log, "DONE\n");
255 if (cLOOP->op_lastop)
256 PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_lastop->op_seq);
258 PerlIO_printf(Perl_debug_log, "DONE\n");
262 if (cCONDOP->op_true)
263 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOP->op_true->op_seq);
265 PerlIO_printf(Perl_debug_log, "DONE\n");
267 if (cCONDOP->op_false)
268 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOP->op_false->op_seq);
270 PerlIO_printf(Perl_debug_log, "DONE\n");
277 if (cLOGOP->op_other)
278 PerlIO_printf(Perl_debug_log, "%d\n", cLOGOP->op_other->op_seq);
280 PerlIO_printf(Perl_debug_log, "DONE\n");
290 if (op->op_flags & OPf_KIDS) {
292 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
306 PerlIO_printf(Perl_debug_log, "{}\n");
311 PerlIO_printf(Perl_debug_log, "{\n");
312 gv_fullname(sv, gv, Nullch);
313 dump("GV_NAME = %s", SvPVX(sv));
314 if (gv != GvEGV(gv)) {
315 gv_efullname(sv, GvEGV(gv), Nullch);
316 dump("-> %s", SvPVX(sv));
335 if (pm->op_pmflags & PMf_ONCE)
340 dump("PMf_PRE %c%s%c\n",ch,pm->op_pmregexp->precomp,ch);
341 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
343 dump_op(pm->op_pmreplroot);
345 if (pm->op_pmshort) {
346 dump("PMf_SHORT = %s\n",SvPEEK(pm->op_pmshort));
348 if (pm->op_pmflags) {
350 if (pm->op_pmflags & PMf_USED)
351 (void)strcat(buf,"USED,");
352 if (pm->op_pmflags & PMf_ONCE)
353 (void)strcat(buf,"ONCE,");
354 if (pm->op_pmflags & PMf_SCANFIRST)
355 (void)strcat(buf,"SCANFIRST,");
356 if (pm->op_pmflags & PMf_ALL)
357 (void)strcat(buf,"ALL,");
358 if (pm->op_pmflags & PMf_SKIPWHITE)
359 (void)strcat(buf,"SKIPWHITE,");
360 if (pm->op_pmflags & PMf_FOLD)
361 (void)strcat(buf,"FOLD,");
362 if (pm->op_pmflags & PMf_CONST)
363 (void)strcat(buf,"CONST,");
364 if (pm->op_pmflags & PMf_KEEP)
365 (void)strcat(buf,"KEEP,");
366 if (pm->op_pmflags & PMf_GLOBAL)
367 (void)strcat(buf,"GLOBAL,");
368 if (pm->op_pmflags & PMf_RUNTIME)
369 (void)strcat(buf,"RUNTIME,");
370 if (pm->op_pmflags & PMf_EVAL)
371 (void)strcat(buf,"EVAL,");
373 buf[strlen(buf)-1] = '\0';
374 dump("PMFLAGS = (%s)\n",buf);
382 #if !defined(I_STDARG) && !defined(I_VARARGS)
384 static void dump(arg1,arg2,arg3,arg4,arg5)
386 long arg2, arg3, arg4, arg5;
390 for (i = dumplvl*4; i; i--)
391 (void)PerlIO_putc(Perl_debug_log,' ');
392 PerlIO_printf(Perl_debug_log, arg1, arg2, arg3, arg4, arg5);
416 for (i = dumplvl*4; i; i--)
417 (void)PerlIO_putc(Perl_debug_log,' ');
418 PerlIO_vprintf(Perl_debug_log,pat,args);