Quiz Entry - updated: 2026.11.10
What does each line of this ESP32 gdbinit file do?
target remote :3333
set remote hardware-watchpoint-limit 2
mon reset halt
flushregs
thb app_main
c
Connect to OpenOCD, tell GDB the chip has only 2 hardware watchpoints, reset the chip and hold it stopped, discard GDB's stale copy of the registers, set a one-time hardware breakpoint on app_main, and continue until it is hit.
gdb -x gdbinit runs these commands in order, as if they were typed at the (gdb) prompt:
target remote :3333connects GDB to the GDB server on this machine (no host before the colon means localhost), port 3333, which is OpenOCD. OpenOCD's log suggeststarget extended-remote :3333instead, which keeps the connection usable after the program exits or is restarted.set remote hardware-watchpoint-limit 2tells GDB that the target has only two hardware watchpoints (comparators that stop the CPU when a memory address is accessed). Without it, GDB would accept more watchpoints than the chip can implement and fail only when it tries to resume.mon reset haltismonitor reset halt.monitorsends the rest of the line to OpenOCD instead of interpreting it, and OpenOCD resets the ESP32 and halts both cores at the first instruction. The program starts from a known clean state.flushregsthrows away the register values GDB had cached, since the reset changed them all. Current GDB versions warn that it is deprecated and call itmaintenance flush register-cache.thb app_mainisthbreak: a temporary hardware breakpoint onapp_main, the entry point of an ESP-IDF application. "Temporary" means it deletes itself after the first hit.ciscontinue: let the chip run from reset. It boots through the bootloader and FreeRTOS start-up and stops at the first line ofapp_main, where GDB prints the source line and returns the prompt.
The result is a debugging session that begins with the program frozen at its start every time.
Go deeper:
GDB manual — Connecting to a Remote Target —
target remote,target extended-remoteandmonitor.GDB manual — Setting Breakpoints —
tbreak,hbreakandthbreak.GDB manual — Remote Configuration —
set remote hardware-watchpoint-limitand related limits.