Debugging and Testing Techniques
Debugging and Testing Techniques
Using the debug() Function
logical = debug(message as character)
The text file is named debug + process ID + .txt. A copy of the latest debug file can also be found in the file debug.txt. The setting set debug enables (on) or disables (off) the logging of the messages.
set debug on // app1.prg debug("program started by: " + user()) //... debug("option chosen: " + m_opt)
Using the assert Command
The assert command is used for program debugging purposes: to display a message box with options when a condition evaluates to False (.F.).
assert <condition as logical> [message <message as character>]
The message box has four buttons, offering the following options:
|Suspends program execution and starts the Debugger. The Debug option is only available if the program is being run uncompiled.
|Stops program execution.
|Continues program execution.
|Continues program execution and issues set asserts off, causing subsequent asserts to be ignored.
Dumping Variables to an External Text File
The list memory command can be used to list all current memory variables, including arrays and objects, to a text file.
list memory to file <filename as character>
Other current status information can be output in a similar way:
- list status - list status information, including data, settings and keys
- list calls - list call stack for the current program, procedure or function
- list procedure - list names of active procedures and functions
- list classes - list active system, user-defined, class library and API classes
Using the Workbench Debugger
The debug command displays a pop-up debugger allowing the specified program to be monitored during execution.
debug <filename as character>
The debugger consists of four lines of information about the current program and eighteen push buttons. Program information consists of the following lines:
|Displays DEBUG operation: STEP, BREAKPOINT or WATCHPOINT.
|Displays the name of the current procedure or program.
|Displays the current line number.
|Displays the next program line to be executed.
The eighteen push buttons are used to access information about the current environment and to specify memory variables and conditions to monitor during program execution. The pop-up debugger provides the following push buttons:
|Step through a line at a time.
|Suspend the program to go to the interactive prompt, RESUME to restart.
|Cancel program execution and create error.mem.
|Display currently declared memory variables.
|Display currently open tables (and their indexes, current record, etc.).
|Show program/procedure call stack.
|Set a watch point. When Executing the program, execution will stop when the specified memory variable's value changes.
|Set a break point. When Executing the program, execution will stop when the specified condition becomes true.
|Show command history trace.
|Run program without stepping until watch point or break point reached.
|Clear all watch points.
|Clear all break points.
|Mark the current line as a break point.
|Clear a particular break point.
|Clear a particular watch point.
|Show all break points.
|Show all watch points.
|Exit the program and debugger.
Use the [UP], [DOWN], [LEFT], and [RIGHT] arrow keys to navigate the push buttons, and press the [RETURN] key to select a button. You may also type the accelerator key to select a button. The accelerator keys are the highlighted letters in the label of each push button.