| Previous | Contents | Index |
DEBUG ON
|
The following example shows how the DEBUG ON statement is used inside an .SPSRC program to enable SheerPower's debug facility.
| Example 2-16 DEBUG ON |
|---|
debug on print '1', print '2', break print '3', print '4', print '5' end 1 2 break at main.0003 |
DEBUG ON is used to enable SheerPower's debug system. SheerPower's debug system helps locate problems in the way a program runs.
DEBUG must be enabled in order to use its features. When DEBUG is enabled, all of SheerPower's debug features are available.
DEBUG ON can be issued in immediate mode or as a statement in a program.
If DEBUG ON is used as a statement in a program, SheerPower enables DEBUG when it encounters the statement. DEBUG remains enabled until a DEBUG OFF command or statement is executed or until a DEBUG feature is executed which disables it.
DEBUG OFF
|
debug off
|
DEBUG OFF is used to disable SheerPower's DEBUG system. Set DEBUG OFF when you have finished correcting your program.
DEBUG OFF can be issued in immediate mode or as a statement in a program. If DEBUG OFF is used in a program, SheerPower disables DEBUG when it encounters the DEBUG OFF statement.
DEBUG will remain disabled until a DEBUG ON statement is executed, or until a DEBUG feature is executed which enables it.
TRACE ON|OFF
|
| Example 2-17 TRACE ON/OFF |
|---|
debug on trace on do_totals trace off stop routine do_totals print "Doing totals..." end routine Doing totals... |
In complex applications, there is often a need to follow an application's program flow in order to figure out how the application works. This is also useful when debugging logic errors in an application.
TRACING is used to follow an application's logic flow. As each statement is executed, the trace window will display the label and line number and source line being executed.
To turn off tracing, just close the trace window. TRACE OFF will stop tracing, but leave the trace window open.
You can copy select or all of the text inside the trace window by highlighting the text with your mouse (CTRL/A will select all) and using CTRL/C to copy it.
In the console window toolbar, you can use the Trace icon to toggle the trace feature on or off.
STATISTICS records information on a program's execution. It records the time each program line takes to execute and the number of times the line is executed. The word "STATISTICS" can be abbreviated to "STATS" (STATS ON, STATS OFF, LIST STATS). This abbreviation will be used frequently in this Guide.
STATS ON
|
| Example 2-18 STATS ON |
|---|
debug on
stats on
dim name$(5)
for i = 1 to 5
input 'Please enter your name': name$(i)
if _exit then exit for
print 'Hello, '; name$(i); '!'
next i
end
Please enter your name? Tester
Hello, Tester!
Please enter your name? exit <---- type in 'exit' and press [Enter]
|
STATS ON is used to turn on the statistics feature, which stores the execution time and count for each program line. Use STATS to tell if statements are being executed the correct number of times and which parts of a program are taking the most time. STATS is especially useful for speeding up a program's execution time.
STATS ON enables SheerPower's statistics feature. SheerPower begins recording statistics when program execution begins. The statistics feature remains enabled until the STATS OFF statement is executed.
STATS ON can be executed in immediate mode or in a program. If STATS ON is executed in immediate mode, DEBUG is automatically switched on. If STATS ON is executed in a program, and DEBUG is off, SheerPower ignores the statement. When STATS ON is executed, any statistics previously recorded are lost.
STATS OFF
|
stats off
|
STATS OFF is used to turn off the statistics feature.
STATS OFF turns off SheerPower's statistics feature. STATS OFF can be executed in immediate mode or in a program. If STATS OFF is executed in a program and DEBUG is off, SheerPower ignores the statement. STATS OFF leaves DEBUG on.
LIST STATS [: routine_name, routine_name ,....]
|
| Example 2-19 Listing statistics in DEBUG system |
|---|
debug on
stats on
dim name$(5)
for i = 1 to 5
input 'Please enter your name': name$(i)
if _exit then exit for
print 'Hello, '; name$(i); '!'
next i
end
Please enter your name? Tester <--- type name in, press [Enter]
Hello, Tester!
Please enter your name? Tester <--- type name in, press [Enter]
Hello, Tester!
Please enter your name? Tester <--- type name in, press [Enter]
Hello, Tester!
Please enter your name? Tester <--- type name in, press [Enter]
Hello, Tester!
Please enter your name? exit <--- type in 'exit', press [Enter]
|
Once you have run the program with the STATS ON, you can use the LIST STATS feature. Type in LIST STATS at the prompt, and the console window will display the file name, the date and time of day, and the statistics for each line in the program.
list stats
c:\sheerpower\list_stats.spsrc 04-SEP-2003 12:46
debug on
1 0.00 stats on
1 0.00 dim name$(5)
1 0.00 for i = 1 to 5
5 20.55 input 'Please enter your name': name$(i)
5 0.00 if _exit then exit for
4 0.00 print 'Hello, '; name$(i); '!'
4 0.00 next i
1 0.00 end
stats off <--- type in to turn off STATS
debug off <--- type in to turn off DEBUG
|
LIST STATS is used to display the statistics recorded by the STATISTICS feature.
LIST STATS lists each program line along with the number of times the line was executed and the execution time of each line.
The far left column lists the number of times each statement was executed. The next column gives the time each statement took to execute. The time is given in seconds and fractions of a second. (0.01 means the program line was executed in one-one hundredth of a second.) The last column lists the program itself. STATS must be ON for LIST STATS to be executed.
All the options available with the "LIST" statement are also available with LIST STATS. (See Section 2.4.3, LIST for more information.)
BREAK
|
| Example 2-20 Using BREAK in DEBUG system |
|---|
debug on print '1', print '2', break print '3', print '4', print '5' end 1 2 break at main.0003 |
BREAK is used to stop program execution when DEBUG is ON. For instance, you might use BREAK to stop the program if a variable is assigned a wrong value.
The BREAK statement can be used anywhere in a program. The BREAK statement will not take effect unless DEBUG is turned on. If DEBUG is off, SheerPower ignores any BREAK statements.
The HALT statement works the same way as the BREAK statement (see Section 2.4.4, HALT Statement) except that it always interrupts program execution.
When SheerPower executes a BREAK statement, it interrupts program execution and prints a BREAK message. The BREAK message tells what line the break occurred in. Program execution can be continued with the GO or STEP commands.
| Previous | Next | Contents | Index |