esp32基于IDF配置 coredump时进行gdb调试

基于ESP-IDF配置,通过串口,在coredump时自动进入gdb调试。

参考:

IDF 监视器 - ESP32-C6 - — ESP-IDF 编程指南 latest 文档 (espressif.com)

核心转储 - ESP32-C6 - — ESP-IDF 编程指南 latest 文档 (espressif.com)

1.配置

打开coredump输出,可选到flash或uart。

(Top) → Component config → Core dump → Data destination
                                 Espressif IoT Development Framework Configuration
( ) Flash
(X) UART
( ) None











[Space/Enter] Toggle/enter  [ESC] Leave menu           [S] Save
[O] Load                    [?] Symbol info            [/] Jump to symbol
[F] Toggle show-help mode   [C] Toggle show-name mode  [A] Toggle show-all mode
[Q] Quit (prompts for save) [D] Save minimal config (advanced)

开启崩溃时调用GDBStub选项:

(Top) → Component config → ESP System Settings → Panic handler behaviour
                                 Espressif IoT Development Framework Configuration
( ) Print registers and halt
( ) Print registers and reboot
( ) Silent reboot
(X) GDBStub on panic
( ) GDBStub at runtime









[Space/Enter] Toggle/enter  [ESC] Leave menu           [S] Save
[O] Load                    [?] Symbol info            [/] Jump to symbol
[F] Toggle show-help mode   [C] Toggle show-name mode  [A] Toggle show-all mode
[Q] Quit (prompts for save) [D] Save minimal config (advanced)

2.烧录运行

烧录程序,触发coredump后就会调用进入gdb调试。

示例代码:

#include <stdio.h>

void set_value(int *value_p)
{
    *value_p = 1;
}

void app_main(void)
{
    printf("gdb test start\r\n");
    set_value(NULL);
    printf("gdb test end\r\n");
}

烧录&运行,打开监视器:

none@ubuntu:~/explore/gdb_demo$ idf.py build && idf.py -p /dev/ttyUSB1 flash monitor

触发coredump后就可以进行gdb调试:

Done!
Coredump checksum='62e8040b'
I (1522) esp_core_dump_uart: Core dump has been written to uart.
Entering gdb stub now.
$T0b#e6GNU gdb (esp-gdb) 12.1_20221002
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=xtensa-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/none/explore/gdb_demo/build/gdb_demo.elf...
Remote debugging using /dev/ttyUSB1
warning: multi-threaded target stopped without sending a thread-id, using first non-exited thread
0x400e4d2d in set_value (value_p=0x0) at ../main/gdb_demo.c:5
5           *value_p = 1;
(gdb) backtrace 
#0  0x400e4d2d in set_value (value_p=0x0) at ../main/gdb_demo.c:5
#1  0x400d782f in app_main () at ../main/gdb_demo.c:11
#2  0x400e56ef in main_task (args=<optimized out>) at /home/none/esp/esp-idf/components/freertos/app_startup.c:208
#3  0x40087df0 in vPortTaskWrapper (pxCode=0x400e5658 <main_task>, pvParameters=0x0)
    at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162
(gdb) frame 0
#0  0x400e4d2d in set_value (value_p=0x0) at ../main/gdb_demo.c:5
5           *value_p = 1;
(gdb) p value_p
$1 = (int *) 0x0

因为配置了输出coredump数据到串口,会输出很多信息:

===============================================================
==================== ESP32 CORE DUMP START ====================

Crashed task handle: 0x3ffafba0, name: 'main', GDB name: 'process 1073413024'

