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);
29 dump_op(PL_main_root);
30 dump_packsubs(PL_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);
48 if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv))
54 if (HeKEY(entry)[HeKLEN(entry)-1] == ':' &&
55 (hv = GvHV(gv)) && HvNAME(hv) && hv != PL_defstash)
56 dump_packsubs(hv); /* nested package */
59 #endif /* DEBUGGING */
66 SV *sv = sv_newmortal();
68 gv_fullname3(sv, gv, Nullch);
69 dump("\nSUB %s = ", SvPVX(sv));
71 dump("(xsub 0x%x %d)\n",
72 (long)CvXSUB(GvCV(gv)),
73 CvXSUBANY(GvCV(gv)).any_i32);
74 else if (CvROOT(GvCV(gv)))
75 dump_op(CvROOT(GvCV(gv)));
78 #endif /* DEBUGGING */
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)));
93 #endif /* DEBUGGING */
100 dump_op(PL_eval_root);
101 #endif /* DEBUGGING */
110 PerlIO_printf(Perl_debug_log, "%-4d", o->op_seq);
112 PerlIO_printf(Perl_debug_log, " ");
113 dump("TYPE = %s ===> ", op_name[o->op_type]);
116 PerlIO_printf(Perl_debug_log, "%d\n", o->op_next->op_seq);
118 PerlIO_printf(Perl_debug_log, "(%d)\n", o->op_next->op_seq);
121 PerlIO_printf(Perl_debug_log, "DONE\n");
124 if (o->op_type == OP_NULL)
125 dump(" (was %s)\n", op_name[o->op_targ]);
127 dump("TARG = %d\n", o->op_targ);
130 dump("ADDR = 0x%lx => 0x%lx\n",o, o->op_next);
133 SV *tmpsv = newSVpv("", 0);
134 switch (o->op_flags & OPf_WANT) {
136 sv_catpv(tmpsv, ",VOID");
138 case OPf_WANT_SCALAR:
139 sv_catpv(tmpsv, ",SCALAR");
142 sv_catpv(tmpsv, ",LIST");
145 sv_catpv(tmpsv, ",UNKNOWN");
148 if (o->op_flags & OPf_KIDS)
149 sv_catpv(tmpsv, ",KIDS");
150 if (o->op_flags & OPf_PARENS)
151 sv_catpv(tmpsv, ",PARENS");
152 if (o->op_flags & OPf_STACKED)
153 sv_catpv(tmpsv, ",STACKED");
154 if (o->op_flags & OPf_REF)
155 sv_catpv(tmpsv, ",REF");
156 if (o->op_flags & OPf_MOD)
157 sv_catpv(tmpsv, ",MOD");
158 if (o->op_flags & OPf_SPECIAL)
159 sv_catpv(tmpsv, ",SPECIAL");
160 dump("FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
164 SV *tmpsv = newSVpv("", 0);
165 if (o->op_type == OP_AASSIGN) {
166 if (o->op_private & OPpASSIGN_COMMON)
167 sv_catpv(tmpsv, ",COMMON");
169 else if (o->op_type == OP_SASSIGN) {
170 if (o->op_private & OPpASSIGN_BACKWARDS)
171 sv_catpv(tmpsv, ",BACKWARDS");
173 else if (o->op_type == OP_TRANS) {
174 if (o->op_private & OPpTRANS_SQUASH)
175 sv_catpv(tmpsv, ",SQUASH");
176 if (o->op_private & OPpTRANS_DELETE)
177 sv_catpv(tmpsv, ",DELETE");
178 if (o->op_private & OPpTRANS_COMPLEMENT)
179 sv_catpv(tmpsv, ",COMPLEMENT");
181 else if (o->op_type == OP_REPEAT) {
182 if (o->op_private & OPpREPEAT_DOLIST)
183 sv_catpv(tmpsv, ",DOLIST");
185 else if (o->op_type == OP_ENTERSUB ||
186 o->op_type == OP_RV2SV ||
187 o->op_type == OP_RV2AV ||
188 o->op_type == OP_RV2HV ||
189 o->op_type == OP_RV2GV ||
190 o->op_type == OP_AELEM ||
191 o->op_type == OP_HELEM )
193 if (o->op_type == OP_ENTERSUB) {
194 if (o->op_private & OPpENTERSUB_AMPER)
195 sv_catpv(tmpsv, ",AMPER");
196 if (o->op_private & OPpENTERSUB_DB)
197 sv_catpv(tmpsv, ",DB");
199 switch (o->op_private & OPpDEREF) {
201 sv_catpv(tmpsv, ",SV");
204 sv_catpv(tmpsv, ",AV");
207 sv_catpv(tmpsv, ",HV");
210 if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
211 if (o->op_private & OPpLVAL_DEFER)
212 sv_catpv(tmpsv, ",LVAL_DEFER");
215 if (o->op_private & HINT_STRICT_REFS)
216 sv_catpv(tmpsv, ",STRICT_REFS");
219 else if (o->op_type == OP_CONST) {
220 if (o->op_private & OPpCONST_BARE)
221 sv_catpv(tmpsv, ",BARE");
223 else if (o->op_type == OP_FLIP) {
224 if (o->op_private & OPpFLIP_LINENUM)
225 sv_catpv(tmpsv, ",LINENUM");
227 else if (o->op_type == OP_FLOP) {
228 if (o->op_private & OPpFLIP_LINENUM)
229 sv_catpv(tmpsv, ",LINENUM");
231 if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
232 sv_catpv(tmpsv, ",INTRO");
234 dump("PRIVATE = (%s)\n", SvPVX(tmpsv) + 1);
238 switch (o->op_type) {
242 SV *tmpsv = NEWSV(0,0);
245 gv_fullname3(tmpsv, cGVOPo->op_gv, Nullch);
246 dump("GV = %s\n", SvPV(tmpsv, PL_na));
253 dump("SV = %s\n", SvPEEK(cSVOPo->op_sv));
258 dump("LINE = %d\n",cCOPo->cop_line);
259 if (cCOPo->cop_label)
260 dump("LABEL = \"%s\"\n",cCOPo->cop_label);
264 if (cLOOPo->op_redoop)
265 PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_redoop->op_seq);
267 PerlIO_printf(Perl_debug_log, "DONE\n");
269 if (cLOOPo->op_nextop)
270 PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_nextop->op_seq);
272 PerlIO_printf(Perl_debug_log, "DONE\n");
274 if (cLOOPo->op_lastop)
275 PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_lastop->op_seq);
277 PerlIO_printf(Perl_debug_log, "DONE\n");
281 if (cCONDOPo->op_true)
282 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOPo->op_true->op_seq);
284 PerlIO_printf(Perl_debug_log, "DONE\n");
286 if (cCONDOPo->op_false)
287 PerlIO_printf(Perl_debug_log, "%d\n", cCONDOPo->op_false->op_seq);
289 PerlIO_printf(Perl_debug_log, "DONE\n");
296 if (cLOGOPo->op_other)
297 PerlIO_printf(Perl_debug_log, "%d\n", cLOGOPo->op_other->op_seq);
299 PerlIO_printf(Perl_debug_log, "DONE\n");
310 if (o->op_flags & OPf_KIDS) {
312 for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
317 #endif /* DEBUGGING */
327 PerlIO_printf(Perl_debug_log, "{}\n");
332 PerlIO_printf(Perl_debug_log, "{\n");
333 gv_fullname3(sv, gv, Nullch);
334 dump("GV_NAME = %s", SvPVX(sv));
335 if (gv != GvEGV(gv)) {
336 gv_efullname3(sv, GvEGV(gv), Nullch);
337 dump("-> %s", SvPVX(sv));
342 #endif /* DEBUGGING */
357 if (pm->op_pmflags & PMf_ONCE)
362 dump("PMf_PRE %c%s%c%s\n",
363 ch, pm->op_pmregexp->precomp, ch,
364 (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : "");
366 dump("PMf_PRE (RUNTIME)\n");
367 if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
369 dump_op(pm->op_pmreplroot);
371 if (pm->op_pmflags || (pm->op_pmregexp && pm->op_pmregexp->check_substr)) {
372 SV *tmpsv = newSVpv("", 0);
373 if (pm->op_pmdynflags & PMdf_USED)
374 sv_catpv(tmpsv, ",USED");
375 if (pm->op_pmdynflags & PMdf_TAINTED)
376 sv_catpv(tmpsv, ",TAINTED");
377 if (pm->op_pmflags & PMf_ONCE)
378 sv_catpv(tmpsv, ",ONCE");
379 if (pm->op_pmregexp && pm->op_pmregexp->check_substr
380 && !(pm->op_pmregexp->reganch & ROPT_NOSCAN))
381 sv_catpv(tmpsv, ",SCANFIRST");
382 if (pm->op_pmregexp && pm->op_pmregexp->check_substr
383 && pm->op_pmregexp->reganch & ROPT_CHECK_ALL)
384 sv_catpv(tmpsv, ",ALL");
385 if (pm->op_pmflags & PMf_SKIPWHITE)
386 sv_catpv(tmpsv, ",SKIPWHITE");
387 if (pm->op_pmflags & PMf_CONST)
388 sv_catpv(tmpsv, ",CONST");
389 if (pm->op_pmflags & PMf_KEEP)
390 sv_catpv(tmpsv, ",KEEP");
391 if (pm->op_pmflags & PMf_GLOBAL)
392 sv_catpv(tmpsv, ",GLOBAL");
393 if (pm->op_pmflags & PMf_CONTINUE)
394 sv_catpv(tmpsv, ",CONTINUE");
395 if (pm->op_pmflags & PMf_RETAINT)
396 sv_catpv(tmpsv, ",RETAINT");
397 if (pm->op_pmflags & PMf_EVAL)
398 sv_catpv(tmpsv, ",EVAL");
399 dump("PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
405 #endif /* DEBUGGING */
417 for (i = PL_dumplvl*4; i; i--)
418 (void)PerlIO_putc(Perl_debug_log,' ');
419 PerlIO_vprintf(Perl_debug_log,pat,args);
421 #endif /* DEBUGGING */