ESP8266 debugging tool intended to be used with esp-open-rtos. Based on Espressif/esp-gdbstub.
-
Build requires premake5 and xtensa-lx106-elf toolchain. Make sure both are in your PATH.
-
Configure with
premake5 gmake
. The following options are supported:--with-eor=/path/to/esp-open-rtos
: this option is required. It should point to an actual esp-open-rtos location.--with-threads
: enable RTOS task debugging. As for now, there is very basic support of threads, you will be able to see multiple tasks when a breakpoint is hit, but GDB will most likely crash shorlty after. This option also has a performance impact because a lot of data will be transferred through serial connection — consider increasing the baudrate.
When thread support is enabled, you need to add the following definitions to CFLAGS of your project before compiling FreeRTOS libs:
EXTRA_CFLAGS+=-DportREMOVE_STATIC_QUALIFIER -DINCLUDE_pcTaskGetTaskName=1 # The line above should go before including common.mk
Run
make clean
after switching the state of this flag. -
Run
make
-
Add library to your project:
PROGRAM=blink # Order is important! EXTRA_CFLAGS+=-I../../../esp-gdbstub/include EXTRA_LDFLAGS+=-L../../../esp-gdbstub/lib include ../../common.mk LIBS+=esp-gdbstub PROGRAM_CFLAGS+=-O0
-
Call
gdbstub_init()
after configuring UART speed.
It has been observed that GDB may crash when user requests step over source in a file compiled with optimization turned on. I haven't figured out why exactly this happens, but it has something to do with stack frame resolving. Turning optimization off for the whole project would impact performance and code size — that's why only PROGRAM_CFLAGS
is modified.
To use Eclipse CDT for debugging, open Eclipse, create a new project and create a debug configuration for C/C++ Remote Application.
You need to set the following options:
- Main → Application: Firmware ELF
- Debugger: Uncheck “Stop on startup at: main”
- Debugger → Main: select GDB binary and .gdbinit file provided with esp-gdbstub
- Debugger → Connection → Type: Serial
- Debugger → Connection → Speed: 115200
Note that upon launching the debug session gdb will send “continue” command if the target is paused at gdbstub_do_break
. If you want to stop right after debug session launch, place gdbstub_do_break
macro twice in your code.
- Using software breakpoints ('br') only works on code that's in RAM. Code in flash can only have a hardware breakpoint ('hbr'). If you know where you want to break before downloading the program to the target, you can use gdbstub_do_break() macro as much as you want.
- Due to hardware limitations, only one hardware breakpount and one hardware watchpoint are available.