3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 * 2002, 2003, 2004, 2005, 2006, 2007, 2008 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,
13 * I have seen more than thou knowest, Grey Fool.' --Denethor
15 * [p.853 of _The Lord of the Rings_, V/vii: "The Pyre of Denethor"]
19 * This file contains various utilities for producing debugging output
20 * (mainly related to displaying the stack)
27 #if defined(PERL_IMPLICIT_CONTEXT)
29 Perl_deb_nocontext(const char *pat, ...)
34 PERL_ARGS_ASSERT_DEB_NOCONTEXT;
40 #endif /* DEBUGGING */
45 Perl_deb(pTHX_ const char *pat, ...)
54 #endif /* DEBUGGING */
59 Perl_vdeb(pTHX_ const char *pat, va_list *args)
63 const char* const file = PL_curcop ? OutCopFILE(PL_curcop) : "<null>";
64 const char* const display_file = file ? file : "<free>";
65 const long line = PL_curcop ? (long)CopLINE(PL_curcop) : 0;
67 PERL_ARGS_ASSERT_VDEB;
70 PerlIO_printf(Perl_debug_log, "(%ld:%s:%ld)\t",
71 (long)PerlProc_getpid(), display_file, line);
73 PerlIO_printf(Perl_debug_log, "(%s:%ld)\t", display_file, line);
74 (void) PerlIO_vprintf(Perl_debug_log, pat, *args);
78 PERL_UNUSED_ARG(args);
79 #endif /* DEBUGGING */
83 Perl_debstackptrs(pTHX)
87 PerlIO_printf(Perl_debug_log,
88 "%8"UVxf" %8"UVxf" %8"IVdf" %8"IVdf" %8"IVdf"\n",
89 PTR2UV(PL_curstack), PTR2UV(PL_stack_base),
90 (IV)*PL_markstack_ptr, (IV)(PL_stack_sp-PL_stack_base),
91 (IV)(PL_stack_max-PL_stack_base));
92 PerlIO_printf(Perl_debug_log,
93 "%8"UVxf" %8"UVxf" %8"UVuf" %8"UVuf" %8"UVuf"\n",
94 PTR2UV(PL_mainstack), PTR2UV(AvARRAY(PL_curstack)),
95 PTR2UV(PL_mainstack), PTR2UV(AvFILLp(PL_curstack)),
96 PTR2UV(AvMAX(PL_curstack)));
97 #endif /* DEBUGGING */
102 /* dump the contents of a particular stack
103 * Display stack_base[stack_min+1 .. stack_max],
104 * and display the marks whose offsets are contained in addresses
105 * PL_markstack[mark_min+1 .. mark_max] and whose values are in the range
106 * of the stack values being displayed
108 * Only displays top 30 max
112 S_deb_stack_n(pTHX_ SV** stack_base, I32 stack_min, I32 stack_max,
113 I32 mark_min, I32 mark_max)
117 register I32 i = stack_max - 30;
118 const I32 *markscan = PL_markstack + mark_min;
120 PERL_ARGS_ASSERT_DEB_STACK_N;
125 while (++markscan <= PL_markstack + mark_max)
130 PerlIO_printf(Perl_debug_log, "... ");
132 if (stack_base[0] != &PL_sv_undef || stack_max < 0)
133 PerlIO_printf(Perl_debug_log, " [STACK UNDERFLOW!!!]\n");
136 if (markscan <= PL_markstack + mark_max && *markscan < i) {
139 PerlIO_putc(Perl_debug_log, '*');
141 while (markscan <= PL_markstack + mark_max && *markscan < i);
142 PerlIO_printf(Perl_debug_log, " ");
146 PerlIO_printf(Perl_debug_log, "%-4s ", SvPEEK(stack_base[i]));
149 PerlIO_printf(Perl_debug_log, "\n");
152 PERL_UNUSED_ARG(stack_base);
153 PERL_UNUSED_ARG(stack_min);
154 PERL_UNUSED_ARG(stack_max);
155 PERL_UNUSED_ARG(mark_min);
156 PERL_UNUSED_ARG(mark_max);
157 #endif /* DEBUGGING */
161 /* dump the current stack */
166 #ifndef SKIP_DEBUGGING
168 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
171 PerlIO_printf(Perl_debug_log, " => ");
172 deb_stack_n(PL_stack_base,
174 PL_stack_sp - PL_stack_base,
175 PL_curstackinfo->si_markoff,
176 PL_markstack_ptr - PL_markstack);
179 #endif /* SKIP_DEBUGGING */
185 static const char * const si_names[] = {
200 /* display all stacks */
204 Perl_deb_stack_all(pTHX)
211 /* rewind to start of chain */
212 si = PL_curstackinfo;
219 const size_t si_name_ix = si->si_type+1; /* -1 is a valid index */
220 const char * const si_name = (si_name_ix >= sizeof(si_names)) ? "????" : si_names[si_name_ix];
222 PerlIO_printf(Perl_debug_log, "STACK %"IVdf": %s\n",
225 for (ix=0; ix<=si->si_cxix; ix++) {
227 const PERL_CONTEXT * const cx = &(si->si_cxstack[ix]);
228 PerlIO_printf(Perl_debug_log,
229 " CX %"IVdf": %-6s => ",
230 (IV)ix, PL_block_type[CxTYPE(cx)]
232 /* substitution contexts don't save stack pointers etc) */
233 if (CxTYPE(cx) == CXt_SUBST)
234 PerlIO_printf(Perl_debug_log, "\n");
237 /* Find the the current context's stack range by searching
238 * forward for any higher contexts using this stack; failing
239 * that, it will be equal to the size of the stack for old
240 * stacks, or PL_stack_sp for the current stack
243 I32 i, stack_min, stack_max, mark_min, mark_max;
244 const PERL_CONTEXT *cx_n = NULL;
247 /* there's a separate stack per SI, so only search
250 for (i=ix+1; i<=si->si_cxix; i++) {
251 if (CxTYPE(cx) == CXt_SUBST)
253 cx_n = &(si->si_cxstack[i]);
257 stack_min = cx->blk_oldsp;
260 stack_max = cx_n->blk_oldsp;
262 else if (si == PL_curstackinfo) {
263 stack_max = PL_stack_sp - AvARRAY(si->si_stack);
266 stack_max = AvFILLp(si->si_stack);
269 /* for the other stack types, there's only one stack
270 * shared between all SIs */
277 if (i > si_n->si_cxix) {
278 if (si_n == PL_curstackinfo)
281 si_n = si_n->si_next;
285 if (CxTYPE(&(si_n->si_cxstack[i])) == CXt_SUBST)
287 cx_n = &(si_n->si_cxstack[i]);
291 mark_min = cx->blk_oldmarksp;
293 mark_max = cx_n->blk_oldmarksp;
296 mark_max = PL_markstack_ptr - PL_markstack;
299 deb_stack_n(AvARRAY(si->si_stack),
300 stack_min, stack_max, mark_min, mark_max);
302 if (CxTYPE(cx) == CXt_EVAL || CxTYPE(cx) == CXt_SUB
303 || CxTYPE(cx) == CXt_FORMAT)
305 const OP * const retop = cx->blk_sub.retop;
307 PerlIO_printf(Perl_debug_log, " retop=%s\n",
308 retop ? OP_NAME(retop) : "(null)"
315 if (si == PL_curstackinfo)
320 break; /* shouldn't happen, but just in case.. */
321 } /* next stackinfo */
323 PerlIO_printf(Perl_debug_log, "\n");
326 #endif /* DEBUGGING */
331 * c-indentation-style: bsd
333 * indent-tabs-mode: t
336 * ex: set ts=8 sts=4 sw=4 noet: