Skip to content

feat(native): inspect DWARF compile units offline - #8523

Merged
N0zoM1z0 merged 37 commits into
morluto:mainfrom
mvanhorn:fix/dwarf-compile-units
Nov 17, 2026
Merged

N0zoM1z0 merged 37 commits into
morluto:mainfrom
mvanhorn:fix/dwarf-compile-units

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add offline inspect-dwarf-units / inspect_dwarf_units for DWARF 2–5 compile-unit headers and unit-DIE build facts in selected ELF, Mach-O or PE files. Reports preserve source ranges, per-unit unknowns, coverage and caller-selected paging/architecture. Targets and separate debug files are not executed or automatically opened.

Integrate current ELF diagnostics through one compression-framing owner: budget preflight and decoding admit the same headers, with bounded expansion and retained inflation-work accounting. Shared application admission preserves omitted versus explicit controls, including late-cancellation Evidence. Limits use the canonical error algebra without adding constructor debt.

Validation

  • 189 focused source checks and 358 public CLI/MCP, filesystem, shared lifecycle and capability-conformance checks passed.
  • Real clang/llvm-dwarfdump oracle: 13 variants and 3 boundary scenarios passed, including DWARF 2–5, DWARF64, zlib, split DWARF, PE DWARF4 and explicit relocatable/dwo limitations. Five variants reported toolchain skips.
  • Real GCC DWARF4/5 ELF: CLI and stdio MCP full/hot-cold results matched independent readelf version/name/directory/producer facts. Omitted and explicit default controls yielded the same report with distinct correct Evidence parameters/IDs; target hashes stayed unchanged.
  • Typecheck, Knip, architecture, advertised schemas, generated metadata, docs and changed-file lint/format passed. Final-head CI passed all required gates, all 12 test shards and the Windows capability/package lane. Automated review passed with no unresolved threads.

Real Zstandard, big-endian ELF and PE DWARF5 were unavailable with this host toolchain; current-host real Mach-O coverage was not run. Local expensive checks were serialized under one CPU and an 8 GiB hard / 6 GiB early-stop memory budget, with no OOM. Full typed lint was not rerun after the preceding integration exceeded that local budget.

Author readiness

Human owner: @mvanhorn

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Documents `inspect_dwarf_units` and `inspect-dwarf-units` for static
inspection of DWARF 2–5 in ELF, Mach-O, and PE images, including
compressed debug sections. The guide explains pagination, artifact
identity, per-unit issues, architecture selection, and coverage
reporting. It also describes unresolved relocations and distinguishes
missing debug information in the selected file from separate debug
files.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-17T09:46:29.918503Z
We couldn’t complete this review. Comment @codex review to try again.
9ec3e34 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge, with no accepted new blocking findings.

Summary

Adds inspect_dwarf_units and inspect-dwarf-units for static DWARF inspection in ELF, Mach-O, and PE files.

  • Compile-unit reports show source facts and clearly mark data the reader cannot resolve.
  • The DWARF reader is available through the CLI and MCP tool catalog.
  • Shared native section readers now expose file-backed data and reuse ELF decompression.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[CLI or MCP request] --> B[DwarfUnitsService]
  B --> C[Stable artifact read]
  C --> D[Select native image]
  D --> E[Locate and decompress sections]
  E --> F[Frame units and decode requested page]
  F --> G[Check report and create Evidence]
Loading

Reviews (29) · Last reviewed commit: "fix(native): preserve DWARF caller contr..." · Reviewed by Greptile

Comment thread src/native/dwarf/DwarfSections.ts Resolved
Comment thread src/native/dwarf/DwarfSections.ts Resolved
Comment thread scripts/verify-dwarf-units.mjs Resolved
Comment thread scripts/verify-dwarf-units.mjs Resolved
Comment thread scripts/verify-dwarf-units.mjs Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 90d840a8c4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/native/dwarf/DwarfSections.ts Resolved
- Charge a failed inflate its declared size, and nothing for a rejected
  header, so an unreadable optional section no longer exhausts the allowance.
- Treat an empty .debug_info as no contents at selection, so a populated
  copy that follows it is still read and empty copies are not counted unread.
- Admit Mach-O sections from an unmapped __DWARF segment by on-disk range
  instead of VM mapping.
