Skip to content

fix: fixing exception on heap dump analysis on Windows - #1495

Merged
sigmaaa merged 1 commit into
masterfrom
fix_heap_tracing_issue
Aug 11, 2026
Merged

fix: fixing exception on heap dump analysis on Windows#1495
sigmaaa merged 1 commit into
masterfrom
fix_heap_tracing_issue

Conversation

@sigmaaa

@sigmaaa sigmaaa commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Description

Heap Dump Analysis on Windows failed with Failed to create trace reader! when opening a multicore .svdat file. OpenOCD already writes per-core dumps (*.svdat_core0, *_core1, …); the handler now prefers those files (any consecutive core count) and passes them as file:// arguments to sysviewtrace_proc.py. If no core siblings exist, it still uses the selected file. On a failed conversion it no longer writes a bogus dump.json or opens the analysis editor.

Fixes # (IEP-XXX)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

Test heap dump analysis feature on Windows and Mac, compare results with ESP-IDF terminal command execution

Test Configuration:

  • ESP-IDF Version:
  • OS (Windows,Linux and macOS):

Dependent components impacted by this PR:

  • Heap Dump Analysis

Checklist

  • PR Self Reviewed
  • Applied Code formatting
  • Added Documentation
  • Added Unit Test
  • Verified on all platforms - Windows,Linux and macOS

Summary by CodeRabbit

  • Bug Fixes
    • Improved heap dump analysis for applications producing separate per-core dump files.
    • Automatically detects and includes sequential core dump files when available.
    • Falls back to the selected dump file when no per-core files are found.
    • Improved validation of analysis data to prevent opening the analysis editor with incomplete or invalid results.
    • Standardized file handling for more reliable dump analysis across supported environments.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Heap dump analysis flow

Layer / File(s) Summary
Trace source resolution
bundles/.../HeapDumpAnalysisHandler.java
The handler discovers contiguous .svdat_coreN files, falls back to the selected dump file, and converts paths to normalized file:// URLs.
Analysis output handling
bundles/.../HeapDumpAnalysisHandler.java
The handler validates command output as JSON before writing build/dump.json and launching the analysis editor.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: kolipakakondal, andriifilippov, alirana01

Sequence Diagram(s)

sequenceDiagram
  participant Handler as HeapDumpAnalysisHandler
  participant Command as HeapDumpCommand
  participant Editor as AnalysisEditor
  Handler->>Command: run with resolved file:// trace sources
  Command-->>Handler: command output
  alt output is JSON
    Handler->>Editor: write build/dump.json and launch
  else output is not JSON
    Handler-->>Editor: skip generation and launch
  end
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: fixing a Windows exception during heap dump analysis.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix_heap_tracing_issue

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/HeapDumpAnalysisHandler.java`:
- Around line 140-142: Update isJsonOutput in HeapDumpAnalysisHandler to parse
the complete output as JSON and return true only when parsing succeeds with an
object root, rather than checking whether trimmed text starts with "{". Ensure
the dump-writing and editor-launch flow uses this validation so malformed or
trailing diagnostic output is not persisted or opened.
- Around line 47-48: Update toFileUrl() to serialize trace file paths through
the standard File URI API, using File.toURI().toASCIIString() or an equivalent.
Remove the raw FILE_URL_PREFIX concatenation so Windows drive letters and
URI-reserved characters are encoded correctly before passing the trace path to
sysviewtrace_proc.py.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 36c25066-9653-4e79-84a5-5080ebf92dbf

📥 Commits

Reviewing files that changed from the base of the PR and between e623b3a and 39facbd.

📒 Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/HeapDumpAnalysisHandler.java

Comment on lines +47 to +48
private static final Pattern CORE_SUFFIX = Pattern.compile("(?i)^(.+\\.svdat)_core\\d+$"); //$NON-NLS-1$
private static final String FILE_URL_PREFIX = "file://"; //$NON-NLS-1$

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

while IFS= read -r script; do
  ast-grep outline "$script" --lang python
  rg -n -C 4 'file:|urlparse|url2pathname|unquote|Path\(' "$script"
done < <(fd -a '^sysviewtrace_proc\.py$' .)

Repository: espressif/idf-eclipse-plugin

Length of output: 218


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Find target files"
fd -a 'HeapDumpAnalysisHandler\.java|sysviewtrace_proc\.py' .

echo
echo "Handler outline"
handler="$(fd 'HeapDumpAnalysisHandler\.java' . | head -n 1)"
if [ -n "${handler:-}" ]; then
  ast-grep outline "$handler" --lang java
  echo
  echo "Relevant handler excerpt"
  sed -n '1,180p' "$handler" | cat -n
fi

echo
echo "Python matches"
while IFS= read -r script; do
  printf '\n=== %s ===\n' "$script"
  ast-grep outline "$script" --lang python || true
  rg -n -C 4 'file:|urlparse|url2pathname|unquote|Path\(|sys.argv|argparse|sysview|trace' "$script" || true
done < <(fd -a '^sysviewtrace_proc\.py$' .)

Repository: espressif/idf-eclipse-plugin

Length of output: 8081


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from urllib.parse import urlparse, unquote
import re

def build_current(path):
    return "file://" + path.replace("\\", "/")

examples = [
    r"C:\project\build\a svdat",
    r"C:\project\build\trace#1.svdat",
    r"C:\project\build\trace?1.svdat",
    r"C:\project\build\trace%1.svdat",
    r"/unix/path/trace.svdat",
]

for path in examples:
    url = build_current(path)
    p = urlparse(url)
    print(path, "=>", url)
    print("  scheme=", p.scheme, "netloc=", p.netloc, "path=", p.path, "fragment=", p.fragment, "query=", p.query)
    print("  decoded_path=", unquote(p.path))
print()
print("Current regex matches:", re.match(r"(?i)file://(/?:|)(C?:)?/.+", "file://C:/foo/svdat").group() if re.match(r"(?i)file://(/?:|)(C?:)?/.+", "file://C:/foo/svdat") else None)
PY

echo
echo "Search for sysviewtrace_proc references"
rg -n "sysviewtrace_proc|IDF_Sysview.*|sysview.*trace|file://|urlparse|unquote|Path\\(" . || true

Repository: espressif/idf-eclipse-plugin

Length of output: 50384


Serialize the trace path with a standard file-URI API.

toFileUrl() builds raw file:// strings, so Windows paths like file://C:/... put C: in the URI authority, and URI-reserved characters such as #, ?, %, or spaces split the path incorrectly. sysviewtrace_proc.py receives the wrong trace argument and can fail conversion. Use File.toURI().toASCIIString() or an equivalent API to serialize the path.

Also applies to: bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/HeapDumpAnalysisHandler.java:135-137

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/HeapDumpAnalysisHandler.java`
around lines 47 - 48, Update toFileUrl() to serialize trace file paths through
the standard File URI API, using File.toURI().toASCIIString() or an equivalent.
Remove the raw FILE_URL_PREFIX concatenation so Windows drive letters and
URI-reserved characters are encoded correctly before passing the trace path to
sysviewtrace_proc.py.

Comment on lines +140 to +142
private static boolean isJsonOutput(String output)
{
return output != null && output.trim().startsWith("{"); //$NON-NLS-1$

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Parse the complete output before writing dump.json.

Line 142 accepts malformed output such as {error or {} diagnostic. Lines 92-93 then persist invalid analysis data and open the editor. Parse the complete string as JSON and require an object root before writing the file or launching the editor.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/HeapDumpAnalysisHandler.java`
around lines 140 - 142, Update isJsonOutput in HeapDumpAnalysisHandler to parse
the complete output as JSON and return true only when parsing succeeds with an
object root, rather than checking whether trimmed text starts with "{". Ensure
the dump-writing and editor-launch flow uses this validation so malformed or
trailing diagnostic output is not persisted or opened.

@kolipakakondal kolipakakondal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@AndriiFilippov AndriiFilippov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tested under:
OS: Windows 11 / Mac arm

LGTM 👍

@sigmaaa
sigmaaa merged commit 944339b into master Aug 11, 2026
8 checks passed
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.

3 participants