Skip to content

[PLAT-16992] Incorrect-stack-trace-on-iOS - #1947

Open
SB-meiyalaganr wants to merge 3 commits into
meiy/Feature/plat-16992-Incorrect-Stack-Trace-On-iOSfrom
meiy/plat-16992-Incorrect-stack-trace-on-iOS
Open

SB-meiyalaganr wants to merge 3 commits into
meiy/Feature/plat-16992-Incorrect-Stack-Trace-On-iOSfrom
meiy/plat-16992-Incorrect-stack-trace-on-iOS

Conversation

@SB-meiyalaganr

Copy link
Copy Markdown
Contributor

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.

@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

Bugsnag.framework binary size increased by 184 bytes from 920,592 to 920,776

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [ = ]       0  [NEW]    +248    __DATA,__thread_bss
  +4.7%    +160  +4.7%    +160    [Mach-O Headers]
  +0.1%    +104  +0.1%    +104    String Table
  +0.0%     +48  +0.0%     +48    Symbol Table
  +1.0%     +32  +1.0%     +32    Binding Info
  [NEW]     +24  [NEW]     +24    __DATA,__thread_vars
  +0.0%     +16  +0.0%     +16    __TEXT,__text
  +0.2%      +8  +0.2%      +8    __TEXT,__unwind_info
  -2.5%     -24  -0.3%     -24    [__DATA]
  [ = ]       0  -1.4%    -184    [__LINKEDIT]
  -0.6%    -184  -0.6%    -184    [__TEXT]
  [ = ]       0  -2.5%    -248    __DATA,__bss
  +0.0%    +184  [ = ]       0    TOTAL

Generated by 🚫 Danger

Copilot AI 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.

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.

Comment thread Tests/KSCrashTests/KSCrashSentry_CPPException_Tests.mm
@SB-meiyalaganr
SB-meiyalaganr marked this pull request as ready for review September 1, 2026 18:11
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.

3 participants