LOGBOOK

HELP

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:

  1. target remote :3333 connects GDB to the GDB server on this machine (no host before the colon means localhost), port 3333, which is OpenOCD. OpenOCD's log suggests target extended-remote :3333 instead, which keeps the connection usable after the program exits or is restarted.
  2. set remote hardware-watchpoint-limit 2 tells 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.
  3. mon reset halt is monitor reset halt. monitor sends 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.
  4. flushregs throws away the register values GDB had cached, since the reset changed them all. Current GDB versions warn that it is deprecated and call it maintenance flush register-cache.
  5. thb app_main is thbreak: a temporary hardware breakpoint on app_main, the entry point of an ESP-IDF application. "Temporary" means it deletes itself after the first hit.
  6. c is continue: let the chip run from reset. It boots through the bootloader and FreeRTOS start-up and stops at the first line of app_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:

From Quiz: SIOT / JTAG Debugging with OpenOCD and GDB | Updated: Nov 10, 2026