Skip to content

Commit 72b2848

Browse files
authored
Enhance coredump command handling in main.py
Refactor coredump command construction to handle extra arguments and core file detection more robustly.
1 parent 1b258f7 commit 72b2848

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

builder/main.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,35 @@ def coredump_analysis(target, source, env):
695695
# Parameters from platformio.ini
696696
extra_args = env.GetProjectOption("custom_esp_coredump_args", "")
697697
if extra_args:
698-
# Parse extra args and add ELF file at the end
699-
cmd.extend(shlex.split(extra_args))
700-
cmd.append(elf_file)
698+
args = shlex.split(extra_args)
699+
cmd.extend(args)
700+
# Ensure ELF is last positional if not present
701+
if not any(a.endswith(".elf") for a in args):
702+
cmd.append(elf_file)
701703
else:
702-
# Use defaults: --chip <mcu> info_corefile <elf_file>
703-
cmd.extend(["--chip", mcu, "info_corefile", elf_file])
704+
# Prefer an explicit core file if configured or present; else read from flash
705+
core_file = env.GetProjectOption("custom_esp_coredump_corefile", "")
706+
if not core_file:
707+
for name in ("coredump.bin", "coredump.b64"):
708+
cand = Path(get_project_dir()) / name
709+
if cand.is_file():
710+
core_file = str(cand)
711+
break
712+
713+
# Global options
714+
cmd.extend(["--chip", mcu])
715+
upload_port = env.subst("$UPLOAD_PORT")
716+
if upload_port:
717+
cmd.extend(["--port", upload_port])
718+
719+
# Subcommand and arguments
720+
cmd.append("info_corefile")
721+
if core_file:
722+
cmd.extend(["--core", core_file])
723+
if core_file.lower().endswith(".b64"):
724+
cmd.extend(["--core-format", "b64"])
725+
# ELF is the required positional
726+
cmd.append(elf_file)
704727

705728
# Set up ESP-IDF environment variables and ensure required packages are installed
706729
coredump_env = os.environ.copy()
@@ -753,7 +776,6 @@ def coredump_analysis(target, source, env):
753776
print(f"Error: Failed to run coredump analysis: {e}")
754777
print(f'Make sure esp-coredump is installed: uv pip install --python "{PYTHON_EXE}" esp-coredump')
755778

756-
757779
#
758780
# Target: Build executable and linkable firmware or FS image
759781
#

0 commit comments

Comments
 (0)