================== CURRENT THREAD REGISTERS ===================
exccause       0x1d (StoreProhibitedCause)
excvaddr       0x0
epc1           0x4008460f
epc2           0x0
epc3           0x0
epc4           0x0
epc5           0x0
epc6           0x0
eps2           0x0
eps3           0x0
eps4           0x0
eps5           0x0
eps6           0x0
pc             0x400e4d2d          0x400e4d2d <set_value+5>
lbeg           0x400014fd          1073747197
lend           0x4000150d          1073747213
lcount         0xfffffffb          4294967291
sar            0x4                 4
ps             0x60a20             395808
threadptr      <unavailable>
br             <unavailable>
scompare1      <unavailable>
acclo          <unavailable>
acchi          <unavailable>
m0             <unavailable>
m1             <unavailable>
m2             <unavailable>
m3             <unavailable>
expstate       <unavailable>
f64r_lo        <unavailable>
f64r_hi        <unavailable>
f64s           <unavailable>
fcr            <unavailable>
fsr            <unavailable>
a0             0x800d782f          -2146600913
a1             0x3ffb6a40          1073441344
a2             0x0                 0
a3             0x3f403854          1061173332
a4             0x3f4038d4          1061173460
a5             0x3ffb6a60          1073441376
a6             0x3ffb6a40          1073441344
a7             0xc                 12
a8             0x1                 1
a9             0x3ffb6a00          1073441280
a10            0xa                 10
a11            0x3ffaeb44          1073408836
a12            0x3ffb6a40          1073441344
a13            0xc                 12
a14            0x3ffb4750          1073432400
a15            0xb33fffff          -1287651329

==================== CURRENT THREAD STACK =====================
#0  0x400e4d2d in set_value (value_p=0x0) at ../main/gdb_demo.c:5
#1  0x400d782f in app_main () at ../main/gdb_demo.c:11
#2  0x400e56ef in main_task (args=<optimized out>) at /home/none/esp/esp-idf/components/freertos/app_startup.c:208
#3  0x40087df0 in vPortTaskWrapper (pxCode=0x400e5658 <main_task>, pvParameters=0x0) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162

======================== THREADS INFO =========================
  Id   Target Id          Frame 
* 1    process 1073413024 0x400e4d2d in set_value (value_p=0x0) at ../main/gdb_demo.c:5
  2    process 1073413368 vPortTaskWrapper (pxCode=0x0, pvParameters=0x0) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:161
  3    process 1073413712 0x400845ee in esp_cpu_wait_for_intr () at /home/none/esp/esp-idf/components/esp_hw_support/cpu.c:121
  4    process 1073410900 0x4000bff0 in ?? ()
  5    process 1073412616 0x4000bff0 in ?? ()
  6    process 1073412272 0x4000bff0 in ?? ()

==================== THREAD 1 (TCB: 0x3ffafba0, name: 'main') =====================
#0  0x400e4d2d in set_value (value_p=0x0) at ../main/gdb_demo.c:5
#1  0x400d782f in app_main () at ../main/gdb_demo.c:11
#2  0x400e56ef in main_task (args=<optimized out>) at /home/none/esp/esp-idf/components/freertos/app_startup.c:208
#3  0x40087df0 in vPortTaskWrapper (pxCode=0x400e5658 <main_task>, pvParameters=0x0) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162

==================== THREAD 2 (TCB: 0x3ffafcf8, name: 'IDLE') =====================
#0  vPortTaskWrapper (pxCode=0x0, pvParameters=0x0) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:161
#1  0x40000000 in ?? ()

==================== THREAD 3 (TCB: 0x3ffafe50, name: 'IDLE') =====================
#0  0x400845ee in esp_cpu_wait_for_intr () at /home/none/esp/esp-idf/components/esp_hw_support/cpu.c:121
#1  0x400d212e in esp_vApplicationIdleHook () at /home/none/esp/esp-idf/components/esp_system/freertos_hooks.c:59
#2  0x4008669d in prvIdleTask (pvParameters=0x0) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:4327
#3  0x40087df0 in vPortTaskWrapper (pxCode=0x40086694 <prvIdleTask>, pvParameters=0x0) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162

==================== THREAD 4 (TCB: 0x3ffaf354, name: 'ipc0') =====================
#0  0x4000bff0 in ?? ()
#1  0x400880d6 in vPortClearInterruptMaskFromISR (prev_level=<optimized out>) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:568
#2  vPortExitCritical (mux=<optimized out>) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:532
#3  0x40087805 in xTaskGenericNotifyWait (uxIndexToWait=0, ulBitsToClearOnEntry=<optimized out>, ulBitsToClearOnExit=4294967295, pulNotificationValue=0x3ffaf290, xTicksToWait=4294967295) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:5911
#4  0x400843d5 in ipc_task (arg=0x0) at /home/none/esp/esp-idf/components/esp_system/esp_ipc.c:58
#5  0x40087df0 in vPortTaskWrapper (pxCode=0x400843a8 <ipc_task>, pvParameters=0x0) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162

==================== THREAD 5 (TCB: 0x3ffafa08, name: 'esp_timer') =====================
#0  0x4000bff0 in ?? ()
#1  0x400880d6 in vPortClearInterruptMaskFromISR (prev_level=<optimized out>) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:568
#2  vPortExitCritical (mux=<optimized out>) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:532
#3  0x400876c9 in ulTaskGenericNotifyTake (uxIndexToWait=0, xClearCountOnExit=1, xTicksToWait=<optimized out>) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:5820
#4  0x400d3bcb in timer_task (arg=0x0) at /home/none/esp/esp-idf/components/esp_timer/src/esp_timer.c:475
#5  0x40087df0 in vPortTaskWrapper (pxCode=0x400d3bbc <timer_task>, pvParameters=0x0) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162

==================== THREAD 6 (TCB: 0x3ffaf8b0, name: 'ipc1') =====================
#0  0x4000bff0 in ?? ()
#1  0x400880d6 in vPortClearInterruptMaskFromISR (prev_level=<optimized out>) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:568
#2  vPortExitCritical (mux=<optimized out>) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:532
#3  0x40087805 in xTaskGenericNotifyWait (uxIndexToWait=0, ulBitsToClearOnEntry=<optimized out>, ulBitsToClearOnExit=4294967295, pulNotificationValue=0x3ffaf7f0, xTicksToWait=4294967295) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:5911
#4  0x400843d5 in ipc_task (arg=0x1) at /home/none/esp/esp-idf/components/esp_system/esp_ipc.c:58
#5  0x40087df0 in vPortTaskWrapper (pxCode=0x400843a8 <ipc_task>, pvParameters=0x1) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162


======================= ALL MEMORY REGIONS ========================
Name   Address   Size   Attrs
.rtc.text 0x400c0000 0x0 RW  
.rtc.dummy 0x3ff80000 0x0 RW  
.rtc.force_fast 0x3ff80000 0x0 RW  
.rtc_noinit 0x50000000 0x0 RW  
.rtc.force_slow 0x50000000 0x0 RW  
.rtc_fast_reserved 0x3ff82000 0x0 RW  
.iram0.vectors 0x40080000 0x403 R XA
.iram0.text 0x40080404 0xbdb7 R XA
.dram0.data 0x3ffb0000 0x35d4 RW A
.ext_ram_noinit 0x3f800000 0x0 RW  
.ext_ram.bss 0x3f800000 0x0 RW  
.flash.appdesc 0x3f400020 0x100 R  A
.flash.rodata 0x3f400120 0x9678 RW A
.flash.rodata_noload 0x3f409798 0x0 RW  
.flash.text 0x400d0020 0x15e7b R XA
.iram0.data 0x4008c1bc 0x0 RW  
.iram0.bss 0x4008c1bc 0x0 RW  
.dram0.heap_start 0x3ffb4780 0x0 RW  
.coredump.tasks.data 0x3ffafba0 0x154 RW 
.coredump.tasks.data 0x3ffb6980 0x1b0 RW 
.coredump.tasks.data 0x3ffafcf8 0x154 RW 
.coredump.tasks.data 0x3ffb7010 0x120 RW 
.coredump.tasks.data 0x3ffafe50 0x154 RW 
.coredump.tasks.data 0x3ffb7590 0x1a0 RW 
.coredump.tasks.data 0x3ffaf354 0x154 RW 
.coredump.tasks.data 0x3ffaf180 0x1c0 RW 
.coredump.tasks.data 0x3ffafa08 0x154 RW 
.coredump.tasks.data 0x3ffb5970 0x1b0 RW 
.coredump.tasks.data 0x3ffaf8b0 0x154 RW 
.coredump.tasks.data 0x3ffaf6e0 0x1c0 RW 

===================== ESP32 CORE DUMP END =====================
===============================================================
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值