01Set up
You need three things besides PEEKaboo:
-
VS Code
From code.visualstudio.com.
-
Bartman's Amiga extension
Search the Extensions view for Amiga C/C++ Compile, Debug & Profile by BartmanAbyss (
bartmanabyss.amiga-debug). It brings the whole toolchain: GCC for the 68000, the assembler, the linker and GDB. There's nothing else to install. -
PEEKaboo's companion extension
It's in the PEEKaboo folder (version 0.2.10 with PEEKaboo 0.9.3). Install it from a terminal, then restart VS Code. Install it again after each PEEKaboo update, so the two match:
code --install-extension extras\vscode\peekaboo-run.vsixIt adds a Peekaboo target to VS Code's Run and Debug list. It doesn't change Bartman's extension, which keeps its own targets.
02A first project
Make an empty folder, open it in VS Code, and run Amiga: Init Project from the Command Palette (F1). Bartman's example appears: main.c, a picture, a bob, a copper list and a tracker module. It's a complete little demo that takes over the machine. It shows a 320×256 picture, wobbles it with the copper, blits 16 bobs in a sine wave and plays music.
Then run Peekaboo: Add Compile & Run Target. It adds this to .vscode/launch.json:
{
"type": "peekaboo",
"request": "launch",
"name": "Peekaboo",
"preLaunchTask": "compile",
"program": "${workspaceFolder}/${config:amiga.program}"
}
Pick Peekaboo in the Run and Debug view, and make sure PEEKaboo is running.
03Press F5
F5 runs Bartman's compile task, then sends the new program to PEEKaboo. PEEKaboo starts a clean Amiga each time, mounts your build folder as a hard drive and runs the program straight from it. There's no disk image to make. It also finds the .elf next to the .exe, which holds the debug information: function names, source lines and variables.
How the program is started is set in :
| Mode | Does |
|---|---|
| Automatic | The fast folder launch, falling back to a bootable disk if the folder can't be mounted. The default. |
| Host directory | The folder launch only. Reports an error if that fails. |
| Bootable ADF | Always builds a bootable floppy image and boots that. Slower, but works where the folder launch doesn't. |
04Stop on a line of C
The Peekaboo target also attaches GDB to PEEKaboo's GDB server (, port 2346). Everything VS Code's debugger does then works on the emulated Amiga: breakpoints in C, stepping, the Variables and Watch panes, and the call stack.
i = 0). Step with F10 and F11 and continue with F5. Note <optimized out> next to copper1 and copPtr; the next section explains it.Attach to something already running
To debug a program PEEKaboo is already running, without sending a new build, add a second target with "request": "attach". Both targets accept server if PEEKaboo's HTTP port isn't 7474, plus timeout (how long to wait for the GDB server) and loadTimeout (how long to wait for the program to load), both in milliseconds:
{
"type": "peekaboo",
"request": "attach",
"name": "Peekaboo (attach)",
"program": "${workspaceFolder}/${config:amiga.program}",
"server": "http://127.0.0.1:7474"
}
If the program doesn't load in time, the Debug Console says how long it actually waited and what PEEKaboo last reported, so a slow boot can be told apart from a program that never started.
05Why the debugger lies: optimisation
Bartman's example compiles with -Ofast -flto -fwhole-program: as fast as possible, optimised across the whole program at once. That's right for a demo. It's also why debugging optimised C can feel slippery, because the compiler is free to rearrange your code as long as the result is the same:
- Lines vanish. A line that was folded into another produces no code of its own, so a breakpoint on it can never fire.
- Lines split. An inlined or unrolled line can produce several separate stretches of code. A breakpoint usually stops in only one of them.
- Functions disappear. Small functions are inlined into their callers. In the example,
WaitLinedoesn't exist as a function at all; its loop is insidemain. The call stack and profiler can't show what isn't there. - Variables go missing. A value that lives in a register, or only for a moment, has nowhere for the debugger to read it from. It shows as
<optimized out>. - Stepping jumps about. F10 moves through lines in the order the compiler put them, not the order you wrote them.
Build for debugging
In the project's Makefile, the compiler flags are on the CCFLAGS line. For a debugging build, swap -Ofast for -Og ("optimise, but keep it debuggable") and take out -flto -fwhole-program:
# release: as shipped
CCFLAGS = -g ... -m68000 -Ofast -nostdlib ... -flto -fwhole-program ...
# debugging
CCFLAGS = -g ... -m68000 -Og -nostdlib ...
Run Bartman's clean task, then F5. Lines, variables and functions now match your source much more closely. -O0 (no optimisation at all) goes further still. But it makes code that's very slow on a 7 MHz 68000, and anything that has to finish within a frame may not.
…and switch back
Put the flags back for anything you release, and measure speed with the release build. The difference is real:
| Bartman's example | -Ofast -flto -fwhole-program | -Og |
|---|---|---|
| Program size | 75,068 bytes | 73,824 bytes |
| What the profiler shows | main 54.5% of the frame (with WaitLine inlined into it) | WaitLine 32.3%, main 19.6%, plus Bartman's debug_* calls |
The optimised build is larger, because inlining copies code into each place it's used in exchange for speed. In this example most of each frame is spent waiting for the beam, so both builds keep up. A demo that uses its whole frame might not under -Og, and then timing-sensitive effects break. Profile your release build, not your debug build.
What PEEKaboo does about it
Most of the time you'll debug the build you ship, so PEEKaboo tries to make optimised code honest rather than ask you to avoid it:
- It tells you when a breakpoint can't do what you asked. VS Code shows a message when the line made no code (and lists nearby lines that did), when GDB moved the breakpoint to another line, and when a line was split into several stretches and the breakpoint covers only one.
- It recovers "optimised out" globals. When the debug information has lost track of a global but the variable is still in memory, the PEEKaboo target reads it straight from its address, using the symbol table for the address and the debug information for its type.
- It answers "did this line run?" without a breakpoint. With CPU tracing on,
COV main.c:487in the Debugger Console lists every stretch of code the line produced and how often each ran. That's the question a breakpoint can't answer on optimised code. - It shows source beside the real instructions. The Disassembly window interleaves your C with the 68000 code it became (see the next section), so you can see what the optimiser merged and reordered.
- It unwinds the stack without frame pointers. The example uses
-fomit-frame-pointer, and the call stack is still rebuilt from the debug information.
06The same stop, from PEEKaboo's side
PEEKaboo's own debugger knows your source too. Switch to the Debugger workspace while the program is stopped:
From here you have everything in the Curious guide as well: the copper list your code built, the blits it started, and the DMA it caused, all for the frame you stopped in.
07Bartman's debug features, in PEEKaboo
Bartman's support library has calls that tell the emulator about your program. PEEKaboo understands them (, on by default):
| In your code | In PEEKaboo |
|---|---|
KPrintF("…") | Appears in the Log window. The example's Hello debugger from Amiga! shows up there. You can also break when a line of output matches some text: the Breakpoints window's KPrintF text section, or BKS in the console. |
debug_register_bitmap(), debug_register_palette() | Your graphics, named, in the Bartman Bitmaps window, drawn with their palette. |
debug_register_copperlist() | Your copper lists, known by name to the debugger and the AI tools. |
debug_start_idle() / debug_stop_idle() | Time spent waiting, drawn in the Frame Scrubber's Idle row, with the frame's total idle time. |
warpmode(1) / warpmode(0) | Turbo on and off from your code, for skipping slow set-up. |
image.bpl and bob.bpl. Here they are, decoded with the live palette, with their addresses one click away.08Where does the time go?
Turn on CPU Trace (in the Profile or Disassembly window) and the Profile window counts cycles for every instruction and source line. Tick Group by function for the summary:
__udivsi3, __umodsi3 and __mulsi3. The 68000 has no 32-bit divide, so the % in sinus32[(frameCounter + i) % sizeof(sinus32)] calls a slow helper for each bob.Untick Group by function to see the same cycles per instruction, each labelled with its line of main.c. For a picture of the whole frame against the beam, open the Frame Scrubber.




