Skip to content

Conversation

Jason2866
Copy link

@Jason2866 Jason2866 commented Sep 27, 2025

# Basic usage (uses defaults: info_corefile --chip esp32s3 firmware.elf)
pio run -t coredump

# Custom coredump analysis with CLI args
pio run -t coredump -- dbg_corefile --chip esp32s3 --core /path/to/coredump.bin

# Info analysis with specific core file
pio run -t coredump -- info_corefile --chip esp32s3 --core coredump.b64 --core-format b64

# Configure defaults in platformio.ini
[env:myboard]
custom_esp_coredump_args = info_corefile --chip esp32s3 --print-mem
custom_esp_coredump_verbose = true

Checklist:

  • The pull request is done against the latest develop branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR, more changes are allowed when changing boards.json
  • I accept the CLA

Summary by CodeRabbit

  • New Features

    • Added coredump analysis commands to inspect device core dumps without rebuilding.
    • Supports passing custom CLI arguments (after --) and optional verbose output.
    • Automatically locates the project ELF and sets required ESP-IDF environment when available; provides clear warnings and guidance on missing tools.
  • Chores

    • Added esp-coredump (>=1.14.0) as an automatic Python dependency to enable coredump analysis.
    • Note: coredump-related public targets were inadvertently duplicated and may appear twice.

Add custom targets for coredump analysis with CLI support.
Copy link

coderabbitai bot commented Sep 27, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds a coredump analysis capability invoking esp-coredump via a new coredump_analysis function, registers two SCons custom targets (“coredump” and “coredump-only”), configures ESP-IDF-related environment variables, supports CLI args after “--”, updates Python deps to include esp-coredump, and duplicates the coredump function and targets within builder/main.py.

Changes

Cohort / File(s) Summary
Coredump analysis feature & targets
builder/main.py
Adds coredump_analysis(target, source, env) to orchestrate running esp-coredump: parses CLI args after --, falls back to custom_esp_coredump_args/custom_esp_coredump_corefile/defaults, locates ELF in $BUILD_DIR or project root (errors if missing), builds esp-coredump CLI (handles corefile and base64 core-format), ensures ESP-IDF/framework rom-elfs availability (may install packages), sets IDF_PATH and ESP_ROM_ELF_DIR when detected, supports verbose logging via custom_esp_coredump_verbose, executes via subprocess and warns on non-zero exit or missing tooling; registers coredump (depends on built ELF) and coredump-only (no build dep) SCons targets with always_build=True; the function and targets are defined twice (duplicated) in the file.
Python dependency update
builder/penv_setup.py
Adds "esp-coredump": ">=1.14.0" to the python_deps mapping alongside existing entries.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Dev as Developer
    participant SCons as SCons/Env
    participant CA as coredump_analysis()
    participant FS as Filesystem
    participant Proc as subprocess(esp-coredump)

    Dev->>SCons: Invoke target "coredump" or "coredump-only"
    alt coredump
        SCons->>FS: Ensure `$BUILD_DIR/${PROGNAME}.elf` exists
    end
    SCons->>CA: Call coredump_analysis(target, source, env)

    rect rgb(245, 250, 255)
    note right of CA: Parse CLI args after `--`\nUse custom_esp_coredump_args/corefile or defaults
    CA->>FS: Locate ELF (build dir or project root)
    FS-->>CA: ELF found / not found
    end

    alt ELF found
        rect rgb(235, 255, 235)
        note over CA: Ensure ESP-IDF and rom-elfs tool\nSet IDF_PATH / ESP_ROM_ELF_DIR if available
        CA->>Proc: Run `esp-coredump` with constructed args/env
        Proc-->>CA: Exit code
        alt Exit != 0
            CA-->>SCons: Warn non-zero exit / provide guidance
        else Success
            CA-->>SCons: Complete successfully
        end
        end
    else ELF missing
        CA-->>SCons: Emit error guidance about missing ELF or corefile
    end

    note over SCons: coredump targets and function appear twice (duplicate registrations)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I twitch my whiskers at a frozen state,
