chapter six
6 Debugging, observability, and profiling
This chapter covers
- Debugging fundamentals: the four broad techniques (print logging, interactive debug, tracing, profiling), the host-to-target debug pipeline, JTAG vs. SWD, and the probes (ST-Link, MCU-Link, J-Link, CMSIS-DAP) that connect them.
- Printing debug messages in
no_stdRust: semihosting, UART, ITM, and RTT, with their blocking behavior, hardware requirements, and host-side tooling. - Structured logging with
defmt: binary log frames, transport backends, linker setup, and decoding output throughprobe-rsorcargo-embed. - Handling panics: panic-handler crates, conditional panic behavior via Cargo features, and recovering fault information from
HardFaultand the configurable Cortex-M faults. - Interactive debugging: choosing between GDB+OpenOCD and
probe-rs, core GDB command groups, OpenOCD configuration, and automating a session with.gdbinit. - Profiling: cycle-accurate timing with the DWT counter, a SysTick-based fallback for cores without DWT, and platform notes spanning Cortex-M and RISC-V.