Skip to content

Commit

Permalink
fix(tools): idf.py: fix detection of raw core dump file
Browse files Browse the repository at this point in the history
When idf.py coredump-debug is launched with '--core' argument, it
tries to determine the file format (raw, elf, b64). To detect the
'raw' core dump the code checked if the version word matched one of
the known values.
However, the version word also contains the chip ID in the high
half-word, so the check failed for anything other than the ESP32.
The detection of core file format has been moved to esp-coredump
package in version 1.9.0, including the fix for chip ID.

Reported in #10852
  • Loading branch information
peterdragun committed Dec 7, 2023
1 parent 9bdcfa6 commit 5085763
Showing 1 changed file with 1 addition and 35 deletions.
36 changes: 1 addition & 35 deletions tools/idf_py_actions/debug_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import sys
import threading
import time
from base64 import b64decode
from textwrap import indent
from threading import Thread
from typing import Any, Dict, List, Optional, Union
Expand Down Expand Up @@ -172,12 +171,10 @@ def _get_espcoredump_instance(ctx: Context,
if extra_gdbinit_file:
espcoredump_kwargs['extra_gdbinit_file'] = extra_gdbinit_file

core_format = None

if core:
espcoredump_kwargs['core'] = core
espcoredump_kwargs['core_format'] = 'auto'
espcoredump_kwargs['chip'] = get_sdkconfig_value(project_desc['config_file'], 'CONFIG_IDF_TARGET')
core_format = get_core_file_format(core)
elif coredump_to_flash:
# If the core dump is read from flash, we don't need to specify the --core-format argument at all.
# The format will be determined automatically
Expand All @@ -191,9 +188,6 @@ def _get_espcoredump_instance(ctx: Context,
espcoredump_kwargs['parttable_off'] = get_sdkconfig_value(project_desc['config_file'],
'CONFIG_PARTITION_TABLE_OFFSET')

if core_format:
espcoredump_kwargs['core_format'] = core_format

if save_core:
espcoredump_kwargs['save_core'] = save_core

Expand All @@ -212,34 +206,6 @@ def _get_espcoredump_instance(ctx: Context,
raise
return coredump

def get_core_file_format(core_file: str) -> str:
bin_v1 = 1
bin_v2 = 2
elf_crc32 = 256
elf_sha256 = 257

with open(core_file, 'rb') as f:
coredump_bytes = f.read(16)

if coredump_bytes.startswith(b'\x7fELF'):
return 'elf'

core_version = int.from_bytes(coredump_bytes[4:7], 'little')
if core_version in [bin_v1, bin_v2, elf_crc32, elf_sha256]:
# esp-coredump will determine automatically the core format (ELF or BIN)
return 'raw'
with open(core_file) as c:
coredump_str = c.read()
try:
b64decode(coredump_str)
except Exception:
print('The format of the provided core-file is not recognized. '
'Please ensure that the core-format matches one of the following: ELF (“elf”), '
'raw (raw) or base64-encoded (b64) binary')
sys.exit(1)
else:
return 'b64'

def is_gdb_with_python(gdb: str) -> bool:
# execute simple python command to check is it supported
return subprocess.run([gdb, '--batch-silent', '--ex', 'python import os'],
Expand Down

0 comments on commit 5085763

Please sign in to comment.