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

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

Removed form-feed comments.

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