From 54f658623d0ddfab9474e10f5ef7a1df4d1ee611 Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Sat, 16 May 2026 18:57:42 -0500 Subject: [PATCH] build(make): emit cc65 debug info (-g + --dbgfile) for PRG Adds --dbgfile build/c64-https.dbg to the main ld65 link and ensures -g is set on ca65 invocations. PRG bytes are bit-identical with -g enabled; the .dbg sidecar is purely additive. VICE monitor and diagnostic tools can consume the .dbg directly for PC -> symbol/source mapping, eliminating the need to grep labels.txt for symbol resolution. Per-overlay .dbg files will ride along with the P-384 overlay work in a separate PR. Co-Authored-By: Claude Opus 4.7 (1M context) --- CLAUDE.md | 7 +++++-- Makefile | 2 +- tools/integration/build_nistcurves_p256.sh | 5 +++++ tools/integration/build_nistcurves_p384.sh | 5 +++++ tools/integration/build_nistcurves_p384_bin.sh | 7 +++++++ tools/integration/build_x25519.sh | 4 ++++ 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index a45ac18..d76a136 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -16,8 +16,11 @@ Dependencies: - VICE (`x64sc`) only for `make run` / the test harness Targets: - - `make` — default, produces `build/c64-https.prg` - and `build/labels.txt` (VICE label format) + - `make` — default, produces `build/c64-https.prg`, + `build/labels.txt` (VICE label format), and + `build/c64-https.dbg` (cc65 debug info, + consumable by VICE's monitor + diagnostic + agents; P-384 overlay gets a `.dbg` sidecar too) - `make clean` — remove build artifacts - `make run` — autostart the PRG in VICE - `make ip65-libs` — rebuild ip65 object libraries from the submodule diff --git a/Makefile b/Makefile index debe323..403efdc 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ IP65_BUILD := ip65-build IP65_BIN := $(IP65_BUILD)/ip65-c64.bin CA65FLAGS := -I src -I src/inc -I src/crypto/shared -I src/net/$(BACKEND) --debug-info -LD65FLAGS := -C $(CFG) -Ln build/labels.txt -m build/c64-https.map +LD65FLAGS := -C $(CFG) -Ln build/labels.txt -m build/c64-https.map --dbgfile build/c64-https.dbg # Source inventory. TOP_SRCS := $(wildcard src/*.s) diff --git a/tools/integration/build_nistcurves_p256.sh b/tools/integration/build_nistcurves_p256.sh index 7f39a52..d8f1cfc 100755 --- a/tools/integration/build_nistcurves_p256.sh +++ b/tools/integration/build_nistcurves_p256.sh @@ -342,7 +342,11 @@ mkdir -p "$OBJ_DIR" "$OUT_DIR" # zp_config.s is the single point of truth for ZP equates; we apply -D # overrides so sibling defaults get replaced with c64-https's canonical map. +# `-g` embeds cc65 debug info into the .o files so the final ld65 --dbgfile +# (driven from the top-level Makefile) can merge per-source line/symbol +# records into build/c64-https.dbg. Does not change emitted code bytes. "$CA65" \ + -g \ -I "$STAGING" \ -I "$PROJECT_ROOT/src/crypto/shared" \ "${ZP_DEFINES[@]}" \ @@ -350,6 +354,7 @@ mkdir -p "$OBJ_DIR" "$OUT_DIR" for src in fp256_raw mod256_raw points256_raw ecdsa256_raw curve256_raw data_p256_raw reu_equates_raw; do "$CA65" \ + -g \ -I "$STAGING" \ -I "$PROJECT_ROOT/src/crypto/shared" \ -o "$OBJ_DIR/$src.o" "$STAGING/$src.s" diff --git a/tools/integration/build_nistcurves_p384.sh b/tools/integration/build_nistcurves_p384.sh index 2caf4d9..a732e3c 100755 --- a/tools/integration/build_nistcurves_p384.sh +++ b/tools/integration/build_nistcurves_p384.sh @@ -258,7 +258,11 @@ mkdir -p "$OBJ_DIR" "$OUT_DIR" # We assemble it with `-D` overrides so the sibling's defaults are # replaced by c64-https's canonical ZP map. The other source files use # `.importzp` to pull these equates from the linker-resolved zp_config.o. +# `-g` embeds cc65 debug info into each .o; the overlay ld65 invocation +# in build_nistcurves_p384_bin.sh merges it into build/lib/overlay-p384.dbg. +# Does not change emitted code bytes. "$CA65" \ + -g \ -I "$STAGING" \ -I "$PROJECT_ROOT/src/crypto/shared" \ "${ZP_DEFINES[@]}" \ @@ -270,6 +274,7 @@ mkdir -p "$OBJ_DIR" "$OUT_DIR" # conflict with the .importzp declaration. for src in fp384_raw mod384_raw points384_raw data_raw; do "$CA65" \ + -g \ -I "$STAGING" \ -I "$PROJECT_ROOT/src/crypto/shared" \ -o "$OBJ_DIR/$src.o" "$STAGING/$src.s" diff --git a/tools/integration/build_nistcurves_p384_bin.sh b/tools/integration/build_nistcurves_p384_bin.sh index 3386751..967378e 100755 --- a/tools/integration/build_nistcurves_p384_bin.sh +++ b/tools/integration/build_nistcurves_p384_bin.sh @@ -101,11 +101,18 @@ mkdir -p "$OUT_DIR" # Link. ld65 -Ln emits labels in the old ca65 format; the main Makefile # rewrites `al 00XXXX .name` to `al C:XXXX .name` via sed. Mirror that. +# Sidecar .dbg path derived from the .bin path (build/lib/overlay-p384.dbg). +# Pairs with the `-g` ca65 flag added in build_nistcurves_p384.sh so ld65 +# can merge per-source line/symbol records. Does not affect the padded +# .bin image bytes. +DBG_OUT="${BIN_OUT%.bin}.dbg" + "$LD65" \ -C "$CFG" \ -o "$BIN_OUT" \ -Ln "$LABELS_OUT" \ -m "$MAP_OUT" \ + --dbgfile "$DBG_OUT" \ --define reu_status=\$df00 \ --define reu_command=\$df01 \ --define reu_c64_lo=\$df02 \ diff --git a/tools/integration/build_x25519.sh b/tools/integration/build_x25519.sh index 5bd645e..bd52fc9 100644 --- a/tools/integration/build_x25519.sh +++ b/tools/integration/build_x25519.sh @@ -326,7 +326,11 @@ rm -rf "$OBJ_DIR" mkdir -p "$OBJ_DIR" "$OUT_DIR" for src in fe25519_raw x25519_raw x25519_init_raw data_x25519_bss_raw data_x25519_rodata_raw; do + # `-g` embeds cc65 debug info; ld65 --dbgfile (top-level Makefile) + # merges per-source line/symbol records into build/c64-https.dbg. + # Does not change emitted code bytes. "$CA65" \ + -g \ -I "$STAGING" \ "${ZP_DEFINES[@]}" \ -o "$OBJ_DIR/$src.o" "$STAGING/$src.s"