source: buchla-68k/ram/dbentr.c@ 0580615

Last change on this file since 0580615 was 0580615, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Point of no return.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 =============================================================================
3 dbentr.c -- debug trace support functions
4 Version 3 -- 1988-03-03 -- D.N. Lynx Crowe
5
6 Use with the "debug.h" header file. Define DEBUGGER to include
7 debug trace code.
8
9 Synopsis:
10
11 Macros:
12
13 DB_ENTR(str) trace an entry
14 DB_EXIT(str) trace an exit
15 DB_CMNT(str) put a comment in the trace
16
17 Functions:
18
19 DB_Clr() clear the debug buffer
20 DB_Dump() dump and clear the debug buffer
21
22 DB_Entr(str) trace an entry
23 DB_Exit(str) trace an exit
24 DB_Cmnt(str) put a comment in the trace
25
26 Variables:
27
28 DB_Flag don't trap to ROMP if non-zero
29 =============================================================================
30*/
31
32#include "stddefs.h"
33
34#define DB_DEPTH 256 /* depth of the debug buffer */
35
36#define DB_entr 0 /* entry tag */
37#define DB_exit 1 /* exit tag */
38#define DB_cmnt 2 /* comment tag */
39
40struct DB_Data { /* debug buffer entry structure */
41
42 char *str;
43 short tag;
44};
45
46/*
47
48*/
49
50short DB_In; /* debug buffer 'in' pointer */
51short DB_Out; /* debug buffer 'out' pointer */
52short DB_Flag; /* ROMP trap disable flag */
53
54long DB_Levl; /* debug function call level */
55
56char *DB_Last; /* last debug string pointer */
57
58struct DB_Data DB_Ents[DB_DEPTH]; /* debug buffer */
59
60char *DB_Type[] = { /* debug buffer entry types */
61
62 "-->>", /* 0 - DB_entr */
63 "<<--", /* 1 - DB_exit */
64 "Note" /* 2 - DB_cmnt */
65};
66
67/*
68
69*/
70
71/*
72 =============================================================================
73 DB_Entr() -- log an entry in the trace buffer
74 =============================================================================
75*/
76
77void DB_Entr(char *str)
78{
79 DB_Ents[DB_In].tag = DB_entr; /* tag an entry */
80 DB_Ents[DB_In].str = str;
81
82 DB_Last = str;
83
84 ++DB_Levl;
85
86 if (++DB_In GE DB_DEPTH) /* update the 'in' pointer */
87 DB_In = 0;
88
89 if (DB_In EQ DB_Out) { /* bump the output pointer if full */
90
91 if (++DB_Out GE DB_DEPTH)
92 DB_Out = 0;
93 }
94}
95
96/*
97
98*/
99
100/*
101 =============================================================================
102 DB_Exit() -- log an exit in the trace buffer
103 =============================================================================
104*/
105
106void DB_Exit(char *str)
107{
108 DB_Ents[DB_In].tag = DB_exit; /* tag an exit */
109 DB_Ents[DB_In].str = str;
110
111 DB_Last = str;
112
113 if (DB_Levl > 0)
114 --DB_Levl;
115 else
116 DB_Levl = 0L;
117
118 if (++DB_In GE DB_DEPTH) /* update the 'in' pointer */
119 DB_In = 0;
120
121 if (DB_In EQ DB_Out) { /* bump the output pointer if full */
122
123 if (++DB_Out GE DB_DEPTH)
124 DB_Out = 0;
125 }
126}
127
128/*
129
130*/
131
132/*
133 =============================================================================
134 DB_Cmnt() -- log a comment in the trace buffer
135 =============================================================================
136*/
137
138void DB_Cmnt(char *str)
139{
140 DB_Ents[DB_In].tag = DB_cmnt; /* tag a comment */
141 DB_Ents[DB_In].str = str;
142
143 DB_Last = str;
144
145 if (++DB_In GE DB_DEPTH) /* update the 'in' pointer */
146 DB_In = 0;
147
148 if (DB_In EQ DB_Out) { /* bump the output pointer if full */
149
150 if (++DB_Out GE DB_DEPTH)
151 DB_Out = 0;
152 }
153}
154
155/*
156
157*/
158
159/*
160 =============================================================================
161 DB_Clr() -- clear the debug buffer
162 =============================================================================
163*/
164
165void DB_Clr(void)
166{
167 register short i;
168
169 DB_In = 0;
170 DB_Out = 0;
171
172 for (i = 0; i < DB_DEPTH; i++) {
173
174 DB_Ents[i].tag = 0;
175 DB_Ents[i].str = (char *)0L;
176 }
177
178 DB_Levl = 0L;
179 DB_Last = (char *)0L;
180}
181
182/*
183
184*/
185
186/*
187 =============================================================================
188 DB_Dump() -- dump and reset the trace buffer
189 =============================================================================
190*/
191
192void DB_Dump(void)
193{
194 register short tag;
195 register long i, lev;
196
197 if ((DB_In GE DB_DEPTH) OR (DB_In < 0)) { /* check DB_In */
198
199 printf("DB_In was corrupt: %d\n", DB_In);
200
201 xtrap15(); /* trap to ROMP */
202
203 DB_Clr(); /* clear the buffer */
204 return;
205 }
206
207 if ((DB_Out GE DB_DEPTH) OR (DB_Out < 0)) { /* check DB_Out */
208
209 printf("DB_Out was corrupt: %d\n", DB_Out);
210
211 xtrap15(); /* trap to ROMP */
212
213 DB_Clr(); /* clear the buffer */
214 return;
215 }
216
217 if (DB_In EQ DB_Out) { /* check for an emtpy buffer */
218
219 printf("Debug buffer is empty: In = Out = %d\n", DB_In);
220
221 if (DB_Levl)
222 printf("Debug trace level = %ld\n", DB_Levl);
223
224 if (DB_Last)
225 printf("Latest entry = \"%s\"\n", DB_Last);
226
227 if (DB_Flag EQ 0) /* trap to ROMP */
228 xtrap15();
229
230 DB_Clr(); /* clear the buffer */
231 return;
232 }
233/*
234
235*/
236 printf("Debug trace level = %ld\n\n", DB_Levl);
237
238 lev = 0L;
239
240 while (DB_Out NE DB_In) { /* print the buffer entries */
241
242 for (i = 0L; i < lev; i++)
243 printf("|");
244
245 tag = DB_Ents[DB_Out].tag;
246
247 printf("%s: %s\n", DB_Type[tag], DB_Ents[DB_Out].str);
248
249 switch (tag) {
250
251 case DB_entr:
252
253 ++lev;
254 break;
255
256 case DB_exit:
257
258 if (--lev < 0L) {
259
260 lev = 0L;
261 printf("\n");
262 }
263
264 break;
265 }
266
267 if (++DB_Out GE DB_DEPTH)
268 DB_Out = 0;
269 }
270
271 printf("\n----- End of debug buffer -----\n\n");
272
273 DB_Clr(); /* clear the buffer */
274
275 if (DB_Flag EQ 0)
276 xtrap15();
277
278 return;
279}
Note: See TracBrowser for help on using the repository browser.