Page 1 of 1

Need help using espcoredump.py with downloaded core file

Posted: Mon Nov 13, 2023 11:22 pm
by felixcollins
Hi, Hopefully @ESP_pdragun is listening and can help!

Running ADF with
IDF 4.4.6

Updated espcoredump.py using pip install to v1.7.0

I have configured settings to save ELF format coredump to flash with SHA256 hash with the following partition table:
otadata,data,ota,0x9000,8K,
phy_init,data,phy,0xb000,4K,
coredump,data,coredump,0xc000,64K,
nvs,data,nvs,0x1c000,32K,
factory,app,factory,0x100000,5M,
ota_0,app,ota_0,0x600000,5M,
ota_1,app,ota_1,0xb00000,5M,

The partition table shouldn't matter though because I'm not using the tool to get the core dump. I've implemented code to upload the core dump to a cloud service. It seems to all get there. See attached file (The extension has been set to .h to allow attaching but it is actually a binary file in the coredump elf format). If someone wants to try loading it I can send the firmware elf file privately.

I generate a core dump using an assert(0) on command.

Code: Select all

ELF file SHA256: 96237f5489361851

I (13953) esp_core_dump_flash: Save core dump to flash...
I (13959) esp_core_dump_common: Backing up stack @ 0x3ffc09d0 and use core dump stack @ 0x3ffb65c0
I (13969) esp_core_dump_flash: Erase flash 28672 bytes @ 0xc000
I (14343) esp_core_dump_flash: Write end offset 0x63c0, check sum length 32
I (14343) esp_core_dump_common: Core dump used 944 bytes on stack. 52 bytes left free.
I (14348) esp_core_dump_common: Restoring stack @ 0x3ffc09d0
I (14354) esp_core_dump_flash: Core dump has been saved to flash.
Rebooting...
When I try to load the coredump I get the following:

Code: Select all

C:\Users\felix\source\beakbox\Firmware\beakbox3>python C:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\scripts\espcoredump.py dbg_corefile -c C:\users\felix\Downloads\full_crashdump.h  c:\Users\felix\source\beakbox\Firmware\beakbox3\build\beakbox3.elf
espcoredump.py v1.7.0
Traceback (most recent call last):
  File "C:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\scripts\espcoredump.py", line 55, in <module>
    main()
  File "C:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\scripts\espcoredump.py", line 42, in main
    temp_core_files = espcoredump.dbg_corefile()
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\coredump.py", line 468, in dbg_corefile
    core_header_info_dict = self.get_core_header_info_dict(e_machine=exe_elf.e_machine)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\coredump.py", line 144, in get_core_header_info_dict
    chip_rev = self.extract_chip_rev_from_elf()
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\coredump.py", line 113, in extract_chip_rev_from_elf
    elf = ElfFile(elf_path=self.core)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\corefile\elf.py", line 119, in __init__
    self.read_elf(elf_path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\corefile\elf.py", line 130, in read_elf
    header_tables = ElfHeaderTables.parse(elf_bytes)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 288, in parse
    return self.parse_stream(io.BytesIO(data), **contextkw)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 300, in parse_stream
    return self._parsereport(stream, context, "(parsing)")
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 1982, in _parse
    subobj = sc._parsereport(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 2440, in _parse
    return self.subcon._parsereport(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 1982, in _parse
    subobj = sc._parsereport(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 2440, in _parse
    return self.subcon._parsereport(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 1982, in _parse
    subobj = sc._parsereport(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 2440, in _parse
    return self.subcon._parsereport(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 2512, in _parse
    raise ConstError("parsing expected %r but parsed %r" % (self.value, obj), path=path)
construct.core.ConstError: Error in path (parsing) -> elf_header -> e_ident -> EI_MAG
parsing expected b'\x7fELF' but parsed b'\xc0c\x00\x00'
If I trim off the first 20 bytes from the file so it starts with 0x7f, 'E', 'L', 'F' then I get this:

Code: Select all

espcoredump.py v1.7.0
Traceback (most recent call last):
  File "C:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\scripts\espcoredump.py", line 55, in <module>
    main()
  File "C:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\scripts\espcoredump.py", line 42, in main
    temp_core_files = espcoredump.dbg_corefile()
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\coredump.py", line 468, in dbg_corefile
    core_header_info_dict = self.get_core_header_info_dict(e_machine=exe_elf.e_machine)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\coredump.py", line 144, in get_core_header_info_dict
    chip_rev = self.extract_chip_rev_from_elf()
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\coredump.py", line 113, in extract_chip_rev_from_elf
    elf = ElfFile(elf_path=self.core)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\corefile\elf.py", line 119, in __init__
    self.read_elf(elf_path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\esp_coredump\corefile\elf.py", line 130, in read_elf
    header_tables = ElfHeaderTables.parse(elf_bytes)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 288, in parse
    return self.parse_stream(io.BytesIO(data), **contextkw)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 300, in parse_stream
    return self._parsereport(stream, context, "(parsing)")
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 1982, in _parse
    subobj = sc._parsereport(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 2440, in _parse
    return self.subcon._parsereport(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 3988, in _parse
    obj = self.subcon._parsereport(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 2222, in _parse
    e = self.subcon._parsereport(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 1982, in _parse
    subobj = sc._parsereport(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 2440, in _parse
    return self.subcon._parsereport(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 1020, in _parse
    data = stream_read(stream, self.length, path)
  File "c:\Users\felix\espclean\tools\python_env\idf4.4_py3.8_env\lib\site-packages\construct\core.py", line 92, 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) -> program_headers -> p_type
stream read less than specified amount, expected 4, found 0
This is starting to look like the format of the coredump does not match the version of the espcoredump.py tool.

SOLVED: Need help using espcoredump.py with downloaded core file

Posted: Tue Nov 14, 2023 2:59 am
by felixcollins
I got this working. I managed to get espcoredump.py to download the dump directly from the flash. I then compared this to the file I had sent to the cloud storage. They were identical except for the fact that the direct flash download seems to download the entire partition, most of which is useless 0xff. I modified my cloud upload to send the entire, mostly blank, partition.

This still did not work but finally I tried changing the core file format argument. --core-format Even though I have SDKCONFIG set to ELF format for the core dump it seems that --core-format raw is required. Go figure...