Using the Return Stack

When the program transfers to an internal subroutine, the return address is pushed onto the return stack. The return address is the line the program transfers to at the end of the subroutine—that is, the line containing the statement immediately following the GOSUB that called the subroutine. If the subroutine calls another subroutine, the second address is pushed on top of the first address on the return stack, and so on for each embedded subroutine. As an ENTER statement is encountered, the top value on the stack is popped and taken as the return address for that subroutine.

Displaying the Return Stack (S)

The S command generates a list of line numbers on the return stack. Possible responses are:

=line# SOURCE LINE

Current subroutine will exit to line line#. When an ENTER statement is encountered, execution will transfer to line line#. (The corresponding source line is printed in half-intensity.)

=line1# SOURCE LINE [=LINE2# SOURCE LINE...]

Multiple subroutines are in effect. The current (top-level) subroutine will exit to line line1#. The next level subroutine will exit to line line2#, and so on. (Corresponding source lines are printed in half-intensity.

STK EMP

Nothing in stack.

ILSTK

Illegal stack. This usually signifies that an external subroutine is being executed. (External subroutines are not monitored by the return stack.)

Popping the Return Stack (R)

The R command pops the return stack. The program returns from the current subroutine as if an ENTER statement had been encountered at that point.

Modal Traps (M)

A modal trap occurs whenever an external subroutine is called, returned from, or when a mainline program enters another mainline program. In response to the modal trap, type M to toggle the modal trap ON or OFF depending on the trap’s previous state.

When a modal trap occurs it will be indicated by entering the BASIC debugger (*), and one of these prompts appears:

*MCxxx

Indicates the modal trap was caused by a CALL statement. xxx indicates the source code line number where the CALL statement occurred.

*MRxxx

Indicates the modal trap was caused by an ENTER statement. xxx indicates the source code line number where the ENTER statement occurred.

*MExxx

Indicates the modal trap was caused by an ENTER statement. xxx indicates the source code line number where the ENTER statement occurred.

In response to the above modal traps, type M at the * prompt to toggle the modal trap ON or OFF.

See Also

Using the mvBASIC Debugger

Debugger Commands: Quick Reference

Fixing a Bug

A Sample Program

Entering the Debugger

Exiting the Debugger

Displaying and Changing a Variable

Accessing Source Code

Using Breakpoints and Tracing

Using Execution Control

Printing Output