Right, I already posted how to debug ESP32-S2 here and the process is pretty similar

I’ll not explain how to wire the ESP32_PROG (or any other FTDI FT232 OpenOCD compatible programmer) to ESP32, you can find it easily in the Internet.

Instead I will use the ESP-WROVER-KIT board that already come with JTAG programmer in the board.

You need to clone the Espressif OpenOCD ESP32 repository:

$ git clone https://github.com/espressif/openocd-esp32

Configure and compile it:

$ ./bootstrap
$ ./configure --program-prefix=esp32- --enable-dummy --enable-ftdi --enable-ftdi-oscan1 --enable-stlink --enable-ti-icdi --enable-ulink --enable-usb-blaster-2 --enable-ft232r --enable-vsllink --enable-xds110 --enable-osbdm --enable-opendous --enable-esp-usb-jtag --enable-aice --enable-usbprog --enable-rlink --enable-armjtagew --enable-cmsis-dap --enable-kitprog --enable-usb-blaster --enable-presto --enable-openjtag --enable-jlink

If you have all the necessary libraries in your system you should see a nice report line mine:

OpenOCD configuration summary
MPSSE mode of FTDI based devices yes
cJTAG OSCAN1 tunneled thru MPSSE yes
ST-Link Programmer yes
TI ICDI JTAG Programmer yes
Keil ULINK JTAG Programmer yes
Altera USB-Blaster II Compatible yes
Bitbang mode of FT232R based devices yes
Versaloon-Link JTAG Programmer yes
TI XDS110 Debug Probe yes
OSBDM (JTAG only) Programmer yes
eStick/opendous JTAG Programmer yes
Espressif JTAG Programmer yes
Andes JTAG Programmer yes
USBProg JTAG Programmer yes
Raisonance RLink JTAG Programmer yes
Olimex ARM-JTAG-EW Programmer yes
CMSIS-DAP Compliant Debugger yes
Cypress KitProg Programmer yes
Altera USB-Blaster Compatible yes
ASIX Presto Adapter yes
OpenJTAG Adapter yes
SEGGER J-Link Programmer yes

Sometimes you could have some missing library and it will report “no”, but most of the time you will not use that feature anyway…

Now just compile and install it:

$ make
$ sudo make install

Finally we can run OpenOCD to debug ESP32:

$ esp32-openocd -f board/esp32-wrover-kit-3.3v.cfg -c "set ESP_RTOS none"
Open On-Chip Debugger v0.10.0-esp32-20201202-6-gc0a2ec6e (2021-05-14-14:19)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : FreeRTOS creation
Info : FreeRTOS creation
none
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi_tdo_sample_edge falling"
Info : clock speed 20000 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32.cpu0: Target halted, PC=0x400803C0, debug_reason=00000001
Info : Listening on port 3333 for gdb connections

Open another terminal and execute:

$ xtensa-esp32-elf-gdb nuttx
GNU gdb (crosstool-NG esp-2020r2) 8.1.0.20180627-git
Copyright (C) 2018 Free Software Foundation, Inc.
...
Reading symbols from nuttx…done.
(gdb) target extended-remote :3333
(gdb) mon reset halt
(gdb) flushregs
(gdb) b nx_start
(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.
esp32.cpu0: Target halted, PC=0x400D1F69, debug_reason=00000001
Set GDB target to 'esp32.cpu0'

Breakpoint 1, nx_start () at init/nx_start.c:355
355 int cpu = 0;
(gdb)