Fault Injection & Debugging
GDB reverse-step and watchpoint firmware debugging
Hit HardFault_Handler, type reverse-stepi, and walk backwards straight to the instruction that trashed the pointer.
Hardware SWD probes stop after a HardFault has already smashed your call stack or jumped to address 0x00000000. Reproducing an intermittent crash takes hours of single-stepping.
CircuitTwin embeds a deterministic GDB RSP server (ct debug) supporting reverse-step, reverse-continue and hardware watchpoints on your compiled ELF.
Essential reverse-debugging GDB commands
| GDB command | Alias | When to use |
|---|---|---|
reverse-stepi | rsi | Step back one machine instruction from a fault trap |
reverse-continue | rc | Run backwards until a hardware watchpoint hits the corrupting write |
watch *(uint32_t*)0x20001000 | w | Catch the exact ISR or DMA descriptor writing a corrupt word |
info registers | i r | Inspect LR, PC, xPSR and stacked exception frame |
Local CLI workflow
Shell - start GDB server and attach
# Terminal 1: start deterministic GDB server
ct debug --board nucleo-f767zi --gdb-port 3333 build/app.elf
# Terminal 2: attach ARM GDB and step backwards from fault
arm-none-eabi-gdb build/app.elf -ex "target remote :3333" -ex "break HardFault_Handler" -ex "continue"Suite & fault configuration
.vscode/launch.json (Cortex-Debug)
{
"version": "0.2.0",
"configurations": [
{
"name": "CircuitTwin GDB Reverse Debug",
"type": "cortex-debug",
"request": "attach",
"servertype": "external",
"gdbTarget": "localhost:3333",
"executable": "${workspaceFolder}/build/app.elf"
}
]
}CI pipeline integration
.github/workflows/capture-on-fail.yml
name: Capture Trace on CI Failure
on: [push, pull_request]
jobs:
debug-trace:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ct run --board nucleo-f767zi --record trace/ build/app.elf
- uses: actions/upload-artifact@v4
if: failure()
with:
name: failure-trace
path: trace/Troubleshooting checklist
| Symptom | Fix |
|---|---|
| GDB shows ?? () instead of function names | Build with -g3 -Og (or -g alongside -O2) and pass the unstripped ELF to arm-none-eabi-gdb. |
| Watchpoint slows down host execution | Set the watchpoint only after reaching the failing fault or phase via a regular breakpoint. |
Frequently asked questions
| Question | Answer |
|---|---|
| Does GDB reverse debugging work inside VS Code? | Yes. Point Cortex-Debug or standard GDB attach to localhost:3333 started by ct debug and run reverse-stepi / reverse-continue from the debug console. |