Skip to content

Instantly share code, notes, and snippets.

@rikka0w0
Last active January 17, 2021 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikka0w0/40c515db111424fdfac42c32d16928bf to your computer and use it in GitHub Desktop.
Save rikka0w0/40c515db111424fdfac42c32d16928bf to your computer and use it in GitHub Desktop.
A linux bash script which helps the developer to convert the address from core dump to meaningful filenames and line numbers

Usage

  1. Download xtensa-lx106-elf-backtrace and place it anywhere that is in the $PATH variable.
  2. cd to your project/build
  3. Run xtensa-lx106-elf-backtrace "xxxxxxx", xxxxxxx is the list of addresses shown in a core dump.

Example

Core dump:

Guru Meditation Error: Core  0 panic'ed (LoadStoreAlignment). Exception was unhandled.
Core 0 register dump:
PC      : 0x40100d96  PS      : 0x00000033  A0      : 0x40100d32  A1      : 0x3fff4d60  
A2      : 0x401099bc  A3      : 0x401099bc  A4      : 0x6874656d  A5      : 0x401099ec  
A6      : 0x6874656d  A7      : 0x00000039  A8      : 0x5c007d0a  A9      : 0x00000090  
A10     : 0x4028730a  A11     : 0x7463656e  A12     : 0x00000000  A13     : 0x00000002  
A14     : 0x401099c4  A15     : 0x00000027  SAR     : 0x0000001f  EXCCAUSE: 0x00000009  

Backtrace: 0x40100d96:0x3fff4d60 0x40221d34:0x3fff4d80 0x4022aba9:0x3fff4db0 0x40241439:0x3fff4dc0 0x40241d4b:0x3fff4e10 0x40223819:0x3fff4e20 0x4023be24:0x3fff4e50 0x4023c4ff:0x3fff4e70 0x4023c5af:0x3fff4ef0 0x4023ca17:0x3fff4f10 0x4023b2d2:0x3fff4f20 0x4023b348:0x3fff4f40 

Use xtensa-lx106-elf-backtrace:

$ xtensa-lx106-elf-backtrace "0x40100d96:0x3fff4d60 0x40221d34:0x3fff4d80 0x4022aba9:0x3fff4db0 0x40241439:0x3fff4dc0 0x40241d4b:0x3fff4e10 0x40223819:0x3fff4e20 0x4023be24:0x3fff4e50 0x4023c4ff:0x3fff4e70 0x4023c5af:0x3fff4ef0 0x4023ca17:0x3fff4f10 0x4023b2d2:0x3fff4f20 0x4023b348:0x3fff4f40"
----------------------------------------------
0x40100d96
_heap_caps_malloc
/root/ESP8266_RTOS_SDK/components/heap/src/esp_heap_caps.c:169
----------------------------------------------
0x40221d34
_heap_caps_realloc
/root/ESP8266_RTOS_SDK/components/heap/src/esp_heap_caps.c:314
----------------------------------------------
0x4022aba9
realloc
/root/ESP8266_RTOS_SDK/components/newlib/src/esp_malloc.c:32
----------------------------------------------
0x40241439
print
/root/ESP8266_RTOS_SDK/components/json/cJSON/cJSON.c:1125
----------------------------------------------
0x40241d4b
cJSON_Print
/root/ESP8266_RTOS_SDK/components/json/cJSON/cJSON.c:1165
----------------------------------------------
0x40223819
json_get_handler
/root/modbus_rtu2tcp/main/http_server.c:223
----------------------------------------------
0x4023be24
httpd_uri
/root/ESP8266_RTOS_SDK/components/esp_http_server/src/httpd_uri.c:218
----------------------------------------------
0x4023c4ff
httpd_parse_req
/root/ESP8266_RTOS_SDK/components/esp_http_server/src/httpd_parse.c:527 (discriminator 15)
----------------------------------------------
0x4023c5af
httpd_req_new
/root/ESP8266_RTOS_SDK/components/esp_http_server/src/httpd_parse.c:594
----------------------------------------------
0x4023ca17
httpd_sess_process
/root/ESP8266_RTOS_SDK/components/esp_http_server/src/httpd_sess.c:299 (discriminator 15)
----------------------------------------------
0x4023b2d2
httpd_server
/root/ESP8266_RTOS_SDK/components/esp_http_server/src/httpd_main.c:192 (discriminator 15)
----------------------------------------------
0x4023b348
httpd_thread
/root/ESP8266_RTOS_SDK/components/esp_http_server/src/httpd_main.c:223 (discriminator 15)
#!/bin/bash
elf_files=$(ls -m *.elf)
IFS="," read -a elf_file_list <<< $elf_files
if [ ${#elf_file_list[@]} != 1 ]; then
exit 1
fi
elf_file=${elf_file_list[0]}
IFS=" " read -a pairs <<< $1
pairs_len=${#pairs[@]}
for (( i=0; i<pairs_len; i++ ))
do
pair="${pairs[$i]}"
IFS=":" read -a addrs <<< $pair
echo "----------------------------------------------"
echo -n ${addrs[0]}": "
xtensa-lx106-elf-addr2line -e ${elf_file} -f ${addrs[0]}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment