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

  1. Enable CONFIG_ESP_SYSTEM_PANIC_GDBSTUB so that when an error occurs, esp_monitor will automatically enter GDB through UART

  2. Use ELF + Core dump records, enter GDB through idf.py coredump-debug

Common GDB commands:

  1. backtrace to trace the call stack (including incoming parameters)

  2. list to print the code location

  3. info threads to print all Task information

  4. info locals to print the local variables of the current Task

  5. print <var> to print the local/global variables of the current Task

  6. thread <id> to switch Task

You can also refer to GDB Cheat Sheet.

GDB Stub Debugging

  1. Enable CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME, you can automatically enter GDB through UART esp_monitor at runtime (Ctrl`+`C)

Common GDB commands:

  1. x/1xw <addr> to print the corresponding 32-bit memory/register address

  2. watch <var> to monitor variables, when the variable value changes, GDB will automatically stop

  3. break <where> to set breakpoints, which can be function names, line numbers, addresses

  4. continue to continue running

  5. step to run step by step, enter the function

  6. next to run step by step, do not enter the function

  7. print <var> to print variable values

  8. 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.