Skip to content

[AUTOMATED] Report the bytes each decompiled function decodes, and the binary's code coverage - #1959

Merged
mahaloz merged 3 commits into
Noelo-Lab:mainfrom
kanonl125:function-ranges-coverage
Nov 25, 2026
Merged

mahaloz merged 3 commits into
Noelo-Lab:mainfrom
kanonl125:function-ranges-coverage

Conversation

@kanonl125

@kanonl125 kanonl125 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

A function's size is an upper bound that runs on through the padding to the next entry, and nothing says how much of a binary's code a whole-binary run decoded. After this change, each record lists the bytes its decompile decoded, and a whole-binary run can say what share of the executable bytes that is.

$ kuna decompile decompiler/crates/kuna-analysis/tests/fixtures/fauxware main --json | jq -c '.functions[0] | {size, ranges}'
before: {"size":195,"ranges":null}
after:  {"size":195,"ranges":[{"start":4196125,"start_hex":"0x40071d","end":4196309,"end_hex":"0x4007d5"}]}

$ kuna decompile-all decompiler/crates/kuna-analysis/tests/fixtures/fauxware --json --coverage | jq -c .coverage
{"executable_bytes":990,"unlifted_nul_bytes":32,"lifted_bytes":853,"decompiled_bytes":853,"lifted_share":0.8904,"decompiled_share":0.8904,"functions":21,"decompiled_functions":21,"unlifted_functions":0}

$ kuna decompile-project decompiler/crates/kuna-analysis/tests/fixtures/fauxware -o /tmp/fx
wrote /tmp/fx: ...; functions: 21 ok, 0 failed; code: 89.0% lifted, 89.0% decompiled of 958 bytes
  • Recording the ranges. When the main flow is done, the drive keeps the extents of its visited map on the Funcdata (flow::decoded_ranges, Funcdata::flow_ranges).
    • Each extent is the step the flow took, so a delay slot is inside it.
    • Code that is later proved dead still counts. An inlined callee's instructions count as the caller's.
    • Artificial-halt stubs (decode failures, cut flows, filled-in stubs) were never decoded, so they are left out.
    • FuncResult::ranges carries the ranges in the units of address, also for a function whose C failed to render. They travel over the --jobs wire and through the result store (KUNAJOBRES13).
  • Measuring. kuna_coverage::Code keeps one bit per executable byte (is it NUL?), so a --jobs parent can measure after it drops its program. It reads the CODE spans funcextent::spans uses. NUL bytes that nothing decoded (alignment fill, zero-filled tails) are left out of the share's total.
  • Where it appears.
    • Every JSON record gets ranges; --omit ranges drops it for a caller who wants the document small.
    • coverage is opt-in. decompile-all --json --coverage adds it. It measures the whole binary, so it is refused with --functions or --addr, and fails a run whose triage filter drops a function. Without the flag, a document is unchanged apart from ranges, so decompile --json and decompile-all --json still answer a one-function image with the same document.
    • A whole-binary export's completion line gets the two shares.
    • There is no option, because nothing changes what is decompiled or printed: apart from the new keys, the documents for fauxware, rust_fmt_pieces_1.90.0 and mcount_x86_64 are byte-identical to main's.

Tests:

  • coverage_cli checks the run's figures against fauxware's sections and NUL bytes, read with object. It also checks:
    • main's ranges equal its symbol's extent, as do MIPS main's (whose last 4 bytes are the delay slot of jr $ra);
    • Thumb thumb_helper's ranges, at its even address;
    • --omit ranges, the refusal of a narrowed --coverage (and a no-op filter still measuring), and that --jobs 2 reports what a serial run does;
    • the export line, streamed or not, and that a narrowed export has none.
  • Unit tests cover the measure (padding between functions, NUL bits across words, word-addressed units) and the pinned wire frame.

Speed, decompile-all --json --coverage (ranges and the measure) at the test profile, median of alternating runs against main: rust_fmt_pieces_1.90.0 (572 functions) 87.6 s → 88.4 s (+0.9%), mcount_x86_64 (1,074 functions) 73.3 s → 74.3 s (+1.4%). Both are within this machine's run-to-run spread of ±10%.

Model: anthropic/claude-opus-5-5

kanonl125 and others added 2 commits November 25, 2026 12:00
…overage

[AUTOMATED] The flow keeps the extents of every instruction it decodes on
the function (`Funcdata::flow_ranges`), delay slots included. A function's
JSON record lists them as `ranges`, in the units of `address`. A
whole-binary `decompile-all --json` run carries a `coverage` object: the
image's executable bytes, the parts decoded and decompiled, and the NUL
bytes nothing decoded, which the shares leave out of their total. A
whole-binary project export's completion line ends with the two shares.
`--omit ranges` drops the records' key. The ranges ride the `--jobs` wire
and the result store (KUNAJOBRES13).
…ort counts

The docs now say that a callee folded onto its call (no branch or call of its
own) adds no ranges, that two records' ranges can overlap and coverage counts
such a byte once, that a triage filter dropping nothing still measures the
whole binary, and that non-NUL fill (x86 NOPs and INT3s) and data in code stay
in the share's total. The pinned wire-layout test is renamed for version 13.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013BBaWTdjVzTz11WxPZmJ9b
@kanonl125

kanonl125 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

[AUTOMATED] Pushed 872215d, on top of ca4c9f9: the run-level coverage object is now opt-in, decompile-all --json --coverage. mapped_flow_boundary::shared_whole_image_and_project_paths_retain_the_recovered_body holds that a one-function image's kuna decompile --json and its whole-binary decompile-all --json are one document, and a coverage object on every whole run broke that.

--coverage keeps the whole-binary rule from ca4c9f9. It is refused with --functions or --addr. It fails a run whose triage filter drops a function, and measures one whose filter drops nothing. Without the flag, a document gains only each record's ranges. The project export's completion line is unchanged.

[AUTOMATED] A one-function image's `kuna decompile --json` and its
whole-binary `decompile-all --json` are one document
(mapped_flow_boundary), so the run-level `coverage` object is opt-in:
`decompile-all --json --coverage`. It is refused with --functions or
--addr, and fails a run whose triage filter drops a function. Without
the flag a document gains only each record's `ranges`.
@mahaloz

mahaloz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed ca4c9f9 on top of 807a3b0: docs and a test name only, no code change. docs/cli.md and spec chapter 2 now say that a callee folded onto its call (one with no branch or call, the EZ inline model) adds nothing to the caller's ranges, that two records' ranges can overlap (a function and its .cold part) and coverage counts such a byte once, that a triage filter that drops nothing still gets coverage, and that non-NUL fill (x86 NOP/INT3 padding) and data in code stay in the share's total. The pinned wire-layout test is renamed for version 13.

@mahaloz
mahaloz merged commit ebb9208 into Noelo-Lab:main Nov 25, 2026
2 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.

2 participants