3 * Copyright (c) 1991-2002, 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 * "Didst thou think that the eyes of the White Tower were blind? Nay, I
12 * have seen more than thou knowest, Gray Fool." --Denethor
19 #if defined(PERL_IMPLICIT_CONTEXT)
21 Perl_deb_nocontext(const char *pat, ...)
29 #endif /* DEBUGGING */
34 Perl_deb(pTHX_ const char *pat, ...)
41 #endif /* DEBUGGING */
45 Perl_vdeb(pTHX_ const char *pat, va_list *args)
48 char* file = OutCopFILE(PL_curcop);
50 PerlIO_printf(Perl_debug_log, "(%s:%ld)\t", (file ? file : "<free>"),
51 (long)CopLINE(PL_curcop));
52 (void) PerlIO_vprintf(Perl_debug_log, pat, *args);
53 #endif /* DEBUGGING */
57 Perl_debstackptrs(pTHX)
60 PerlIO_printf(Perl_debug_log,
61 "%8"UVxf" %8"UVxf" %8"IVdf" %8"IVdf" %8"IVdf"\n",
62 PTR2UV(PL_curstack), PTR2UV(PL_stack_base),
63 (IV)*PL_markstack_ptr, (IV)(PL_stack_sp-PL_stack_base),
64 (IV)(PL_stack_max-PL_stack_base));
65 PerlIO_printf(Perl_debug_log,
66 "%8"UVxf" %8"UVxf" %8"UVuf" %8"UVuf" %8"UVuf"\n",
67 PTR2UV(PL_mainstack), PTR2UV(AvARRAY(PL_curstack)),
68 PTR2UV(PL_mainstack), PTR2UV(AvFILLp(PL_curstack)),
69 PTR2UV(AvMAX(PL_curstack)));
70 #endif /* DEBUGGING */
75 /* dump the contents of a particular stack
76 * Display stack_base[stack_min+1 .. stack_max],
77 * and display the marks whose offsets are contained in addresses
78 * PL_markstack[mark_min+1 .. mark_max] and whose values are in the range
79 * of the stack values being displayed
81 * Only displays top 30 max
85 S_deb_stack_n(pTHX_ SV** stack_base, I32 stack_min, I32 stack_max,
86 I32 mark_min, I32 mark_max)
89 register I32 i = stack_max - 30;
90 I32 *markscan = PL_markstack + mark_min;
94 while (++markscan <= PL_markstack + mark_max)
99 PerlIO_printf(Perl_debug_log, "... ");
101 if (stack_base[0] != &PL_sv_undef || stack_max < 0)
102 PerlIO_printf(Perl_debug_log, " [STACK UNDERFLOW!!!]\n");
105 if (markscan <= PL_markstack + mark_max && *markscan < i) {
108 PerlIO_putc(Perl_debug_log, '*');
110 while (markscan <= PL_markstack + mark_max && *markscan < i);
111 PerlIO_printf(Perl_debug_log, " ");
115 PerlIO_printf(Perl_debug_log, "%-4s ", SvPEEK(stack_base[i]));
118 PerlIO_printf(Perl_debug_log, "\n");
119 #endif /* DEBUGGING */
123 /* dump the current stack */
128 #ifndef SKIP_DEBUGGING
129 if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_)
132 PerlIO_printf(Perl_debug_log, " => ");
133 deb_stack_n(PL_stack_base,
135 PL_stack_sp - PL_stack_base,
136 PL_curstackinfo->si_markoff,
137 PL_markstack_ptr - PL_markstack);
140 #endif /* SKIP_DEBUGGING */
146 static char * si_names[] = {
161 /* display all stacks */
165 Perl_deb_stack_all(pTHX)
172 /* rewind to start of chain */
173 si = PL_curstackinfo;
181 int si_name_ix = si->si_type+1; /* -1 is a valid index */
182 if (si_name_ix>= sizeof(si_names))
185 si_name = si_names[si_name_ix];
186 PerlIO_printf(Perl_debug_log, "STACK %"IVdf": %s\n",
189 for (ix=0; ix<=si->si_cxix; ix++) {
191 cx = &(si->si_cxstack[ix]);
192 PerlIO_printf(Perl_debug_log,
193 " CX %"IVdf": %-6s => ",
194 (IV)ix, PL_block_type[CxTYPE(cx)]
196 /* substitution contexts don't save stack pointers etc) */
197 if (CxTYPE(cx) == CXt_SUBST)
198 PerlIO_printf(Perl_debug_log, "\n");
201 /* Find the the current context's stack range by searching
202 * forward for any higher contexts using this stack; failing
203 * that, it will be equal to the size of the stack for old
204 * stacks, or PL_stack_sp for the current stack
207 I32 i, stack_min, stack_max, mark_min, mark_max;
208 I32 ret_min, ret_max;
212 cx_n = Null(PERL_CONTEXT*);
214 /* there's a separate stack per SI, so only search
217 for (i=ix+1; i<=si->si_cxix; i++) {
218 if (CxTYPE(cx) == CXt_SUBST)
220 cx_n = &(si->si_cxstack[i]);
224 stack_min = cx->blk_oldsp;
227 stack_max = cx_n->blk_oldsp;
229 else if (si == PL_curstackinfo) {
230 stack_max = PL_stack_sp - AvARRAY(si->si_stack);
233 stack_max = AvFILLp(si->si_stack);
236 /* for the other stack types, there's only one stack
237 * shared between all SIs */
241 cx_n = Null(PERL_CONTEXT*);
244 if (i > si_n->si_cxix) {
245 if (si_n == PL_curstackinfo)
248 si_n = si_n->si_next;
252 if (CxTYPE(&(si_n->si_cxstack[i])) == CXt_SUBST)
254 cx_n = &(si_n->si_cxstack[i]);
258 mark_min = cx->blk_oldmarksp;
259 ret_min = cx->blk_oldretsp;
261 mark_max = cx_n->blk_oldmarksp;
262 ret_max = cx_n->blk_oldretsp;
265 mark_max = PL_markstack_ptr - PL_markstack;
266 ret_max = PL_retstack_ix;
269 deb_stack_n(AvARRAY(si->si_stack),
270 stack_min, stack_max, mark_min, mark_max);
272 if (ret_max > ret_min) {
273 PerlIO_printf(Perl_debug_log, " retop=%s\n",
275 ? OP_NAME(PL_retstack[ret_min])
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 */