[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 |
|
---|
| 32 | #include "stddefs.h"
|
---|
| 33 |
|
---|
[e225e77] | 34 | #include "stdio.h"
|
---|
| 35 |
|
---|
| 36 | extern void xtrap15(void);
|
---|
| 37 |
|
---|
[f40a309] | 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 |
|
---|
| 44 | struct DB_Data { /* debug buffer entry structure */
|
---|
| 45 |
|
---|
[7258c6a] | 46 | int8_t *str;
|
---|
| 47 | int16_t tag;
|
---|
[f40a309] | 48 | };
|
---|
| 49 |
|
---|
| 50 | /* |
---|
| 51 |
|
---|
| 52 | */
|
---|
[7258c6a] | 53 |
|
---|
| 54 | int16_t DB_In; /* debug buffer 'in' pointer */
|
---|
| 55 | int16_t DB_Out; /* debug buffer 'out' pointer */
|
---|
[f40a309] | 56 | int16_t DB_Flag; /* ROMP trap disable flag */
|
---|
[7258c6a] | 57 |
|
---|
[f40a309] | 58 | int32_t DB_Levl; /* debug function call level */
|
---|
[7258c6a] | 59 |
|
---|
[f40a309] | 60 | int8_t *DB_Last; /* last debug string pointer */
|
---|
| 61 |
|
---|
| 62 | struct DB_Data DB_Ents[DB_DEPTH]; /* debug buffer */
|
---|
[7258c6a] | 63 |
|
---|
[f40a309] | 64 | int8_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 | =============================================================================
|
---|
[7258c6a] | 79 | */
|
---|
[f40a309] | 80 |
|
---|
| 81 | void 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
|
---|
[7258c6a] | 107 | =============================================================================
|
---|
[f40a309] | 108 | */
|
---|
| 109 |
|
---|
| 110 | void 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 | =============================================================================
|
---|
[7258c6a] | 138 | DB_Cmnt() -- log a comment in the trace buffer
|
---|
[f40a309] | 139 | =============================================================================
|
---|
| 140 | */
|
---|
| 141 |
|
---|
| 142 | void 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 | /*
|
---|
[0580615] | 164 | =============================================================================
|
---|
[f40a309] | 165 | DB_Clr() -- clear the debug buffer
|
---|
[7258c6a] | 166 | =============================================================================
|
---|
[f40a309] | 167 | */
|
---|
| 168 |
|
---|
| 169 | void DB_Clr(void)
|
---|
| 170 | {
|
---|
| 171 | register int16_t i;
|
---|
| 172 |
|
---|
| 173 | DB_In = 0;
|
---|
[7258c6a] | 174 | DB_Out = 0;
|
---|
[f40a309] | 175 |
|
---|
| 176 | for (i = 0; i < DB_DEPTH; i++) {
|
---|
| 177 |
|
---|
[7258c6a] | 178 | DB_Ents[i].tag = 0;
|
---|
[f40a309] | 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 |
|
---|
[0580615] | 190 | /*
|
---|
[f40a309] | 191 | =============================================================================
|
---|
[7258c6a] | 192 | DB_Dump() -- dump and reset the trace buffer
|
---|
| 193 | =============================================================================
|
---|
[f40a309] | 194 | */
|
---|
| 195 |
|
---|
| 196 | void DB_Dump(void)
|
---|
| 197 | {
|
---|
| 198 | register int16_t tag;
|
---|
| 199 | register int32_t i, lev;
|
---|
[9519422] | 200 |
|
---|
[f40a309] | 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 | }
|
---|
[9519422] | 210 |
|
---|
[f40a309] | 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 | }
|
---|