Call Stack and Variables
When the machine is paused, the Call Stack panel answers who called this code, and the Variables panel shows the program’s variables by name, with their types. For a program built with source-level debug information (BASIC built with Boriel BASIC, or C built with z88dk), both work at the level of your source: frames are SUBs, FUNCTIONs and C functions, and variables are decoded by type. For an assembly program the Call Stack shows the raw stack.
123- The statement that runs next.
- The Call Stack: the SUB and the line in the main program that called it.
- The Variables panel: the SUB’s locals and the program’s globals.
Debug a BASIC or C program at source level
Build a debuggable program
Source-level debug information comes with every Boriel BASIC build and with z88dk debug builds that use the sccz80 compiler. SDCC builds carry no line information, so a C program built with SDCC is debugged in the disassembly only.
Stop in your program
Set a breakpoint on a statement and start a debug run. The editor highlights the statement that runs next; on a line with several statements, only that statement.
Open the panels
In the Debug activity, open Call Stack and Variables. Step with the source-level step commands (see Running, pausing and stepping): the panels follow each stop.
The Call Stack panel
For a source-level program
The panel lists one row per active call, the innermost first: the routine’s name and the file and line it stands at. The bottom row is the main program.
- Click a row to make it the selected frame. The editor moves to that frame’s statement, and the Variables panel shows that frame’s parameters and locals.
- Run to this frame, the button on an outer row (also in the row’s context menu, beside Go to this frame), runs until control is back in that frame and stops at the return point there. It is Step Out repeated, done as one run.
When the machine stops in code that has no statements (the runtime, or machine code), the top row reads runtime code at an address, or runtime error: and the error. Click it to expand the raw return addresses between the stack pointer and your innermost routine.
For any other program
For assembly, and any program without source-level information, the panel shows the top 16 words
of the stack, starting at SP: the row labelled Top: is the word SP points at, then 1:, 2:
and so on. Each row shows where the word is stored, an arrow, and its value. When the value points
into a routine of your build, the routine’s name and offset follow (MAIN+12). Hover a row for the
addresses in hexadecimal and decimal.
These are raw stack words: a return address and a value the program pushed look the same.
While in the execution history
When you step back into the execution history, the
memory above SP may already hold other data, so the panel rebuilds the frames from the recorded
calls and returns instead. Each row says how the routine was entered (CALL, RST, an interrupt or
an NMI), where it was called from and where it returns to. The frames are exact as far back as the
history reaches; the last row says earlier frames before recorded history when there were more.
The Variables panel
The Variables panel needs a program with source-level debug information and a paused machine. It has up to four sections:
| Section | Shows |
|---|---|
| Returned | After a step out of a FUNCTION, or a step over a statement that called FUNCTIONs: the value each returned. |
| Locals — routine | The parameters and local variables of the frame selected in the Call Stack panel. |
| Globals | The program’s global variables. |
| Watch | BASIC expressions you add yourself. |
Arrays and other compound values expand with the chevron beside them. The tooltip of a value gives its address (and its bank, for a banked variable).
- Change a value: double-click a number, type the new value and press Enter (Esc cancels). The value is checked against the variable’s type. Strings and banked variables cannot be edited. Changing a value while standing in the past takes over there, after asking.
- Add a BASIC watch: type an expression in the Add watch box at the bottom and press Enter. The trash button on a watch row removes it.
A Boriel BASIC program’s FASTCALL routine shows no parameter, and an array whose bounds are not
constant shows only its address (see Debugging at source level).
If the selected routine has not set up its frame yet (the machine stopped at its very first instruction), the Locals section says so.
z88dk’s C programs show scalar variables (char, int, long, signed and unsigned) and pointers.
Banked functions, floats, structs and arrays are not described; the build output lists what was left
out.
For the symbols of an assembly program, use the Watch panel.
Settings that affect source stepping
On the Debugging page of Settings:
- Just My Code (on by default): source steps run through the standard library as they run
through the runtime. Off, stepping also stops in the library’s statements. The command is
em-jmc on|off. - Stop in interrupt handlers while stepping (off by default): an interrupt handler taken during a source step runs outside the step, unless this is on. Breakpoints in handlers always stop.
- Stop at runtime errors (on by default): a debug run of a compiled BASIC program stops where it
raises an error, before the ROM prints the report, and shows the statement. The command is
em-err on|off.