- Verifier: parse readelf values after the attribute separator (including
  indexed strings), stop collecting unit attributes at the first child DIE,
  anchor unit header matches, and run compiler, linker and dumper commands
  through createVerifierCommands with one cleanup that keeps the temp
  directory when a stop fails. Only a nonzero exit or a missing tool skips a
  variant; a timeout fails the run.
- Drop the test that matched verification record prose.
@mvanhorn

mvanhorn commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 7d9f698 to this branch. I read each finding against the code at 90d840a and each one held.

  • Inflate allowance: a rejected header or non-GNU section no longer charges anything, and a failed inflate charges its declared size instead of the whole allowance. A corrupt compressed .debug_line_str before a valid compressed .debug_info now still reads the units.
  • Empty .debug_info: it is classified as no contents at section selection, so it gives no_debug_info, a populated copy after it is still read, and empty copies are not counted as unread.
  • Mach-O unmapped __DWARF: the Mach-O owner now records an on_disk fact (not zero-fill, inside the file and the segment file range, independent of VM mapping), and the DWARF reader admits sections by it. This touches MachoImage.ts and BinaryContainer.ts, and I added a type declaration for the existing verifier loader; the description now says so.
  • Verifier parsing: values are read after the attribute separator, including (indirect string, offset) and (indexed string) prefixes, so https://... and /tmp/two:words keep their text. Attributes stop at the first child DIE, and unit header matches are anchored so producer text cannot split a unit.
  • Verifier processes: compiler, linker and dumper now run through createVerifierCommands, with one cleanup that keeps the temp directory if the commands cannot be stopped. A timeout or crash now fails the run; only a nonzero exit or a missing tool skips a variant.
  • Test of record prose: the assertions on the verification record are removed, and the loader check now imports through the loader.

Checked locally on Node 24.22.1: typecheck and lint (check:fast), format check, docs:check, 11 focused test files (104 tests) covering the DWARF, Mach-O, ELF decode, CLI, MCP and verifier tests, and npm run verify:dwarf-units against llvm-dwarfdump (one variant, big-endian PowerPC, skipped because this clang lacks that target). I did not run the full suite; CI is running on the new head.

Comment thread src/native/dwarf/DwarfSections.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d9f698ab0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/native/dwarf/DwarfSections.ts Resolved
Comment thread src/native/dwarf/DwarfSections.ts Resolved
- Charge a failed compressed section the larger of its declared output and
  the compressed input it read, so aliased failing streams hit the allowance.
- Decode GNU //base64 COFF long section names as well as /decimal ones.
- Take the Mach-O cpu type and the PE COFF symbol table declaration from
  their metadata owners instead of rereading file headers in the DWARF reader.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5bcd794544

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/native/dwarf/DwarfSections.ts Resolved
mvanhorn and others added 2 commits November 1, 2026 08:37
A valid stream that expands to nothing charged no allowance, so aliased
section headers could inflate the same large empty stream repeatedly. The
compression owner now reports the larger of decoded output and compressed
input on success as it does on failure, and the DWARF reader charges that.

Drop `.ok` assertions that ran ahead of the typed error guard, which hid the
cause when a read failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KuWHGvzJkrhCqjtEHUwqyH
Comment thread scripts/verify-dwarf-units.mjs Resolved
GNU readelf prints offsets with %#x, which drops the 0x prefix for
zero, so a string at offset zero reads "(indirect string, offset: 0):".
Make the prefix optional and cover that output in the verifier test.
…nits

Resolve docs/index.md by keeping the new wxapkg guide link from main
and the DWARF compile units link from this branch.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Comment thread src/native/dwarf/DwarfUnitsProvider.ts Resolved
Pass stableArtifactInputRecovery into the path/format input error so
CLI and MCP callers get the resolved file path to retry, matching the
other stable artifact readers.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Resolve conflicts with the binary hardening addition by keeping both
entries in the README tables, docs index, VitePress sidebar and
package.json verify scripts.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Resolve conflicts from the upstream docs reorganization: keep the
DWARF compile units rows in README tables, link the guide from
docs/index.md, and register docs/dwarf-units.md in the new
documentation.ts sidebar registry. Upstream removed the execution
wording exception list in toolEffects.test.ts, so that file takes
upstream as is.
Resolve conflicts with the contracts, ports, resources and domain moves on
main: the DWARF contract now declares cli and its effects inline, the port
lives in src/ports, and the compressed ELF section decoder moves to
src/domain/native beside the section name table.
…ARF units

