Repository navigation
fix(ghidra): stage sibling dSYM beside target snapshot for DWARF analysis - #10768
cainiao1992 wants to merge 2 commits into
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The change affects Ghidra snapshot analysis and checkpoint selection for targets with sibling dSYM files. The PR still needs to check that the staged companion matches the digest used to select its checkpoint. Findings
Fix with agent prompt### Issue 1
src/ghidra/GhidraTargetSnapshot.ts:undefined-136
With `REA_GHIDRA_CHECKPOINT_DIR` set, analyze a Mach-O without its dSYM, then add the matching dSYM and reopen it. `resolveGhidraCheckpoint` selects the same saved Program because its key covers only the executable hash and profile. The launcher restores that Program with `-noanalysis`, so the newly staged symbols and types are ignored.
Commit the companion's presence and digest before choosing a checkpoint, and verify the staged copy against that commitment. The repository requires cache keys to cover inputs that affect results.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryStages sibling dSYM files beside Ghidra’s renamed target snapshot and includes their content digest in checkpoint selection.
Source review only; no runtime verification was performed. Checking whether another PR supersedes this one was blocked by unavailable GitHub authentication. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Resolve analysis profile] --> B[Read optional companion digest]
B --> C[Choose checkpoint key]
C --> D[Acquire checkpoint]
D --> E[Create target snapshot]
E --> F[Read and stage optional companion]
F --> G{Saved Program exists?}
G -->|Yes| H[Restore saved Program]
G -->|No| I[Analyze staged target]
I --> J[Save Program in selected checkpoint]
Reviews (3) · Last reviewed commit: "fix(ghidra): verify the companion dSYM c..." · Reviewed by Greptile |
| // staged Mach-O keeps no __debug_info. Ghidra's DWARFAnalyzer only discovers | ||
| // a bundle named after the staged executable's path, so stage a renamed copy | ||
| // next to the snapshot; the runtime root owner cleans it up with the tree. | ||
| await stageCompanionDsym(sourcePath, snapshotPath); |
There was a problem hiding this comment.
Added debug symbols stay missing
With REA_GHIDRA_CHECKPOINT_DIR set, analyze a Mach-O without its dSYM, then add the matching dSYM and reopen it. resolveGhidraCheckpoint selects the same saved Program because its key covers only the executable hash and profile. The launcher restores that Program with -noanalysis, so the newly staged symbols and types are ignored.
Commit the companion's presence and digest before choosing a checkpoint, and verify the staged copy against that commitment. The repository requires cache keys to cover inputs that affect results.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/ghidra/GhidraTargetSnapshot.ts
Line: 136
Comment:
**Added debug symbols stay missing**
With `REA_GHIDRA_CHECKPOINT_DIR` set, analyze a Mach-O without its dSYM, then add the matching dSYM and reopen it. `resolveGhidraCheckpoint` selects the same saved Program because its key covers only the executable hash and profile. The launcher restores that Program with `-noanalysis`, so the newly staged symbols and types are ignored.
Commit the companion's presence and digest before choosing a checkpoint, and verify the staged copy against that commitment. The repository requires cache keys to cover inputs that affect results.
**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Fixed. The checkpoint manifest now records a companion_dsym_sha256 commitment, and resolution verifies the staged companion against it asymmetrically: when companion evidence exists at resolve time and does not match the recorded commitment (added later, changed content, or a rewritten commitment), the checkpoint is not reused and the target is analyzed fresh; when no companion is present there is no new evidence, so an existing Program stays reusable (preserving symbol provenance in the manifest). Wired through an optional targetPath argument at the provider call site.
5f77805 to
f2b8c26
Compare
940bd63 to
dbefbc2
Compare
|
Thanks @cainiao1992! Most of this has since landed on main: #12081 made Ghidra 12.2 with JDK 25 the verified build and dropped 12.1.x, and Homebrew Ghidra discovery is already in |
…ysis Xcode 17 clang emits all DWARF into a sibling <name>.dSYM bundle while the Mach-O keeps no debug sections. Ghidra's DWARF analyzer discovers that bundle next to the staged executable's path, so the staged target-<hash>.bin lost every DWARF symbol. Copy the source dSYM's DWARF member beside the snapshot under the staged name with the existing cancellable chunked-copy path. Include the companion's content digest in the checkpoint key so a newly available or changed dSYM starts a fresh analysis instead of restoring a Program built without its symbols. Targets without a companion keep the established key, so existing checkpoints and analysis profiles stay reusable.
dbefbc2 to
03d73cd
Compare
…bytes The companion staging path copied the source DWARF member without the coverage and same-regular-file checks its sibling readers already apply, so a dSYM rewritten during the copy window staged truncated or mixed bytes and Ghidra analyzed them as symbols with no signal. An unstable companion now removes the partial staged bundle and keeps the snapshot's no-companion semantics, matching the digest probe. The new regression test grows the source mid-copy; reverting the fix fails it. Also correct the test mock comment, which claimed to hook only the source member while the pattern also matched the staged copy's open.
|
@morluto Done — this PR is now only the dSYM companion staging change, rebased on current What remains:
Verified on macOS arm64 with real Ghidra 12.2 / JDK 25: a stripped arm64 Mach-O cannot resolve Thanks! |
Summary
Stage the caller-selected sibling
.dSYMbeside the Ghidra target snapshot so Xcode 17 clang DWARF is visible to Ghidra, and bind that companion to the checkpoint identity.createGhidraTargetSnapshotcopies<source>.dSYM/Contents/Resources/DWARF/<source>to the staged name using the existing cancellable chunked-copy path, then verifies read coverage and source identity. An unstable companion removes the partial bundle and keeps the snapshot's no-companion semantics, matching the digest probe; absent, malformed, or unreadable companions stay optional and cancellation propagates.resolveGhidraCheckpointhashes the companion and includes its digest in the checkpoint key when present. Adding or changing a dSYM therefore starts a separate analysis instead of restoring a Program built without those symbols, and never overwrites the saved Program. Targets without a companion keep the established two-part key.Per maintainer request, this PR now contains only the dSYM change and is rebased on current
main; the 12.2/JDK 25 and Homebrew work already landed separately.Problem and expected behavior
Xcode 17 clang emits all DWARF into a sibling
.dSYMwhile the Mach-O keeps no debug sections. Ghidra's DWARF analyzer only discovers a bundle named after the staged executable, so a stagedtarget-<hash>.binlost every DWARF symbol and procedures resolved only by raw Mach-O names. After this change, a matching companion stages under the staged name and its symbols participate in the analysis.Change and scope
Follow the contribution scope. Not applicable: this uses existing provider and owned-runtime boundaries. It adds no target authority, injection, mutation, or protection-recovery capability.
The checkpoint key change is deliberately additive for no-companion targets so existing manifests and Evidence remain valid. A companion changes which analysis inputs produced the Program, so it receives its own key rather than reusing or overwriting an incompatible saved Program.
Contract and boundary impact
GhidraTargetSnapshotowns companion staging and its content digest;GhidraCheckpointconsumes that digest in the storage key;GhidraProviderpasses the caller-selected target path.owned_checkpoint/Evidence shape is unchanged, so no-companion replay is unaffected.Expected effects:
Evidence and regression coverage
GhidraTargetSnapshot.test.tscovers renamed staging, absent/malformed companions, staging cleanup, a source rewritten mid-copy, cancellation during copy, and cancellation while hashing the digest;GhidraCheckpoint.test.tscovers unchanged identity without a companion, a separate checkpoint when one appears with the old manifest untouched, content-bound identity, and malformed-layout fallback.procedure_not_found: rea_checkpoint_leafwhen the staged Mach-O lost DWARF, and restored bare names and struct types after placing a renamed dSYM beside the snapshot. That real-provider observation was made on the earlier branch and was not re-run in this environment.verify:ghidra:checkpointsrun here because no real Ghidra/JDK is available in this environment.For boundary fixes, this adds checkpoint-identity regressions at the staging and storage owners plus a focused lifecycle boundary test; real-provider checkpoint replay remains a gap.
For evidence-bearing changes:
Validation performed
npm run test:local -- src/ghidra/GhidraTargetSnapshot.test.ts src/ghidra/GhidraCheckpoint.test.ts— 29 passed.npm run test:local -- src/ghidra/GhidraTargetSnapshot.test.tswith the parent revision's implementation and the current test file — 1 failed, 6 passed, confirming the mid-copy rewrite regression.npx vitest run src/ghidra— 1297 passed, 1 skipped.npm run test:focused -- tests/boundary/providers/ghidra/ghidraCheckpointLifecycle.test.ts— 8 passed.npm run check:fast— passed (typecheck, lint, architecture guards).npm run docs:check— passed.verify:ghidra:checkpoints(no real Ghidra/JDK in this environment).Compatibility, safety, and release
Author readiness
Human owner: @cainiao1992
Before merge
type(scope): outcome.