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

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

Added include files for global functions and variables.

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