Import resources through its index, register the DWARF units provider as a
native entry file, and read the Evidence subject format from its identity.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Merged current main into this branch in 8278e68 and fixed the fallout in 90e080a.

Conflicts resolved: the DWARF contract now sets cli: true and passes its effects through toolContractMetadata, since main dropped the separate CLI name table and effect audit. The port moved to src/ports/binaryDiagnostics, the compressed ELF section decoder moved to src/domain/native next to the section name table, the binding table keeps both sides, and the raw buffer baseline follows main's file moves. After the merge, the provider imports resources through its index, is registered as a native entry file, and the tests read the subject format from subject.identity.

Comment thread scripts/verify-dwarf-units.mjs Resolved
Add the dwarfUnits capability to PROVIDER_CAPABILITY_CONFORMANCE with the
CLI and MCP workflow tests, and add rea-dwarf-units to
PROVIDER_LIFECYCLE_COVERAGE as an in-process provider whose operation and
cancellation stages name the existing DWARF tests.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Parse the dumper format before reading a value: llvm-dwarfdump wraps an
escaped string in ("..."), while readelf prints the raw value after its
prefix. A readelf comp_dir with quotes was cut to the first quoted run.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Main now counts hand-built resource-constraint refusals. The DWARF section
allowance failure is a ParseFailureError limit, so it and the native
structural limit go through parseLimitConstraint; only the input read
budget refusal stays hand-built and is recorded in the baseline.

Also regenerates the Cursor plugin skill and the advertised schema summary
for inspect_dwarf_units, adds the DWARF compile units row to the Bulgarian
README that main added, and splits the dumper comparison tests to stay under
the function length limit.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Merged current main in 30a1147 and fixed the fallout in e4ec4d6: the DWARF section allowance and structural limit refusals now go through parseLimitConstraint, and the Cursor skill files, the inspect_dwarf_units schema summary and the Bulgarian README row are regenerated. The input read budget refusal is still hand-built, so I added it to resource-constraint-constructor.json with count 1; if you would rather route it through a shared helper instead of the baseline, I can change it.

readPeSectionDirectory decoded PointerToSymbolTable and NumberOfSymbols
from the raw COFF bytes beside readPeCoffHeader, which owns that record.
The owner now returns symbolTableOffset and symbolCount, reads every
field through BinaryReader, and the section directory consumes them.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

inspect_dwarf_units brings the catalog to 256 tools, one more than a single
native search_tool query can return. The grok verifier now queries each
name the earlier pages missed and checks the union against the catalog,
instead of asserting the catalog fits in one page.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@mvanhorn

Copy link
Copy Markdown
Contributor Author

One design change to flag in 8435c37: with inspect_dwarf_units the catalog is 256 tools, one more than a single native search_tool query can return (its limit is a uint8), so the verifier's fits-in-one-page assertion could no longer hold. The native client verifier in scripts/ now drops that assertion; it searches by name for each tool the rea query missed, then requires the combined results to match the catalog exactly and still checks every input schema, and native-discovery.json now holds every page as a JSON array. The paging has not been tried against the real client, since CI drives the verifier with a fake one, so if you'd rather keep a single-page check and trim the catalog some other way, I can change it.

gensokyo-dev and others added 2 commits November 17, 2026 09:30
Preserve the integrated ELF diagnostics and current Grok verifier. Share compression framing between budget preflight and the common decoder while retaining DWARF decompression accounting.

Co-authored-by: gensokyo-dev <[email protected]>
Use application admission and the shared caller-parameter selector while retaining resolved defaults for decoding. Migrate selected input limits and fixed ceiling facts to the canonical owner, and verify public and late-cancellation Evidence provenance.

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)

Co-authored-by: gensokyo-dev <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@N0zoM1z0 N0zoM1z0 changed the title feat(native): inspect DWARF compile units without a provider feat(native): inspect DWARF compile units offline Nov 17, 2026

@gensokyo-dev gensokyo-dev 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.

Reviewed the offline selected-file scope, shared compression-framing owner, canonical limit recovery and caller-selection provenance. Source and public/lifecycle checks passed, with real compiler oracles and real GCC CLI/stdio MCP full/hot-cold validation. Toolchain gaps are recorded. Exact-head CI and automated review remain the merge gates.

@N0zoM1z0
N0zoM1z0 enabled auto-merge (squash) November 17, 2026 09:54
@N0zoM1z0
N0zoM1z0 merged commit 637e4cb into morluto:main Nov 17, 2026
57 checks passed
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants