LOGBOOK

HELP

Quiz Entry - updated: 2026.11.10

In what order are the three terminal sessions for an ESP32 JTAG debugging session started, and why does each need the ESP-IDF environment?

First build, flash and start the serial monitor; second start OpenOCD, the GDB server; third start GDB, which connects to OpenOCD. Each terminal first runs the ESP-IDF activation script, because a new shell does not know the paths to the cross-compiler, OpenOCD, its scripts or GDB.

Serpentine flow of the debugging session: activate ESP-IDF, build flash and monitor, start OpenOCD with the board config, wait for it to listen on port 3333, start GDB with the gdbinit file and the ELF, then debug with break, next and continue

* The server must be listening before the client connects. *

  1. Terminal 1: build, flash, monitor. source ~/.espressif/tools/activate_idf_v6.1.sh, then idf.py -p /dev/ttyUSB0 build flash monitor. This compiles the project, writes it to the ESP32 over the serial bridge and shows its output (Hello world!). Leave the monitor running so you can see what the program prints while it is being debugged. Ctrl+] exits it.
  2. Terminal 2: OpenOCD. Activate the environment again, then openocd -f board/esp32-wrover-kit-3.3v.cfg (the full path to the file is under OPENOCD_SCRIPTS). OpenOCD scans the JTAG chain, finds the two ESP32 cores and waits for GDB on port 3333.
  3. Terminal 3: GDB. Activate once more, then xtensa-esp32-elf-gdb -x gdbinit build/hello_world.elf. GDB loads the program's symbols, runs the commands in gdbinit, connects to port 3333, resets the chip and stops at app_main.

The order follows the dependencies: GDB is a client and fails with "connection refused" if no server is listening, and debugging only makes sense against firmware that matches the ELF file on the laptop.

The environment matters because these tools are not installed system-wide. The activation script only changes the current shell. It sets variables such as IDF_PATH and OPENOCD_SCRIPTS (where OpenOCD finds its board/, interface/ and target/ files) and puts the toolchain on PATH. A terminal where it was not run gets "command not found". A root shell opened with sudo bash also starts without these variables, which is why the environment is activated again inside it.

Tip: idf.py openocd and idf.py gdb start the same two programs with the project's settings filled in.

Go deeper:

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