Skip to content

[AUTOMATED] feat(cli): list a function's warnings in its JSON record - #1601

Open
phix33 wants to merge 1 commit into
Noelo-Lab:mainfrom
phix33:json-function-warnings
Open

phix33 wants to merge 1 commit into
Noelo-Lab:mainfrom
phix33:json-function-warnings

Conversation

@phix33

@phix33 phix33 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

The problem

When a function decompiles with warnings, its --json record does not say so: error is null, and the bad-instruction, truncated-flow and unresolved-jump warnings appear only as C comments inside code. To tell a truncated body from a clean one, a consumer has to parse the C text.

$ kuna decompile decompiler/crates/kuna-analysis/tests/fixtures/adrnext_x86_64 0x0 --json --raw-image --target AARCH64:LE:64:v8A --base 0x0
{
  "binary": "decompiler/crates/kuna-analysis/tests/fixtures/adrnext_x86_64",
  "language": "c-language",
  "count": 1,
  "error": null,
  "functions": [
    {
      "name": "sub_0",
      "address": 0,
      "address_hex": "0x0",
      "aliases": [],
      "object_location": null,
      "size": 1072,
      "code": "void sub_0(void) // warn: Control flow encountered bad instruction data\n{\n  halt_baddata(); // warn: Bad instruction - Truncating control flow here\n}",
      "error": null,
      "unstructured_gotos": 0,
      "line_mappings": [
        {
          "line_number": 3,
          "addresses": [
            0
          ]
        }
      ],
      "variables": [],
      "types": []
    }
  ],
  "assertions": []
}

The record should also have a warnings array giving the kind and instruction address of each warning in code, with error still null.

The fix

  • Every --json function record from decompile and decompile-all, and from the browser front-end, now has a warnings array of {kind,message,line,address}. The array is always present and is [] for a function with no warnings and for one that failed.
  • The printer records an entry each time it writes one of the engine's own warning comments: a header warning, a body warning, an inline slug, or the note on a body it has no structure for. A comment whose text merely reads like a warning is never listed. That covers an --assert comment, a storage comment, and the original name a Rust or Go render keeps above the prototype.
  • address is the instruction the warning was recorded at, or the function's entry for a header warning. It is null only for structuring-declined. line is the line of code that holds the comment, and message is the warning text without its WARNING: marker.
  • kind is assigned by matching the warning text. A fixed table covers decode failures, flow cut at the instruction budget, out-of-bounds and unmapped flow, unrecovered jump tables and declined structuring. Any other warning gets the slug warnstyle inline prints for it (without its xN count) or a kuna producer tag. Text that matches none of these gets other.
  • The --jobs result wire and the result store carry the records, and the wire format moves to KUNAJOBRES12. Both warnstyle values give the same records except for line.

Not changed: Warnings change neither error nor the exit status, and the warning comments in code print as before.

The tests

Adds 6 tests in decompiler/crates/kuna-cli/tests/function_warnings_cli.rs and a case to decompiler/crates/kuna-cli/tests/integration.rs. The acceptance case fails without the fix.

- Every `--json` function record from `decompile` and `decompile-all`, and from the browser front-end, now has a `warnings` array of `{kind,message,line,address}`. The array is always present and is `[]` for a function with no warnings and for one that failed.
- The printer records an entry each time it writes one of the engine's own warning comments: a header warning, a body warning, an inline slug, or the note on a body it has no structure for. A comment whose text merely reads like a warning is never listed. That covers an `--assert comment`, a storage comment, and the original name a Rust or Go render keeps above the prototype.
- `address` is the instruction the warning was recorded at, or the function's entry for a header warning. It is `null` only for `structuring-declined`. `line` is the line of `code` that holds the comment, and `message` is the warning text without its `WARNING: ` marker.
- `kind` is assigned by matching the warning text. A fixed table covers decode failures, flow cut at the instruction budget, out-of-bounds and unmapped flow, unrecovered jump tables and declined structuring. Any other warning gets the slug `warnstyle inline` prints for it (without its ` xN` count) or a kuna producer tag. Text that matches none of these gets `other`.
- The `--jobs` result wire and the result store carry the records, and the wire format moves to `KUNAJOBRES12`. Both `warnstyle` values give the same records except for `line`.

This branch has not been deployed

No deployments
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.

1 participant