1.

上次写了一个 ESP32 入门,我想有必要再写这篇文章,这次主要是分析 coredump 的,这就像 Android 和 Linux 系统的死机分析,有意思,也有难度。我们写代码的时候,不可避免的会遇到一些 coredump 的问题,这时候我们就要去分析 coredump 的原因,在 Linux 内核也是一样, coredump 主要是打印一些堆栈调用,通过看到这些堆栈调用信息,我们可以定位到问题原因。

 

网上有很多分析 coredump 的文章,但是清一色的都是翻译官网的东西,没有实际去测试运行过。

 

我觉得 ESP32 还有一个好处是,对于初学者真的太方便了,买个 Linux 开发板可能要几百块,但是买一个 ESP32 模块的话,也就 40 块钱,而且也是跑 Freertos 系统的,还有还有就是非常方便携带,调试烧录供电都可以用一个 usb 线搞定,说真的,我没有收钱宣传,是真的适合没有钱又喜欢入门嵌入式的同学们,但是这个只是起点,嵌入式后期我觉得一定是要学习Linux 的。

 

2.

coredump 官方文档

https://esp-idf-zh.readthedocs.io/zh_CN/latest/api-guides/core_dump.html

 

保存出现 coredump 的日志

sC4AAA4AAABkAQAA	
	
fLr8P1Dx/T8U8/0/	
	
gPH9P7Dy/T+suvw/xD/8P7jl/T98uvw/vD/8PxQAAAAAAAAAOGD8P3y6/D8AAAAA	
	
BQAAABjn/T9wdGhyZWFkAAcAAFEFNFQAfxTz/T8AAAAAIAsGAAUAAAAAAAAA	
	
AAAAAAAAAAAAAAAAAJj8P2iY/D/QmPw/AAAAAAAAAAABAAAAAAAAAAhCQD8AAAAA	
	
SB0AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA	
	
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA	
	
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA	
	
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA	
	
AAAAAAAAAAAAAAAAAAAAAAAAAAA=	
	
hOkRgEoVDkAwBwYAsggOgBDy/T/ku/w/fLr8PwAAAAD/AAAAAAAAAAAAAAAA	
	
8PH9P+S7/D/ku/w/3OUTQAEAAAAhAAYABAAAAAgAAAAcAAAAAAAAAP0UAEANFQBA	
	
........

 

烧录到设备上对应的 elf 文件

elf 文件类似于 Linux 上的 Vmlinx 文件, 通过这个文件和 dump 信息,还有 gdb 就可以找到 crash 位置附近的上下文代码,有了上下文代码,作为百里挑一码农的你,肯定不会放过蛛丝马迹找到 bug 所在。

 

elf 文件是我们编译的时候生成的,我们每次编译一次就会有不同的符号表,当然,我们分析 coredump 的时候,烧录到设备的 bin 文件和 elf 文件要对应,要不然分析结果千壤之别。

ESP32 coredump 分析_coredump

 

3.执行命令如下

官网还有另外一个命令,那个命令每次运行都出现错误,如果有知道原因的可以留言告知我,万分感谢。

./components/espcoredump/espcoredump.py dbg_corefile cat-wc/build/app_main.elf -c cat-wc/build/coredump.bin -t b64

 

$ ./components/espcoredump/espcoredump.py dbg_corefile cat-wc/build/app_main.elf -c cat-wc/build/coredump.bin -t b64	
espcoredump.py v0.1-dev	
GNU gdb (crosstool-NG crosstool-ng-1.22.0-61-gab8375a) 7.10	
Copyright (C) 2015 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=i686-build_pc-cygwin --target=xtensa-esp32-elf".	
Type "show configuration" for configuration details.	
For bug reporting instructions, please see:	
<http://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 cat-wc/build/app_main.elf...done.	
[New <main task>]	
[New process 1]	
[New process 2]	
[New process 3]	
[New process 4]	
[New process 5]	
[New process 6]	
[New process 7]	
[New process 8]	
[New process 9]	
[New process 10]	
[New process 11]	
[New process 12]	
[New process 13]	
[New process 14]	
#0  0x4012cbc3 in ledc_channel_config (ledc_conf=<optimized out>)	
    at /cygdrive/e/AiThinkerIDE_V0.5/cygwin/home/aithinker/project/esp-idf/components/driver/ledc.c:328	
328         return ret;	
[Current thread is 1 (<main task>)]	
(gdb)

推荐阅读

推荐周立功先生的一本书

一个从华为离职的朋友

分享一个非常 nice 的工具

ESP32 coredump 分析_coredump_02   

ESP32 coredump 分析_coredump_03