Code Monkey home page Code Monkey logo

esp-coredump's Introduction

esp-coredump

A Python-based utility that helps users to retrieve and analyse core dumps. This tool provides two commands for core dumps analysis:

  • info_corefile - prints crashed task’s registers, callstack, list of available tasks in the system, memory regions and contents of memory stored in core dump (TCBs and stacks)

  • dbg_corefile - creates core dump ELF file and runs GDB debug session with this file. User can examine memory, variables and tasks states manually. Note that since not all memory is saved in core dump only values of variables allocated on stack will be meaningful

Installation

esp-coredump is a standalone utility integrated into ESP-IDF. It is recommended to run esp-coredump from within ESP-IDF environment due to the ease of setup.

To install the ESP-IDF framework please visit the documentation.

Standalone Installation (without ESP-IDF)

If you're attempting to run esp-coredump outside of the ESP-IDF environment, you'll need to install esp-gdb. The most recent version can be downloaded from the GitHub releases page. To determine the appropriate version for your environment, refer to the ESP-IDF documentation. Note that toolchain versions may vary between ESP-IDF versions. To get the correct version for your needs, select your version of ESP-IDF in the top left corner. Ensure you download the correct version that matches the architecture of your ESP32. After downloading the toolchain, verify that it's accessible in your system's PATH.

Examples

esp-coredump can be used as a CLI tool as well as a separate package. Before executing any examples, ensure that all requirements outlined in the Installation section have been met. If you decide to use ESP-IDF, all commands should be run from within the ESP-IDF environment.

Build test_apps for a target, flash and get a base64 text (test_apps folder)

from esp_coredump import CoreDump

# Instantiate the coredump object
coredump = CoreDump(chip='esp32',core="./test/esp32/coredump.b64",core_format='b64', prog='./test_apps/build/test_core_dump.elf')
coredump.info_corefile()  #  print the info of the test app corefile
coredump.dbg_corefile()  #  run GDB debug session with provided ELF file

Documentation

Visit the documentation or run esp-coredump -h.

Contributing

Code Style & Static Analysis

Please follow these coding standards when writing code for esp-coredump:

Pre-commit checks

pre-commit is a framework for managing pre-commit hooks. These hooks help to identify simple issues before committing code for review.

To use the tool, first install pre-commit. Then enable the pre-commit and commit-msg git hooks:

python -m pip install pre-commit
pre-commit install -t pre-commit -t commit-msg

On the first commit pre-commit will install the hooks, subsequent checks will be significantly faster. If an error is found an appropriate error message will be displayed.

Conventional Commits

esp-coredump complies with the Conventional Commits standard. Every commit message is checked with Conventional Precommit Linter, ensuring it adheres to the standard.

License

This document and the attached source code are released as Free Software under Apache Software License Version 2.0.

esp-coredump's People

Contributors

alekseiapa avatar dobairoland avatar erhankur avatar espressif-bot avatar igrr avatar lapshin avatar mahavirj avatar peterdragun avatar projectgus avatar radimkarnis avatar tomassebestik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp-coredump's Issues

espcoredump.py crashes when the host CPU is not idle (IDFGH-8988)

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.0

Operating System used.

Linux

How did you build your project?

Other (please specify in More Information)

If you are using Windows, please specify command line type.

None

Development Kit.

none

Power Supply used.

USB

What is the expected behavior?

espcoredump.py should always return the same result if the same inputfiles and arguments are used.

What is the actual behavior?

depending on the system load of the host system, the python script crashes at different program points.

Steps to reproduce.

  1. generate CPU load on you're development machine (building a huge project on all CPUs)
  2. run python3 /esp-idf/components/espcoredump/espcoredump.py info_corefile --print-mem --core-format raw --core core.dump firmware.elf

Debug Logs.

example crash:
the program crashes in many different places, which indicates that the GDB communication is faulty!

