- Overview
- Built-in Debugger
- Logging
- Common Issues
- Debugging Tools
- Test ROM Debugging
- Performance Profiling
RustyNES provides comprehensive debugging tools for both developers and users troubleshooting emulation issues.
The egui debugger ships in the default frontend build (no separate feature flag). Launch the app and toggle the debugger overlay in-app:
cargo run --release -p rustynes-frontend -- rom.nesPress ` (backtick) to toggle the debugger overlay, or open individual
chip panels from the Debug menu. The panels are read-only and never
advance emulator-visible state. See
../frontend.md §"Debugger panels" for the full panel list.
CPU Debugger:
- Disassembly view
- Register inspection
- Breakpoints (PC, memory read/write)
- Step execution (instruction, scanline, frame)
- Stack viewer
PPU Debugger:
- Nametable viewer
- Pattern table viewer
- Sprite viewer (OAM)
- Palette viewer
- VRAM inspector
Memory Viewer:
- CPU address space ($0000-$FFFF)
- PPU address space ($0000-$3FFF)
- Cartridge RAM/ROM
Execution Control:
s / step - Step one instruction
n / next - Step over (JSR)
c / continue - Resume execution
p / pause - Pause execution
Breakpoints:
bp <addr> - Set breakpoint at address
bp del <addr> - Delete breakpoint
bp list - List all breakpoints
watch <addr> - Break on memory write
Inspection:
r / regs - Display CPU registers
m <addr> [len] - Display memory
d <addr> [len] - Disassemble from address
ppu - Display PPU state
Environment variable:
RUST_LOG=debug cargo run -- rom.nes
RUST_LOG=rustynes::cpu=trace cargo run -- rom.neserror - Critical errors only
warn - Warnings and errors
info - General information
debug - Detailed debugging
trace - Extremely verbose (per-instruction)
[INFO] Loading ROM: super_mario_bros.nes
[DEBUG] Mapper: 0 (NROM)
[DEBUG] PRG-ROM: 32KB, CHR-ROM: 8KB
[TRACE] CPU: A:00 X:00 Y:00 P:24 SP:FD PC:C000
[TRACE] CPU: Executing: LDA #$10 (2 cycles)
Symptoms: Incorrect sprites, background corruption
Debugging:
- Enable PPU debugger
- Check pattern tables (correct tiles loaded?)
- Check nametables (correct tile IDs?)
- Verify palette RAM
- Check PPU register writes
Common Causes:
- PPU timing errors
- Incorrect scrolling implementation
- CHR banking bugs (mappers)
Symptoms: Missing sound, distorted audio
Debugging:
- Check APU register writes
- Verify channel enable flags ($4015)
- Check frame counter mode
- Inspect channel waveforms
Common Causes:
- APU timing errors
- Incorrect mixer output
- Sample rate mismatch
Symptoms: Controller unresponsive
Debugging:
- Log $4016/$4017 reads/writes
- Verify strobe sequence
- Check button state propagation
Common Causes:
- Missing strobe write
- Incorrect read sequence
- DPCM conflict (rare)
CPU trace (compare with golden log):
fn log_cpu_state(&self) {
println!(
"{:04X} A:{:02X} X:{:02X} Y:{:02X} P:{:02X} SP:{:02X}",
self.pc, self.a, self.x, self.y, self.p.bits(), self.sp
);
}Compare with nestest.log:
cargo run -- nestest.nes --log-cpu > output.log
diff output.log nestest.log.goldenfn dump_ram(&self) {
for addr in 0x0000..=0x07FF {
if addr % 16 == 0 {
print!("\n{:04X}: ", addr);
}
print!("{:02X} ", self.read(addr));
}
println!();
}fn dump_ppu_state(&self) {
println!("PPU Registers:");
println!(" PPUCTRL: {:08b}", self.ctrl);
println!(" PPUMASK: {:08b}", self.mask);
println!(" PPUSTATUS: {:08b}", self.status);
println!(" Scanline: {}, Cycle: {}", self.scanline, self.cycle);
println!(" VRAM Addr: ${:04X}", self.vram_addr);
}Run with logging:
cargo run --release -- tests/roms/nestest.nes --automationExpected output:
[PASS] nestest automated test
All 8000+ instructions validated
On failure:
[FAIL] nestest: Mismatch at line 4523
Expected: A:42 X:00 Y:00 P:24 SP:FD
Got: A:43 X:00 Y:00 P:24 SP:FD
Run specific test:
cargo test --test blargg_cpu_exec_spaceInterpret results:
- Test writes status to $6000
- $00 = Pass
- $01-$FF = Failure code
- Text message in $6004+
Using perf:
cargo build --release -p rustynes-frontend
perf record -g ./target/release/rustynes rom.nes
perf reportUsing flamegraph:
cargo install flamegraph
cargo flamegraph --bin rustynes -- rom.nesUsing valgrind (massif):
valgrind --tool=massif ./target/release/rustynes rom.nes
ms_print massif.out.<pid>Related Documents:
- TESTING.md - Test suite
- BUILD.md - Build instructions
- CONTRIBUTING.md - Development workflow