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

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

Regenerate global headers.

  • Property mode set to 100644
File size: 5.1 KB
RevLine 
[f40a309]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
[6262b5c]32#include "all.h"
[e225e77]33
34extern void xtrap15(void);
35
[f40a309]36#define DB_DEPTH 256 /* depth of the debug buffer */
37
38#define DB_entr 0 /* entry tag */
39#define DB_exit 1 /* exit tag */
40#define DB_cmnt 2 /* comment tag */
41
42struct DB_Data { /* debug buffer entry structure */
43
[7258c6a]44 int8_t *str;
45 int16_t tag;
[f40a309]46};
47
48/*
49
50*/
[7258c6a]51
52int16_t DB_In; /* debug buffer 'in' pointer */
53int16_t DB_Out; /* debug buffer 'out' pointer */
[f40a309]54int16_t DB_Flag; /* ROMP trap disable flag */
[7258c6a]55
[f40a309]56int32_t DB_Levl; /* debug function call level */
[7258c6a]57
[f40a309]58int8_t *DB_Last; /* last debug string pointer */
[39a696b]59
60static struct DB_Data DB_Ents[DB_DEPTH];
[f40a309]61 /* debug buffer */
[7258c6a]62
[f40a309]63int8_t *DB_Type[] = { /* debug buffer entry types */
64
65 "-->>", /* 0 - DB_entr */
66 "<<--", /* 1 - DB_exit */
67 "Note" /* 2 - DB_cmnt */
68};
69
70/*
71
72*/
73
74/*
75 =============================================================================
76 DB_Entr() -- log an entry in the trace buffer
77 =============================================================================
[7258c6a]78*/
[f40a309]79
80void DB_Entr(int8_t *str)
81{
82 DB_Ents[DB_In].tag = DB_entr; /* tag an entry */
83 DB_Ents[DB_In].str = str;
84
85 DB_Last = str;
86
87 ++DB_Levl;
88
89 if (++DB_In GE DB_DEPTH) /* update the 'in' pointer */
90 DB_In = 0;
91
92 if (DB_In EQ DB_Out) { /* bump the output pointer if full */
93
94 if (++DB_Out GE DB_DEPTH)
95 DB_Out = 0;
96 }
97}
98
99/*
100
101*/
102
103/*
104 =============================================================================
105 DB_Exit() -- log an exit in the trace buffer
[7258c6a]106 =============================================================================
[f40a309]107*/
108
109void DB_Exit(int8_t *str)
110{
111 DB_Ents[DB_In].tag = DB_exit; /* tag an exit */
112 DB_Ents[DB_In].str = str;
113
114 DB_Last = str;
115
116 if (DB_Levl > 0)
117 --DB_Levl;
118 else
119 DB_Levl = 0L;
120
121 if (++DB_In GE DB_DEPTH) /* update the 'in' pointer */
122 DB_In = 0;
123
124 if (DB_In EQ DB_Out) { /* bump the output pointer if full */
125
126 if (++DB_Out GE DB_DEPTH)
127 DB_Out = 0;
128 }
129}
130
131/*
132
133*/
134
135/*
136 =============================================================================
[7258c6a]137 DB_Cmnt() -- log a comment in the trace buffer
[f40a309]138 =============================================================================
139*/
140
141void DB_Cmnt(int8_t *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/*
[0580615]163 =============================================================================
[f40a309]164 DB_Clr() -- clear the debug buffer
[7258c6a]165 =============================================================================
[f40a309]166*/
167
168void DB_Clr(void)
169{
170 register int16_t i;
171
172 DB_In = 0;
[7258c6a]173 DB_Out = 0;
[f40a309]174
175 for (i = 0; i < DB_DEPTH; i++) {
176
[7258c6a]177 DB_Ents[i].tag = 0;
[f40a309]178 DB_Ents[i].str = (int8_t *)0L;
179 }
180
181 DB_Levl = 0L;
182 DB_Last = (int8_t *)0L;
183}
184
185/*
186
187*/
188
[0580615]189/*
[f40a309]190 =============================================================================
[7258c6a]191 DB_Dump() -- dump and reset the trace buffer
192 =============================================================================
[f40a309]193*/
194
195void DB_Dump(void)
196{
197 register int16_t tag;
198 register int32_t i, lev;
[9519422]199
[f40a309]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 }
[9519422]209
[f40a309]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
[6262b5c]276 DB_Clr(); /* clear the buffer */
277
278 if (DB_Flag EQ 0)
279 xtrap15();
280
281 return;
282}
283
Note: See TracBrowser for help on using the repository browser.