Traceback (most recent call last):
  File "/esp-idf/components/espcoredump/espcoredump.py", line 350, in <module>
    temp_core_files = info_corefile()
  File "/esp-idf/components/espcoredump/espcoredump.py", line 200, in info_corefile
    threads, _ = gdb.get_thread_info()
  File "/esp-idf/components/espcoredump/corefile/gdb.py", line 114, in get_thread_info
    current_thread_id = result['current-thread-id']
TypeError: 'NoneType' object is not subscriptable

More Information.

the problem can be easily reproduced under ubuntu 22.04 and windows 10.

it looks like pygdbmi has problems when the GDB does not react fast enough due to high system load.

Coredump to flash not working in SDK V5.2.1 (bin or elf same error) (IDFGH-12462)

partition as of
nvs, data, nvs, 0xA000, 24K,
otadata, data, ota, , 8K,
phy_init, data, phy, , 4K,
nvs_keys, data, nvs_keys, , 24K,
factory_nvs, data, nvs, , 24K,
ota_0, app, ota_0, 0x20000, 0x340000,encrypted
coredump, data, coredump, , 64K, encrypted

made proposital error doing
//crash proposital area for coredump
global_var = 25;
int *ptr = NULL;
*ptr = 42; // This will cause a crash due to null pointer dereference
int zero = 0;
int result = 10 / zero; // This will cause a crash due to division by zero
//end crash area for coredump

so this will bring the coredump to be executed,

after it, set the debug board to run in download mode and run

idf.py coredump-debug --port com3
Executing action: coredump-debug
Failed to load core dump: parttool script execution failed with error 1, failed command was: 'C:\Espressif\python_env\idf5.2_py3.11_env\Scripts\python.exe C:\Espressif\frameworks\esp-idf-v5.2\components\partition_table\parttool.py --port com3 --baud 460800 --partition-table-offset 0x9000
read_partition --partition-type data --partition-subtype coredump --output C:\Users\devop\AppData\Local\Temp\tmpz_btbjwn'

┌────── Additional information about the error:

│ esptool.py v4.7.0
│ Serial port com3
│ Connecting...
│ Failed to get PID of a device on com3, using standard reset sequence.
│ ...............................
│ Detecting chip type... Unsupported detection protocol, switching and trying again...
│ Connecting...
│ Failed to get PID of a device on com3, using standard reset sequence.

│ Detecting chip type... ESP32
│ Chip is ESP32-D0WD-V3 (revision v3.0)
│ Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
│ Crystal is 40MHz
│ MAC: 08:3a:f2:04:a3:c8
│ Uploading stub...
│ Running stub...
│ Stub running...
│ Changing baud rate to 460800
│ Changed.
│ 3072 (100 %)
│ 3072 (100 %)
│ Read 3072 bytes at 0x00009000 in 0.1 seconds (305.4 kbit/s)...
│ Hard resetting via RTS pin...
│ Running C:\Espressif\python_env\idf5.2_py3.11_env\Scripts\python.exe C:\Espressif\frameworks\esp-idf-v5.2\components\esptool_py\esptool\esptool.py --port com3 --baud 460800 read_flash 36864 3072 C:\Users\devop\AppData\Local\Temp\tmp4thh57q6...
│ Traceback (most recent call last):
│ File "C:\Espressif\frameworks\esp-idf-v5.2\components\partition_table\parttool.py", line 363, in
│ main()
│ File "C:\Espressif\frameworks\esp-idf-v5.2\components\partition_table\parttool.py", line 332, in main
│ target = ParttoolTarget(**target_args)
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ File "C:\Espressif\frameworks\esp-idf-v5.2\components\partition_table\parttool.py", line 105, in init
│ partition_table = gen.PartitionTable.from_binary(f.read())
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ File "C:\Espressif\frameworks\esp-idf-v5.2\components\partition_table\gen_esp32part.py", line 319, in from_binary
│ result.append(PartitionDefinition.from_binary(data))
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ File "C:\Espressif\frameworks\esp-idf-v5.2\components\partition_table\gen_esp32part.py", line 475, in from_binary
│ res.name = res.name.decode()
│ ^^^^^^^^^^^^^^^^^
│ UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 2: invalid start byte

