source: buchla-68k/orig/MT/DBENTR.C@ a838f5b

Last change on this file since a838f5b was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

  • Property mode set to 100755
File size: 7.4 KB
Line 
1/*
2 =============================================================================
3 dbentr.c -- special debug trace support functions for the Multi-Tasker
4 Version 8 -- 1988-04-13 -- D.N. Lynx Crowe
5
6 -------------------------- Important Note ---------------------------
7 These are like the usual dbentr functions, but with the variables
8 located elsewhere. See "Multi-Tasker wierdness", below, for details.
9 We also shut off interrupts while making entries into the buffer.
10 ---------------------------------------------------------------------
11
12 Use with the "debug.h" header file. Define DEBUGGER to include
13 debug trace code.
14
15 Define "SNAPSHOT" non-zero for snapshot mode: once the buffer is
16 filled up no more entries will be added (no wrap-around).
17
18 Synopsis:
19
20 Macros:
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 Functions:
27
28 DB_Clr() clear the debug buffer
29 DB_Dump() dump and clear the debug buffer
30
31 DB_Entr(str) trace an entry
32 DB_Exit(str) trace an exit
33 DB_Cmnt(str) put a comment in the trace
34
35 Variables:
36
37 DB_Flag don't trap to ROMP if non-zero
38 DB_Full trace buffer full
39 =============================================================================
40*/
41
42/*
43
44*/
45
46#include "stddefs.h"
47
48#define SNAPSHOT 0 /* define non-zero for snapshot mode */
49
50#define DB_DEPTH 512 /* depth of the debug buffer */
51
52#define DB_entr 0 /* entry tag */
53#define DB_exit 1 /* exit tag */
54#define DB_cmnt 2 /* comment tag */
55
56struct DB_Data { /* debug buffer entry structure */
57
58 char *str;
59 short tag;
60};
61
62/*
63 =============================================================================
64 Multi-Tasker wierdness:
65
66 DB_In..DB_Data are normally defined here, but for the Multi-Tasker we
67 define them as equates in an assembly language module so we can relocate
68 them out of harm's way (e.g. being cleared by reset, etc.).
69 =============================================================================
70*/
71
72extern short DB_In; /* debug buffer 'in' pointer */
73extern short DB_Out; /* debug buffer 'out' pointer */
74extern short DB_Flag; /* ROMP trap disable flag */
75extern short DB_Full; /* debug buffer full flag */
76
77extern long DB_Levl; /* debug function call level */
78
79extern char *DB_Last; /* last debug string pointer */
80
81extern struct DB_Data DB_Ents[]; /* debug buffer */
82
83/*
84 =============================================================================
85 End of Multi-Tasker wierdness
86 =============================================================================
87*/
88
89char *DB_Type[] = { /* debug buffer entry types */
90
91 "+-->>", /* 0 - DB_entr */
92 "<<--", /* 1 - DB_exit */
93 " Note" /* 2 - DB_cmnt */
94};
95
96/*
97
98*/
99
100/*
101 =============================================================================
102 DB_Entr() -- log an entry in the trace buffer
103 =============================================================================
104*/
105
106DB_Entr(str)
107char *str;
108{
109 register short oldipl;
110
111 oldipl = setipl(7);
112
113#if SNAPSHOT
114 if (DB_Full) {
115
116 setipl(oldipl);
117 return;
118 }
119#endif
120
121 DB_Ents[DB_In].tag = DB_entr; /* tag an entry */
122 DB_Ents[DB_In].str = str;
123
124 DB_Last = str;
125
126 ++DB_Levl;
127
128 if (++DB_In GE DB_DEPTH) /* update the 'in' pointer */
129 DB_In = 0;
130
131 if (DB_In EQ DB_Out) { /* bump the output pointer if full */
132
133 DB_Full = TRUE; /* indicate that buffer got filled up */
134
135 if (++DB_Out GE DB_DEPTH)
136 DB_Out = 0;
137 }
138
139 setipl(oldipl);
140}
141
142/*
143
144*/
145
146/*
147 =============================================================================
148 DB_Exit() -- log an exit in the trace buffer
149 =============================================================================
150*/
151
152DB_Exit(str)
153char *str;
154{
155 register short oldipl;
156
157 oldipl = setipl(7);
158
159#if SNAPSHOT
160 if (DB_Full) {
161
162 setipl(oldipl);
163 return;
164 }
165#endif
166
167 DB_Ents[DB_In].tag = DB_exit; /* tag an exit */
168 DB_Ents[DB_In].str = str;
169
170 DB_Last = str;
171
172 if (DB_Levl > 0)
173 --DB_Levl;
174 else
175 DB_Levl = 0L;
176
177 if (++DB_In GE DB_DEPTH) /* update the 'in' pointer */
178 DB_In = 0;
179
180 if (DB_In EQ DB_Out) { /* bump the output pointer if full */
181
182 DB_Full = TRUE; /* indicate that buffer got filled up */
183
184 if (++DB_Out GE DB_DEPTH)
185 DB_Out = 0;
186 }
187
188 setipl(oldipl);
189}
190
191/*
192
193*/
194
195/*
196 =============================================================================
197 DB_Cmnt() -- log a comment in the trace buffer
198 =============================================================================
199*/
200
201DB_Cmnt(str)
202char *str;
203{
204 register short oldipl;
205
206 oldipl = setipl(7);
207
208#if SNAPSHOT
209 if (DB_Full) {
210
211 setipl(oldipl);
212 return;
213 }
214#endif
215
216 DB_Ents[DB_In].tag = DB_cmnt; /* tag a comment */
217 DB_Ents[DB_In].str = str;
218
219 DB_Last = str;
220
221 if (++DB_In GE DB_DEPTH) /* update the 'in' pointer */
222 DB_In = 0;
223
224 if (DB_In EQ DB_Out) { /* bump the output pointer if full */
225
226 DB_Full = TRUE; /* indicate that buffer got filled up */
227
228 if (++DB_Out GE DB_DEPTH)
229 DB_Out = 0;
230 }
231
232 setipl(oldipl);
233}
234
235/*
236
237*/
238
239/*
240 =============================================================================
241 DB_Clr() -- clear the debug buffer
242 =============================================================================
243*/
244
245DB_Clr()
246{
247 register short i;
248
249 DB_In = 0;
250 DB_Out = 0;
251 DB_Full = FALSE;
252
253 for (i = 0; i < DB_DEPTH; i++) {
254
255 DB_Ents[i].tag = 0;
256 DB_Ents[i].str = (char *)0L;
257 }
258
259 DB_Levl = 0L;
260 DB_Last = (char *)0L;
261}
262
263/*
264
265*/
266
267/*
268 =============================================================================
269 DB_Dump() -- dump and reset the trace buffer
270 =============================================================================
271*/
272
273DB_Dump()
274{
275 register short tag;
276 register long i, lev;
277
278 if ((DB_In GE DB_DEPTH) OR (DB_In < 0)) { /* check DB_In */
279
280 printf("DB_In was corrupt: %d\n", DB_In);
281
282 xtrap15(); /* trap to ROMP */
283
284 DB_Clr(); /* clear the buffer */
285 return;
286 }
287
288 if ((DB_Out GE DB_DEPTH) OR (DB_Out < 0)) { /* check DB_Out */
289
290 printf("DB_Out was corrupt: %d\n", DB_Out);
291
292 xtrap15(); /* trap to ROMP */
293
294 DB_Clr(); /* clear the buffer */
295 return;
296 }
297
298#if SNAPSHOT
299 if (DB_Full) {
300
301 DB_In = DB_DEPTH;
302 DB_Out = 0;
303 }
304#endif
305
306 if (DB_In EQ DB_Out) { /* check for an emtpy buffer */
307
308 printf("Debug buffer is empty: In = Out = %d\n", DB_In);
309
310 if (DB_Levl)
311 printf("Debug trace level = %ld\n", DB_Levl);
312
313 if (DB_Last)
314 printf("Latest entry = \"%s\"\n", DB_Last);
315
316 if (DB_Flag EQ 0) /* trap to ROMP */
317 xtrap15();
318
319 DB_Clr(); /* clear the buffer */
320 return;
321 }
322/*
323
324*/
325#if SNAPSHOT
326 printf("Snapshot mode -- buffer is %s\n",
327 DB_Full ? "full" : "part full");
328#endif
329
330 printf("Debug trace level = %ld\n\n", DB_Levl);
331
332 lev = 0L;
333
334 while (DB_Out NE DB_In) { /* print the buffer entries */
335
336 for (i = 0L; i < lev; i++)
337 printf("|");
338
339 tag = DB_Ents[DB_Out].tag;
340
341 printf("%s: %s\n", DB_Type[tag], DB_Ents[DB_Out].str);
342
343 switch (tag) {
344
345 case DB_entr:
346
347 ++lev;
348 break;
349
350 case DB_exit:
351
352 if (--lev < 0L) {
353
354 lev = 0L;
355 printf("\n");
356 }
357
358 break;
359 }
360
361 if (++DB_Out GE DB_DEPTH) {
362
363#if SNAPSHOT
364 break;
365#else
366 DB_Out = 0;
367#endif
368 }
369 }
370
371 printf("\n----- End of debug buffer -----\n\n");
372
373 DB_Clr(); /* clear the buffer */
374
375 if (DB_Flag EQ 0)
376 xtrap15();
377
378 return;
379}
Note: See TracBrowser for help on using the repository browser.