Overview
The toolkit includes debugger source code (debugger.zig) that provides interactive debugging capabilities via a TCP connection. However, this functionality is not currently exposed as a usable tool in the default build.
Current status
Thebuild.zig file only builds two executables:
4004-assembler- The assembler tool4004-emulator- The emulator tool
Planned debugging architecture
The debugger code implements a TCP-based debugging protocol:Connection model
The debugger would connect to a modified emulator on TCP port 5005:Planned commands
The debugger source code includes implementations for these commands:s - Step
s - Step
Execute a single instruction and display the next instruction and program counter.
r - Run
r - Run
Continue execution until a breakpoint is reached.
b - Breakpoint
b - Breakpoint
Set a breakpoint at a specific address.The address parameter is a program memory address (0-4095).
p - Print registers
p - Print registers
Display all 16 index registers.
m - Memory
m - Memory
Read a single nibble from DRAM using three nibble parameters.Parameters are: bank, chip/register, character position.
args - Arguments
args - Arguments
Display command-line arguments stored in memory by the runtime.
Emulator integration
The emulator source includes astart_cpu_with_debugger() function that:
- Listens on TCP port 5005
- Waits for debugger connection
- Executes instructions on command
- Responds to debugger queries
main() function calls start_cpu() instead, so this mode is not accessible.
Enabling debugger support
To enable debugging, you would need to:Modify emulator to use debugger mode
In
emulator.zig, replace the start_cpu() call with start_cpu_with_debugger() or add a command-line flag to enable it.Alternative debugging approaches
Until the debugger is properly integrated, you can:- Add print statements to the emulator source code
- Use Zig’s built-in debugger (gdb/lldb) to step through emulator execution
- Examine the emulator’s CPU state by modifying the source
- Write test programs that output diagnostic information to the monitor
Protocol details
The debugger uses a simple text-based protocol:- Commands are single letters followed by optional arguments
- Responses are newline-terminated
- Maximum command size is 1024 bytes
- The debugger tracks command history and supports repeating the last command by pressing Enter
If you’re interested in using or improving the debugger, consider opening a pull request to add it to the build configuration and make it a first-class tool in the toolkit.