How probe-rs/probe-rs works
Project type and purpose
• This is a multi-crate Rust workspace providing a modern embedded-debugging toolkit (“probe-rs”) and a suite of companion command-line tools (cargo-flash, cargo-embed, GDB/DAP servers, etc.).
• The core library (“probe-rs”) exposes abstractions for connecting to probes, establishing debug sessions, halting/stepping cores, reading/writing memory, flashing, and trace. Additional crates (probe-rs-debug, probe-rs-target, probe-rs-mi) extend debug-info parsing, target definitions, and MI (Machine Interface) support. The “probe-rs-tools” crate implements the end-user CLIs and servers (DAP, GDB).
Top-level component breakdown
A. Workspace manager
• Cargo workspace (root Cargo.toml) aggregates all crates.
B. Core library (“probe-rs”)
• src/lib.rs & submodules:
• probe abstraction (open, connect, list probes)
• session & core (halt/run/step, memory access)
• flashing (builder, loader, algorithm)
• architecture modules (ARM, RISC-V, Xtensa)
• adapters for actual hardware probes (CMSIS-DAP, ST-Link, JLink, FTDI, Blackmagic, ESP-USB-JTAG, WLink, FakeProbe)
• Target definitions (.yaml under probe-rs/targets) loaded at runtime.
C. Support crates
1. probe-rs-debug: parse DWARF, unwind stacks, semihosting, RTT snapshots
2. probe-rs-target: structures & serialization for target pack data
3. probe-rs-mi: MI protocol support (GDB/IDE machine interface)
4. target-gen: CMSIS-Pack processor/flash-algorithm generator for YAML target files
5. rtthost: host side of RTT protocol
6. smoke-tester: integration tests (assembly, stepping, coredumps)
7. xtask: workspace maintenance tasks
D. End-user tools (probe-rs-tools/src/bin)
• cargo-flash, cargo-embed, probe-rs CLI, GDB server, DAP server, plus their subcommands and RPC layers.
How components interact
• User invokes a CLI tool (cargo-flash / cargo-embed / probe-rs).
→ CLI parses command args, constructs a session via probe-rs library
→ Library uses adapter crates to open a debug probe (USB/JTAG)
→ Library loads target definition (YAML) via probe-rs-target/target-gen
→ Library executes flash algorithm, memory reads/writes, core control
• GDB server & DAP server:
→ Listen on TCP or stdio, process GDB/DAP protocol messages
→ Marshal messages to probe-rs-mi (MI) or to library functions directly
→ Return responses/events back to client IDE/GDB
• probe-rs-debug & rtthost:
→ parse ELF/DWARF for backtraces, semihosting, RTT data
→ coordinate with library & CLI for debug-info-dependent features
Architectural patterns & principles
• Modular crate-based design (workspace + multiple crates).
• Adapter pattern: each hardware probe implements a common Probe trait.
• Strategy/Builder pattern: flashing pipeline built step by step.
• Protocol layers: RPC modules for MI, DAP, GDB encapsulate transport (websocket, TCP, stdio).
• Separation of concerns: core library (logic), adapters (hardware), tools (user interface), target definitions (data files).