sniff out ELFs and trace the fate—
esp-coredump hums beneath my paws,
I hop through stacks and read the laws.
Two targets echo? I'll tidy the lair, then bound away with care. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title accurately summarizes the primary change by explicitly stating that coredump analysis targets are being implemented with CLI support. It is concise, focused on the main feature addition, and uses clear terminology that aligns with the PR objectives and changes. The title avoids unnecessary details and noise while giving a reviewer immediate understanding of the scope. It directly reflects the introduction of new build targets and CLI argument handling for coredump analysis.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Jason2866
Copy link
Author

@coderabbitai full review

Copy link

coderabbitai bot commented Sep 27, 2025

✅ Actions performed

Full review triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c22d9e and dd471c6.

📒 Files selected for processing (1)
  • builder/main.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.13.1)
builder/main.py

653-653: Unused function argument: target

(ARG001)


653-653: Unused function argument: source

(ARG001)


704-704: subprocess call: check for execution of untrusted input

(S603)


712-712: Do not catch blind exception: Exception

(BLE001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: build (macos-15, examples/tasmota)
  • GitHub Check: build (macos-15, examples/espidf-ulp-riscv)
  • GitHub Check: build (macos-15, examples/espidf-arduino-littlefs)
  • GitHub Check: build (macos-15, examples/espidf-coap-server)
  • GitHub Check: build (windows-latest, examples/espidf-arduino-blink)
  • GitHub Check: build (windows-latest, examples/espidf-hello-world)
  • GitHub Check: build (macos-15, examples/arduino-blink)
  • GitHub Check: build (windows-latest, examples/espidf-peripherals-usb)
  • GitHub Check: build (windows-latest, examples/espidf-http-request)
  • GitHub Check: build (windows-latest, examples/espidf-arduino-littlefs)
  • GitHub Check: build (windows-latest, examples/espidf-blink)
  • GitHub Check: build (windows-latest, examples/arduino-zigbee-switch)
  • GitHub Check: build (windows-latest, examples/arduino-NimBLE-ext_client)
  • GitHub Check: build (windows-latest, examples/tasmota)
  • GitHub Check: build (windows-latest, examples/arduino-rmt-blink)
  • GitHub Check: build (windows-latest, examples/arduino-zigbee-light)
  • GitHub Check: build (windows-latest, examples/arduino-wifiscan)
  • GitHub Check: build (ubuntu-latest, examples/espidf-arduino-matter-light)
  • GitHub Check: build (ubuntu-latest, examples/espidf-http-request)
  • GitHub Check: build (ubuntu-latest, examples/arduino-blink)

@Jason2866
Copy link
Author

@coderabbitai full review

Copy link

coderabbitai bot commented Sep 27, 2025

✅ Actions performed

Full review triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c22d9e and 0e39880.

📒 Files selected for processing (3)
  • builder/frameworks/espidf.py (1 hunks)
  • builder/main.py (2 hunks)
  • builder/penv_setup.py (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📚 Learning: 2025-08-10T19:13:25.599Z
Learnt from: Jason2866
PR: pioarduino/platform-espressif32#255
File: builder/penv_setup.py:26-40
Timestamp: 2025-08-10T19:13:25.599Z
Learning: In the pioarduino/platform-espressif32 repository's builder/penv_setup.py file, semantic_version is imported but intentionally not listed in python_deps because it's a transitive dependency of platformio-core (version 2.10.*). When platformio is installed from the GitHub URL, semantic_version is automatically installed as one of its dependencies.

Applied to files:

  • builder/penv_setup.py
📚 Learning: 2025-09-23T14:15:00.476Z
Learnt from: Jason2866
PR: pioarduino/platform-espressif32#0
File: :0-0
Timestamp: 2025-09-23T14:15:00.476Z
Learning: In the pioarduino/platform-espressif32 project, espidf.py creates and manages its own separate IDF virtual environment (accessed via get_python_exe() from get_idf_venv_dir()). This IDF venv is completely isolated from the penv setup, so different cryptography versions between penv_setup.py and espidf.py don't cause conflicts as they exist in separate virtual environments.

Applied to files:

  • builder/frameworks/espidf.py
📚 Learning: 2025-08-20T14:13:13.842Z
Learnt from: Jason2866
PR: pioarduino/platform-espressif32#263
File: platform.py:80-84
Timestamp: 2025-08-20T14:13:13.842Z
Learning: For the pioarduino/platform-espressif32 project, Jason2866 prefers to always override IDF_TOOLS_PATH environment variable with PlatformIO's core directory, rather than respecting any existing user-defined IDF_TOOLS_PATH values. This ensures consistent ESP32 tool management within PlatformIO.

Applied to files:

  • builder/frameworks/espidf.py
📚 Learning: 2025-09-23T14:15:00.476Z
Learnt from: Jason2866
PR: pioarduino/platform-espressif32#0
File: :0-0
Timestamp: 2025-09-23T14:15:00.476Z
Learning: In the pioarduino/platform-espressif32 project, espidf.py creates an extra/separate virtual environment from the penv setup, so cryptography version differences between penv_setup.py and espidf.py do not cause conflicts since they operate in isolated environments.

Applied to files:

  • builder/frameworks/espidf.py
📚 Learning: 2025-08-05T11:47:41.756Z
Learnt from: Jason2866
PR: pioarduino/platform-espressif32#246
File: builder/main.py:0-0
Timestamp: 2025-08-05T11:47:41.756Z
Learning: In the ESP32 platform builder, subprocess calls correctly use the virtual environment Python by explicitly passing PYTHON_EXE (which is set to the venv python path) as the first argument in the command array, rather than relying on environment variable propagation. The env=os.environ parameter only affects environment variables, not the executable path itself.

Applied to files:

  • builder/frameworks/espidf.py
📚 Learning: 2025-07-13T20:03:29.695Z
Learnt from: Jason2866
PR: pioarduino/platform-espressif32#225
File: builder/main.py:99-108
Timestamp: 2025-07-13T20:03:29.695Z
Learning: In the ESP32 platform builder, the subprocess call to get site-packages directory in setup_python_paths() function is intentionally left without error handling because if this basic Python operation fails, it indicates a fundamental system issue that would cause the entire build process to fail anyway.

Applied to files:

  • builder/frameworks/espidf.py
🪛 Ruff (0.13.1)
builder/main.py

653-653: Unused function argument: target

(ARG001)


653-653: Unused function argument: source

(ARG001)


723-723: subprocess call: check for execution of untrusted input

(S603)


731-731: Do not catch blind exception: Exception

(BLE001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: build (macos-15, examples/espidf-ulp-lp)
  • GitHub Check: build (macos-15, examples/espidf-peripherals-usb)
  • GitHub Check: build (macos-15, examples/espidf-blink)
  • GitHub Check: build (macos-15, examples/arduino-NimBLE-ext_client)
  • GitHub Check: build (windows-latest, examples/espidf-peripherals-usb)
  • GitHub Check: build (windows-latest, examples/espidf-peripherals-uart)
  • GitHub Check: build (windows-latest, examples/espidf-hello-world)
  • GitHub Check: build (macos-15, examples/arduino-blink)
  • GitHub Check: build (windows-latest, examples/espidf-storage-sdcard)
  • GitHub Check: build (windows-latest, examples/espidf-arduino-littlefs)
  • GitHub Check: build (windows-latest, examples/espidf-coap-server)
  • GitHub Check: build (windows-latest, examples/espidf-blink)
  • GitHub Check: build (ubuntu-latest, examples/espidf-arduino-matter-light)
  • GitHub Check: build (windows-latest, examples/arduino-wifiscan)
  • GitHub Check: build (windows-latest, examples/arduino-blink)
  • GitHub Check: build (ubuntu-latest, examples/espidf-arduino-littlefs)
  • GitHub Check: build (ubuntu-latest, examples/espidf-hello-world)
  • GitHub Check: build (ubuntu-latest, examples/tasmota)
  • GitHub Check: build (ubuntu-latest, examples/arduino-blink)
🔇 Additional comments (1)
builder/main.py (1)

693-705: Default coredump invocation fails without the required core file.

Line 703 assembles esp_coredump without a --core/-c argument (and with the subcommand after --chip), so pio run -t coredump currently exits immediately with “the following arguments are required: --core”. Please surface a usable default core file (config option or conventional filenames) and omit execution when none is found. This guarantees the documented target works out of the box.

         if cli_args:
             cmd.extend(cli_args)
             # ELF file should be at the end as positional argument
             if not any(arg.endswith('.elf') for arg in cli_args):
                 cmd.append(elf_file)
         else:
-            # Default arguments if none provided
-            # Parameters from platformio.ini
-            extra_args = env.GetProjectOption("custom_esp_coredump_args", "")
-            if extra_args:
-                # Parse extra args and add ELF file at the end
-                cmd.extend(shlex.split(extra_args))
-                cmd.append(elf_file)
-            else:
-                # Use defaults: --chip <mcu> info_corefile <elf_file>
-                cmd.extend(["--chip", mcu, "info_corefile", elf_file])
+            extra_args = env.GetProjectOption("custom_esp_coredump_args", "")
+            if extra_args:
+                cmd.extend(shlex.split(extra_args))
+                cmd.append(elf_file)
+            else:
+                core_path = env.GetProjectOption("custom_esp_coredump_corefile", "")
+                if not core_path:
+                    default_bin = Path(get_project_dir()) / "coredump.bin"
+                    default_b64 = Path(get_project_dir()) / "coredump.b64"
+                    if default_bin.is_file():
+                        core_path = str(default_bin)
+                    elif default_b64.is_file():
+                        core_path = str(default_b64)
+                if not core_path:
+                    print(
+                        "Error: No coredump file specified. Provide one via CLI "
+                        "(-- --core <path>) or set custom_esp_coredump_corefile."
+                    )
+                    return
+                core_args = ["info_corefile", "--chip", mcu, "--core", core_path]
+                if core_path.endswith(".b64"):
+                    core_args.extend(["--core-format", "b64"])
+                cmd.extend(core_args + [elf_file])

@Jason2866
Copy link
Author

@coderabbitai full review

Copy link

coderabbitai bot commented Sep 28, 2025

✅ Actions performed

Full review triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
builder/main.py (5)

653-666: Silence ARG001 by marking SCons action params unused.

Rename target/source to underscores to avoid “unused argument” warnings without changing behavior.

-def coredump_analysis(target, source, env):
+def coredump_analysis(_target, _source, env):

687-704: Make default run robust: auto-pick core file if present, add port if known.

Today the default path reads the coredump from flash (no --core), which fails when no device is attached or auto-detection picks the wrong one. Prefer a local core file when available, infer core-format from extension, and include --port if UPLOAD_PORT is set; still fall back to reading from flash if no file found. This matches esp-coredump’s CLI where is positional ELF and --core/-c is optional. (docs.espressif.com)

-        else:
-            # Default arguments if none provided
-            # Parameters from platformio.ini
-            extra_args = env.GetProjectOption("custom_esp_coredump_args", "")
-            if extra_args:
-                # Parse extra args and add ELF file at the end
-                cmd.extend(shlex.split(extra_args))
-                cmd.append(elf_file)
-            else:
-                # Use defaults: --chip <mcu> info_corefile <elf_file>
-                cmd.extend(["--chip", mcu, "info_corefile", elf_file])
+        else:
+            # Default arguments if none provided
+            # Parameters from platformio.ini
+            extra_args = env.GetProjectOption("custom_esp_coredump_args", "")
+            if extra_args:
+                args = shlex.split(extra_args)
+                cmd.extend(args)
+                # Ensure ELF is last positional if not present
+                if not any(a.endswith(".elf") for a in args):
+                    cmd.append(elf_file)
+            else:
+                # Prefer an explicit core file if configured or present; else read from flash
+                core_file = env.GetProjectOption("custom_esp_coredump_corefile", "")
+                if not core_file:
+                    for name in ("coredump.bin", "coredump.b64"):
+                        cand = Path(get_project_dir()) / name
+                        if cand.is_file():
+                            core_file = str(cand)
+                            break
+
+                # Global options
+                cmd.extend(["--chip", mcu])
+                upload_port = env.subst("$UPLOAD_PORT")
+                if upload_port:
+                    cmd.extend(["--port", upload_port])
+
+                # Subcommand and arguments
+                cmd.append("info_corefile")
+                if core_file:
+                    cmd.extend(["--core", core_file])
+                    if core_file.lower().endswith(".b64"):
+                        cmd.extend(["--core-format", "b64"])
+                # ELF is the required positional
+                cmd.append(elf_file)

737-742: Parse boolean project option correctly.

PlatformIO options come in as strings; "false" currently evaluates truthy. Normalize to a real boolean.

-        if env.GetProjectOption("custom_esp_coredump_verbose", False):
+        if str(env.GetProjectOption("custom_esp_coredump_verbose", "false")).lower() in ("1","true","yes","on"):

744-748: Add a timeout to prevent hanging runs.

Long-running esp-coredump sessions can stall. Add a generous timeout (or make it configurable).

-        result = subprocess.run(cmd, check=False, capture_output=False, env=coredump_env)
+        timeout_sec = int(str(env.GetProjectOption("custom_esp_coredump_timeout_sec", "600")))
+        result = subprocess.run(cmd, check=False, capture_output=False, env=coredump_env, timeout=timeout_sec)

749-755: Narrow exception handling.

Catching bare Exception obscures actionable errors. Limit to OSError/SubprocessError and print stderr when available.

-    except Exception as e:
-        print(f"Error: Failed to run coredump analysis: {e}")
+    except (OSError, subprocess.SubprocessError) as e:
+        print(f"Error: Failed to run coredump analysis: {e}")
         print(f'Make sure esp-coredump is installed: uv pip install --python "{PYTHON_EXE}" esp-coredump')
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c22d9e and 1b258f7.

📒 Files selected for processing (2)
  • builder/main.py (2 hunks)
  • builder/penv_setup.py (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-10T19:13:25.599Z
Learnt from: Jason2866
PR: pioarduino/platform-espressif32#255
File: builder/penv_setup.py:26-40
Timestamp: 2025-08-10T19:13:25.599Z
Learning: In the pioarduino/platform-espressif32 repository's builder/penv_setup.py file, semantic_version is imported but intentionally not listed in python_deps because it's a transitive dependency of platformio-core (version 2.10.*). When platformio is installed from the GitHub URL, semantic_version is automatically installed as one of its dependencies.

Applied to files:

  • builder/penv_setup.py
🪛 Ruff (0.13.1)
builder/main.py

653-653: Unused function argument: target

(ARG001)


653-653: Unused function argument: source

(ARG001)


718-718: Do not catch blind exception: Exception

(BLE001)


727-727: Do not catch blind exception: Exception

(BLE001)


744-744: subprocess call: check for execution of untrusted input

(S603)


752-752: Do not catch blind exception: Exception

(BLE001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: build (macos-15, examples/espidf-blink)
  • GitHub Check: build (macos-15, examples/arduino-wifiscan)
  • GitHub Check: build (macos-15, examples/tasmota)
  • GitHub Check: build (windows-latest, examples/espidf-peripherals-usb)
  • GitHub Check: build (macos-15, examples/espidf-arduino-matter-light)
  • GitHub Check: build (macos-15, examples/arduino-blink)
  • GitHub Check: build (windows-latest, examples/tasmota)
  • GitHub Check: build (windows-latest, examples/espidf-coap-server)
  • GitHub Check: build (windows-latest, examples/espidf-blink)
  • GitHub Check: build (windows-latest, examples/arduino-blink)
  • GitHub Check: build (windows-latest, examples/arduino-wifiscan)
🔇 Additional comments (3)
builder/main.py (2)

1038-1057: Targets look good.

The coredump and coredump-only targets are registered as expected and align with the new analysis helper.


709-729: Remove unnecessary install_package guard
install_package is provided by PlatformBase (inherited by Espressif32Platform), so it’s always available—no extra availability check needed.

Likely an incorrect or invalid review comment.

builder/penv_setup.py (1)

58-60: Approve dependencies Verified esp-idf-size latest on PyPI is 1.7.1 and esp-coredump is 1.14.0; the >=1.6.1 and >=1.14.0 specifiers are valid.

Refactor coredump command construction to handle extra arguments and core file detection more robustly.
@Jason2866
Copy link
Author

@coderabbitai full review

Copy link

coderabbitai bot commented Sep 28, 2025

✅ Actions performed

Full review triggered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant