perl 5.0 alpha 8
[p5sagit/p5-mst-13.2.git] / deb.c
1 /* $RCSfile: op.c,v $$Revision: 4.1 $$Date: 92/08/07 17:19:16 $
2  *
3  *    Copyright (c) 1991, Larry Wall
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  *
8  * $Log:        op.c,v $
9  * Revision 4.1  92/08/07  17:19:16  lwall
10  * Stage 6 Snapshot
11  * 
12  * Revision 4.0.1.5  92/06/08  12:00:39  lwall
13  * patch20: the switch optimizer didn't do anything in subroutines
14  * patch20: removed implicit int declarations on funcions
15  * 
16  * Revision 4.0.1.4  91/11/11  16:29:33  lwall
17  * patch19: do {$foo ne "bar";} returned wrong value
18  * patch19: some earlier patches weren't propagated to alternate 286 code
19  * 
20  * Revision 4.0.1.3  91/11/05  16:07:43  lwall
21  * patch11: random cleanup
22  * patch11: "foo\0" eq "foo" was sometimes optimized to true
23  * patch11: foreach on null list could spring memory leak
24  * 
25  * Revision 4.0.1.2  91/06/07  10:26:45  lwall
26  * patch4: new copyright notice
27  * patch4: made some allowances for "semi-standard" C
28  * 
29  * Revision 4.0.1.1  91/04/11  17:36:16  lwall
30  * patch1: you may now use "die" and "caller" in a signal handler
31  * 
32  * Revision 4.0  91/03/20  01:04:18  lwall
33  * 4.0 baseline.
34  * 
35  */
36
37 #include "EXTERN.h"
38 #include "perl.h"
39
40 void deb_growlevel();
41
42 #if !defined(STANDARD_C) && !defined(I_VARARGS)
43
44 /*
45  * Fallback on the old hackers way of doing varargs
46  */
47
48 /*VARARGS1*/
49 void
50 deb(pat,a1,a2,a3,a4,a5,a6,a7,a8)
51     char *pat;
52 {
53     register I32 i;
54
55     fprintf(stderr,"(%s:%ld)\t",
56         SvPVX(GvSV(curcop->cop_filegv)),(long)curcop->cop_line);
57     for (i=0; i<dlevel; i++)
58         fprintf(stderr,"%c%c ",debname[i],debdelim[i]);
59     fprintf(stderr,pat,a1,a2,a3,a4,a5,a6,a7,a8);
60 }
61
62 #else /* !defined(STANDARD_C) && !defined(I_VARARGS) */
63
64 #  ifdef STANDARD_C
65 void
66 deb(char *pat, ...)
67 #  else
68 /*VARARGS1*/
69 void
70 deb(pat, va_alist)
71     char *pat;
72     va_dcl
73 #  endif
74 {
75     va_list args;
76     register I32 i;
77
78     fprintf(stderr,"(%s:%ld)\t",
79         SvPVX(GvSV(curcop->cop_filegv)),(long)curcop->cop_line);
80     for (i=0; i<dlevel; i++)
81         fprintf(stderr,"%c%c ",debname[i],debdelim[i]);
82
83 #  if STANDARD_C
84     va_start(args, pat);
85 #  else
86     va_start(args);
87 #  endif
88     (void) vfprintf(stderr,pat,args);
89     va_end( args );
90 }
91 #endif /* !defined(STANDARD_C) && !defined(I_VARARGS) */
92
93 void
94 deb_growlevel()
95 {
96     dlmax += 128;
97     Renew(debname, dlmax, char);
98     Renew(debdelim, dlmax, char);
99 }
100
101 I32
102 debstackptrs()
103 {
104     fprintf(stderr, "%8lx %8lx %8ld %8ld %8ld\n",
105         stack, stack_base, *markstack_ptr, stack_sp-stack_base, stack_max-stack_base);
106     fprintf(stderr, "%8lx %8lx %8ld %l8d %8ld\n",
107         mainstack, AvARRAY(stack), mainstack, AvFILL(stack), AvMAX(stack));
108     return 0;
109 }
110
111 I32
112 debstack()
113 {
114     register I32 i;
115     I32 markoff = markstack_ptr > markstack ? *markstack_ptr : -1;
116
117     fprintf(stderr, "     =>");
118     if (stack_base[0] || stack_sp < stack_base)
119         fprintf(stderr, " [STACK UNDERFLOW!!!]\n");
120     for (i = 1; i <= 30; i++) {
121         if (stack_sp >= &stack_base[i])
122         {
123             fprintf(stderr, "\t%-4s%s%s", SvPEEK(stack_base[i]),
124                 markoff == i ? " [" : "",
125                 stack_sp == &stack_base[i] ?
126                         (markoff == i ? "]" : " ]") : "");
127         }
128     }
129     fprintf(stderr, "\n");
130     return 0;
131 }