This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Patch for perl.pod
[perl5.git] / deb.c
CommitLineData
a0d0e21e 1/* deb.c
79072805 2 *
9607fc9c 3 * Copyright (c) 1991-1997, Larry Wall
79072805
LW
4 *
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.
7 *
a0d0e21e
LW
8 */
9
10/*
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
79072805
LW
13 */
14
15#include "EXTERN.h"
16#include "perl.h"
17
a0d0e21e
LW
18#ifdef DEBUGGING
19#if !defined(I_STDARG) && !defined(I_VARARGS)
8990e307
LW
20
21/*
22 * Fallback on the old hackers way of doing varargs
23 */
24
79072805 25/*VARARGS1*/
8990e307
LW
26void
27deb(pat,a1,a2,a3,a4,a5,a6,a7,a8)
28 char *pat;
79072805
LW
29{
30 register I32 i;
a0d0e21e 31 GV* gv = curcop->cop_filegv;
79072805 32
760ac839 33 PerlIO_printf(Perl_debug_log, "(%s:%ld)\t",
a0d0e21e
LW
34 SvTYPE(gv) == SVt_PVGV ? SvPVX(GvSV(gv)) : "<free>",
35 (long)curcop->cop_line);
79072805 36 for (i=0; i<dlevel; i++)
760ac839
LW
37 PerlIO_printf(Perl_debug_log, "%c%c ",debname[i],debdelim[i]);
38 PerlIO_printf(Perl_debug_log, pat,a1,a2,a3,a4,a5,a6,a7,a8);
79072805 39}
8990e307 40
a0d0e21e 41#else /* !defined(I_STDARG) && !defined(I_VARARGS) */
8990e307 42
ecfc5424 43# ifdef I_STDARG
8990e307 44void
71be2cbc 45deb(const char *pat, ...)
79072805
LW
46# else
47/*VARARGS1*/
8990e307
LW
48void
49deb(pat, va_alist)
71be2cbc 50 const char *pat;
8990e307
LW
51 va_dcl
52# endif
79072805
LW
53{
54 va_list args;
79072805 55 register I32 i;
a0d0e21e 56 GV* gv = curcop->cop_filegv;
79072805 57
760ac839 58 PerlIO_printf(Perl_debug_log, "(%s:%ld)\t",
a0d0e21e
LW
59 SvTYPE(gv) == SVt_PVGV ? SvPVX(GvSV(gv)) : "<free>",
60 (long)curcop->cop_line);
79072805 61 for (i=0; i<dlevel; i++)
760ac839 62 PerlIO_printf(Perl_debug_log, "%c%c ",debname[i],debdelim[i]);
79072805 63
a0d0e21e 64# ifdef I_STDARG
8990e307
LW
65 va_start(args, pat);
66# else
67 va_start(args);
68# endif
760ac839 69 (void) PerlIO_vprintf(Perl_debug_log,pat,args);
79072805
LW
70 va_end( args );
71}
a0d0e21e 72#endif /* !defined(I_STDARG) && !defined(I_VARARGS) */
79072805
LW
73
74void
75deb_growlevel()
76{
77 dlmax += 128;
78 Renew(debname, dlmax, char);
79 Renew(debdelim, dlmax, char);
80}
81
82I32
83debstackptrs()
84{
760ac839 85 PerlIO_printf(Perl_debug_log, "%8lx %8lx %8ld %8ld %8ld\n",
0c2634fc 86 (unsigned long)curstack, (unsigned long)stack_base,
a0d0e21e
LW
87 (long)*markstack_ptr, (long)(stack_sp-stack_base),
88 (long)(stack_max-stack_base));
760ac839 89 PerlIO_printf(Perl_debug_log, "%8lx %8lx %8ld %8ld %8ld\n",
0c2634fc 90 (unsigned long)mainstack, (unsigned long)AvARRAY(curstack),
91 (long)mainstack, (long)AvFILL(curstack), (long)AvMAX(curstack));
79072805
LW
92 return 0;
93}
94
95I32
96debstack()
97{
a0d0e21e
LW
98 I32 top = stack_sp - stack_base;
99 register I32 i = top - 30;
100 I32 *markscan = markstack;
101
102 if (i < 0)
103 i = 0;
104
105 while (++markscan <= markstack_ptr)
106 if (*markscan >= i)
107 break;
79072805 108
760ac839 109 PerlIO_printf(Perl_debug_log, i ? " => ... " : " => ");
a0d0e21e 110 if (stack_base[0] != &sv_undef || stack_sp < stack_base)
760ac839 111 PerlIO_printf(Perl_debug_log, " [STACK UNDERFLOW!!!]\n");
a0d0e21e
LW
112 do {
113 ++i;
114 if (markscan <= markstack_ptr && *markscan < i) {
115 do {
116 ++markscan;
760ac839 117 PerlIO_putc(Perl_debug_log, '*');
a0d0e21e
LW
118 }
119 while (markscan <= markstack_ptr && *markscan < i);
760ac839 120 PerlIO_printf(Perl_debug_log, " ");
79072805 121 }
a0d0e21e
LW
122 if (i > top)
123 break;
760ac839 124 PerlIO_printf(Perl_debug_log, "%-4s ", SvPEEK(stack_base[i]));
79072805 125 }
a0d0e21e 126 while (1);
760ac839 127 PerlIO_printf(Perl_debug_log, "\n");
79072805
LW
128 return 0;
129}
a0d0e21e
LW
130#else
131static int dummy; /* avoid totally empty deb.o file */
132#endif /* DEBUGGING */