Section 1338: Debugging
Once is working, you should be able to diagnose most errors with the \show
commands and other diagnostic features.
But for the initial stages of debugging, and for the revelation of really deep mysteries, you can compile with a few more aids, including the Pascal runtime checks and its debugger.
An additional routine called debug_help will also come into play when you type ‘D
’ after an error message;
debug_help also occurs just before a fatal error causes to succumb.
The interface to debug_help is primitive, but it is good enough when used with a Pascal debugger that allows you to set breakpoints and to read variables and change their values.
After getting the prompt ‘debug #
’, you type either a negative number (this exits debug_help), or zero (this goes to a location where you can set a breakpoint, thereby entering into dialog with the Pascal debugger), or a positive number m followed by an argument n.
The meaning of m and n will be clear from the program below.
(If m = 13, there is an additional argument, l.)
⟨ Last-minute procedures 1333 ⟩+≡
#ifdef DEBUG
// routine to display various things
void debug_help() {
int k, l, m, n;
int err; // handling input error
clear_terminal;
while(true) {
print_nl("debug # (-1 to exit):");
update_terminal;
err = scanf("%d", &m);
if (err != 1) {
print("?");
continue;
}
if (m < 0) {
return;
}
err = scanf("%d", &n);
if (err != 1) {
print("?");
continue;
}
switch (m) {
// << Numbered cases for |debug_help|, 1339 >>
default:
print("?");
}
}
}
#endif
Section 1339
⟨ Numbered cases for debug_help 1339 ⟩≡
case 1:
print_word(mem[n]);
break; // display |mem[n]| in all forms
case 2:
print_int(info(n));
break;
case 3:
print_int(link(n));
break;
case 4:
print_word(eqtb[n]);
break;
case 5:
print_word(font_info[n]);
break;
case 6:
print_word(save_stack[n]);
break;
case 7:
// show a box, abbreviated by |show_box_depth| and |show_box_breadth|
show_box(n);
break;
case 8:
// show a box in its entirety
breadth_max = 10000;
depth_threshold = POOL_SIZE - pool_ptr - 10;
show_node_list(n);
break;
case 9:
show_token_list(n, null, 1000);
break;
case 10:
slow_print(n);
break;
case 11:
// check wellformedness; print new busy locations if |n > 0|
check_mem(n > 0);
break;
case 12:
// look for pointers to |n|
search_mem(n);
break;
case 13:
err = scanf("%d", &l);
if (err != 1) {
print("?");
continue;
}
print_cmd_chr(n, l);
break;
case 14:
for(k = 0; k <= n; k++) {
print_strnumber(buffer[k]);
}
break;
case 15:
font_in_short_display = NULL_FONT;
short_display(n);
break;
case 16:
panicking = !panicking;
break;