Program Debugging [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation
HP Business BASIC/XL Reference Manual
Program Debugging
Two HP Business BASIC/XL features make debugging the current program
easier: trace statements and suspension during execution. Trace
statements print messages when one line transfers control to another that
is not sequentially the next line in the program, or when a variable is
assigned a value.
The program is suspended when one of the following occurs:
* The program executes a PAUSE statement.
* You press CONTROL Y (when no ON HALT is active).
* You press CONTROL Y twice in rapid succession.
* An error occurs (and error-handling is not active).
When program execution is suspended, control returns to the terminal
keyboard. From the keyboard, you can do any of the following:
* Variable values can be displayed (type the variable name and press
RETURN ).
* Commands can be executed.
* Variable values can be changed (with the LET command).
* Program lines can be modified (with the MODIFY command).
* Program lines can be inserted.
* Program lines can be deleted (with the DELETE command or as explained
in "Creating and Modifying a Program").
* Control can be transferred to another part of the program (with a
GOTO, GOSUB, or CALL command).
* Program lines can be added (as explained in "Creating and Modifying a
Program").
A busy line or subunit cannot be modified or deleted when the program is
suspended. See "Busy Lines and Busy Subunits" for more information.
Table 2-7 lists the debugging statements and commands and their effects.
All of the debugging statements and commands affect the current program.
None of the debugging commands are compilable.
Table 2-7. Program Debugging Commands
-----------------------------------------------------------------------------------------------
| | | |
| Command | Command or | Effect |
| | Statement? | |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| CALLS | Command | Prints names of busy program units on |
| | | system printer. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| CONTINUE | Command | Restarts suspended program. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| FILES | Command | Prints names and numbers of open files on |
| | | system printer. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| HOP | Command | Executes program and suspends it at next |
| | | line that is in same program unit and not |
| | | in a loop. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| PAUSE | Statement | Suspends program execution.* |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| STEP | Command | Executes next line of suspended program and |
| | | suspends program at line following it. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| Trace Statements | Either | See Table 2-8. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| Untrace Statements | Either | See Table 2-9. |
| | | |
-----------------------------------------------------------------------------------------------
Table 2-7 Note
* The PAUSE statement is defined in chapter 4.
Busy Lines and Busy Subunits
A line is busy if one of the following is true:
* The line made a call that has not returned.
* The line was interrupted with the halt key before it finished
executing. (Not all lines can be interrupted in this way. A PRINT
statement is an example of a line that cannot be busy.)
A busy line cannot be modified or deleted.
A subunit is busy if it has been called, but has not returned.
A busy subunit can be modified, but not deleted. When modifying a
subunit, observe the following restrictions:
* A busy SUB statement can only be changed to another SUB statement.
* A busy DEF statement can only be changed to another DEF statement.
Numeric type variables can only be changed to another numeric type.
The type cannot be changed from numeric to string or vice versa.
* Changes to the subunit header take effect the next time the subunit
is called.
To make other header changes to a busy DEF or SUB statement, you must
first stop the program with the STOP command (chapter 4 explains the STOP
command).
CALLS Command
The CALLS command prints the names of busy program units on the system
printer or another device. (The SEND SYSTEM OUTPUT TO statement
specifies the device; see chapter 6.) The CALLS command is a
command-only statement. That is, it can only be issued at the
interpreter prompt and cannot be placed in a program.
Syntax
CALLS
Example
If the program is not running:
>CALLS
MAIN Not executing.
If the program has paused at line 10:
>CALLS
MAIN @ 10
Suppose that the following are true:
Line 10 of the main program calls subunit FNBeep$.
Line 40 of FNBeep$ calls subunit FNBeep.
Line 50 of FNBeep calls subunit B.
The program pauses at line 100 in subunit B.
Then:
>CALLS
SUB B @ 100
FNBeep @ 50
FNBeep$ @ 40
MAIN @ 10
CONTINUE Command
The CONTINUE command restarts a suspended program. The CONTINUE command
is a command-only statement. That is, it can only be issued at the
interpreter prompt and cannot be placed in a program.
Syntax
{CONTINUE}[line_id]
{CONT }[* ]
Parameters
line_id Line that program execution will restart at. The line
must belong to the program unit that was executing when
the program was suspended. An error occurs if line_id
is not in the program.
* Restarts the program at the last line executed.
If neither line_id nor * is specified, the CONTINUE command restarts
program execution at the next line to be executed.
An error occurs if the CONTINUE command is executed and there is no
current program in the work space.
Examples
The following shows examples of the CONTINUE command:
CONTINUE
CONT
CONTINUE 100 !Continues the program at line 100
CONT Label5 !Continues the program at the line number in Label5
CONT * !Continues the program at the last line executed
FILES Command
The FILES command prints the file numbers of the files that have been
declared in the currently executing subunit. If a file is open, the
FILES command prints the file name after the number. The FILES command
prints a message if a file is not open. The FILES command also prints
COMMON after each common file and PARAMETER after each file that was
passed to the subunit as a parameter. The FILES command prints its
information on the system printer. The FILES command is a command-only
statement. That is, it can only be issued at the interpreter prompt and
cannot be placed in a program.
Syntax
FILES
Examples
The following shows an example of the FILES command:
>FILES
#1: File is not currently open.
#2: MYFILE.MYGROUP.MYACCT, REC:1, WRD:1
#3: MYFILE1.MYGROUP.MYACCT, REC:1, WRD:1, PARAMETER
#4: MYFILE2.MYGROUP.MYACCT, REC:1, WRD:1, COMMON
If no files are declared in the currently executing subunit the FILES
command will return a message.
>FILES
No files are declared in the current subprogram.
HOP Command
The HOP command can single-step from one line of a program unit to the
next line of the same program unit, without suspending execution during
loops or subunits. Specifically, the HOP command does the following:
* Does a TRACE PAUSE on the line that follows the next line to be
executed (even if it is in another program unit).
* Does a CONTINUE.
The HOP command is a command-only statement. That is, it can only be
issued at the interpreter prompt and cannot be placed in a program.
Syntax
HOP
The HOP command is useful for the following:
* Hopping through a GOSUB or CALL.
* Hopping through a loop (when executed on the last line of the loop).
The breakpoint that the HOP statement sets is reset by the next HOP
statement (only one HOP breakpoint per program).
Example
The following shows an example of the HOP command. The program pauses at
line 110. The HOP command has been issued during that pause.
>LIST
! exam246
100 LET A=3
105 PRINT "HI"
110 PAUSE
120 PRINT A
130 PRINT A+A
140 PRINT A*A
150 PRINT "BYE"
999 END
>RUN
HI
>HOP
3
130 PRINT A+A
>HOP
6
140 PRINT A*A
>hop
9
150 PRINT "BYE"
>HOP
BYE
999 END
STEP Command
The STEP command--or several STEP commands--can single-step through a
suspended program. Specifically, the STEP command does the following:
1. Executes the line that the program is suspended at.
2. Displays the next line to be executed.
3. Suspends the program at the displayed line.
The STEP command is a command-only statement. That is, it can only be
issued at the interpreter prompt and cannot be placed in a program.
Pressing CONTROL E also issues the STEP command.
Syntax
STEP
Examples
The following shows an example of the STEP command. The program pauses
at line 110, and the STEP command is issued during that pause.
>LIST
100 LET A=3
105 PRINT "HI"
110 PAUSE
120 PRINT A
130 PRINT A+A
140 PRINT A*A
150 PRINT "BYE"
999 END
>RUN
HI
>STEP
3
130 PRINT A+A
>STEP
6
140 PRINT A*A
>STEP
9
150 PRINT "BYE"
>CONT
BYE
>
Trace and Untrace Statements
Trace statements trace lines, variables, or both. Untrace statements
cancel trace statements.
A trace statement, while tracing lines, prints the following message
whenever one line transfers control to another:
TRACE IN LINE line_num1; BRANCH TO line_num2
A trace statement, while tracing variables, prints the following messages
whenever variables change value:
For a scalar variable:
TRACE IN LINE line_num; var_name = new_value
For an entire array variable:
TRACE IN LINE line_num; ARRAY var_name IS CHANGED
For an array element:
TRACE IN LINE line_num; array_name (Subscript_of_element) = new_value
TRACE IN LINE line_num; ELEMENT n IN ARRAY var_name = new_value
Trace statements print their output on the system printer. (The system
printer is specified by the SEND SYSTEM OUTPUT TO statement. The default
is the standard list device, that is, the terminal if HP Business
BASIC/XL is running interactively.)
Every trace and untrace statement can also be a command.
Table 2-8 shows which trace statements trace lines, which trace variables
and how the trace statements differ. For details about a particular
trace statement, see the section about that statement.
Table 2-8. Trace Statements
----------------------------------------------------------------------------------------------
| | | |
| Statement | Traces lines | Traces variables |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| TRACE ALL | Throughout program. | Throughout program. |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| TRACE EXEC[UTION] | From execution of first | No. |
| | specified line through | |
| | execution of last | |
| | specified line. | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| TRACE EXEC[UTION] VAR[S] | No. | From execution of first |
| | | specified line through |
| | | execution of last |
| | | specified line. |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| TRACE LINES | Within specified range. | No. |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| TRACE PAUSE | Within specified range | No. |
| | and pauses before each | |
| | line is executed. | |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| TRACE VAR[S] | No. | As specified. |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| TRACE VAR[S] IN | No. | In specified program |
| | | units or lines. |
| | | |
----------------------------------------------------------------------------------------------
| | | |
| TRACE WAIT | No. | No. |
| | | |
----------------------------------------------------------------------------------------------
Table 2-9 matches each trace statement with the untrace statements that
partially or totally cancel it.
Table 2-9. Trace/Untrace Statement Correspondence
---------------------------------------------------------------------------------------------
| | |
| Trace Statement | Untrace Statements That Cancel It |
| | |
---------------------------------------------------------------------------------------------
| | |
| TRACE ALL | UNTRACE LINES |
| | UNTRACE VAR[S] |
| | UNTRACE VAR[S] IN |
| | UNTRACE ALL |
| | TRACE OFF |
| | |
---------------------------------------------------------------------------------------------
| | |
| TRACE EXEC[UTION] | UNTRACE EXEC[UTION] |
| | TRACE OFF |
| | |
---------------------------------------------------------------------------------------------
| | |
| TRACE EXEC[UTION] VAR[S] | UNTRACE EXEC[UTION] VAR[S] |
| | TRACE OFF |
| | |
---------------------------------------------------------------------------------------------
| | |
| TRACE LINES | UNTRACE LINES |
| | UNTRACE ALL |
| | TRACE OFF |
| | |
---------------------------------------------------------------------------------------------
| | |
| TRACE PAUSE | UNTRACE PAUSE |
| | TRACE OFF |
| | |
---------------------------------------------------------------------------------------------
| | |
| TRACE VAR[S] | UNTRACE VAR[S] |
| | UNTRACE ALL |
| | TRACE OFF |
| | |
---------------------------------------------------------------------------------------------
| | |
| TRACE VAR[S] IN | UNTRACE VAR[S] IN |
| | UNTRACE VAR[S] |
| | UNTRACE ALL |
| | TRACE OFF |
| | |
---------------------------------------------------------------------------------------------
| | |
| TRACE WAIT | TRACE OFF |
| | TRACE WAIT n where n<0 |
| | |
---------------------------------------------------------------------------------------------
TRACE ALL and UNTRACE ALL
The TRACE ALL statement is the equivalent of the TRACE LINES and TRACE
VARS statements. It traces lines and variables throughout the program.
The UNTRACE ALL statement cancels TRACE ALL.
Syntax
TRACE ALL
UNTRACE ALL
TRACE EXEC and UNTRACE EXEC
The TRACE EXEC statement traces lines, beginning when the first specified
line executes and ending when the last specified line executes. If lines
are not specified, TRACE EXEC applies to the entire program. If the
first specified line does not exist or is not executed, TRACE EXEC does
not trace lines. If the last specified line does not exist or is not
executed, the TRACE EXEC statement does not stop tracing lines (unless an
UNTRACE EXEC or TRACE OFF statement executes).
The UNTRACE EXEC statement cancels the TRACE EXEC statement (for every
line).
Syntax
{EXECUTION}
TRACE {EXEC } [line_id1 [TO line_id2]]
{EXECUTION}
UNTRACE {EXEC }
Parameters
line_id1 Line tracing begins when this line executes. If this
line does not execute, line tracing never begins.
Default is the first program line.
line_id2 Line tracing ends when this line executes. If this line
is not specified or does not execute, line tracing does
not end until an UNTRACE EXEC or a TRACE OFF statement
executes.
TRACE EXEC VARS and UNTRACE EXEC VARS
The TRACE EXEC VARS statement traces variables, beginning when the first
specified line executes and ending when the last specified line executes.
If lines are not specified, TRACE EXEC VARS applies to the entire
program. If the first specified line does not exist or is not executed,
TRACE EXEC VARS does not trace variables. If the last specified line
does not exist or is not executed, the TRACE EXEC VARS statement does not
stop tracing variables (unless an UNTRACE EXEC or TRACE OFF statement
executes).
The UNTRACE EXEC VARS statement cancels TRACE EXEC VARS (for every line).
Syntax
{EXECUTION} {VARS}
TRACE {EXEC } {VAR } [line_id1 [TO line_id2]]
{EXECUTION}{VARS}
UNTRACE {EXEC }{VAR }
Parameters
line_id1 Variable tracing begins when this line executes. If
this line does not execute, variable tracing never
begins. The default is the first program line.
line_id2 Variable tracing ends when this line executes. If this
line is not specified or does not execute, variable
tracing does not end until an UNTRACE EXEC VARS or an
TRACE OFF statement executes.
TRACE LINES and UNTRACE LINES
The TRACE LINES statement traces specified lines.
The UNTRACE LINES statement cancels TRACE LINES for specified lines (not
necessarily for every line that TRACE LINES traces).
Syntax
TRACE LINES [line_range_list1]
UNTRACE LINES [line_range_list2]
Parameters
line_range_ Lines to be traced. The default is all program lines.
list1
line_range_ Lines that TRACE LINES is to be canceled for (can be a
list2 subset of line_range_list1). The default is all program
lines.
TRACE PAUSE and UNTRACE PAUSE
The TRACE PAUSE statement traces specified lines exactly as TRACE LINES
does. It also suspends the program like the PAUSE statement does before
the lines are executed. The CONTINUE command causes the suspended
program to resume execution.
The UNTRACE PAUSE statement cancels TRACE PAUSE for specified lines (not
necessarily for every line that TRACE PAUSE traces). If another trace
statement traces those lines, that statement continues to trace them, but
TRACE PAUSE does not delay the program after the trace messages that are
associated with those lines.
Syntax
TRACE PAUSE [line_range_list1]
UNTRACE PAUSE [line_range_list2]
Parameters
line_range_ Lines to be traced with pause. The default is all
list1 program lines.
line_range_ Lines for which TRACE PAUSE is to be canceled (can be a
list2 subset of line_range_list1). The default is all program
lines.
TRACE VARS and UNTRACE VARS
The TRACE VARS statement traces specified variables.
The UNTRACE VARS statement cancels TRACE VARS for specified variables
(not necessarily for every variable that TRACE VARS traces).
Syntax
{VARS}
TRACE {VAR } [var_name1 [, var_name2]...]
{VARS}
UNTRACE {VAR } [var_name3 [, var_name4]...]
Parameters
var_name1 var_name1 specifies variable to be traced. The default
is all variables in the program.
var_name2 Each var_name2 specifies an additional variable to be
traced.
var_name3 var_name3 specifies a variable that TRACE VARS is to be
canceled for. The default is all variables in the
program.
var_name4 Each var_name4 specifies an additional variable that
TRACE VARS is to be canceled for.
TRACE VARS IN and UNTRACE VARS IN
The TRACE VARS IN statement traces all variables in one or more specified
subunits.
The UNTRACE VARS IN statement cancels TRACE VARS IN for specified
subunits (not necessarily for every subunit that TRACE VARS IN
specified).
Syntax
{VARS}
TRACE {VAR } IN sub_id1 [, sub_id3]...
{VARS}
UNTRACE {VAR } IN sub_id2 [, sub_id4]...
Parameters
sub_id1 sub_id1 specifies a subunit that variables will be
traced in. sub_id1 is specified by [SUB] sub_id or
MAIN.
sub_id3 Each sub_id3 specifies an additional subunit that
variables will be traced in. Each sub_id3 is specified
by [SUB] sub_id or MAIN.
sub_id2 sub_id2 specifies a subunit that variables will no
longer be traced in. sub_id is specified by [SUB]
sub_id or MAIN.
sub_id4 Each sub_id4 specifies an addition subunit that
variables will no longer be traced in. Each sub_id4 is
specified by [SUB] sub_id or MAIN.
The UNTRACE ALL, UNTRACE VARS, and TRACE OFF statements also cancel the
TRACE VARS IN statement.
Example
The following shows examples of the TRACE VARS IN command. The first
example is in a program, the last two are issued as commands.
10 TRACE VARS IN MAIN, SUB A
TRACE VARS IN Sub_a, Sub_b, FNX
UNTRACE VARS IN X,Y,Z
TRACE WAIT
The TRACE WAIT statement delays the program for a specified time after
each trace message (for line tracing and variable tracing).
Syntax
TRACE WAIT num_expr
Parameters
num_expr Number of seconds to delay the program after each trace
message. The value of num_expr must be in the range
[-32768, 32767]. If num_expr < 0, TRACE WAIT does not
delay the program after trace messages.
TRACE OFF
The TRACE OFF statement cancels every TRACE statement.
Syntax
TRACE OFF
OPTION TRACE and OPTION NOTRACE
The OPTION TRACE statement enables the trace statements in the program
unit that contains it. The OPTION NOTRACE statement disables the trace
statements in the program unit that contains it. If a program unit
contains neither an OPTION TRACE nor an OPTION NOTRACE statement, the
global option applies (its default is GLOBAL OPTION TRACE).
Syntax
OPTION TRACE
{NO TRACE}
OPTION {NOTRACE }
The OPTION TRACE and OPTION NOTRACE statements can appear anywhere in a
program unit. The highest-numbered TRACE statement affects the entire
program unit the entire time that the program unit is executing.
Example
100 TRACE LINES
110 READ A,B
120 IF A=B THEN GOTO 140
130 PRINT "A<>B"
140 PRINT "A=B"
.
.
.
200 OPTION TRACE
.
.
.
300 OPTION NOTRACE
999 END
In the above program, the OPTION NOTRACE statement at line 300 disables
the trace statement at line 100, despite the OPTION TRACE statement at
line 200. HP Business BASIC/XL does not trace the branch from line 120
to line 140 when the program runs.
MPE/iX 5.0 Documentation