In a JTAG debugging setup for the ESP32, what are the roles of the FT232H adapter, OpenOCD and GDB, and how do they talk to each other?
GDB is the debugger you type into. OpenOCD translates GDB's requests into JTAG operations and acts as a GDB server on TCP port 3333. The FT232H turns OpenOCD's USB commands into the electrical JTAG signals on the ESP32's pins.
* Three programs on the laptop, two USB links to the hardware. *
Each layer only knows its neighbours:
- GDB (the client),
xtensa-esp32-elf-gdb, is a GDB built for the ESP32's Xtensa processor. It knows the program: it reads the ELF file to map addresses to source lines, function names and variables. It knows nothing about JTAG. It speaks the generic GDB remote serial protocol to a server ("read 4 bytes at this address", "set a breakpoint here", "continue"). - OpenOCD (the server), the Open On-Chip Debugger, knows the chip. A board configuration tells it which adapter to use, how the JTAG chain looks and how the ESP32's debug unit works. It listens for GDB on port 3333 and turns every request into the right sequence of JTAG register accesses.
- The FT232H (the adapter) knows the wires. It receives bytes over USB and clocks them out on TCK, TMS and TDI, reading TDO back.
The separation means the same GDB works with any chip OpenOCD supports, and the debugger does not have to run on the machine the board is plugged into: GDB can connect to port 3333 over the network.
The third program, idf.py flash monitor, is independent of the other two. It uses the DevKitC's own USB serial port to load the firmware and to show its log output.
Go deeper:
ESP-IDF — JTAG Debugging — Espressif's overview of the adapter, OpenOCD and GDB stack, with setup steps.
OpenOCD — GDB and OpenOCD — how GDB connects to OpenOCD and what the server provides.
Wikipedia — GNU Debugger — GDB itself, including remote debugging through a stub or server.