Skip to content

fix(ios): send debug images with native exception frames so Sentry symbolicates them - #36

Merged
farfromrefug merged 2 commits into
masterfrom
fix/ios-native-exception-debug-images
Nov 20, 2026
Merged

farfromrefug merged 2 commits into
masterfrom
fix/ios-native-exception-debug-images

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What

The NativeException integration chains the native throw-site stack of a JS error that carries a nativeException (an NSException raised under a JS call). On iOS it now:

  • reads callStackReturnAddresses alongside callStackSymbols (both index-aligned, newest frame first);
  • looks up each address in sentry-cocoa's binary image cache (SentryDependencies.binaryImageCache.imageByAddress) and sets image_addr and package on the frame;
  • adds one macho debug image (debug_id, image_addr, image_size, code_file) per binary to event.debug_meta.images, skipping images already listed;
  • marks the stack trace with instruction_addr_adjustment: "all", since every address in callStackReturnAddresses is a return address, the newest frame included;
  • splits each device name (__exceptionPreprocess + 172) into function and symbol_addr. Sentry trims function to a bare symbol name, so sending the combined string showed only the offset (172) on frames it couldn't symbolicate.

The names parsed from callStackSymbols stay on each frame as a fallback for when the image cache is empty (native SDK not started) or no dSYM was uploaded.

Why

These frames were resolved on the device only. Without debug_meta images, Sentry can't match the addresses to any dSYM, so the event shows whatever dladdr returned on the device:

  • App code: Release archives strip the app executable (STRIP_STYLE = all), so app frames in this stack show the image name plus an offset (MyApp + 16788).
  • System libraries: on a device, system frames arrive as an image UUID plus an offset (D79F14D9-F948-… + 620780 for CoreFoundation).
  • NativeScript runtime: perf: strip local symbols from the release framework, log decodable native backtraces NativeScript/ios#556 strips the runtime's local symbols in release builds (−2.7 MB per app). Frames in V8 and runtime internals then show the nearest exported name (e.g. v8::CppHeap::CollectGarbageInYoungGenerationForTesting + 1132812 for v8::internal::Execution::Call). That PR's docs call this out: raw addresses need their image list to be resolvable.

With the image list, Sentry resolves these frames server-side, the same way it already does for native crashes captured by SentryCrash. Apps need the runtime's NativeScript.framework.dSYM uploaded next to their own. When the runtime comes from the SwiftPM xcframework, Xcode copies that dSYM next to the app's own dSYM, so uploading the build's dSYMs covers it.

This mirrors what @sentry/react-native does in RNSentry+fetchNativeStack.m (image cache lookup, then debug images). SentryInternalDebugApi would be the cleaner entry point, but it is a Swift struct and not reachable from JS. SentryDependencies and SentryBinaryImageCache are @objc and appear in the NativeScript metadata generated for sentry-cocoa 9.19.1. SentryDependencyContainer.binaryImageCache defaults to that same instance, so it is the cache the SDK starts.

Testing

End to end, as an A/B: plugin 5.0.0 against this branch. The test app is a scratch NativeScript app that throws an NSException from a JS→native call (objectAtIndex past the end of an NSArray), catches it in JS and calls captureException. The runtime is the CI build of NativeScript/ios#556 (local symbols stripped). dSYMs and sourcemaps were uploaded before each run, and results were read from the raw event JSON.

iPad Pro, iOS 27.2.1, release device build (app executable and runtime both stripped):

Frame 5.0.0 This branch
CoreFoundation throw site D79F14D9-F948-… + 1905360 __boundsFail
NSArray D79F14D9-… + 540584 -[__NSArrayI objectAtIndex:]
V8 call v8::CppHeap::CollectGarbageInYoungGenerationForTesting + 1034724 v8::internal::Execution::Call
Runtime timer _register_isolate_timers + 792 tns::TimerState::RunIfEarliest (Timers.cpp:220)
App sentrysym + 16788 main (main.m:62)

With 5.0.0 every native frame is unknown_image. With this branch all 43 frames are symbolicated: system frames by Sentry's iOS symbol server, the runtime and the app from their dSYMs. debug_meta carries the device's image UUIDs, and there are no processing errors.

iOS 26.3 simulator, release build: same result for the runtime and app frames. System frames stay unsymbolicated there (Sentry has no simulator system symbols) and fall back to the device names, which the symbol_addr change keeps readable.

Other checks:

  • atos against the runtime's dSYM gives the same names and lines as Sentry. With instruction_addr_adjustment: "all" they are call-site lines; unadjusted return addresses would give the line after the call (Interop.mm:1887 instead of :1844).
  • The package's tsc reports no new diagnostics; Prettier clean.

…mbolicates them

The throw-site stack chained from `nativeException` was built from
`callStackSymbols` only: names resolved on the device and no `debug_meta`
images, so Sentry could not symbolicate those frames against dSYMs. Release
app executables are fully stripped, so their frames already showed wrong or
missing names, and NativeScript runtimes that strip local symbols
(NativeScript/ios#556) do the same for the runtime's internal functions.

* Read `callStackReturnAddresses` alongside `callStackSymbols` and attach
  `image_addr`/`package` from sentry-cocoa's binary image cache to each frame.
* Add one `macho` debug image per binary to `event.debug_meta.images`.
* Mark the stack with `instruction_addr_adjustment: all`, since every
  address is a return address.
* Keep the device names as the fallback when the image cache is empty
  (native SDK not started) or no dSYM is uploaded.
@edusperoni
edusperoni marked this pull request as ready for review November 11, 2026 21:36
@farfromrefug

Copy link
Copy Markdown
Member

@edusperoni did you actually test this? the Pr says it was not tested

`callStackSymbols` lines end in "symbol + offset". Sentry trims a frame's
`function` to a bare symbol name, so frames it could not symbolicate showed
only the offset ("172" instead of "__exceptionPreprocess").

* Split the device name into `function` and `symbol_addr` (the line's own
  address minus the offset).
@edusperoni

edusperoni commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@farfromrefug It's tested now, end to end, on the simulator and on an iPad. I used a scratch NativeScript iOS app with the runtime from NativeScript/ios#556's CI build of 80e868332 (local symbols stripped). Plugin 5.0.0 was the control and this branch was the change. The app throws an NSException from a JS→native call, catches it in JS and calls captureException. dSYMs and sourcemaps were uploaded first.

iPad Pro, iOS 27.2.1, release device build (app executable and runtime both stripped):

Frame 5.0.0 This branch
CoreFoundation throw site D79F14D9-F948-… + 1905360 __boundsFail
V8 call v8::CppHeap::CollectGarbageInYoungGenerationForTesting + 1034724 v8::internal::Execution::Call
Runtime timer _register_isolate_timers + 792 tns::TimerState::RunIfEarliest (Timers.cpp:220)
App sentrysym + 16788 main (main.m:62)
  • 5.0.0: every native frame is unknown_image. System frames have no names at all on a device, and the runtime internals get wrong ones.
  • This branch: all 43 frames are symbolicated: system frames by Sentry's iOS symbol server, the runtime and the app from their dSYMs. debug_meta carries the device's image UUIDs, there are no processing errors, and atos against the dSYM gives the same names and lines.

The simulator gave the same result for the runtime and app frames.

The test also caught an existing bug, which I fixed in cf935ef: frames Sentry can't symbolicate showed only the offset (172 instead of __exceptionPreprocess), because we sent "name + offset" as the function name.

@farfromrefug
farfromrefug merged commit 6e25447 into master Nov 20, 2026
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