3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "Didst thou think that the eyes of the White Tower were blind? Nay, I
13 * have seen more than thou knowest, Gray Fool." --Denethor
17 * This file contains various utilities for producing debugging output
18 * (mainly related to displaying the stack)
25 #if defined(PERL_IMPLICIT_CONTEXT)
27 Perl_deb_nocontext(const char *pat, ...)
35 #endif /* DEBUGGING */
40 Perl_deb(pTHX_ const char *pat, ...)
49 #endif /* DEBUGGING */
53 Perl_vdeb(pTHX_ const char *pat, va_list *args)
57 char* file = OutCopFILE(PL_curcop);
59 PerlIO_printf(Perl_debug_log, "(%s:%ld)\t", (file ? file : "<free>"),
60 (long)CopLINE(PL_curcop));
61 (void) PerlIO_vprintf(Perl_debug_log, pat, *args);
64 PERL_UNUSED_ARG(args);
65 #endif /* DEBUGGING */
69 Perl_debstackptrs(pTHX)
73 PerlIO_printf(Perl_debug_log,
74 "%8"UVxf" %8"UVxf" %8"IVdf" %8"IVdf" %8"IVdf"\n",
75 PTR2UV(PL_curstack), PTR2UV(PL_stack_base),
76 (IV)*PL_markstack_ptr, (IV)(PL_stack_sp-PL_stack_base),
77 (IV)(PL_stack_max-PL_stack_base));
78 PerlIO_printf(Perl_debug_log,
79 "%8"UVxf" %8"UVxf" %8"UVuf" %8"UVuf" %8"UVuf"\n",
80 PTR2UV(PL_mainstack), PTR2UV(AvARRAY(PL_curstack)),
81 PTR2UV(PL_mainstack), PTR2UV(AvFILLp(PL_curstack)),
82 PTR2UV(AvMAX(PL_curstack)));
83 #endif /* DEBUGGING */
88 /* dump the contents of a particular stack
89 * Display stack_base[stack_min+1 .. stack_max],
90 * and display the marks whose offsets are contained in addresses
91 * PL_markstack[mark_min+1 .. mark_max] and whose values are in the range
92 * of the stack values being displayed
94 * Only displays top 30 max
98 S_deb_stack_n(pTHX_ SV** stack_base, I32 stack_min, I32 stack_max,
99 I32 mark_min, I32 mark_max)
103 register I32 i = stack_max - 30;
104 const I32 *markscan = PL_markstack + mark_min;
108 while (++markscan <= PL_markstack + mark_max)
113 PerlIO_printf(Perl_debug_log, "... ");
115 if (stack_base[0] != &PL_sv_undef || stack_max < 0)
116 PerlIO_printf(Perl_debug_log, " [STACK UNDERFLOW!!!]\n");
119 if (markscan <= PL_markstack + mark_max && *markscan < i) {
122 PerlIO_putc(Perl_debug_log, '*');
124 while (markscan <= PL_markstack + mark_max && *markscan < i);
125 PerlIO_printf(Perl_debug_log, " ");
129 PerlIO_printf(Perl_debug_log, "%-4s ", SvPEEK(stack_base[i]));
132 PerlIO_printf(Perl_debug_log, "\n");
134 PERL_UNUSED_ARG(stack_base);
135 PERL_UNUSED_ARG(stack_min);
136 PERL_UNUSED_ARG(stack_max);
137 PERL_UNUSED_ARG(mark_min);
138 PERL_UNUSED_ARG(mark_max);
139 #endif /* DEBUGGING */
143 /* dump the current stack */
148 #ifndef SKIP_DEBUGGING
150 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
153 PerlIO_printf(Perl_debug_log, " => ");
154 deb_stack_n(PL_stack_base,
156 PL_stack_sp - PL_stack_base,
157 PL_curstackinfo->si_markoff,
158 PL_markstack_ptr - PL_markstack);
161 #endif /* SKIP_DEBUGGING */
167 static const char * const si_names[] = {
182 /* display all stacks */
186 Perl_deb_stack_all(pTHX)
193 /* rewind to start of chain */
194 si = PL_curstackinfo;
201 const int si_name_ix = si->si_type+1; /* -1 is a valid index */
202 const char * const si_name = (si_name_ix>= sizeof(si_names)) ? "????" : si_names[si_name_ix];
204 PerlIO_printf(Perl_debug_log, "STACK %"IVdf": %s\n",
207 for (ix=0; ix<=si->si_cxix; ix++) {
209 const PERL_CONTEXT * const cx = &(si->si_cxstack[ix]);
210 PerlIO_printf(Perl_debug_log,
211 " CX %"IVdf": %-6s => ",
212 (IV)ix, PL_block_type[CxTYPE(cx)]
214 /* substitution contexts don't save stack pointers etc) */
215 if (CxTYPE(cx) == CXt_SUBST)
216 PerlIO_printf(Perl_debug_log, "\n");
219 /* Find the the current context's stack range by searching
220 * forward for any higher contexts using this stack; failing
221 * that, it will be equal to the size of the stack for old
222 * stacks, or PL_stack_sp for the current stack
225 I32 i, stack_min, stack_max, mark_min, mark_max;
226 const PERL_CONTEXT *cx_n;
229 cx_n = Null(PERL_CONTEXT*);
231 /* there's a separate stack per SI, so only search
234 for (i=ix+1; i<=si->si_cxix; i++) {
235 if (CxTYPE(cx) == CXt_SUBST)
237 cx_n = &(si->si_cxstack[i]);
241 stack_min = cx->blk_oldsp;
244 stack_max = cx_n->blk_oldsp;
246 else if (si == PL_curstackinfo) {
247 stack_max = PL_stack_sp - AvARRAY(si->si_stack);
250 stack_max = AvFILLp(si->si_stack);
253 /* for the other stack types, there's only one stack
254 * shared between all SIs */
258 cx_n = Null(PERL_CONTEXT*);
261 if (i > si_n->si_cxix) {
262 if (si_n == PL_curstackinfo)
265 si_n = si_n->si_next;
269 if (CxTYPE(&(si_n->si_cxstack[i])) == CXt_SUBST)
271 cx_n = &(si_n->si_cxstack[i]);
275 mark_min = cx->blk_oldmarksp;
277 mark_max = cx_n->blk_oldmarksp;
280 mark_max = PL_markstack_ptr - PL_markstack;
283 deb_stack_n(AvARRAY(si->si_stack),
284 stack_min, stack_max, mark_min, mark_max);
286 if (CxTYPE(cx) == CXt_EVAL || CxTYPE(cx) == CXt_SUB
287 || CxTYPE(cx) == CXt_FORMAT)
289 const OP * const retop = (CxTYPE(cx) == CXt_EVAL)
290 ? cx->blk_eval.retop : cx->blk_sub.retop;
292 PerlIO_printf(Perl_debug_log, " retop=%s\n",
293 retop ? OP_NAME(retop) : "(null)"
300 if (si == PL_curstackinfo)
305 break; /* shouldn't happen, but just in case.. */
306 } /* next stackinfo */
308 PerlIO_printf(Perl_debug_log, "\n");
309 #endif /* DEBUGGING */
314 * c-indentation-style: bsd
316 * indent-tabs-mode: t
319 * ex: set ts=8 sts=4 sw=4 noet: