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