ValueError: invalid literal for int() with base 16: '' (IDFGH-12154)

I can't longer decode crash dumps because I'm getting a ValueError, the crash is from an ESP32-C6 with esp-idf v5.2

esp-coredump --chip esp32s3 info_corefile --print-mem --core-format elf --core crash.elf firmware.elf

esp-coredump output
espcoredump.py v1.10.0
===============================================================
==================== ESP32 CORE DUMP START ====================

Crashed task handle: 0x40841798, name: 'wifi', GDB name: 'process 1082398616'
Crashed task is not in the interrupt context
Panic reason: assert failed: block_locate_free heap_tlsf.c:476 (block_size(block) >= size)

================== CURRENT THREAD REGISTERS ===================
pc             <unavailable>
lbeg           <unavailable>
lend           <unavailable>
lcount         <unavailable>
sar            <unavailable>
ps             <unavailable>
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             <unavailable>
a1             <unavailable>
a2             <unavailable>
a3             <unavailable>
a4             <unavailable>
a5             <unavailable>
a6             <unavailable>
a7             <unavailable>
a8             <unavailable>
a9             <unavailable>
a10            <unavailable>
a11            <unavailable>
a12            <unavailable>
a13            <unavailable>
a14            <unavailable>
a15            <unavailable>

==================== CURRENT THREAD STACK =====================
#0  <unavailable> in ?? ()

======================== THREADS INFO =========================
  Id   Target Id         Frame 
* 1    process 1         <unavailable> in ?? ()


       TCB             NAME PRIO C/B  STACK USED/FREE
---------- ---------------- -------- ----------------
Traceback (most recent call last):
  File "/opt/homebrew/bin/esp-coredump", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/esp_coredump/scripts/espcoredump.py", line 40, in main
    temp_core_files = espcoredump.info_corefile()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/esp_coredump/coredump.py", line 566, in info_corefile
    self.print_threads_info(task_info)
  File "/opt/homebrew/lib/python3.11/site-packages/esp_coredump/coredump.py", line 355, in print_threads_info
    pxEndOfStack = int(self.gdb_esp.parse_tcb_variable(tcb_addr, 'pxEndOfStack'), 16)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 16: ''

Allow passing partition table to forward to parttool (IDFGH-12300)

Right now the tool crashes when the partition table isn't in the default location in flash:

thomas@thomas-mbp ~/W/myproject (main) [SIGINT]> python ~/.espressif/esp-idf/v5.1.3/components/espcoredump/espcoredump.py -p /dev/cu.usbserial-114201 info_corefile firmware/target/xtensa-esp32-espidf/release/esp-firmware
WARNING: /Users/thomas/Workspace/myproject/firmware/target/xtensa-esp32-espidf/release/project_description.json does not exist. Please build the app with "idf.py build"
INFO: Invoke parttool to read image.
Failed to load core dump: parttool script execution failed with error 1, failed command was: '/Users/thomas/.espressif/python_env/idf5.1_py3.11_env/bin/python /Users/thomas/.espressif/esp-idf/v5.1.3/components/partition_table/parttool.py --port /dev/cu.usbserial-114201 --baud 115200 read_partition --partition-type data --partition-subtype coredump --output /var/folders/tn/8gmb5b0d3n939xr1fwtj8s2m0000gn/T/tmp2u3apg6e'

