mirror of
https://github.com/imjasonh/nescript
synced 2026-07-08 17:06:04 +00:00
linker: add ca65-compatible --dbg output for source-level debugging
Emit a `.dbg` debug-info file in the same format `ld65` produces, so Mesen / Mesen2 / fceuX pick it up automatically and enable source-line stepping, labelled variable inspection, and symbol-based breakpoints without manual address lookups. Closes #23. The new `render_dbg` helper stitches together metadata the compiler already surfaces (linker label table, IR codegen `__src_<N>` markers, analyzer variable allocations) into the file/mod/seg/scope/span/line/sym records documented at https://cc65.github.io/doc/debugfile.html. Each source-loc marker becomes a span that stretches to the next marker (so breakpoints cover every byte the statement compiled into) plus a line record pointing into it; `seg.ooffs` tracks the fixed bank's PRG-relative start so banked MMC1/UxROM/MMC3 ROMs map cleanly too. Reuses the `.mlb` symbol-name filter so internal skip/block labels stay out of the debugger's symbol browser. `--dbg` implies the same `__src_` marker emission as `--source-map` but leaves release builds byte-identical when neither flag is passed. https://claude.ai/code/session_01DfN3pKJLryr7vvNFBpcqmC
This commit is contained in:
parent
f9198ac52c
commit
e4751df143
6 changed files with 566 additions and 16 deletions
|
|
@ -53,7 +53,7 @@ Each module has a `mod.rs` (implementation) and a co-located `tests.rs` with uni
|
|||
`mod.rs`, `opcodes.rs`, `inline_parser.rs`, `tests.rs`. The built-in assembler and the inline-asm parser. `opcodes.rs` defines the 6502 opcode table with addressing modes. `inline_parser.rs` parses the body of `asm { ... }` blocks so codegen can splice real instructions in-line.
|
||||
|
||||
### `linker/`
|
||||
`mod.rs`, `tests.rs`. Assigns addresses to code and data segments, resolves label/symbol fixups, lays out banks for banked mappers (MMC1/UxROM/MMC3), and emits the final iNES byte stream via `rom::RomBuilder`.
|
||||
`mod.rs`, `debug_symbols.rs`, `tests.rs`. Assigns addresses to code and data segments, resolves label/symbol fixups, lays out banks for banked mappers (MMC1/UxROM/MMC3), and emits the final iNES byte stream via `rom::RomBuilder`. `debug_symbols.rs` owns the three debug-info writers — `render_mlb` (Mesen `.mlb`), `render_source_map` (plain-text ROM→source line map), and `render_dbg` (ca65-compatible `.dbg` debug-info file for Mesen source-level debugging).
|
||||
|
||||
### `rom/`
|
||||
`mod.rs`, `tests.rs`. Builds the final iNES ROM file. Generates the 16-byte iNES header and places the NMI/RESET/IRQ vector table.
|
||||
|
|
|
|||
|
|
@ -148,7 +148,16 @@ writes when `--debug` is passed, and are stripped entirely in release builds.
|
|||
state-handler, and variable addresses (with PRG ROM offsets for code and
|
||||
CPU addresses for RAM). `--source-map <path>` consumes the `SourceLoc` IR
|
||||
op and writes a plain-text map of `<rom_offset> <file_id> <line> <col>`
|
||||
entries for every lowered statement. Debug builds emit array bounds checks
|
||||
entries for every lowered statement. **`--dbg <path>` writes a
|
||||
ca65-compatible `.dbg` debug-info file** that Mesen / Mesen2 / fceuX pick
|
||||
up automatically for source-level stepping, labelled variable inspection,
|
||||
and symbol-based breakpoints. The file stitches together the linker's
|
||||
label table, the `__src_<N>` IR markers, and the analyzer's variable
|
||||
allocations into the `file`/`mod`/`seg`/`scope`/`span`/`line`/`sym`
|
||||
records documented at
|
||||
<https://cc65.github.io/doc/debugfile.html>. `ooffs` on the segment
|
||||
record tracks the fixed bank's PRG-relative start, so banked ROMs
|
||||
(MMC1/UxROM/MMC3) also map cleanly inside the debugger. Debug builds emit array bounds checks
|
||||
(CMP against size, BCC past a `JMP __debug_halt` wedge) and bump an
|
||||
overrun counter at `$07FF` in the NMI handler when the main loop didn't
|
||||
reach `wait_frame` before the next vblank.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue