Win32Forth

Debugging in Win32Forth

Debugging Words

Win32Forth includes a debugging facility similar to the debugger in F-PC. The keys you press however may have changes, so you can use the '?' (question mark) key while debugging to see a list of the available debugging commands.

To select a word for debugging, you use the word DEBUG as follows;

DEBUG WORDS [enter] 

The debugger installs a breakpoint into the first cell of the definition WORDS , and waits for WORDS to be executed. It also sets the value of base which the debugger will use to the current base. Since we haven't executed WORDS yet, nothing more happens.

NOTE: As soon as you perform the following suggested command, the debugger will automatically tell the editor to display the source for WORDS . To return to WINED, use Ctrl-PgUp.

To get the debugger to start, you need to execute the word where the breakpoint is set like this;

WORDS ! [enter] 

The debugger will be invoked, and it will display the stack on entry to WORDS , and the source for WORDS will be displayed in the editor. Return here as described in the note above.

Following the stack display (probably the word 'empty'), you will see 'const 0' which means CONSTANT with a value of zero. If you press [enter] while the console window is selected, you will see a '[1] 0' displayed indicating one stack item with a value of zero. The debugger then displays TO WORDS-CNT which is where the zero is about to be stored, into the value WORDS-CNT . You can press the '?' key at this point to see the commands available in the debugger. Specifically the commands 'N' (nest) and 'U' (unnest) are useful for stepping into or out of definitions while debugging to get to the point where you can see what is really happening in your program.

Another debugging words is DBG ; it works like DEBUG , but it immediately invokes the word following. So you need to setup whatever stack arguments before using it. Of course you also need to do this with DEBUG as well, before the word being debugged gets executed. Here is an example;

DBG WORDS ! [enter] 

The debugger starts immediately debugging WORDS , the character '!' is passed to WORDS in the input stream as a substring parameter.

NOTE: The debugger commands are shown here. They are case-insensitve;

NOTE: The words WITHOUT-SOURCE and WITH-SOURCE can be used to turn source level debugging off and on respectively. If you have limited memory, you may need to use WITHOUT-SOURCE to turn off source level debugging.

Debugging Objects

The words MDEBUG and MDBG are the versions of DEBUG and DBG for use with objects. Their use is identical to their non-object counterparts except they take both a method and an object;

 MDEBUG ERASERECT: TEMPRECT [enter] 

will set the breakpoint into the ERASERECT: method of the object TEMPRECT . Since all objects of the same class have the same methods then any object of class RECTANGLE or any classes that inherit the method will be debugged, although you can't specify a CLASS as the second argument


Document $Id: p-debugging.htm,v 1.1 2004/12/21 00:18:56 alex_mcdonald Exp $