470  PART 52: DEBUGGING  TEX82 §1338

1338. Debugging. Once TEX is working, you should be able to diagnose most errors with the commands and other diagnostic features. But for the initial stages of debugging, and for the revelation of really deep mysteries, you can compile TEX 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 ‘ ’ after an error message; debug help also occurs just before a fatal error causes TEX 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 ‘ #’, 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.)

define breakpoint = 888 { place where a breakpoint is desirable } ⟨ Last-minute procedures 1333 ⟩ +≡

debug procedure debug help; { routine to display various things }

label breakpoint , exit ;

var k, l, m, n: integer ;

begin loop

begin wake up terminal ; print nl ( ␣#␣ ␣ ␣ ); update terminal ; read (term in, m); if m < 0 then return else if m = 0 then

begin goto breakpoint ; { go to every label at least once } breakpoint : m ← 0; ´ ´

end else begin read (term in, n);

case m of

⟨ Numbered cases for debug help 1339 ⟩

othercases print ( )

endcases;

end; end;

exit : end; gubed

§1339  TEX82  PART 52: DEBUGGING 471

1339. ⟨ Numbered cases for debug help 1339 ⟩ ≡ 1: print word (mem[n]); { display mem[n] in all forms } 2: print int (info(n)); 3: print int (link (n)); 4: print word (eqtb[n]); 5: print word (font info[n]); 6: print word (save stack [n]); 7: show box (n); { show a box, abbreviated by show box depth and show box breadth } 8: begin breadth max ← 10000; depth threshold ← pool size − pool ptr − 10; show node list (n);

{ show a box in its entirety } end;

9: show token list (n, null , 1000); 10: slow print (n); 11: check mem(n > 0); { check wellformedness; print new busy locations if n > 0 } 12: search mem(n); { look for pointers to n } 13: begin read (term in, l); print cmd chr (n, l);

end; 14: for k ← 0 to n do print (buffer [k]); 15: begin font in short display ← null font ; short display (n);

end; 16: panicking ← ¬panicking ;

This code is used in section 1338.