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

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

Added missing includes and declarations.

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