1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
char *tecdebug_c_version = "tecdebug.c: $Revision: 1.1 $";
/*
* $Date: 2007/12/10 21:59:20 $
* $Source: /cvsroot/videoteco/videoteco/tecdebug.c,v $
* $Revision: 1.1 $
* $Locker: $
*/
/* tecdebug.c
* Debugging routines for Teco
*
* COPYRIGHT (c) 1985-2003 BY
* PAUL CANTRELL & J. M. NISHINAGA
* SUDBURY, MA 01776
* ALL RIGHTS RESERVED
*
* This software is furnished in it's current state free of charge.
* The authors reserve all rights to the software. Further
* distribution of the software is not authorized. Modifications to
* the software may be made locally, but shall not be distributed
* without the consent of the authors. This software or any other
* copies thereof, may not be provided or otherwise made available
* to anyone without express permission of the authors. Title to and
* ownership of this software remains with the authors.
*
*/
#include "teco.h"
#include "tecparse.h"
extern struct screen_line *saved_screen;
extern char saved_screen_valid;
extern int term_lines;
extern struct buff_header *buffer_headers;
extern struct buff_header *curbuf;
extern struct buff_header *qregister_push_down_list;
extern struct format_line *format_line_free_list;
extern struct format_line *format_line_alloc_list;
extern char format_lines_invalid;
void
do_preamble_checks()
{
tecdebug_check_screen_magic();
tecdebug_check_buffer_magic();
tecdebug_check_line_magic();
tecdebug_check_format_magic();
tecdebug_check_companion_pointers();
tecdebug_check_window_pointers();
}
void
do_return_checks()
{
do_preamble_checks();
}
/* TECDEBUG_CHECK_SCREEN_MAGIC - Check for matching magic numbers
*
* Function:
*
* This routine checks that each saved screen array element has
* the correct magic number.
*/
void
tecdebug_check_screen_magic()
{
register int i;
register struct screen_line *sbp;
/*
* Basic checks first - check that each saved screen structure has the proper
* magic number in it.
*/
if(saved_screen_valid){
for(sbp = saved_screen,i = 0; i < term_lines && sbp != NULL;i++,sbp++){
if(sbp->scr_magic != MAGIC_SCREEN){
restore_tty();
fprintf(
stderr,
"?saved_screen[%d] bad magic#, 0x%08x should be 0x%08x\n",
i,
sbp->scr_magic,
(int)MAGIC_SCREEN
);
CAUSE_BUS_ERROR();
}/* End IF */
}/* End FOR */
}/* End IF */
}/* End Routine */
/* TECDEBUG_CHECK_BUFFER_MAGIC - Check for matching magic numbers
*
* Function:
*
* This routine checks that each buffer header to check for
* the correct magic number.
*/
void
tecdebug_check_buffer_magic()
{
register struct buff_header *bp;
register char saw_curbuf;
register int count;
bp = buffer_headers;
count = 0;
saw_curbuf = 0;
while(bp){
if(bp == curbuf) saw_curbuf = 1;
if(bp->buf_magic != MAGIC_BUFFER){
restore_tty();
fprintf(
stderr,
"?buff_headers[%d] bad magic#, 0x%08x should be 0x%08x\n",
count,
bp->buf_magic,
(int)MAGIC_BUFFER
);
CAUSE_BUS_ERROR();
}/* End IF */
count += 1;
bp = bp->next_header;
}/* End While */
if(curbuf != NULL && saw_curbuf == 0){
restore_tty();
fprintf(
stderr,
"?curbuf 0x%x not on buff_headers list\n",
(unsigned int)curbuf
);
CAUSE_BUS_ERROR();
}/* End IF */
bp = qregister_push_down_list;
count = 0;
while(bp){
if(bp->buf_magic != MAGIC_BUFFER){
restore_tty();
fprintf(
stderr,
"?qpushdown[%d] bad magic#, 0x%08x should be 0x%08x\n",
count,
bp->buf_magic,
(int)MAGIC_BUFFER
);
CAUSE_BUS_ERROR();
}/* End IF */
count += 1;
bp = bp->next_header;
}/* End While */
}/* End Routine */
/* TECDEBUG_CHECK_LINE_MAGIC - Check for matching magic numbers
*
* Function:
*
* This routine checks that each line buffer data structure for
* the correct magic number.
*/
void
tecdebug_check_line_magic()
{
register struct buff_header *bp;
register struct buff_line *lbp;
register int count;
bp = buffer_headers;
while(bp){
lbp = bp->first_line;
count = 0;
while(lbp){
if(lbp->lin_magic != MAGIC_LINE){
restore_tty();
fprintf(
stderr,
"?buf[%s] line %d bad magic#, 0x%08x should be 0x%08x\n",
bp->name,
count,
lbp->lin_magic,
(int)MAGIC_LINE
);
CAUSE_BUS_ERROR();
}/* End IF */
count += 1;
lbp = lbp->next_line;
}/* End While */
bp = bp->next_header;
}/* End While */
bp = qregister_push_down_list;
while(bp){
lbp = bp->first_line;
count = 0;
while(lbp){
if(lbp->lin_magic != MAGIC_LINE){
restore_tty();
fprintf(
stderr,
"?qreg pdl line %d bad magic#, 0x%08x should be 0x%08x\n",
count,
lbp->lin_magic,
(int)MAGIC_LINE
);
CAUSE_BUS_ERROR();
}/* End IF */
count += 1;
lbp = lbp->next_line;
}/* End While */
bp = bp->next_header;
}/* End While */
}/* End Routine */
/* TECDEBUG_CHECK_FORMAT_MAGIC - Check for matching magic numbers
*
* Function:
*
* This routine checks each screen format buffer data structure for
* the correct magic number.
*/
void
tecdebug_check_format_magic()
{
register struct format_line *fp;
register int count;
fp = format_line_alloc_list;
while(fp){
if(fp->fmt_magic != MAGIC_FORMAT){
restore_tty();
fprintf(
stderr,
"?format line bad magic#, 0x%08x should be 0x%08x\n",
fp->fmt_magic,
(int)MAGIC_FORMAT
);
CAUSE_BUS_ERROR();
}/* End IF */
fp = fp->fmt_next_alloc;
}/* End While */
fp = format_line_free_list;
count = 0;
while(fp){
if(fp->fmt_magic != MAGIC_FORMAT_LOOKASIDE){
restore_tty();
fprintf(
stderr,
"?format lookaside[%d] bad magic#, 0x%08x should be 0x%08x\n",
count,
fp->fmt_magic,
(int)MAGIC_FORMAT_LOOKASIDE
);
CAUSE_BUS_ERROR();
}/* End IF */
fp = fp->fmt_next_line;
count += 1;
}/* End While */
}/* End Routine */
/* TECDEBUG_CHECK_COMPANION_POINTERS - Check for pointer consistency
*
* Function:
*
* This routine checks that each saved_screen entry points to
* a single format line which also points back. It's an error
* if a structure points to another structure which doesn't
* point back.
*/
void
tecdebug_check_companion_pointers()
{
register int i;
register struct screen_line *sbp;
register struct format_line *fbp;
/*
* First check from the saved screen side that the pointers seem to be
* consistent - i.e. that every structure points to one and only one
* structure which points back.
*/
if(!saved_screen_valid) return;
for(sbp = saved_screen,i = 0; i < term_lines && sbp != NULL;i++,sbp++){
if(sbp->companion == NULL) continue;
if(sbp->companion->fmt_saved_line != sbp){
restore_tty();
fprintf(
stderr,
"?saved_screen[%d] companion 0x%08x ->fmt_saved_line 0x%08x\n",
i,
(unsigned int)sbp->companion,
(unsigned int)sbp->companion->fmt_saved_line
);
CAUSE_BUS_ERROR();
}/* End IF */
}/* End FOR */
/*
* Now check from the allocated format structure side of things, to make sure
* that each one of them which points to a screen structure is pointed back
* at by that screen structure.
*/
fbp = format_line_alloc_list;
while(fbp){
if(fbp->fmt_saved_line && fbp->fmt_saved_line->companion != fbp){
restore_tty();
fprintf(
stderr,
"?fbp 0x%08x fbp->fmt_saved 0x%08x ->companion 0x%08x\n",
(unsigned int)fbp,
(unsigned int)fbp->fmt_saved_line,
(unsigned int)fbp->fmt_saved_line->companion
);
CAUSE_BUS_ERROR();
}/* End IF */
fbp = fbp->fmt_next_alloc;
}/* End While */
}/* End Routine */
/* TECDEBUG_CHECK_WINDOW_POINTERS - Check for window pointer consistency
*
* Function:
*
* This routine checks that every format line is correctly chained with respect
* to which window it is connected to. An error occurs if the line_buffer does
* not chain down to it. Also, for every "next_window" pointer, all format
* structures chained off of it must belong to the same window.
*/
void
tecdebug_check_window_pointers()
{
register struct format_line *fbp,*fl_win_head,*fl_temp;
register struct window *wptr;
register struct buff_line *blp;
char saw_our_format_line;
if(format_lines_invalid) return;
/*
* Check each format line on the allocated list
*/
for(fbp = format_line_alloc_list; fbp != NULL; fbp = fbp->fmt_next_alloc){
saw_our_format_line = 0;
blp = fbp->fmt_buffer_line;
fl_win_head = blp->format_line;
for(; fl_win_head != NULL; fl_win_head = fl_win_head->fmt_next_window){
wptr = fl_win_head->fmt_window_ptr;
for(fl_temp = fl_win_head; fl_temp != NULL; fl_temp = fl_temp->fmt_next_line){
if(fl_temp == fbp) saw_our_format_line = 1;
if(fl_temp->fmt_window_ptr != wptr){
restore_tty();
fprintf(
stderr,
"?wrong window in fmt chain format_line 0x%08x format_line->wptr 0x%08x wptr 0x%08x\n",
(unsigned int)fl_temp,
(unsigned int)fl_temp->fmt_window_ptr,
(unsigned int)wptr
);
CAUSE_BUS_ERROR();
}/* End IF */
if(fl_temp->fmt_buffer_line != blp){
restore_tty();
fprintf(
stderr,
"?wrong buffer_line in fmt chain fmt 0x%08x fmt->fmt_buffer_line 0x%08x lbp 0x%08x\n",
(unsigned int)fl_temp,
(unsigned int)fl_temp->fmt_buffer_line,
(unsigned int)blp
);
CAUSE_BUS_ERROR();
}/* End IF */
}/* End FOR */
}/* End FOR */
if(saw_our_format_line == 0){
restore_tty();
fprintf(
stderr,
"?never encountered our format line 0x%08x in format list\n",
(unsigned int)fbp
);
CAUSE_BUS_ERROR();
}/* End IF */
}/* End FOR */
}/* End Routine */
|