Repository navigation
feat(native): observe function and Objective-C method calls under LLDB - #964
Conversation
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]>
Codex Review SummaryThis 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. |
There was a problem hiding this comment.
💡 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".
| count += breakpoint.GetNumLocations() | ||
| for position in range(breakpoint.GetNumLocations()): | ||
| if len(locations) < MAX_REPORTED_LOCATIONS: | ||
| locations.append( | ||
| _location(breakpoint.GetLocationAtIndex(position).GetAddress(), target) |
There was a problem hiding this comment.
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 👍 / 👎.
| const eventLimit = run.outcome === "event-limit"; | ||
| const partial = | ||
| eventLimit || run.outcome === "stop-limit" || unresolved.length > 0; |
There was a problem hiding this comment.
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 👍 / 👎.
| target: { | ||
| path: target.path, | ||
| sha256: target.sha256, | ||
| architecture: target.architecture, | ||
| arguments: input.arguments, | ||
| working_directory: input.working_directory ?? null, |
There was a problem hiding this comment.
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 👍 / 👎.
| signal?.throwIfAborted(); | ||
| const { bytesRead } = await handle.read(buffer, 0, buffer.length, null); |
There was a problem hiding this comment.
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 👍 / 👎.
…rvation # Conflicts: # package.json
There was a problem hiding this comment.
💡 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".
| launch.AddOpenFileAction(1, config["stdout_path"], False, True) | ||
| launch.AddOpenFileAction(2, config["stderr_path"], False, True) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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]>
There was a problem hiding this comment.
💡 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) |
There was a problem hiding this comment.
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]>
There was a problem hiding this comment.
💡 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) |
There was a problem hiding this comment.
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]>
There was a problem hiding this comment.
💡 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".
| if (attempt === 10 && (await commandOf(pid)) === executable) | ||
| try { | ||
| process.kill(pid, "SIGKILL"); |
There was a problem hiding this comment.
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 👍 / 👎.
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]>
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]>
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]>
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]>
feat(native): observe function and Objective-C method calls under LLDB
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).
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).
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.
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.
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 bridgebridge/native/rea_lldb_tracer.py. It stops at caller-selected entries, records them and continues automatically:Recorded per entry (observed):
_cmdand 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:
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:
max_events, orduration_ms. The last two are resource-safety bounds, and each is explained in limitations.Results:
location_count;objc_directcalls are not observed, ASLR is disabled by LLDB, and the duration is checked about once a second.Failures keep their reason:
capability_unavailable;capability_unavailablewith reasondebugger-attach-denied: …and remediation (Developer Tools access, orget-task-allowfor hardened-runtime targets; seeinspect_signature's debugger-attach facet);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)
Verification
npm run verify:native-callspassed on macOS 26 arm64 (lldb-2100.0.17.203). It compilestests/conformance/native/calls.mand runs the tool through both the packaged CLI and stdio MCP. It checks:nm's symbol addresses;event-limitandduration-elapsedoutcomes, with the process confirmed gone;debugger-attach-denied, while the same copy signed withget-task-allowis traced.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.tscovers 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:checkpassed.contractPresentation,cliToolCoverage,productCatalog,toolSchemaValidityandconformancePackage.npm pack --dry-runincludesbridge/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