As of May 15, 1988 this code is not working correctly. Please contact me for a more recent version. Gary Bergstrom 191 Miles Rd. Chagrin Falls, OH 44022 \ Load Screen for High Level Trace 04oct86mapONLY FORTH ALSO DEFINITIONS 1 4 +THRU CR .( Debugger Loaded ) ONLY FORTH ALSO DEFINITIONS EXIT The debugger is designed to let the user single step the execution of a high level definition. To invoke the debugger, type DEBUG XXX where XXX is the name of the word you wish to trace. When XXX executes, you will get a single step trace showing you the word within XXX that is about to execute, and the contents of the parameter stack. If you wish to poke around, type F and you can interpret Forth commands until you type RESUME, and execution of XXX will continue where it left off. This debugger works by patching the NEXT routine, so it is highly machine and implementation dependent. The same idea should work however on any Forth system with a centralized NEXT routine. \ High Level Trace 28JAN86GEBVOCABULARY BUG BUG ALSO DEFINITIONS VARIABLE 'DEBUG ( Code field for high level trace ) VARIABLE <IP ( Lower limit of IP ) VARIABLE IP> ( Upper limit of IP ) VARIABLE CNT ( How many times thru debug next ) ASSEMBLER HEX LABEL FNEXT ( Fix the >NEXT code back to normal ) 0AD # AL MOV AL >NEXT #) MOV E0FF # AX MOV AX >NEXT 1+ #) MOV RET LABEL DNEXT ( The Debugger version of a normal >NEXT ) AX LODS AX JMP DECIMAL \ High Level Trace 28JAN86GEBHEX ASSEMBLER LABEL DEBNEXT <IP #) IP CMP U> IF IP> #) IP CMP U<= IF CNT #) AL MOV AL INC AL CNT #) MOV 2 # AL CMP 0= IF AL AL SUB AL CNT #) MOV FNEXT #) CALL BX PUSH IP BX MOV 'DEBUG #) AX MOV AX JMP THEN THEN THEN DNEXT #) JMP CODE PNEXT (S -- ) 0E9 # AL MOV AL >NEXT #) MOV DEBNEXT >NEXT 3 + - # AX MOV AX >NEXT 1+ #) MOV NEXT END-CODE FORTH DEFINITIONS CODE UNBUG (S -- ) FNEXT #) CALL NEXT END-CODE DECIMAL \ Print a High Level Trace 08JAN84MAPBUG ALSO DEFINITIONS : L.ID (S nfa len -- ) SWAP DUP .ID DUP NAME> 1- - + SPACES ; VARIABLE SLOW VARIABLE RES : (DEBUG) (S low-adr hi-adr -- ) 1 CNT ! IP> ! <IP ! PNEXT ; : 'UNNEST (S Pfa -- Pfa' ) BEGIN 1+ DUP @ ['] UNNEST = UNTIL ; \ Enter and Leave the Debugger 06Oct83map: TRACE (S Ip - ) >R .S R> CR @ >NAME 10 L.ID SLOW @ NOT KEY? OR IF SLOW OFF RES OFF ." --> " KEY UPC ASCII C OVER = IF SLOW @ NOT SLOW ! THEN ASCII F OVER = IF DROP BEGIN QUERY RUN RES @ UNTIL THEN ASCII Q OVER = ABORT" Unbug" DROP THEN PNEXT ; ' TRACE 'DEBUG ! FORTH DEFINITIONS : DEBUG (S -- ) ' 2- DUP [ BUG ] 'UNNEST (DEBUG) ; : RESUME (S -- ) [ BUG ] RES ON 0 PNEXT ; ONLY FORTH ALSO DEFINITIONS 12Oct83map For example, DEBUG WORDS will trace the execution of WORDS the next time it is used. \ High Level Trace 11OCT83HHL BUG The vocabulary that holds the high level trace words. FNEXT A machine language subroutine that Fixes NEXT back to the way it used to be. DNEXT A copy of next that gets exeucted instead of the normal one. \ High Level Trace 11OCT83HHLDEBNEXT is the debugger's version of next If the IP is between <IP and IP> then the contents of the execution variable 'DEBUG are executed. First the IP is pushed onto the parameter stack. The word pointed to by 'DEBUG can be any high or low level word so long as it discards the IP that was pushed before it is called, and it must terminate by callingPNEXT to patch next once again for more tracing. PNEXT patches Forth's Next to jump to DEBNEXT. This puts us into DEBUG mode and allows for tracing. FIX restores Forth's Next to its original condition. Effectively disabling tracing. \ Print a High Level Trace 21jun86mapPut component words in BUG vocabulary. L.ID print the name of a word left justified in a field of least len characters. SLOW when true, step continuously. RES when true, resume debugging. See TRACE. (DEBUG) sets the upper and lower limits of the tracing window to the given values, and patches next. 'UNNEST find end of word to debug. DEBUG patches NEXT to the debugging version of NEXT. DEBUG also sets the upper and lower limits of the tracing region to the ends of the parameter field of the specified word. RESUME turns on RES, which enables tracing to continue. \ Enter and Leave the Debugger 21jun86mapTRACE is executed every other pass thru NEXT. It displays the contents of the parameter stack and the name of the next word to be executed in the routine being debugged. TRACE then waits for a key unless SLOW is true. If the key is C, F, or Q, special action is taken, otherwise a single step is performed. C turns on continuous running ( and SLOW). F re-enters Forth and interprets commands until RESUME is executed. Q aborts the trace and restores NEXT with FIX.