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.'"
19 static void dump(char *pat, ...);
20 #endif /* PERL_OBJECT */
27 PerlIO_setlinebuf(Perl_debug_log);
30 dump_packsubs(defstash);
31 #endif /* DEBUGGING */
35 dump_packsubs(HV *stash)
44 for (i = 0; i <= (I32) HvMAX(stash); i++) {
45 for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) {
46 GV *gv = (GV*)HeVAL(entry);
52 if (HeKEY(entry)[HeKLEN(entry)-1] == ':' &&
53 (hv = GvHV(gv)) && HvNAME(hv) && hv != defstash)
54 dump_packsubs(hv); /* nested package */
57 #endif /* DEBUGGING */
64 SV *sv = sv_newmortal();
66 gv_fullname3(sv, gv, Nullch);
67 dump("\nSUB %s = ", SvPVX(sv));
69 dump("(xsub 0x%x %d)\n",
70 (long)CvXSUB(GvCV(gv)),
71 CvXSUBANY(GvCV(gv)).any_i32);
72 else if (CvROOT(GvCV(gv)))
73 dump_op(CvROOT(GvCV(gv)));
76 #endif /* DEBUGGING */
83 SV *sv = sv_newmortal();
85 gv_fullname3(sv, gv, Nullch);
86 dump("\nFORMAT %s = ", SvPVX(sv));
87 if (CvROOT(GvFORM(gv)))
88 dump_op(CvROOT(GvFORM(gv)));
91 #endif /* DEBUGGING */
99 #endif /* DEBUGGING */
108 PerlIO_printf(Perl_debug_log, "%-4d", o->op_seq);
110 PerlIO_printf(Perl_debug_log, " ");
111 dump("TYPE = %s ===> ", op_name[o->op_type]);
114 PerlIO_printf(Perl_debug_log, "%d\n", o->op_next->op_seq);
116 PerlIO_printf(Perl_debug_log, "(%d)\n", o->op_next->op_seq);
119 PerlIO_printf(Perl_debug_log, "DONE\n");
122 if (o->op_type == OP_NULL)
123 dump(" (was %s)\n", op_name[o->op_targ]);
125 dump("TARG = %d\n", o->op_targ);
128 dump("ADDR = 0x%lx => 0x%lx\n",o, o->op_next);
131 SV *tmpsv = newSVpv("", 0);
132 switch (o->op_flags & OPf_WANT) {
134 sv_catpv(tmpsv, ",VOID");
136 case OPf_WANT_SCALAR:
137 sv_catpv(tmpsv, ",SCALAR");
140 sv_catpv(tmpsv, ",LIST");
143 sv_catpv(tmpsv, ",UNKNOWN");
146 if (o->op_flags & OPf_KIDS)
147 sv_catpv(tmpsv, ",KIDS");
148 if (o->op_flags & OPf_PARENS)
149 sv_catpv(tmpsv, ",PARENS");
150 if (o->op_flags & OPf_STACKED)
151 sv_catpv(tmpsv, ",STACKED");
152 if (o->op_flags & OPf_REF)
153 sv_catpv(tmpsv, ",REF");
154 if (o->op_flags & OPf_MOD)
155 sv_catpv(tmpsv, ",MOD");
156 if (o->op_flags & OPf_SPECIAL)
157 sv_catpv(tmpsv, ",SPECIAL");
158 dump("FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
162 SV *tmpsv = newSVpv("", 0);
163 if (o->op_type == OP_AASSIGN) {
164 if (o->op_private & OPpASSIGN_COMMON)
165 sv_catpv(tmpsv, ",COMMON");
167 else if (o->op_type == OP_SASSIGN) {
168 if (o->op_private & OPpASSIGN_BACKWARDS)
169 sv_catpv(tmpsv, ",BACKWARDS");
171 else if (o->op_type == OP_TRANS) {
172 if (o->op_private & OPpTRANS_SQUASH)
173 sv_catpv(tmpsv, ",SQUASH");
174 if (o->op_private & OPpTRANS_DELETE)
175 sv_catpv(tmpsv, ",DELETE");
176 if (o->op_private & OPpTRANS_COMPLEMENT)
177 sv_catpv(tmpsv, ",COMPLEMENT");
179 else if (o->op_type == OP_REPEAT) {
180 if (o->op_private & OPpREPEAT_DOLIST)
181 sv_catpv(tmpsv, ",DOLIST");
183 else if (o->op_type == OP_ENTERSUB ||
184 o->op_type == OP_RV2SV ||
185 o->op_type == OP_RV2AV ||
186 o->op_type == OP_RV2HV ||
187 o->op_type == OP_RV2GV ||
188 o->op_type == OP_AELEM ||
189 o->op_type == OP_HELEM )
191 if (o->op_type == OP_ENTERSUB) {
192 if (o->op_private & OPpENTERSUB_AMPER)
193 sv_catpv(tmpsv, ",AMPER");
194 if (o->op_private & OPpENTERSUB_DB)
195 sv_catpv(tmpsv, ",DB");
197 switch (o->op_private & OPpDEREF) {
199 sv_catpv(tmpsv, ",SV");
202 sv_catpv(tmpsv, ",AV");
205 sv_catpv(tmpsv, ",HV");
208 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
209 if (o->op_private & OPpLVAL_DEFER)
210 sv_catpv(tmpsv, ",LVAL_DEFER");
213 if (o->op_private & HINT_STRICT_REFS)
214 sv_catpv(tmpsv, ",STRICT_REFS");
217 else if (o->op_type == OP_CONST) {
218 if (o->op_private & OPpCONST_BARE)
219 sv_catpv(tmpsv, ",BARE");
221 else if (o->op_type == OP_FLIP) {
222 if (o->op_private & OPpFLIP_LINENUM)
223 sv_catpv(tmpsv, ",LINENUM");
225 else if (o->op_type == OP_FLOP) {
226 if (o->op_private & OPpFLIP_LINENUM)
227 sv_catpv(tmpsv, ",LINENUM");
229 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
230 sv_catpv(tmpsv, ",INTRO");
232 dump("PRIVATE = (%s)\n", SvPVX(tmpsv) + 1);
236 switch (o->op_type) {
240 SV *tmpsv = NEWSV(0,0);
243 gv_fullname3(tmpsv, cGVOPo->op_gv, Nullch);
244 dump("GV = %s\n", SvPV(tmpsv, na));
251 dump("SV = %s\n", SvPEEK(cSVOPo->op_sv));
256 dump("LINE = %d\n",cCOPo->cop_line);
257 if (cCOPo->cop_label)
258 dump("LABEL = \"%s\"\n",cCOPo->cop_label);
262 if (cLOOPo->op_redoop)
263 PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_redoop->op_seq);
265 PerlIO_printf(Perl_debug_log, "DONE\n");
267 if (cLOOPo->op_nextop)
268 PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_nextop->op_seq);
270 PerlIO_printf(Perl_debug_log, "DONE\n");
272 if (cLOOPo->op_lastop)
273 PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_lastop->op_seq);
275 PerlIO_printf(Perl_debug_log, "DONE\n");
279 if (cCONDOPo->op_true)
280 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOPo->op_true->op_seq);
282 PerlIO_printf(Perl_debug_log, "DONE\n");
284 if (cCONDOPo->op_false)
285 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOPo->op_false->op_seq);
287 PerlIO_printf(Perl_debug_log, "DONE\n");
294 if (cLOGOPo->op_other)
295 PerlIO_printf(Perl_debug_log, "%d\n", cLOGOPo->op_other->op_seq);
297 PerlIO_printf(Perl_debug_log, "DONE\n");
307 if (o->op_flags & OPf_KIDS) {
309 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
314 #endif /* DEBUGGING */
324 PerlIO_printf(Perl_debug_log, "{}\n");
329 PerlIO_printf(Perl_debug_log, "{\n");
330 gv_fullname3(sv, gv, Nullch);
331 dump("GV_NAME = %s", SvPVX(sv));
332 if (gv != GvEGV(gv)) {
333 gv_efullname3(sv, GvEGV(gv), Nullch);
334 dump("-> %s", SvPVX(sv));
339 #endif /* DEBUGGING */
354 if (pm->op_pmflags & PMf_ONCE)
359 dump("PMf_PRE %c%s%c%s\n",
360 ch, pm->op_pmregexp->precomp, ch,
361 (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
363 dump("PMf_PRE (RUNTIME)\n");
364 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
366 dump_op(pm->op_pmreplroot);
368 if (pm->op_pmflags || (pm->op_pmregexp && pm->op_pmregexp->check_substr)) {
369 SV *tmpsv = newSVpv("", 0);
370 if (pm->op_pmdynflags & PMdf_USED)
371 sv_catpv(tmpsv, ",USED");
372 if (pm->op_pmflags & PMf_ONCE)
373 sv_catpv(tmpsv, ",ONCE");
374 if (pm->op_pmregexp && pm->op_pmregexp->check_substr
375 && !(pm->op_pmregexp->reganch & ROPT_NOSCAN))
376 sv_catpv(tmpsv, ",SCANFIRST");
377 if (pm->op_pmregexp && pm->op_pmregexp->check_substr
378 && pm->op_pmregexp->reganch & ROPT_CHECK_ALL)
379 sv_catpv(tmpsv, ",ALL");
380 if (pm->op_pmflags & PMf_SKIPWHITE)
381 sv_catpv(tmpsv, ",SKIPWHITE");
382 if (pm->op_pmflags & PMf_CONST)
383 sv_catpv(tmpsv, ",CONST");
384 if (pm->op_pmflags & PMf_KEEP)
385 sv_catpv(tmpsv, ",KEEP");
386 if (pm->op_pmflags & PMf_GLOBAL)
387 sv_catpv(tmpsv, ",GLOBAL");
388 if (pm->op_pmflags & PMf_CONTINUE)
389 sv_catpv(tmpsv, ",CONTINUE");
390 if (pm->op_pmflags & PMf_TAINTMEM)
391 sv_catpv(tmpsv, ",TAINTMEM");
392 if (pm->op_pmflags & PMf_EVAL)
393 sv_catpv(tmpsv, ",EVAL");
394 dump("PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
400 #endif /* DEBUGGING */
412 for (i = dumplvl*4; i; i--)
413 (void)PerlIO_putc(Perl_debug_log,' ');
414 PerlIO_vprintf(Perl_debug_log,pat,args);
416 #endif /* DEBUGGING */