source: buchla-68k/orig/RAM/DBENTR.C@ d21fc6f

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

Imported original source code.

  • Property mode set to 100755
File size: 5.3 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
77DB_Entr(str)
78char *str;
79{
80 DB_Ents[DB_In].tag = DB_entr; /* tag an entry */
81 DB_Ents[DB_In].str = str;
82
83 DB_Last = str;
84
85 ++DB_Levl;
86
87 if (++DB_In GE DB_DEPTH) /* update the 'in' pointer */
88 DB_In = 0;
89
90 if (DB_In EQ DB_Out) { /* bump the output pointer if full */
91
92 if (++DB_Out GE DB_DEPTH)
93 DB_Out = 0;
94 }
95}
96
97/*
98
99*/
100
101/*
102 =============================================================================
103 DB_Exit() -- log an exit in the trace buffer
104 =============================================================================
105*/
106
107DB_Exit(str)
108char *str;
109{
110 DB_Ents[DB_In].tag = DB_exit; /* tag an exit */
111 DB_Ents[DB_In].str = str;
112
113 DB_Last = str;
114
115 if (DB_Levl > 0)
116 --DB_Levl;
117 else
118 DB_Levl = 0L;
119
120 if (++DB_In GE DB_DEPTH) /* update the 'in' pointer */
121 DB_In = 0;
122
123 if (DB_In EQ DB_Out) { /* bump the output pointer if full */
124
125 if (++DB_Out GE DB_DEPTH)
126 DB_Out = 0;
127 }
128}
129
130/*
131
132*/
133
134/*
135 =============================================================================
136 DB_Cmnt() -- log a comment in the trace buffer
137 =============================================================================
138*/
139
140DB_Cmnt(str)
141char *str;
142{
143 DB_Ents[DB_In].tag = DB_cmnt; /* tag a comment */
144 DB_Ents[DB_In].str = str;
145
146 DB_Last = str;
147
148 if (++DB_In GE DB_DEPTH) /* update the 'in' pointer */
149 DB_In = 0;
150
151 if (DB_In EQ DB_Out) { /* bump the output pointer if full */
152
153 if (++DB_Out GE DB_DEPTH)
154 DB_Out = 0;
155 }
156}
157
158/*
159
160*/
161
162/*
163 =============================================================================
164 DB_Clr() -- clear the debug buffer
165 =============================================================================
166*/
167
168DB_Clr()
169{
170 register short i;
171
172 DB_In = 0;
173 DB_Out = 0;
174
175 for (i = 0; i < DB_DEPTH; i++) {
176
177 DB_Ents[i].tag = 0;
178 DB_Ents[i].str = (char *)0L;
179 }
180
181 DB_Levl = 0L;
182 DB_Last = (char *)0L;
183}
184
185/*
186
187*/
188
189/*
190 =============================================================================
191 DB_Dump() -- dump and reset the trace buffer
192 =============================================================================
193*/
194
195DB_Dump()
196{
197 register short tag;
198 register long i, lev;
199
200 if ((DB_In GE DB_DEPTH) OR (DB_In < 0)) { /* check DB_In */
201
202 printf("DB_In was corrupt: %d\n", DB_In);
203
204 xtrap15(); /* trap to ROMP */
205
206 DB_Clr(); /* clear the buffer */
207 return;
208 }
209
210 if ((DB_Out GE DB_DEPTH) OR (DB_Out < 0)) { /* check DB_Out */
211
212 printf("DB_Out was corrupt: %d\n", DB_Out);
213
214 xtrap15(); /* trap to ROMP */
215
216 DB_Clr(); /* clear the buffer */
217 return;
218 }
219
220 if (DB_In EQ DB_Out) { /* check for an emtpy buffer */
221
222 printf("Debug buffer is empty: In = Out = %d\n", DB_In);
223
224 if (DB_Levl)
225 printf("Debug trace level = %ld\n", DB_Levl);
226
227 if (DB_Last)
228 printf("Latest entry = \"%s\"\n", DB_Last);
229
230 if (DB_Flag EQ 0) /* trap to ROMP */
231 xtrap15();
232
233 DB_Clr(); /* clear the buffer */
234 return;
235 }
236/*
237
238*/
239 printf("Debug trace level = %ld\n\n", DB_Levl);
240
241 lev = 0L;
242
243 while (DB_Out NE DB_In) { /* print the buffer entries */
244
245 for (i = 0L; i < lev; i++)
246 printf("|");
247
248 tag = DB_Ents[DB_Out].tag;
249
250 printf("%s: %s\n", DB_Type[tag], DB_Ents[DB_Out].str);
251
252 switch (tag) {
253
254 case DB_entr:
255
256 ++lev;
257 break;
258
259 case DB_exit:
260
261 if (--lev < 0L) {
262
263 lev = 0L;
264 printf("\n");
265 }
266
267 break;
268 }
269
270 if (++DB_Out GE DB_DEPTH)
271 DB_Out = 0;
272 }
273
274 printf("\n----- End of debug buffer -----\n\n");
275
276 DB_Clr(); /* clear the buffer */
277
278 if (DB_Flag EQ 0)
279 xtrap15();
280
281 return;
282}
Note: See TracBrowser for help on using the repository browser.