fix: fixing exception on heap dump analysis on Windows - #1495
Conversation
📝 WalkthroughWalkthroughChangesHeap dump analysis flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/HeapDumpAnalysisHandler.java
| 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$ |
There was a problem hiding this comment.
🎯 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\\(" . || trueRepository: 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.
| private static boolean isJsonOutput(String output) | ||
| { | ||
| return output != null && output.trim().startsWith("{"); //$NON-NLS-1$ |
There was a problem hiding this comment.
🎯 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.
AndriiFilippov
left a comment
There was a problem hiding this comment.
Tested under:
OS: Windows 11 / Mac arm
LGTM 👍
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.
How has this been tested?
Test heap dump analysis feature on Windows and Mac, compare results with ESP-IDF terminal command execution
Test Configuration:
Dependent components impacted by this PR:
Checklist
Summary by CodeRabbit