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, ...);
28 # if defined(I_VARARGS)
43 setlinebuf(Perl_debug_log);
45 setvbuf(Perl_debug_log, Nullch, _IOLBF, 0);
49 dump_packsubs(defstash);
61 for (i = 0; i <= (I32) HvMAX(stash); i++) {
62 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
63 GV *gv = (GV*)HeVAL(entry);
69 if (HeKEY(entry)[HeKLEN(entry)-1] == ':' &&
70 (hv = GvHV(gv)) && HvNAME(hv) && hv != defstash)
71 dump_packsubs(hv); /* nested package */
80 SV *sv = sv_newmortal();
83 dump("\nSUB %s = ", SvPVX(sv));
85 dump("(xsub 0x%x %d)\n",
86 (long)CvXSUB(GvCV(gv)),
87 CvXSUBANY(GvCV(gv)).any_i32);
88 else if (CvROOT(GvCV(gv)))
89 dump_op(CvROOT(GvCV(gv)));
98 SV *sv = sv_newmortal();
101 dump("\nFORMAT %s = ", SvPVX(sv));
102 if (CvROOT(GvFORM(gv)))
103 dump_op(CvROOT(GvFORM(gv)));
122 fprintf(Perl_debug_log, "%-4d", op->op_seq);
124 fprintf(Perl_debug_log, " ");
125 dump("TYPE = %s ===> ", op_name[op->op_type]);
128 fprintf(Perl_debug_log, "%d\n", op->op_next->op_seq);
130 fprintf(Perl_debug_log, "(%d)\n", op->op_next->op_seq);
133 fprintf(Perl_debug_log, "DONE\n");
136 if (op->op_type == OP_NULL)
137 dump(" (was %s)\n", op_name[op->op_targ]);
139 dump("TARG = %d\n", op->op_targ);
142 dump("ADDR = 0x%lx => 0x%lx\n",op, op->op_next);
146 if (op->op_flags & OPf_KNOW) {
147 if (op->op_flags & OPf_LIST)
148 (void)strcat(buf,"LIST,");
150 (void)strcat(buf,"SCALAR,");
153 (void)strcat(buf,"UNKNOWN,");
154 if (op->op_flags & OPf_KIDS)
155 (void)strcat(buf,"KIDS,");
156 if (op->op_flags & OPf_PARENS)
157 (void)strcat(buf,"PARENS,");
158 if (op->op_flags & OPf_STACKED)
159 (void)strcat(buf,"STACKED,");
160 if (op->op_flags & OPf_REF)
161 (void)strcat(buf,"REF,");
162 if (op->op_flags & OPf_MOD)
163 (void)strcat(buf,"MOD,");
164 if (op->op_flags & OPf_SPECIAL)
165 (void)strcat(buf,"SPECIAL,");
167 buf[strlen(buf)-1] = '\0';
168 dump("FLAGS = (%s)\n",buf);
170 if (op->op_private) {
172 if (op->op_type == OP_AASSIGN) {
173 if (op->op_private & OPpASSIGN_COMMON)
174 (void)strcat(buf,"COMMON,");
176 else if (op->op_type == OP_SASSIGN) {
177 if (op->op_private & OPpASSIGN_BACKWARDS)
178 (void)strcat(buf,"BACKWARDS,");
180 else if (op->op_type == OP_TRANS) {
181 if (op->op_private & OPpTRANS_SQUASH)
182 (void)strcat(buf,"SQUASH,");
183 if (op->op_private & OPpTRANS_DELETE)
184 (void)strcat(buf,"DELETE,");
185 if (op->op_private & OPpTRANS_COMPLEMENT)
186 (void)strcat(buf,"COMPLEMENT,");
188 else if (op->op_type == OP_REPEAT) {
189 if (op->op_private & OPpREPEAT_DOLIST)
190 (void)strcat(buf,"DOLIST,");
192 else if (op->op_type == OP_ENTERSUB ||
193 op->op_type == OP_RV2SV ||
194 op->op_type == OP_RV2AV ||
195 op->op_type == OP_RV2HV ||
196 op->op_type == OP_RV2GV ||
197 op->op_type == OP_AELEM ||
198 op->op_type == OP_HELEM )
200 if (op->op_private & OPpENTERSUB_AMPER)
201 (void)strcat(buf,"AMPER,");
202 if (op->op_private & OPpENTERSUB_DB)
203 (void)strcat(buf,"DB,");
204 if (op->op_private & OPpDEREF_AV)
205 (void)strcat(buf,"AV,");
206 if (op->op_private & OPpDEREF_HV)
207 (void)strcat(buf,"HV,");
208 if (op->op_private & HINT_STRICT_REFS)
209 (void)strcat(buf,"STRICT_REFS,");
211 else if (op->op_type == OP_CONST) {
212 if (op->op_private & OPpCONST_BARE)
213 (void)strcat(buf,"BARE,");
215 else if (op->op_type == OP_FLIP) {
216 if (op->op_private & OPpFLIP_LINENUM)
217 (void)strcat(buf,"LINENUM,");
219 else if (op->op_type == OP_FLOP) {
220 if (op->op_private & OPpFLIP_LINENUM)
221 (void)strcat(buf,"LINENUM,");
223 if (op->op_flags & OPf_MOD && op->op_private & OPpLVAL_INTRO)
224 (void)strcat(buf,"INTRO,");
226 buf[strlen(buf)-1] = '\0';
227 dump("PRIVATE = (%s)\n",buf);
231 switch (op->op_type) {
238 gv_fullname(tmpsv,cGVOP->op_gv);
239 dump("GV = %s\n", SvPV(tmpsv, na));
246 dump("SV = %s\n", SvPEEK(cSVOP->op_sv));
251 dump("LINE = %d\n",cCOP->cop_line);
253 dump("LABEL = \"%s\"\n",cCOP->cop_label);
257 if (cLOOP->op_redoop)
258 fprintf(Perl_debug_log, "%d\n", cLOOP->op_redoop->op_seq);
260 fprintf(Perl_debug_log, "DONE\n");
262 if (cLOOP->op_nextop)
263 fprintf(Perl_debug_log, "%d\n", cLOOP->op_nextop->op_seq);
265 fprintf(Perl_debug_log, "DONE\n");
267 if (cLOOP->op_lastop)
268 fprintf(Perl_debug_log, "%d\n", cLOOP->op_lastop->op_seq);
270 fprintf(Perl_debug_log, "DONE\n");
274 if (cCONDOP->op_true)
275 fprintf(Perl_debug_log, "%d\n", cCONDOP->op_true->op_seq);
277 fprintf(Perl_debug_log, "DONE\n");
279 if (cCONDOP->op_false)
280 fprintf(Perl_debug_log, "%d\n", cCONDOP->op_false->op_seq);
282 fprintf(Perl_debug_log, "DONE\n");
289 if (cLOGOP->op_other)
290 fprintf(Perl_debug_log, "%d\n", cLOGOP->op_other->op_seq);
292 fprintf(Perl_debug_log, "DONE\n");
302 if (op->op_flags & OPf_KIDS) {
304 for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
318 fprintf(Perl_debug_log,"{}\n");
323 fprintf(Perl_debug_log,"{\n");
325 dump("GV_NAME = %s", SvPVX(sv));
326 if (gv != GvEGV(gv)) {
327 gv_efullname(sv,GvEGV(gv));
328 dump("-> %s", SvPVX(sv));
347 if (pm->op_pmflags & PMf_ONCE)
352 dump("PMf_PRE %c%s%c\n",ch,pm->op_pmregexp->precomp,ch);
353 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
355 dump_op(pm->op_pmreplroot);
357 if (pm->op_pmshort) {
358 dump("PMf_SHORT = %s\n",SvPEEK(pm->op_pmshort));
360 if (pm->op_pmflags) {
362 if (pm->op_pmflags & PMf_USED)
363 (void)strcat(buf,"USED,");
364 if (pm->op_pmflags & PMf_ONCE)
365 (void)strcat(buf,"ONCE,");
366 if (pm->op_pmflags & PMf_SCANFIRST)
367 (void)strcat(buf,"SCANFIRST,");
368 if (pm->op_pmflags & PMf_ALL)
369 (void)strcat(buf,"ALL,");
370 if (pm->op_pmflags & PMf_SKIPWHITE)
371 (void)strcat(buf,"SKIPWHITE,");
372 if (pm->op_pmflags & PMf_FOLD)
373 (void)strcat(buf,"FOLD,");
374 if (pm->op_pmflags & PMf_CONST)
375 (void)strcat(buf,"CONST,");
376 if (pm->op_pmflags & PMf_KEEP)
377 (void)strcat(buf,"KEEP,");
378 if (pm->op_pmflags & PMf_GLOBAL)
379 (void)strcat(buf,"GLOBAL,");
380 if (pm->op_pmflags & PMf_RUNTIME)
381 (void)strcat(buf,"RUNTIME,");
382 if (pm->op_pmflags & PMf_EVAL)
383 (void)strcat(buf,"EVAL,");
385 buf[strlen(buf)-1] = '\0';
386 dump("PMFLAGS = (%s)\n",buf);
394 #if !defined(I_STDARG) && !defined(I_VARARGS)
396 static void dump(arg1,arg2,arg3,arg4,arg5)
398 long arg2, arg3, arg4, arg5;
402 for (i = dumplvl*4; i; i--)
403 (void)putc(' ',Perl_debug_log);
404 fprintf(Perl_debug_log,arg1, arg2, arg3, arg4, arg5);
431 for (i = dumplvl*4; i; i--)
432 (void)putc(' ',stderr);
433 vfprintf(Perl_debug_log,pat,args);