3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 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, ...)
47 #endif /* DEBUGGING */
51 Perl_vdeb(pTHX_ const char *pat, va_list *args)
54 char* file = OutCopFILE(PL_curcop);
56 PerlIO_printf(Perl_debug_log, "(%s:%ld)\t", (file ? file : "<free>"),
57 (long)CopLINE(PL_curcop));
58 (void) PerlIO_vprintf(Perl_debug_log, pat, *args);
59 #endif /* DEBUGGING */
63 Perl_debstackptrs(pTHX)
66 PerlIO_printf(Perl_debug_log,
67 "%8"UVxf" %8"UVxf" %8"IVdf" %8"IVdf" %8"IVdf"\n",
68 PTR2UV(PL_curstack), PTR2UV(PL_stack_base),
69 (IV)*PL_markstack_ptr, (IV)(PL_stack_sp-PL_stack_base),
70 (IV)(PL_stack_max-PL_stack_base));
71 PerlIO_printf(Perl_debug_log,
72 "%8"UVxf" %8"UVxf" %8"UVuf" %8"UVuf" %8"UVuf"\n",
73 PTR2UV(PL_mainstack), PTR2UV(AvARRAY(PL_curstack)),
74 PTR2UV(PL_mainstack), PTR2UV(AvFILLp(PL_curstack)),
75 PTR2UV(AvMAX(PL_curstack)));
76 #endif /* DEBUGGING */
81 /* dump the contents of a particular stack
82 * Display stack_base[stack_min+1 .. stack_max],
83 * and display the marks whose offsets are contained in addresses
84 * PL_markstack[mark_min+1 .. mark_max] and whose values are in the range
85 * of the stack values being displayed
87 * Only displays top 30 max
91 S_deb_stack_n(pTHX_ SV** stack_base, I32 stack_min, I32 stack_max,
92 I32 mark_min, I32 mark_max)
95 register I32 i = stack_max - 30;
96 const I32 *markscan = PL_markstack + mark_min;
100 while (++markscan <= PL_markstack + mark_max)
105 PerlIO_printf(Perl_debug_log, "... ");
107 if (stack_base[0] != &PL_sv_undef || stack_max < 0)
108 PerlIO_printf(Perl_debug_log, " [STACK UNDERFLOW!!!]\n");
111 if (markscan <= PL_markstack + mark_max && *markscan < i) {
114 PerlIO_putc(Perl_debug_log, '*');
116 while (markscan <= PL_markstack + mark_max && *markscan < i);
117 PerlIO_printf(Perl_debug_log, " ");
121 PerlIO_printf(Perl_debug_log, "%-4s ", SvPEEK(stack_base[i]));
124 PerlIO_printf(Perl_debug_log, "\n");
125 #endif /* DEBUGGING */
129 /* dump the current stack */
134 #ifndef SKIP_DEBUGGING
135 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
138 PerlIO_printf(Perl_debug_log, " => ");
139 deb_stack_n(PL_stack_base,
141 PL_stack_sp - PL_stack_base,
142 PL_curstackinfo->si_markoff,
143 PL_markstack_ptr - PL_markstack);
146 #endif /* SKIP_DEBUGGING */
152 static const char * si_names[] = {
167 /* display all stacks */
171 Perl_deb_stack_all(pTHX)
177 /* rewind to start of chain */
178 si = PL_curstackinfo;
185 const int si_name_ix = si->si_type+1; /* -1 is a valid index */
186 const char *si_name = (si_name_ix>= sizeof(si_names)) ? "????" : si_names[si_name_ix];
187 PerlIO_printf(Perl_debug_log, "STACK %"IVdf": %s\n",
190 for (ix=0; ix<=si->si_cxix; ix++) {
192 const PERL_CONTEXT *cx = &(si->si_cxstack[ix]);
193 PerlIO_printf(Perl_debug_log,
194 " CX %"IVdf": %-6s => ",
195 (IV)ix, PL_block_type[CxTYPE(cx)]
197 /* substitution contexts don't save stack pointers etc) */
198 if (CxTYPE(cx) == CXt_SUBST)
199 PerlIO_printf(Perl_debug_log, "\n");
202 /* Find the the current context's stack range by searching
203 * forward for any higher contexts using this stack; failing
204 * that, it will be equal to the size of the stack for old
205 * stacks, or PL_stack_sp for the current stack
208 I32 i, stack_min, stack_max, mark_min, mark_max;
213 cx_n = Null(PERL_CONTEXT*);
215 /* there's a separate stack per SI, so only search
218 for (i=ix+1; i<=si->si_cxix; i++) {
219 if (CxTYPE(cx) == CXt_SUBST)
221 cx_n = &(si->si_cxstack[i]);
225 stack_min = cx->blk_oldsp;
228 stack_max = cx_n->blk_oldsp;
230 else if (si == PL_curstackinfo) {
231 stack_max = PL_stack_sp - AvARRAY(si->si_stack);
234 stack_max = AvFILLp(si->si_stack);
237 /* for the other stack types, there's only one stack
238 * shared between all SIs */
242 cx_n = Null(PERL_CONTEXT*);
245 if (i > si_n->si_cxix) {
246 if (si_n == PL_curstackinfo)
249 si_n = si_n->si_next;
253 if (CxTYPE(&(si_n->si_cxstack[i])) == CXt_SUBST)
255 cx_n = &(si_n->si_cxstack[i]);
259 mark_min = cx->blk_oldmarksp;
261 mark_max = cx_n->blk_oldmarksp;
264 mark_max = PL_markstack_ptr - PL_markstack;
267 deb_stack_n(AvARRAY(si->si_stack),
268 stack_min, stack_max, mark_min, mark_max);
270 if (CxTYPE(cx) == CXt_EVAL || CxTYPE(cx) == CXt_SUB
271 || CxTYPE(cx) == CXt_FORMAT)
273 retop = (CxTYPE(cx) == CXt_EVAL)
274 ? cx->blk_eval.retop : cx->blk_sub.retop;
276 PerlIO_printf(Perl_debug_log, " retop=%s\n",
277 retop ? OP_NAME(retop) : "(null)"
284 if (si == PL_curstackinfo)
289 break; /* shouldn't happen, but just in case.. */
290 } /* next stackinfo */
292 PerlIO_printf(Perl_debug_log, "\n");
293 #endif /* DEBUGGING */
298 * c-indentation-style: bsd
300 * indent-tabs-mode: t
303 * ex: set ts=8 sts=4 sw=4 noet: