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


    目前只会在崩溃时使用gdb的方法,gdb实时运行调试好像要用jlink这一类硬件调试器,这种方法可以通过串口在崩溃时,调用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)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    开启崩溃时调用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)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    2.烧录运行

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

    示例代码:

    #include 
    
    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");
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

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

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

    触发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=) at /home/none/esp/esp-idf/components/freertos/app_startup.c:208
    #3  0x40087df0 in vPortTaskWrapper (pxCode=0x400e5658 , 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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    因为配置了输出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=) at /home/none/esp/esp-idf/components/freertos/app_startup.c:208
    #3  0x40087df0 in vPortTaskWrapper (pxCode=0x400e5658 , 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=) at /home/none/esp/esp-idf/components/freertos/app_startup.c:208
    #3  0x40087df0 in vPortTaskWrapper (pxCode=0x400e5658 , 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 , 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=) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:568
    #2  vPortExitCritical (mux=) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:532
    #3  0x40087805 in xTaskGenericNotifyWait (uxIndexToWait=0, ulBitsToClearOnEntry=, 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 , 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=) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:568
    #2  vPortExitCritical (mux=) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:532
    #3  0x400876c9 in ulTaskGenericNotifyTake (uxIndexToWait=0, xClearCountOnExit=1, xTicksToWait=) 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 , 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=) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos/portmacro.h:568
    #2  vPortExitCritical (mux=) at /home/none/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:532
    #3  0x40087805 in xTaskGenericNotifyWait (uxIndexToWait=0, ulBitsToClearOnEntry=, 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 , 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 =====================
    ===============================================================
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
  • 相关阅读:
    vscode远程调试c++
    c语言初阶指针
    开学季征文 | 新学期给自己的一些小建议
    上架即封神!3.6k Star 的开源游戏模拟器,Delta 冲上 App Store 免费榜
    MySQL数据库设计需要注意的点
    从零开始学习rust语言
    服务器、云服务器、高防服务器都有什么优势呢?
    Leetcode第150题—逆波兰表达式
    动态规划:LeetCode第10题 正则表达式匹配
    IDEA实用工具
  • 原文地址:https://blog.csdn.net/qq_41790078/article/details/134480841