我们调试ESP32都知道,在idf monitor中,如果出现Guru Meditation Error 错误时,会看到错误出现的具体文件函数以及代码行数。如下这样:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| Guru Meditation Error of type StoreProhibited occurred on core 0. Exception was unhandled. Register dump: PC : 0x400f360d PS : 0x00060330 A0 : 0x800dbf56 A1 : 0x3ffb7e00 0x400f360d: do_something_to_crash at /home/gus/esp/32/idf/examples/get-started/hello_world/main/./hello_world_main.c:57 (inlined by) inner_dont_crash at /home/gus/esp/32/idf/examples/get-started/hello_world/main/./hello_world_main.c:52 A2 : 0x3ffb136c A3 : 0x00000005 A4 : 0x00000000 A5 : 0x00000000 A6 : 0x00000000 A7 : 0x00000080 A8 : 0x00000000 A9 : 0x3ffb7dd0 A10 : 0x00000003 A11 : 0x00060f23 A12 : 0x00060f20 A13 : 0x3ffba6d0 A14 : 0x00000047 A15 : 0x0000000f SAR : 0x00000019 EXCCAUSE: 0x0000001d EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000
Backtrace: 0x400f360d:0x3ffb7e00 0x400dbf56:0x3ffb7e20 0x400dbf5e:0x3ffb7e40 0x400dbf82:0x3ffb7e60 0x400d071d:0x3ffb7e90 0x400f360d: do_something_to_crash at /home/gus/esp/32/idf/examples/get-started/hello_world/main/./hello_world_main.c:57 (inlined by) inner_dont_crash at /home/gus/esp/32/idf/examples/get-started/hello_world/main/./hello_world_main.c:52 0x400dbf56: still_dont_crash at /home/gus/esp/32/idf/examples/get-started/hello_world/main/./hello_world_main.c:47 0x400dbf5e: dont_crash at /home/gus/esp/32/idf/examples/get-started/hello_world/main/./hello_world_main.c:42 0x400dbf82: app_main at /home/gus/esp/32/idf/examples/get-started/hello_world/main/./hello_world_main.c:33 0x400d071d: main_task at /home/gus/esp/32/idf/components/esp32/./cpu_start.c:254
|
可是更多的我们没有条件使用 idf monitor ,不如我们调试Arduino框架程序时出现错误就会是这样的:
1 2 3 4 5 6 7 8 9 10 11
| Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled. Core 1 register dump: PC : 0x4000c46c PS : 0x00060c30 A0 : 0x80123439 A1 : 0x3ffffda0 A2 : 0x00000000 A3 : 0x00000000 A4 : 0x00000800 A5 : 0x00000000 A6 : 0x00000008 A7 : 0x00000080 A8 : 0x00000000 A9 : 0x3ffffd50 A10 : 0x00000000 A11 : 0x00000000 A12 : 0x3ffcf644 A13 : 0x00000000 A14 : 0x3ffcf3ec A15 : 0x00000018 SAR : 0x00000004 EXCCAUSE: 0x0000001d EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x0000007f Backtrace:0x4000c469:0x3ffffda0 0x40123436:0x3ffffdb0 0x40123a5d:0x3ffffe20 0x40123b33:0x3ffffe40
ELF file SHA256: aa23852d5f02b6c3
|
这时候我们就需要使用Backtrace 来溯源,Backtrace包含的信息其实就是出现错的具体函数具体位置,我们需要借助官方工具以及我们当前固件的工程文件,一定要确保此工程版本和固件版本对应,不然定位可能会不准。
我们需要先安装IDF工具这部分在官网有说明,我后期也会出一篇文章详细介绍一下。安装完工具后在工程目录中打开ESP-IDF 4.4 PowerShell终端,输入以下代码
1
| xtensa-esp32-elf-addr2line -pfiaC -e build/SP1.elf 0x40123436:0x3ffffdb0
|
然后会输出
1 2
| lcz@LCX ~/WORK/CHANGE/ubibot-SmartPlug xtensa-esp32-elf-addr2line -pfiaC -e build/SP1.elf 0x40123436:0x3ffffdb0 0x40123436: read_485_co2_task at /home/lcz/WORK/CHANGE/ubibot-SmartPlug/components/RS485_Read/RS485_Read.c:498
|
SP1.elf为工程生成的中间文件,SP1是工程名称,0x40123436:0x3ffffdb0 就是错误代码的地址,一般使用Backtrace中第二个地址几个定位到出问题的函数。(注意:0x4000c469:0x3ffffda0 为一段完整的地址 )
Gitalk 加载中 ...