Skip to content

feat(native): observe function and Objective-C method calls under LLDB - #964

Merged
kaoru0822-kitauji merged 5 commits into
mainfrom
feat/native-call-observation
Oct 8, 2026
Merged

kaoru0822-kitauji merged 5 commits into
mainfrom
feat/native-call-observation

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

This adds observe_native_calls, a bounded runtime observe tool for the LLDB part of #385. It answers the question "which of these functions or Objective-C methods does this Mach-O actually call in one run, and with what?"

  • REA launches the active Mach-O as a new, owned process under lldb --batch, using the Python bridge bridge/native/rea_lldb_tracer.py. It stops at caller-selected entries, records them and continues automatically:

    • functions by exact symbol name, optionally limited to one image;
    • Objective-C methods by selector, optionally limited to one class and to instance or class methods.
  • Recorded per entry (observed):

    • thread, image, symbol, load and file address;
    • raw integer argument registers;
    • optional caller frames;
    • for methods, the selector read from _cmd and the receiver's dynamic class.

    The receiver class comes from LLDB's Objective-C runtime reader with eDynamicDontRunTarget. Breakpoints are placed at the symbol itself (target.skip-prologue false), so the registers hold the ABI arguments.

  • Authority:

    • no expression evaluation;
    • no target code runs on REA's behalf;
    • no attachment to a process REA did not launch;
    • no approval flags, because selecting the operation is the intent.

    The effects are declared: it launches a process, writes temporary files, and the target may show UI or use the network. The result is never served from the snapshot cache.

  • Lifecycle:

    • The run ends on process exit, max_events, or duration_ms. The last two are resource-safety bounds, and each is explained in limitations.
    • REA kills the process, confirms it is gone, and kills a survivor only when it is still the traced executable.
    • Cancellation and a hard deadline kill LLDB's process group; debugserver then takes the target with it.
  • Results:

    • exit status and description;
    • stdout and stderr, with 1 MiB kept per stream and the remainder counted;
    • signal and exception stops;
    • every breakpoint's resolved locations, with location_count;
    • partial coverage when the event limit is reached or a request matched no loaded code;
    • limitations: entry only, no floating-point or stack arguments, inlined and objc_direct calls are not observed, ASLR is disabled by LLDB, and the duration is checked about once a second.
  • Failures keep their reason:

    • LLDB missing → capability_unavailable;
    • a target LLDB may not debug → capability_unavailable with reason debugger-attach-denied: … and remediation (Developer Tools access, or get-task-allow for hardened-runtime targets; see inspect_signature's debugger-attach facet);
    • a changed target digest → evidence integrity error;
    • malformed input → invalid_request.

Contract

New native tool: observe_native_calls. The native family goes from 7 to 8 tools; READMEs and the generated catalog are updated.

{
  "name": "observe_native_calls",
  "arguments": {
    "breakpoints": [
      { "kind": "objc-method", "class_name": "ReaCallGreeter", "selector": "greet:times:", "method_type": "instance" },
      { "kind": "function", "name": "rea_call_add" }
    ],
    "environment": { "REA_CALLS_MARKER": "observed" },
    "argument_registers": 4,
    "backtrace_frames": 1
  }
}

The result excerpt below is from the conformance fixture. Paths are trimmed, and only one event of each kind is shown.

{
  "process": { "outcome": "exited", "exit_status": 0, "terminated": true,
               "stdout": { "text": "world x0 40\nworld x1 41\nworld x2 42\nmarker observed\n", "truncated": false } },
  "events": [
    { "symbol": "-[ReaCallGreeter greet:times:]", "file_address": "0x100000928", "module": "ReaCalls",
      "receiver_class": "ReaCallGreeter", "selector": "greet:times:",
      "registers": [{ "name": "x0", "value": "0x…" }, { "name": "x1", "value": "0x…" }, { "name": "x2", "value": "0x…" }, { "name": "x3", "value": "0x0" }],
      "backtrace": [{ "symbol": "main", "module": "ReaCalls" }] },
    { "symbol": "rea_call_add", "registers": [{ "name": "x0", "value": "0x0" }, { "name": "x1", "value": "0x28" }] }
  ],
  "coverage": { "status": "complete", "event_limit_reached": false, "unresolved_breakpoints": [] }
}

CLI: rea observe-native-calls <app-or-mach-o> <input-json>. The input is the same object as the MCP arguments, inline or as a JSON file path.

Out of scope (rest of #385)

  • Frida;
  • return-value capture;
  • unified-log capture;
  • attaching to processes REA did not launch.

Verification

  • Real lane: npm run verify:native-calls passed on macOS 26 arm64 (lldb-2100.0.17.203). It compiles tests/conformance/native/calls.m and runs the tool through both the packaged CLI and stdio MCP. It checks:
    • the receiver class, selector and argument registers of all six entries;
    • breakpoint file addresses equal to nm's symbol addresses;
    • captured stdout and an environment override;
    • CLI and MCP parity;
    • the event-limit and duration-elapsed outcomes, with the process confirmed gone;
    • that a hardened-runtime copy is refused with debugger-attach-denied, while the same copy signed with get-task-allow is traced.
  • Boundary tests:
    • tests/boundary/providers/native/nativeCallObservation.test.ts (fake tracer) covers projection, partial coverage, input rejection before any launch, changed and non-Mach-O targets, passthrough of tracer failures, and cancellation.
    • tests/boundary/mcp/nativeCallObservationMcp.test.ts covers MCP routing and input-schema rejection; it runs on Linux too.
  • npm run check:changed: 295 files and 2,987 tests passed.
  • npm run docs:generate && npm run docs:check passed.
  • The contract, catalog and schema guards passed: contractPresentation, cliToolCoverage, productCatalog, toolSchemaValidity and conformancePackage.
  • npm pack --dry-run includes bridge/native/rea_lldb_tracer.py.

No Hopper, Ghidra or IDA code is touched, so I didn't run any real provider verification.

🤖 Generated with Claude Code

Add observe_native_calls (CLI: observe-native-calls <path> <input-json>). It
launches the active Mach-O as an owned process under `lldb --batch`, stops at
caller-selected functions or Objective-C methods, records each entry and
auto-continues:

- thread, image, symbol, load and file address;
- raw integer argument registers and optional caller frames;
- for methods, the selector read from _cmd and the receiver's dynamic class,
  from LLDB's runtime reader without running target code.

No expression is evaluated and no existing process is attached. The run ends
on exit, max_events or duration_ms; REA then kills the process and confirms
that it is gone. The result also carries exit status, bounded stdout/stderr,
breakpoint resolution with partial coverage for unresolved requests, and
limitations. A target LLDB may not debug fails with a debugger-attach-denied
reason and remediation.

verify:native-calls checks the tool through the CLI and stdio MCP against a
compiled fixture, compares breakpoint addresses with nm, exercises every
outcome, and checks hardened-runtime targets with and without get-task-allow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T05:05:13.175222Z 2a7dcb7 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.

@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: 9837203234

ℹ️ 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 on lines +181 to +185
count += breakpoint.GetNumLocations()
for position in range(breakpoint.GetNumLocations()):
if len(locations) < MAX_REPORTED_LOCATIONS:
locations.append(
_location(breakpoint.GetLocationAtIndex(position).GetAddress(), target)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Filter reported locations by requested method type

For a selector-only Objective-C request with method_type: "instance" or "class", the breakpoint matches both method kinds and _wanted filters only recorded events, while this report counts and returns every location. If only the opposite method kind implements the selector, the result therefore reports a nonzero location_count, omits the request from unresolved_breakpoints, and marks coverage complete even though no requested location exists; filter these locations by the same predicate or create type-specific breakpoints.

AGENTS.md reference: AGENTS.md:L52-L56

Useful? React with 👍 / 👎.

Comment on lines +85 to +87
const eventLimit = run.outcome === "event-limit";
const partial =
eventLimit || run.outcome === "stop-limit" || unresolved.length > 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Mark duration-bounded traces as partial

When a long-running target reaches duration_ms, it is killed while later calls may still have occurred, but partial remains false unless another condition also applies. This makes the structured coverage claim complete for a time-truncated experiment, unlike the equivalent max_events truncation; include duration-elapsed in the partial condition so consumers cannot mistake the bounded observation for exhaustive call coverage.

AGENTS.md reference: AGENTS.md:L81-L83

Useful? React with 👍 / 👎.

Comment on lines +89 to +94
target: {
path: target.path,
sha256: target.sha256,
architecture: target.architecture,
arguments: input.arguments,
working_directory: input.working_directory ?? null,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve caller-selected environment overrides

Whenever the caller supplies environment, those values affect the launched process and can determine the observed calls, but the result target records arguments and the working directory while dropping the environment entirely. Include the selected overrides in the result contract so saved evidence remains reproducible rather than losing a caller-selected experimental input.

AGENTS.md reference: AGENTS.md:L16-L16

Useful? React with 👍 / 👎.

Comment on lines +173 to +174
signal?.throwIfAborted();
const { bytesRead } = await handle.read(buffer, 0, buffer.length, null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Convert hash-time aborts into cancellation results

If cancellation arrives after execute's initial aborted check but while a large Mach-O is being hashed, throwIfAborted() rejects observeNativeCalls instead of returning the operation's tagged AnalysisCancelledError. Because this branch in NativeMacOSClient.execute has no catch, CLI/MCP callers receive a generic rejected/internal failure rather than the documented cancellation result; catch the abort around hashing and translate it consistently.

AGENTS.md reference: AGENTS.md:L58-L58

Useful? React with 👍 / 👎.

@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: a0f5e33bd8

ℹ️ 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 on lines +201 to +202
launch.AddOpenFileAction(1, config["stdout_path"], False, True)
launch.AddOpenFileAction(2, config["stderr_path"], False, True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bound the files used to capture target output

When the launched target continuously writes to stdout or stderr, these actions direct every byte to regular files until the duration or event limit is reached; the 1 MiB limit is applied only later by capturedOutput, so a ten-minute trace can exhaust the host filesystem. Capture through a bounded collector or enforce a write limit while preserving the byte count and truncation metadata.

AGENTS.md reference: AGENTS.md:L82-L82

Useful? React with 👍 / 👎.

for thread in process:
reason = thread.GetStopReason()
if reason == lldb.eStopReasonBreakpoint:
index = context["breakpoint_index"].get(thread.GetStopReasonDataAtIndex(0))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Process every breakpoint pair in the stop reason

When two requests resolve to the same address, such as duplicate function specifications or an Objective-C method also requested by its symbol name, LLDB reports multiple breakpoint/location ID pairs for the stop. Reading only element 0 attributes the hit to the first request, while another request can be reported as resolved yet never receive events; iterate over all pairs or associate the event with every matching request.

AGENTS.md reference: AGENTS.md:L54-L54

Useful? React with 👍 / 👎.

observe-native-calls now runs through composition/directAnalysis, where #965
moved runProviderAnalysis.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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: a11c6bd5e4

ℹ️ 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".

if (!parsed.success)
return err(new AnalysisInputError(OPERATION, { cause: parsed.error }));
// Observe the bytes the session's other Evidence describes.
if ((await fileSha256(target.path, signal)) !== target.sha256)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pin the verified target bytes before launching LLDB

If a rebuild or updater replaces the executable after this digest check but before tracer.trace opens target.path, LLDB observes the replacement while the result still reports the session's original SHA-256, silently binding events to the wrong artifact. Launch an immutable verified snapshot or otherwise revalidate the executable identity around the launch so observations cannot be attributed to stale evidence.

AGENTS.md reference: AGENTS.md:L16-L16

Useful? React with 👍 / 👎.

Follow #973's native ownership: the call-observation schemas move to
src/domain/native/, and the contract now lives in src/contracts/native/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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: 90b25f2e30

ℹ️ 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".

.number()
.int()
.min(1)
.max(100_000)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bound the aggregate trace payload

With the accepted combination max_events: 100000 and backtrace_frames: 64, a deep-stack target can produce 6.4 million location records in addition to the events themselves. The bridge retains all of these objects in events, serializes the entire array, and Node reads it back in one operation, so a valid request can exhaust the LLDB or MCP process before returning; enforce an aggregate byte/record budget or stream the trace rather than independently allowing both maxima.

AGENTS.md reference: AGENTS.md:L82-L82

Useful? React with 👍 / 👎.

Resolve conflicts against main:
- package.json: ship both the LLDB tracer bridge and main's process run
  token reader sources.
- README.md: take main's simplified English README, which no longer has
  the tool-family table.
- README_ja.md: take main's reworded table and count
  observe_native_calls in the macOS native row (7 -> 8).
- Skill: the references gain the observe_native_calls paragraph, so the
  version moves to 29 (main already uses 28).
- Regenerate the product catalog, conformance manifest, skill digest and
  package metadata (135 tools). The MCP tool catalog is now built rather
  than committed (#997), so it is removed here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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: 2a7dcb77c1

ℹ️ 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 on lines +365 to +367
if (attempt === 10 && (await commandOf(pid)) === executable)
try {
process.kill(pid, "SIGKILL");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Verify PID identity before killing a survivor

If the launched program exits and macOS reuses its PID for a new invocation of the same executable during this polling loop, commandOf only compares its path, so attempt 10 sends SIGKILL to that unrelated process. Record and verify a launch-unique identity (such as the process start time) before signaling, or leave an unverified PID alone.

AGENTS.md reference: AGENTS.md:L89-L91

Useful? React with 👍 / 👎.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit 1d13cef into main Oct 8, 2026
28 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the feat/native-call-observation branch October 8, 2026 05:57
kaoru0822-kitauji added a commit that referenced this pull request Oct 8, 2026
main now carries #964 at skill version 29, so this branch moves to 30.
Regenerate the product catalog, conformance manifest, skill digest and
package metadata on top of it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kaoru0822-kitauji added a commit that referenced this pull request Oct 8, 2026
main now carries #964 at skill version 29, so this branch moves to 30.
Regenerate the product catalog, conformance manifest, skill digest and
package metadata on top of it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kaoru0822-kitauji added a commit that referenced this pull request Oct 8, 2026
main now carries #964 (skill version 29, macOS native row 7 -> 8):
- README_ja/ar/ko/zh: take main's tables and count
  trace_dylib_resolution in the artifact graph row (5 -> 6).
- Skill: move to version 30.
- Regenerate the product catalog, conformance manifest, skill digest and
  package metadata (136 tools).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kaoru0822-kitauji added a commit that referenced this pull request Oct 8, 2026
Bring in #927's merge of main (#964 at skill version 29):
- README_ja/ar/ko/zh: keep the merged tables and count
  inspect_dyld_shared_cache in application workflows (13 -> 14).
- Skill: #927 now uses version 30, so this branch moves to 31.
- Regenerate the product catalog, conformance manifest, skill digest and
  package metadata (137 tools).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
feat(native): observe function and Objective-C method calls under LLDB
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
main now carries morluto#964 (skill version 29, macOS native row 7 -> 8):
- README_ja/ar/ko/zh: take main's tables and count
  trace_dylib_resolution in the artifact graph row (5 -> 6).
- Skill: move to version 30.
- Regenerate the product catalog, conformance manifest, skill digest and
  package metadata (136 tools).
@morluto morluto added enhancement New feature or request area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
Iyanuoluwa007 pushed a commit to Iyanuoluwa007/rea that referenced this pull request Oct 21, 2026
Bring in morluto#927's merge of main (morluto#964 at skill version 29):
- README_ja/ar/ko/zh: keep the merged tables and count
  inspect_dyld_shared_cache in application workflows (13 -> 14).
- Skill: morluto#927 now uses version 30, so this branch moves to 31.
- Regenerate the product catalog, conformance manifest, skill digest and
  package metadata (137 tools).
Iyanuoluwa007 pushed a commit to Iyanuoluwa007/rea that referenced this pull request Oct 21, 2026
main now carries morluto#964 at skill version 29, so this branch moves to 30.
Regenerate the product catalog, conformance manifest, skill digest and
package metadata on top of it.
Iyanuoluwa007 pushed a commit to Iyanuoluwa007/rea that referenced this pull request Oct 21, 2026
main now carries morluto#964 at skill version 29, so this branch moves to 30.
Regenerate the product catalog, conformance manifest, skill digest and
package metadata on top of it.
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.

2 participants