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, ...);
35 PerlIO_setlinebuf(Perl_debug_log);
38 dump_packsubs(defstash);
42 dump_packsubs(HV *stash)
50 for (i = 0; i <= (I32) HvMAX(stash); i++) {
51 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
52 GV *gv = (GV*)HeVAL(entry);
58 if (HeKEY(entry)[HeKLEN(entry)-1] == ':' &&
59 (hv = GvHV(gv)) && HvNAME(hv) && hv != defstash)
60 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)));
85 SV *sv = sv_newmortal();
87 gv_fullname3(sv, gv, Nullch);
88 dump("\nFORMAT %s = ", SvPVX(sv));
89 if (CvROOT(GvFORM(gv)))
90 dump_op(CvROOT(GvFORM(gv)));
106 PerlIO_printf(Perl_debug_log, "%-4d", o->op_seq);
108 PerlIO_printf(Perl_debug_log, " ");
109 dump("TYPE = %s ===> ", op_name[o->op_type]);
112 PerlIO_printf(Perl_debug_log, "%d\n", o->op_next->op_seq);
114 PerlIO_printf(Perl_debug_log, "(%d)\n", o->op_next->op_seq);
117 PerlIO_printf(Perl_debug_log, "DONE\n");
120 if (o->op_type == OP_NULL)
121 dump(" (was %s)\n", op_name[o->op_targ]);
123 dump("TARG = %d\n", o->op_targ);
126 dump("ADDR = 0x%lx => 0x%lx\n",o, o->op_next);
129 SV *tmpsv = newSVpv("", 0);
130 switch (o->op_flags & OPf_WANT) {
132 sv_catpv(tmpsv, ",VOID");
134 case OPf_WANT_SCALAR:
135 sv_catpv(tmpsv, ",SCALAR");
138 sv_catpv(tmpsv, ",LIST");
141 sv_catpv(tmpsv, ",UNKNOWN");
144 if (o->op_flags & OPf_KIDS)
145 sv_catpv(tmpsv, ",KIDS");
146 if (o->op_flags & OPf_PARENS)
147 sv_catpv(tmpsv, ",PARENS");
148 if (o->op_flags & OPf_STACKED)
149 sv_catpv(tmpsv, ",STACKED");
150 if (o->op_flags & OPf_REF)
151 sv_catpv(tmpsv, ",REF");
152 if (o->op_flags & OPf_MOD)
153 sv_catpv(tmpsv, ",MOD");
154 if (o->op_flags & OPf_SPECIAL)
155 sv_catpv(tmpsv, ",SPECIAL");
156 dump("FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
160 SV *tmpsv = newSVpv("", 0);
161 if (o->op_type == OP_AASSIGN) {
162 if (o->op_private & OPpASSIGN_COMMON)
163 sv_catpv(tmpsv, ",COMMON");
165 else if (o->op_type == OP_SASSIGN) {
166 if (o->op_private & OPpASSIGN_BACKWARDS)
167 sv_catpv(tmpsv, ",BACKWARDS");
169 else if (o->op_type == OP_TRANS) {
170 if (o->op_private & OPpTRANS_SQUASH)
171 sv_catpv(tmpsv, ",SQUASH");
172 if (o->op_private & OPpTRANS_DELETE)
173 sv_catpv(tmpsv, ",DELETE");
174 if (o->op_private & OPpTRANS_COMPLEMENT)
175 sv_catpv(tmpsv, ",COMPLEMENT");
177 else if (o->op_type == OP_REPEAT) {
178 if (o->op_private & OPpREPEAT_DOLIST)
179 sv_catpv(tmpsv, ",DOLIST");
181 else if (o->op_type == OP_ENTERSUB ||
182 o->op_type == OP_RV2SV ||
183 o->op_type == OP_RV2AV ||
184 o->op_type == OP_RV2HV ||
185 o->op_type == OP_RV2GV ||
186 o->op_type == OP_AELEM ||
187 o->op_type == OP_HELEM )
189 if (o->op_type == OP_ENTERSUB) {
190 if (o->op_private & OPpENTERSUB_AMPER)
191 sv_catpv(tmpsv, ",AMPER");
192 if (o->op_private & OPpENTERSUB_DB)
193 sv_catpv(tmpsv, ",DB");
195 switch (o->op_private & OPpDEREF) {
197 sv_catpv(tmpsv, ",SV");
200 sv_catpv(tmpsv, ",AV");
203 sv_catpv(tmpsv, ",HV");
206 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
207 if (o->op_private & OPpLVAL_DEFER)
208 sv_catpv(tmpsv, ",LVAL_DEFER");
211 if (o->op_private & HINT_STRICT_REFS)
212 sv_catpv(tmpsv, ",STRICT_REFS");
215 else if (o->op_type == OP_CONST) {
216 if (o->op_private & OPpCONST_BARE)
217 sv_catpv(tmpsv, ",BARE");
219 else if (o->op_type == OP_FLIP) {
220 if (o->op_private & OPpFLIP_LINENUM)
221 sv_catpv(tmpsv, ",LINENUM");
223 else if (o->op_type == OP_FLOP) {
224 if (o->op_private & OPpFLIP_LINENUM)
225 sv_catpv(tmpsv, ",LINENUM");
227 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
228 sv_catpv(tmpsv, ",INTRO");
230 dump("PRIVATE = (%s)\n", SvPVX(tmpsv) + 1);
234 switch (o->op_type) {
238 SV *tmpsv = NEWSV(0,0);
241 gv_fullname3(tmpsv, cGVOPo->op_gv, Nullch);
242 dump("GV = %s\n", SvPV(tmpsv, na));
249 dump("SV = %s\n", SvPEEK(cSVOPo->op_sv));
254 dump("LINE = %d\n",cCOPo->cop_line);
255 if (cCOPo->cop_label)
256 dump("LABEL = \"%s\"\n",cCOPo->cop_label);
260 if (cLOOPo->op_redoop)
261 PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_redoop->op_seq);
263 PerlIO_printf(Perl_debug_log, "DONE\n");
265 if (cLOOPo->op_nextop)
266 PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_nextop->op_seq);
268 PerlIO_printf(Perl_debug_log, "DONE\n");
270 if (cLOOPo->op_lastop)
271 PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_lastop->op_seq);
273 PerlIO_printf(Perl_debug_log, "DONE\n");
277 if (cCONDOPo->op_true)
278 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOPo->op_true->op_seq);
280 PerlIO_printf(Perl_debug_log, "DONE\n");
282 if (cCONDOPo->op_false)
283 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOPo->op_false->op_seq);
285 PerlIO_printf(Perl_debug_log, "DONE\n");
292 if (cLOGOPo->op_other)
293 PerlIO_printf(Perl_debug_log, "%d\n", cLOGOPo->op_other->op_seq);
295 PerlIO_printf(Perl_debug_log, "DONE\n");
305 if (o->op_flags & OPf_KIDS) {
307 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
320 PerlIO_printf(Perl_debug_log, "{}\n");
325 PerlIO_printf(Perl_debug_log, "{\n");
326 gv_fullname3(sv, gv, Nullch);
327 dump("GV_NAME = %s", SvPVX(sv));
328 if (gv != GvEGV(gv)) {
329 gv_efullname3(sv, GvEGV(gv), Nullch);
330 dump("-> %s", SvPVX(sv));
348 if (pm->op_pmflags & PMf_ONCE)
353 dump("PMf_PRE %c%s%c%s\n",
354 ch, pm->op_pmregexp->precomp, ch,
355 (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
357 dump("PMf_PRE (RUNTIME)\n");
358 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
360 dump_op(pm->op_pmreplroot);
362 if (pm->op_pmflags || (pm->op_pmregexp && pm->op_pmregexp->check_substr)) {
363 SV *tmpsv = newSVpv("", 0);
364 if (pm->op_pmflags & PMf_USED)
365 sv_catpv(tmpsv, ",USED");
366 if (pm->op_pmflags & PMf_ONCE)
367 sv_catpv(tmpsv, ",ONCE");
368 if (pm->op_pmregexp && pm->op_pmregexp->check_substr
369 && !(pm->op_pmregexp->reganch & ROPT_NOSCAN))
370 sv_catpv(tmpsv, ",SCANFIRST");
371 if (pm->op_pmregexp && pm->op_pmregexp->check_substr
372 && pm->op_pmregexp->reganch & ROPT_CHECK_ALL)
373 sv_catpv(tmpsv, ",ALL");
374 if (pm->op_pmflags & PMf_SKIPWHITE)
375 sv_catpv(tmpsv, ",SKIPWHITE");
376 if (pm->op_pmflags & PMf_CONST)
377 sv_catpv(tmpsv, ",CONST");
378 if (pm->op_pmflags & PMf_KEEP)
379 sv_catpv(tmpsv, ",KEEP");
380 if (pm->op_pmflags & PMf_GLOBAL)
381 sv_catpv(tmpsv, ",GLOBAL");
382 if (pm->op_pmflags & PMf_CONTINUE)
383 sv_catpv(tmpsv, ",CONTINUE");
384 if (pm->op_pmflags & PMf_EVAL)
385 sv_catpv(tmpsv, ",EVAL");
386 dump("PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
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);