┌────── Additional information about the error:
│
│   esptool.py v4.7.0
│   Serial port /dev/cu.usbserial-114201
│   Connecting.....
│   Detecting chip type... Unsupported detection protocol, switching and trying again...
│   Connecting....
│   Detecting chip type... ESP32
│   Chip is ESP32-D0WD-V3 (revision v3.1)
│   Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
│   Crystal is 40MHz
│   MAC: fc:b4:67:ce:55:cc
│   Uploading stub...
│   Running stub...
│   Stub running...
│   3072 (100 %)
│   3072 (100 %)
│   Read 3072 bytes at 0x00008000 in 0.3 seconds (76.8 kbit/s)...
│   Hard resetting via RTS pin...
│   Running /Users/thomas/.espressif/python_env/idf5.1_py3.11_env/bin/python /Users/thomas/.espressif/esp-idf/v5.1.3/components/esptool_py/esptool/esptool.py --port /dev/cu.usbserial-114201 --baud 115200 read_flash 32768 3072 /var/folders/tn/8gmb5b0d3n939xr1fwtj8s2m0000gn/T/tmpchjndu0k...
│   Traceback (most recent call last):
│     File "/Users/thomas/.espressif/esp-idf/v5.1.3/components/partition_table/parttool.py", line 358, in <module>
│       main()
│     File "/Users/thomas/.espressif/esp-idf/v5.1.3/components/partition_table/parttool.py", line 327, in main
│       target = ParttoolTarget(**target_args)
│                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│     File "/Users/thomas/.espressif/esp-idf/v5.1.3/components/partition_table/parttool.py", line 105, in __init__
│       partition_table = gen.PartitionTable.from_binary(f.read())
│                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│     File "/Users/thomas/.espressif/esp-idf/v5.1.3/components/partition_table/gen_esp32part.py", line 318, in from_binary
│       result.append(PartitionDefinition.from_binary(data))
│                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│     File "/Users/thomas/.espressif/esp-idf/v5.1.3/components/partition_table/gen_esp32part.py", line 467, in from_binary
│       res.name = res.name.decode()
│                  ^^^^^^^^^^^^^^^^^
│   UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

│
└────── end of additional information about the error.

This is my partition table:

# name,   type, subtype,  offset,   size,   flags
ota_0,    app,  ota_0,    0x10000,  4M,
ota_1,    app,  ota_1,    0x410000, 4M,
coredump, data, coredump, 0x810000, 64k,
otadata,  data, ota,      0x820000, 0x2000,
phy_init, data, phy,      0x822000, 0x1000,
nvs_key,  data, nvs_keys, 0x823000, 0x1000, encrypted
efuse_em, data, efuse,    0x824000, 0x2000,
nvs,      data, nvs,      0x900000, 6M,     encrypted

Note: I'm not using idf.py directly because I'm using the ESP IDF with Rust.

stream read less than specified amount, expected 1073422928, found 0 (IDFGH-10433)

I am trying to read coredump that I copied from flash to sd card. I have an elf file of my firmware.
I see that there is a stream.read() exception raised but when i run stream.read() just after creation of the stream it doesn't rise the exception. And the expected size of the stream does not fit any of my files.

from esp_coredump import CoreDump
import os

elf_path = "C:/test\.pio\\build\lolin_d32\\firmware.elf"

# print  the size of the test app ELF file
print("Size of the test app ELF file: ", os.path.getsize(elf_path), "bytes")


bin_path = "D:/coredump_3221.bin"

# print the size of the test app corefile
print("Size of the test app corefile: ", os.path.getsize(bin_path), "bytes")
# Instantiate the coredump object
coredump = CoreDump(chip='esp32',core=bin_path,core_format='elf', prog=elf_path)
coredump.info_corefile()  #  print the info of the test app corefile
# coredump.dbg_corefile()  #  run GDB debug session with provided ELF file

as a result i see the next error

