Skip to Content
Get StartedDebug your program

Debug your program

A debugger lets you stop a program and look inside the machine: which instruction runs next, what the registers hold, and what is in memory. On this page you stop the border-colours program from the previous page and step through it.

Stop at a breakpoint

Set a breakpoint

In the editor, click just left of the line number 13, the line out (#fe),a. A red dot appears: that is a breakpoint. Click the dot again to remove it.

Start debugging

Click Debug on the build bar, or press Ctrl+F5. Klive builds and starts the program as before, but now it stops when it reaches the breakpoint.

Open the Debug side bar

Click the Debug icon in the activity bar, the second one from the top.

Fig. 7.1Paused at the breakpoint
The IDE paused at the breakpoint on line 13123
  1. The breakpoint. The highlighted line is the instruction that runs next: the machine stopped before running it.
  2. The stepping buttons on the toolbar: Step Into, Step Over and Step Out.
  3. The Z80 CPU panel shows the registers. A holds 07, the colour about to be written: white.

Step through the code

Press F10 (Step Over) twice. Each press runs one instruction and stops again.

Fig. 7.2Two instructions later
The IDE after two steps, stopped at the HALT instruction1
  1. The machine stopped at halt. On the way, out (#fe),a set the border to white, and ld e,25 put 25 into E; check it in the Z80 CPU panel.

Look at the emulator, too. The machine stopped in the middle of drawing a frame, so the screen is drawn only down to where the beam had got to. The hatched part below it is still the previous frame, and the label at the top says exactly where the beam is.

To see this, the beam position must be turned on. If the emulator’s screen shows no hatched part, click Show/Hide the beam position while paused on the emulator’s toolbar: the icon with a line between four corner marks, highlighted while it is on.

Fig. 7.3The emulator while the program is paused
The paused emulator, drawn down to the beam, with the previous frame hatched below

The stepping commands

CommandShortcutWhat it does
ContinueF5Runs until the next breakpoint.
Step IntoF11 (F12 on macOS)Runs one instruction. On a CALL, stops at the first instruction of the subroutine.
Step OverF10Runs one instruction. A CALL, an RST or a block instruction such as LDIR runs completely.
Step OutShift+F11 (Shift+F12 on macOS)Runs until the current subroutine returns.
StopF4Switches the machine off.
💡

Press F5 a few times: each time, the program runs once around its loop and stops at the breakpoint again, with A one less than before.

More to look at

The Debug side bar has more panels; click a title to open or close one. The toolbar’s last buttons open the Memory and Disassembly views. Breakpoints explains conditions, hit counts and memory breakpoints, and the other debugging guides cover every view.

Next, write your first BASIC program.

Last updated on