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