home *** CD-ROM | disk | FTP | other *** search
- \ Debugger. Thanks, Mike Perry, Henry Laxen, Mark Smeder.
- \
- \ The debugger lets you 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.
- \ Debugging makes everything run slightly slower, even outside
- \ the word being debugged. see debug-off
- \
- \ debug name Mark that word for debugging
- \ step Debug in single step mode
- \ trace Debug in trace mode
- \ debug-off Turn off the debugger (makes the system run fast again)
- \ resume Exit from a pushed interpreter (see the f keystroke)
- \
- \ Keystroke commands while you're single-stepping:
- \ d go down a level
- \ u go up a level
- \ c continue; trace without single stepping
- \ g go; turn off stepping and continue execution
- \ f push a Forth interpreter; execute "resume" to get back
- \ q abort back to the top level
-
- only forth also definitions
- : interpret-line \ input-line ( -- ?? )
- 0 0 0 0 0 prompt 2drop 2drop drop \ Hack to make showstack work
- tib 80 expect
- tib span @ eval
- ;
-
- hex
- variable slow-next? slow-next? off
-
- only forth hidden also forth also definitions
- bug also definitions
- : l.id (s anf len -- )
- swap dup .id ( len anf acf )
- c@ th 1f and ( len namelen )
- - spaces
- ;
- variable step? step? on
- variable res
- : (debug) (s low-adr hi-adr -- )
- \ Silently refuse to debug the kernel; it's too dangerous
- over low-dictionary-adr fence @ between if 2drop exit then
-
- unbug 1 cnt ! ip> ! <ip ! pnext
- slow-next? @ 0=
- if ['] forth low-dictionary-adr slow-next
- slow-next? on
- then abort
- ;
- : 'unnest (s pfa -- pfa' )
- begin #align + dup token@ ['] unnest = until
- ;
-
- \ Enter and leave the debugger
- variable #out-save variable #line-save variable save-status
- : (debug ( acf -- )
- ['] status >data token@ save-status token!
- /token - dup 'unnest (debug)
- ;
- : up1 ( ip -- ) dup find-cfa swap 'unnest (debug) ;
- : (trace (s - )
- step? @ if
- \ Always interact with the debugger at a fixed location
- #out @ #out-save ! #line @ #lines 1- max #line-save !
- 0 0 at
- else
- cr
- then
- kill-line ." ( " .s ." )" cr \ Show stack
- kill-line r@ token@ >name td 10 l.id \ Show word name
- step? @ key? or
- if step? on res off
- ." [<space> Down Up Continue Forth Go Quit] : "
- key upc
- #line-save @ #out-save @ at
- case
- ascii D of r@ token@ (debug endof \ Down
- ascii U of rp@ na1+ @ up1 endof \ Up
- ascii C of step? @ not step? ! endof \ Continue
- ascii F of begin interpret-line res @ until endof \ Forth
- ascii G of <ip off ip> off endof \ Go
- ascii Q of cr ." unbug" abort endof \ Quit
- endcase
- #line-save @ #out-save @ at
- then
- pnext
- ;
- ' (trace 'debug token!
-
- only forth bug also forth definitions
-
- : debug \ name (s -- )
- ' (debug
- ;
- : resume (s -- ) res on pnext ;
- : step (s -- ) step? on ;
- : trace (s -- ) step? off ;
- : debug-off (s -- )
- unbug here low-dictionary-adr fast-next slow-next? off
- save-status token@ is status
- ;
-
- only forth also definitions
-