This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Initial 3-way merge from (5.001m, thr1m, 5.003) plus fixups.
[perl5.git] / deb.c
CommitLineData
a0d0e21e 1/* deb.c
79072805 2 *
a0d0e21e 3 * Copyright (c) 1991-1994, 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 29{
11343788 30 dTHR;
79072805 31 register I32 i;
a0d0e21e 32 GV* gv = curcop->cop_filegv;
79072805 33
11343788
MB
34#ifdef USE_THREADS
35 fprintf(stderr,"0x%lx (%s:%ld)\t",
36 (unsigned long) thr,
37 SvTYPE(gv) == SVt_PVGV ? SvPVX(GvSV(gv)) : "<free>",
38 (long)curcop->cop_line);
39#else
8990e307 40 fprintf(stderr,"(%s:%ld)\t",
a0d0e21e
LW
41 SvTYPE(gv) == SVt_PVGV ? SvPVX(GvSV(gv)) : "<free>",
42 (long)curcop->cop_line);
11343788 43#endif /* USE_THREADS */
79072805
LW
44 for (i=0; i<dlevel; i++)
45 fprintf(stderr,"%c%c ",debname[i],debdelim[i]);
46 fprintf(stderr,pat,a1,a2,a3,a4,a5,a6,a7,a8);
47}
8990e307 48
a0d0e21e 49#else /* !defined(I_STDARG) && !defined(I_VARARGS) */
8990e307 50
ecfc5424 51# ifdef I_STDARG
8990e307
LW
52void
53deb(char *pat, ...)
79072805
LW
54# else
55/*VARARGS1*/
8990e307
LW
56void
57deb(pat, va_alist)
58 char *pat;
59 va_dcl
60# endif
79072805 61{
11343788 62 dTHR;
79072805 63 va_list args;
79072805 64 register I32 i;
a0d0e21e 65 GV* gv = curcop->cop_filegv;
79072805 66
11343788
MB
67#ifdef USE_THREADS
68 fprintf(stderr,"0x%lx (%s:%ld)\t",
69 (unsigned long) thr,
70 SvTYPE(gv) == SVt_PVGV ? SvPVX(GvSV(gv)) : "<free>",
71 (long)curcop->cop_line);
72#else
8990e307 73 fprintf(stderr,"(%s:%ld)\t",
a0d0e21e
LW
74 SvTYPE(gv) == SVt_PVGV ? SvPVX(GvSV(gv)) : "<free>",
75 (long)curcop->cop_line);
11343788 76#endif /* USE_THREADS */
79072805
LW
77 for (i=0; i<dlevel; i++)
78 fprintf(stderr,"%c%c ",debname[i],debdelim[i]);
79
a0d0e21e 80# ifdef I_STDARG
8990e307
LW
81 va_start(args, pat);
82# else
83 va_start(args);
84# endif
79072805
LW
85 (void) vfprintf(stderr,pat,args);
86 va_end( args );
87}
a0d0e21e 88#endif /* !defined(I_STDARG) && !defined(I_VARARGS) */
79072805
LW
89
90void
91deb_growlevel()
92{
93 dlmax += 128;
94 Renew(debname, dlmax, char);
95 Renew(debdelim, dlmax, char);
96}
97
98I32
99debstackptrs()
100{
11343788 101 dTHR;
79072805 102 fprintf(stderr, "%8lx %8lx %8ld %8ld %8ld\n",
a0d0e21e
LW
103 (unsigned long)stack, (unsigned long)stack_base,
104 (long)*markstack_ptr, (long)(stack_sp-stack_base),
105 (long)(stack_max-stack_base));
106 fprintf(stderr, "%8lx %8lx %8ld %8ld %8ld\n",
107 (unsigned long)mainstack, (unsigned long)AvARRAY(stack),
108 (long)mainstack, (long)AvFILL(stack), (long)AvMAX(stack));
79072805
LW
109 return 0;
110}
111
112I32
113debstack()
114{
11343788 115 dTHR;
a0d0e21e
LW
116 I32 top = stack_sp - stack_base;
117 register I32 i = top - 30;
118 I32 *markscan = markstack;
119
120 if (i < 0)
121 i = 0;
122
123 while (++markscan <= markstack_ptr)
124 if (*markscan >= i)
125 break;
79072805 126
11343788
MB
127#ifdef USE_THREADS
128 fprintf(stderr, i ? "0x%lx => ... " : "0x%lx => ",
129 (unsigned long) thr);
130#else
a0d0e21e 131 fprintf(stderr, i ? " => ... " : " => ");
11343788 132#endif /* USE_THREADS */
a0d0e21e 133 if (stack_base[0] != &sv_undef || stack_sp < stack_base)
79072805 134 fprintf(stderr, " [STACK UNDERFLOW!!!]\n");
a0d0e21e
LW
135 do {
136 ++i;
137 if (markscan <= markstack_ptr && *markscan < i) {
138 do {
139 ++markscan;
140 putc('*', stderr);
141 }
142 while (markscan <= markstack_ptr && *markscan < i);
143 fprintf(stderr, " ");
79072805 144 }
a0d0e21e
LW
145 if (i > top)
146 break;
147 fprintf(stderr, "%-4s ", SvPEEK(stack_base[i]));
79072805 148 }
a0d0e21e 149 while (1);
79072805
LW
150 fprintf(stderr, "\n");
151 return 0;
152}
a0d0e21e
LW
153#else
154static int dummy; /* avoid totally empty deb.o file */
155#endif /* DEBUGGING */