[PLAT-16992] Incorrect-stack-trace-on-iOS - #1947
Open
SB-meiyalaganr wants to merge 3 commits into
Open
SB-meiyalaganr wants to merge 3 commits into
SB-meiyalaganr wants to merge 3 commits into
Conversation
|
Generated by 🚫 Danger |
There was a problem hiding this comment.
Pull request overview
This PR addresses incorrect stack traces for C++ exceptions on iOS by eliminating process-global exception backtrace state and improving frame skipping and fallback capture behavior, including new automated coverage for concurrent/rethrow/inspection cases.
Changes:
- Made C++ exception capture state thread-local and gated capture via an atomic “installed” flag to avoid cross-thread overwrites.
- Adjusted stack trace frame skipping and added a safer fallback backtrace capture path (e.g., bare terminate / uncaptured throws).
- Expanded automated validation via new unit tests and additional Maze Runner scenarios/features for concurrency/rethrow/inspection behaviors.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/KSCrashTests/KSCrashSentry_CPPException_Tests.mm | Adds unit tests for thread-local state isolation and stack-trace “view” frame skipping. |
| features/release/unhandled_cpp_exception.feature | Extends acceptance checks to assert correct top frame and adds scenario outlines for concurrency/rethrow/inspection/bare-throw cases. |
| features/fixtures/shared/scenarios/CxxExceptionScenario.mm | Adds new fixture scenarios to deterministically reproduce concurrent throw/reraise/inspection behaviors. |
| features/fixtures/shared/scenarios/CxxBareThrowScenario.mm | Adds a scenario to ensure a previously caught exception doesn’t supply a later bare-throw stack trace. |
| Bugsnag/KSCrash/Source/KSCrash/Recording/Sentry/BSG_KSCrashSentry_CPPException.mm | Converts backtrace state to thread_local, gates capture on an atomic install flag, and updates frame skipping + fallback capture logic. |
| Bugsnag/KSCrash/Source/KSCrash/Recording/Sentry/BSG_KSCrashSentry_CPPException_Private.h | Introduces a private header encapsulating a thread-local state struct and stack-trace view helper. |
| Bugsnag.xcodeproj/project.pbxproj | Wires the new unit test file and private header into the Xcode project. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
SB-jigneshR
approved these changes
Aug 31, 2026
SB-meiyalaganr
marked this pull request as ready for review
September 1, 2026 18:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Fix incorrect stack traces for C++ exceptions on iOS — ensuring the original throw site is preserved across concurrent throws, rethrows, and exception inspection.
Design
Make stack trace state thread_local and gate capture on an atomic install flag, eliminating the process-global race condition that caused wrong traces.
Changeset
Converted bsg_g_stackTrace, bsg_g_stackTraceCount, and bsg_g_captureNextStackTrace to thread_local; switched bsg_g_installed to std::atomic; extracted thread state into a reusable private header; added new concurrent/rethrow/inspect scenarios.
Testing
New KSCrashSentry_CPPException_Tests unit tests verify thread isolation and frame-skipping logic; new Maze Runner scenarios cover concurrent, background-thread, rethrow, bare-throw-after-catch, and exception-inspecting cases.