Size of the test app ELF file:  16086728 bytes
Size of the test app corefile:  36588 bytes
Traceback (most recent call last):
  File "C:\test\scripts\coredump.py", line 16, in <module>      
    coredump.info_corefile()  #  print the info of the test app corefile
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\esp_coredump\coredump.py", line 465, in info_corefile
    core_header_info_dict = self.get_core_header_info_dict(e_machine=self.exe_elf.e_machine)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\esp_coredump\coredump.py", line 140, in get_core_header_info_dict
    chip_rev = self.extract_chip_rev_from_elf()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\esp_coredump\coredump.py", line 109, in extract_chip_rev_from_elf
    elf = ElfFile(elf_path=self.core)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\esp_coredump\corefile\elf.py", line 119, in __init__
    self.read_elf(elf_path)
  File "C:\Python311\Lib\site-packages\esp_coredump\corefile\elf.py", line 135, in read_elf
    self._model = self._struct.parse(elf_bytes)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 291, in parse
    return self.parse_stream(io.BytesIO(data), **contextkw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 303, in parse_stream
    return self._parsereport(stream, context, "(parsing)")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 315, in _parsereport
    obj = self._parse(stream, context, path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 2123, in _parse
    subobj = sc._parsereport(stream, context, path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 315, in _parsereport
    obj = self._parse(stream, context, path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 2656, in _parse
    return self.subcon._parsereport(stream, context, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 315, in _parsereport
    obj = self._parse(stream, context, path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 2278, in _parse
    subobj = sc._parsereport(stream, context, path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 315, in _parsereport
    obj = self._parse(stream, context, path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 2123, in _parse
    subobj = sc._parsereport(stream, context, path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 315, in _parsereport
    obj = self._parse(stream, context, path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 2656, in _parse
    return self.subcon._parsereport(stream, context, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 315, in _parsereport
    obj = self._parse(stream, context, path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 4298, in _parse
    obj = self.subcon._parsereport(stream, context, path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 315, in _parsereport
    obj = self._parse(stream, context, path)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 851, in _parse
    return stream_read(stream, length, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\construct\core.py", line 91, in stream_read
    raise StreamError("stream read less than specified amount, expected %d, found %d" % (length, len(data)), path=path)
construct.core.StreamError: Error in path (parsing) -> load_segments -> data
stream read less than specified amount, expected 1073422928, found 0

I found that coredup that is stored to the flash does not start with right bytes so i have created a function that searches for start sequence of coredump

void copyCoredumpPartitionToSDCard(int16_t boot_number)
{

    esp_core_dump_init();
    esp_core_dump_summary_t *summary = (esp_core_dump_summary_t *)malloc(sizeof(esp_core_dump_summary_t));
    if (summary)
    {
        // esp_log_level_set("esp_core_dump_elf", ESP_LOG_VERBOSE); // so that func below prints stuff.. but doesn't actually work, have to set logging level globally through menuconfig
        log.printf("Retrieving core dump summary..\n");
        esp_err_t err = esp_core_dump_get_summary(summary);
        if (err == ESP_OK)
        {
            // get summary function already pints stuff
            log.printf("Getting core dump summary ok.\n");
            // todo: do something with dump summary
        }
        else
        {
            log.printf("Getting core dump summary not ok. Error: %d\n", (int)err);
            log.printf("Probably no coredump present yet.\n");
            log.printf("esp_core_dump_image_check() = %d\n", esp_core_dump_image_check());
        }
        free(summary);
    }

    // implement esp_core_dump_image_get()
    size_t addr;
    size_t size;
    esp_err_t err = esp_core_dump_image_get(&addr, &size);
    if (err != ESP_OK)
    {
        log.printf("esp_core_dump_image_get() failed with error: %d\n", (int)err);
        return;
    }
    log.printf("esp_core_dump_image_get() ok. addr: %d, size: %d\n", addr, size);

    String coredump_path = "/coredump_" + String(boot_number - 1) + ".bin";
    FS *sd_fs = get_sd_fs();
    if (sd_fs == NULL)
    {
        log.printf("sd_fs == NULL\n");
        return;
    }
    File partition_file = sd_fs->open(coredump_path.c_str(), FILE_APPEND);
    // read the flash
    uint8_t buffer[256];

    int sequence_index = -1;
    for (int i = 0; i < size; i += 256)
    {
        err = esp_flash_read(esp_flash_default_chip, buffer, addr + i, 256);
        if (err != ESP_OK)
        {
            log.printf("esp_flash_read() failed with error: %d\n", (int)err);
            return;
        }
        if (sequence_index == -1)
        {
            char sequence[4] = {0x7f, 0x45, 0x4c, 0x46};
            for (int j = 0; j < 256 - sizeof(sequence); j++)
            {
                if (buffer[j] == sequence[0] && buffer[j + 1] == sequence[1] && buffer[j + 2] == sequence[2] && buffer[j + 3] == sequence[3])
                {
                    sequence_index = j;
                    break;
                }
            }
            // write buffer to flash from sequence_index
            log.printf("sequence_index: %d\n", sequence_index);
            partition_file.write(buffer + sequence_index, 256 - sequence_index);
            continue;
        }
        log.printf("esp_flash_read() ok.\n");
        partition_file.write(buffer, 512);
        // todo append buffer to file
    }
    log.printf("esp_flash_read() ok.\n");
    partition_file.close();
    log.println("Coredump partition copied to SD card");
}

idf.py coredump-info failed due to IndexError: list index out of range (IDFGH-9103)

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.1-dev-2669-gd152d007c6

Operating System used.

Windows

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

PowerShell

What is the expected behavior?

coredump should work

What is the actual behavior?

coredump did not work

Steps to reproduce.

  1. make sure coredump to flash
  2. crash the esp32
  3. run idf.py coredump-info

Build or installation Logs.

PS C:\Users\wuyua\Documents\Project\CrystalVisionLtd\Embedded\unilab\usb_communication_dongle> idf.py coredump-info
Executing action: coredump-info
Serial port COM14
Connecting...
Detecting chip type... ESP32-S3
Traceback (most recent call last):
  File "C:\Espressif\frameworks\esp-idf-master\components\partition_table\parttool.py", line 359, in <module>
    main()
  File "C:\Espressif\frameworks\esp-idf-master\components\partition_table\parttool.py", line 352, in main
    op(**common_args)
  File "C:\Espressif\frameworks\esp-idf-master\components\partition_table\parttool.py", line 183, in _read_partition
    target.read_partition(partition_id, output)
  File "C:\Espressif\frameworks\esp-idf-master\components\partition_table\parttool.py", line 159, in read_partition
    partition = self.get_partition_info(partition_id)
  File "C:\Espressif\frameworks\esp-idf-master\components\partition_table\parttool.py", line 141, in get_partition_info
    partition = partition[0]
IndexError: list index out of range
ERROR:root:parttool script execution failed with err 1
ERROR:root:Error during the subprocess execution
Traceback (most recent call last):
  File "C:\Espressif\frameworks\esp-idf-master\tools\idf.py", line 772, in <module>
    main()
  File "C:\Espressif\frameworks\esp-idf-master\tools\idf.py", line 707, in main
    cli(sys.argv[1:], prog_name=PROG, complete_var=SHELL_COMPLETE_VAR)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\click\core.py", line 1689, in invoke
    return _process_result(rv)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\click\core.py", line 1626, in _process_result
    value = ctx.invoke(self._result_callback, value, **ctx.params)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "C:\Espressif\frameworks\esp-idf-master\tools\idf.py", line 602, in execute_tasks
    task(ctx, global_args, task.action_args)
  File "C:\Espressif\frameworks\esp-idf-master\tools\idf.py", line 189, in __call__
    self.callback(self.name, context, global_args, **action_args)
  File "c:\espressif\frameworks\esp-idf-master\tools\idf_py_actions\debug_ext.py", line 540, in coredump_info
    espcoredump.info_corefile()
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\esp_coredump\coredump.py", line 339, in info_corefile
    core_elf_path, target, temp_files = self.get_core_dump_elf(e_machine=self.exe_elf.e_machine)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\esp_coredump\coredump.py", line 108, in get_core_dump_elf
    loader = ESPCoreDumpFlashLoader(self.off, self.chip, port=self.port, baud=self.baud)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\esp_coredump\corefile\loader.py", line 429, in __init__
    self.target = self._load_core_src()
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\esp_coredump\corefile\loader.py", line 151, in _load_core_src
    _header = EspCoreDumpV1Header.parse(coredump_bytes)  # first we use V1 format to get version
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\construct\core.py", line 288, in parse
    return self.parse_stream(io.BytesIO(data), **contextkw)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\construct\core.py", line 300, in parse_stream
    return self._parsereport(stream, context, "(parsing)")
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\construct\core.py", line 2120, in _parse
    subobj = sc._parsereport(stream, context, path)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\construct\core.py", line 2653, in _parse
    return self.subcon._parsereport(stream, context, path)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\construct\core.py", line 1041, in _parse
    data = stream_read(stream, self.length, path)
  File "C:\Espressif\python_env\idf5.1_py3.8_env\lib\site-packages\construct\core.py", line 91, in stream_read
    raise StreamError("stream read less than specified amount, expected %d, found %d" % (length, len(data)), path=path)
construct.core.StreamError: Error in path (parsing) -> tot_len
stream read less than specified amount, expected 4, found 0

More Information.

partition table

nvs,      data, nvs,     0x9000,  0x4000,
otadata,  data, ota,     0xd000,  0x2000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory,,  5200K,
ota_0,    app,  ota_0,, 5200K,
ota_1,    app,  ota_1,, 5200K,
coredump, data, coredump,,        64K

Cannot find GDB (IDFGH-12412)

Install dependencies

pip install esp-coredump

Copy the provided example to core.py

from esp_coredump import CoreDump

# Instantiate the coredump object
coredump = CoreDump(chip='esp32s3',core="./dump.bin", prog='./app.elf')
coredump.info_corefile()  #  print the info of the test app corefile

Try to run the app

python3 core.py

Result

===============================================================
==================== ESP32 CORE DUMP START ====================
GDB executable not found. Please install GDB or set up ESP-IDF to complete the action. Read more: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html

Question

How can I install the esp specific gdb executables without installing the entire esp-idf framework?

Workaround

  • Step 1 copied the xtensa-esp-elf-gdb folder from esp-idf next to core.py
  • Run the following command: export PATH="$(pwd)/xtensa-esp-elf-gdb/bin:$PATH"
  • Then run python3 core.py and now it works
  • Is there a nicer way to properly install the required esp specific GDB tools?

v4.4.6 espcoredump.py fails to analyze coredump (IDFGH-12480)

As per discussion https://esp32.com/viewtopic.php?f=13&t=38973&p=129635

I am using esp-idf v4.4.6, espcoredump.py hangs when reading it, after I trimmed the header

This is the ELF core, before trimming the header:

coredump.dmp

`
spcoredump.py v0.4-dev

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

Crashed task handle: 0x3ffdcf3c, name: '', GDB name: 'process 1073598268'

================== CURRENT THREAD REGISTERS ===================
exccause 0x1d (StoreProhibitedCause)
excvaddr 0x0
epc1 0x401224ff
epc2 0x0
epc3 0x0
epc4 0x0
epc5 0x0
epc6 0x0
eps2 0x0
eps3 0x0
eps4 0x0
eps5 0x0
eps6 0x0

==================== CURRENT THREAD STACK =====================
[New process 1073598268]
[New process 1073527168]
[New process 1073529056]
[New process 1073535472]
[New process 1073525280]
[New process 1073594844]
[New process 1073604136]
[New process 1073508900]
[New process 1073411924]
[New process 1073608364]
[New process 1073608712]
[New process 1073513808]
[New process 1073625240]
[Current thread is 1 (process 1073598268)]

======================== THREADS INFO =========================

Traceback (most recent call last):
File "C:\exp\frameworks\esp-idf-v4.4.6\components\espcoredump\espcoredump.py", line 387, in
temp_core_files = info_corefile()
^^^^^^^^^^^^^^^
File "C:\exp\frameworks\esp-idf-v4.4.6\components\espcoredump\espcoredump.py", line 237, in info_corefile
threads, _ = gdb.get_thread_info()
^^^^^^^^^^^^^^^^^^^^^
File "C:\exp\frameworks\esp-idf-v4.4.6\components\espcoredump\corefile\gdb.py", line 114, in get_thread_info
current_thread_id = result['current-thread-id']
~~~~~~^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.