Overview: Panic Handler and Common Code Debugging Methods Introduction
Panic Handler is described in detail in the ESP-IDF Programming Guide, and will not be repeated here.
The common code debugging methods are as follows.
Log Printing / App Trace
ESP-IDF provides a convenient and easy-to-use log printing library ESP Logging and App trace.
Backtrace / Core Dump
For detailed guidance on this part, please refer to Locating Problems Using Backtrace & Coredump.
GDB Stub through UART
Please refer to GDB Stub, which can be briefly summarized as follows.
GDB Stub Postmortem
Enable CONFIG_ESP_SYSTEM_PANIC_GDBSTUB so that when an error occurs, esp_monitor will automatically enter GDB through UART
Use ELF + Core dump records, enter GDB through idf.py coredump-debug
Common GDB commands:
backtrace to trace the call stack (including incoming parameters)
list to print the code location
info threads to print all Task information
info locals to print the local variables of the current Task
print <var> to print the local/global variables of the current Task
thread <id> to switch Task
You can also refer to GDB Cheat Sheet.
GDB Stub Debugging
Enable CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME, you can automatically enter GDB through UART esp_monitor at runtime (Ctrl`+`C)
Common GDB commands:
x/1xw <addr> to print the corresponding 32-bit memory/register address
watch <var> to monitor variables, when the variable value changes, GDB will automatically stop
break <where> to set breakpoints, which can be function names, line numbers, addresses
continue to continue running
step to run step by step, enter the function
next to run step by step, do not enter the function
print <var> to print variable values
set <var> = <value> to modify variable values
You can also refer to GDB Cheat Sheet.
OpenOCD & GDB
Please refer to JTAG Debugging.
GPIO tracing
GPIO tracing often flips IO to mark events, such as implementing GPIO flipping when a certain event occurs in the code, so that you can determine whether the event is triggered by querying the flipping status of GPIO.
SystemView through UART/JTAG
For detailed guidance on this part, please refer to Using SystemView for System Analysis and Optimization.