Skip to content

M3: dual backend (probe-rs + OpenOCD) + AI crash diagnosis (0.3.0) - #4

Merged
Adancurusul merged 13 commits into
mainfrom
feat/m3-dual-backend
Jul 16, 2026
Merged

M3: dual backend (probe-rs + OpenOCD) + AI crash diagnosis (0.3.0)#4
Adancurusul merged 13 commits into
mainfrom
feat/m3-dual-backend

Conversation

@Adancurusul

Copy link
Copy Markdown
Owner

Summary

Adds a dual debug backend behind a single DebugBackend trait — probe-rs (default, native) and openocd (via the GDB Remote Serial Protocol) — plus AI-facing crash diagnosis. The AI sees one tool set; the backend is chosen at connect. 24 tools total. Bumps to 0.3.0.

What's in it

  • src/backend/: DebugBackend trait + ProbeRsBackend + OpenOcdBackend (minimal GDB-RSP client in rsp.rs).
  • diagnose_fault: aggregates the Cortex-M SCB fault registers (CFSR/HFSR/MMFAR/BFAR/SHCSR/CPUID) + PC/SP/LR into one compact structured evidence bundle.
  • unwind_exception: full DWARF backtrace on probe-rs; Cortex-M exception-frame read + source mapping on OpenOCD.
  • Memory / target-control / breakpoint tools routed through the trait (probe-rs semantics preserved). Flash and RTT stay probe-rs-only.
  • Docs (README en/zh, SKILL), CHANGELOG.md, and an openocd_smoke example.

Validation

  • OpenOCD backend verified end-to-end on a real ESP32-S3 (openocd-esp32): connect, memory read/write, halt/run/step/reset, and register reads (PC/SP/LR correct).
  • 20 unit tests (RSP codec, fault + EXC_RETURN decode, register-output parse, 24-tool router) + a mock GDB-RSP integration test.
  • clippy -D warnings clean, cargo doc -D warnings clean, cargo package builds.

Honest caveat

diagnose_fault / unwind_exception and the probe-rs path are unit-tested and reuse probe-rs's own tested DWARF/register code, but have not yet been run on a physical Cortex-M crash. Follow-up: a Cortex-M hardware smoke (0.3.1).

Merge

Clean fast-forward from main, no conflicts.

🤖 Generated with Claude Code

Adancurusul and others added 13 commits July 16, 2026 01:24
…agnose_fault

M3 slice 1: DebugBackend trait unifies probe-rs and OpenOCD (GDB RSP) behind one MCP tool set. Memory/target-control/breakpoint tools route through the backend; flash/RTT stay probe-rs-only. Add diagnose_fault aggregating SCB fault registers into one compact structured evidence bundle. connect gains backend/openocd_address args. 23 tools; unit tests for RSP codec and fault decode.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Update SKILL.md and README (en/zh): add Backends section (probe-rs default, OpenOCD experimental via GDB RSP, not yet hardware-validated), diagnose_fault tool, and diagnose_fault step in the MCP workflow.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
probe-rs backend returns a full DWARF backtrace via probe-rs own unwinder (DebugInfo::unwind); OpenOCD backend reads the Cortex-M exception stack frame and maps faulting PC / caller LR to source lines via DebugInfo::get_source_location. Compact JSON frames. DebugInfo (!Send) is confined to synchronous blocks to keep the tool future Send. Pure EXC_RETURN decode is unit-tested. Docs updated (SKILL, README en/zh). 24 tools.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ackend

Spins up a local TCP server speaking minimal GDB RSP and drives OpenOcdBackend end-to-end (connect, read/write memory, register read, status, monitor halt/run, breakpoints) — verifies the RSP protocol wiring without any hardware.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Drives OpenOcdBackend against a running openocd GDB server and prints each op (connect/halt/status/read/reg/run). Used to validate the RSP wiring on real hardware (ESP32-S3 via openocd-esp32).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Real ESP32-S3 smoke (openocd-esp32) confirmed the OpenOCD backend: connect/halt/run/status/read_memory work; core_reg returns 0 on Xtensa (ARM gdb reg numbers). Document the required gdb_memory_map disable openocd flag (else it rejects the gdb connection) and the Xtensa register limitation; add a TODO in reg_number.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…sions)

Add: Fetch authoritative info yourself (tiered sources: target self-description > ELF/DWARF > datasheet method > ARM arch registers) and Know your versions (probe-rs / openocd fork+flags / probe firmware). The skill points to sources of truth instead of embedding static chip tables — aligns with the flagship-model, save-context, do-not-over-teach philosophy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…stic)

esp32-s3 Xtensa exposes no register map in the GDB target description, but openocd resolves register names. Read PC/SP/LR by candidate names (pc; sp|a1; lr|ra|a0) via monitor reg <name> and parse the value, instead of hardcoded ARM gdb register numbers. Fixes core_reg returning 0 on Xtensa. parse_reg_value + updated mock unit-tested.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…rdware

openocd returns monitor (qRcmd) output as a single hex-encoded packet (no O prefix, no trailing OK). Our monitor() returned it raw, so core_reg parsing failed on the ESP32-S3. Hex-decode the final qRcmd result. Mock updated to the real openocd reply form (a regression the O-packet mock previously masked).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Update the stale ARM-reg-number note now that core_reg reads by name via monitor reg and PC/SP/LR are verified correct on real ESP32-S3.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Bump version to 0.3.0, sync Cargo.lock, add CHANGELOG. OpenOCD backend validated on real ESP32-S3; probe-rs backend and diagnose_fault/unwind reuse probe-rs tested code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…h diagnosis)

Update README intro / What It Provides / Architecture (en+zh) and Cargo.toml description + keywords to reflect the dual backend (probe-rs/OpenOCD), Xtensa/ESP32, and crash-diagnosis tools. Earlier edits only touched the Backends section and tool tables.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Document openocd as an alternative to a probe-rs probe, and add a Crash Diagnosis section showing the halt -> diagnose_fault -> unwind_exception flow with its Cortex-M scope and debug-info requirement.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Adancurusul
Adancurusul merged commit 7113ae4 into main Jul 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant