Languages with a slow edit/compile/link/test development loop tend to require sophisticated tracing/stepping debuggers to facilate debugging.
A much better (faster) way in fast-compiling languages is to add printing code at well-selected places, let the program run, look at the output, see where things went wrong, add more printing code, etc., until the bug is found.
The simple debugging aids provided in debugs.fs are meant to support this style of debugging.
The word ~~ prints debugging information (by default the source
location and the stack contents). It is easy to insert. If you use Emacs
it is also easy to remove (C-x ~ in the Emacs Forth mode to
query-replace them with nothing). The deferred words
printdebugdata and .debugline control the output of
~~. The default source location output format works well with
Emacs’ compilation mode, so you can step through the program at the
source level using C-x ` (the advantage over a stepping debugger
is that you can step in any direction and you know where the crash has
happened or where the strange data has occurred).
Prints the source code location of the ~~ and the stack
contents with .debugline.
Print the source code location indicated by nfile nline, and
additional debugging information; the default .debugline
prints the additional information with printdebugdata.
Output file for debugging words. By default it is the process’s
stderr.
~~ (and assertions) will usually print the wrong file name if a
marker is executed in the same file after their occurrence. They will
print ‘*somewhere*’ as file name if a marker is executed in the
same file before their occurrence.
do the following up to THEN only once
print stackdump and backtrace
print stackdump and backtrace once
Open a debuging shell
Open a debugging shell with backtrace and stack dump
word that should never be reached
make xt2 do xt1, both need to be colon definitions
Define name and reserve a cell at addr.
name execution: ( -- addr ) Show a ~~ tracer
with addr @ on the top of the data stack. In all
other respects name behaves like a normal variable.
Define name with the initial value w; like value
but with tracers on the to and +to actions.
name execution: ( – w2 ) push the current value of
name.
to name run-time: ( w3 – )
Show a ~~ tracer with the xt of name on top of
w3, then change the value of name to w3.
+to name run-time: ( n|u – )
Show a ~~ tracer with the xt of name on top of
n|u, then increment the value of name by n|u.
turn on line tracing
turn off line tracing
set next word’s location to nline nchar in "file"