Skip to content

Commit e102ea7

Browse files
Merge e9a42a7 into e5c0f86
2 parents e5c0f86 + e9a42a7 commit e102ea7

20 files changed

+1755
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Capturing fatal CPPExceptions via hooking into cxa_throw when enabling `options.experimental.enableUnhandledCPPExceptionsV2 = true` (#5256)
8+
59
### Improvements
610

711
- Threading issues in internal dependency container (#5225)

Samples/SentrySampleShared/SentrySampleShared/SentrySDKWrapper.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public struct SentrySDKWrapper {
130130

131131
// Experimental features
132132
options.experimental.enableFileManagerSwizzling = !SentrySDKOverrides.Other.disableFileManagerSwizzling.boolValue
133+
options.experimental.enableUnhandledCPPExceptionsV2 = true
133134
}
134135

135136
func configureInitialScope(scope: Scope) -> Scope {

Sentry.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
620467AC2D3FFD230025F06C /* SentryNSErrorCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 620467AB2D3FFD1C0025F06C /* SentryNSErrorCodable.swift */; };
8686
6205B4A42CE73AA100744684 /* TestDebugImageProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85790282976A69F00C6AC1F /* TestDebugImageProvider.swift */; };
8787
6205CF262D549D8A001E6049 /* SentryDateCodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6205CF252D549D8A001E6049 /* SentryDateCodableTests.swift */; };
88+
621655662DB12A8900810504 /* SentryCrashMach-OTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 621655652DB12A8900810504 /* SentryCrashMach-OTests.m */; };
8889
621AE74B2C626C230012E730 /* SentryANRTrackerV2.h in Headers */ = {isa = PBXBuildFile; fileRef = 621AE74A2C626C230012E730 /* SentryANRTrackerV2.h */; };
8990
621AE74D2C626C510012E730 /* SentryANRTrackerV2.m in Sources */ = {isa = PBXBuildFile; fileRef = 621AE74C2C626C510012E730 /* SentryANRTrackerV2.m */; };
9091
621D22012DBB7E09006F9C48 /* SentryANRTrackerV1IntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 621D22002DBB7E09006F9C48 /* SentryANRTrackerV1IntegrationTests.swift */; };
@@ -113,9 +114,14 @@
113114
62862B1E2B1DDC35009B16E3 /* SentryDelayedFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 62862B1D2B1DDC35009B16E3 /* SentryDelayedFrame.m */; };
114115
62872B632BA1B86100A4FA7D /* NSLockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62872B622BA1B86100A4FA7D /* NSLockTests.swift */; };
115116
62885DA729E946B100554F38 /* TestConncurrentModifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62885DA629E946B100554F38 /* TestConncurrentModifications.swift */; };
117+
628B45342DB8D5E700934391 /* SentryCrashCxaThrowSwapper_Tests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 628B45332DB8D5E700934391 /* SentryCrashCxaThrowSwapper_Tests.mm */; };
116118
628B89022D841D7F004B6F2A /* SentryDateUtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 628B89012D841D7F004B6F2A /* SentryDateUtilsTests.swift */; };
117119
629194A92D51F976000F7C6B /* SentryDebugMetaCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 629194A82D51F976000F7C6B /* SentryDebugMetaCodable.swift */; };
118120
629258552DAF91940049388F /* SentryCrashStackCursorSelfThreadTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 629258542DAF91940049388F /* SentryCrashStackCursorSelfThreadTests.swift */; };
121+
629258592DAFA57F0049388F /* SentryCrashCxaThrowSwapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 629258582DAFA57F0049388F /* SentryCrashCxaThrowSwapper.h */; };
122+
6292585B2DAFA5F70049388F /* SentryCrashCxaThrowSwapper.c in Sources */ = {isa = PBXBuildFile; fileRef = 6292585A2DAFA5F70049388F /* SentryCrashCxaThrowSwapper.c */; };
123+
6292585E2DAFA8290049388F /* SentryCrashMach-O.h in Headers */ = {isa = PBXBuildFile; fileRef = 6292585C2DAFA8290049388F /* SentryCrashMach-O.h */; };
124+
6292585F2DAFA8290049388F /* SentryCrashMach-O.c in Sources */ = {isa = PBXBuildFile; fileRef = 6292585D2DAFA8290049388F /* SentryCrashMach-O.c */; };
119125
6293F5752D422A95002BC3BD /* SentryStacktraceCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6293F5742D422A8A002BC3BD /* SentryStacktraceCodable.swift */; };
120126
62950F1029E7FE0100A42624 /* SentryTransactionContextTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62950F0F29E7FE0100A42624 /* SentryTransactionContextTests.swift */; };
121127
629690532AD3E060000185FA /* SentryReachabilitySwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 629690522AD3E060000185FA /* SentryReachabilitySwiftTests.swift */; };
@@ -1186,6 +1192,7 @@
11861192
620379DC2AFE1432005AC0C1 /* SentryBuildAppStartSpans.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryBuildAppStartSpans.m; sourceTree = "<group>"; };
11871193
620467AB2D3FFD1C0025F06C /* SentryNSErrorCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSErrorCodable.swift; sourceTree = "<group>"; };
11881194
6205CF252D549D8A001E6049 /* SentryDateCodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDateCodableTests.swift; sourceTree = "<group>"; };
1195+
621655652DB12A8900810504 /* SentryCrashMach-OTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "SentryCrashMach-OTests.m"; sourceTree = "<group>"; };
11891196
621AE74A2C626C230012E730 /* SentryANRTrackerV2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryANRTrackerV2.h; path = include/SentryANRTrackerV2.h; sourceTree = "<group>"; };
11901197
621AE74C2C626C510012E730 /* SentryANRTrackerV2.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryANRTrackerV2.m; sourceTree = "<group>"; };
11911198
621AE74E2C626CF70012E730 /* SentryANRTrackerV2Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryANRTrackerV2Tests.swift; sourceTree = "<group>"; };
@@ -1216,9 +1223,14 @@
12161223
62862B1D2B1DDC35009B16E3 /* SentryDelayedFrame.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryDelayedFrame.m; sourceTree = "<group>"; };
12171224
62872B622BA1B86100A4FA7D /* NSLockTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSLockTests.swift; sourceTree = "<group>"; };
12181225
62885DA629E946B100554F38 /* TestConncurrentModifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestConncurrentModifications.swift; sourceTree = "<group>"; };
1226+
628B45332DB8D5E700934391 /* SentryCrashCxaThrowSwapper_Tests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = SentryCrashCxaThrowSwapper_Tests.mm; sourceTree = "<group>"; };
12191227
628B89012D841D7F004B6F2A /* SentryDateUtilsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDateUtilsTests.swift; sourceTree = "<group>"; };
12201228
629194A82D51F976000F7C6B /* SentryDebugMetaCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDebugMetaCodable.swift; sourceTree = "<group>"; };
12211229
629258542DAF91940049388F /* SentryCrashStackCursorSelfThreadTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashStackCursorSelfThreadTests.swift; sourceTree = "<group>"; };
1230+
629258582DAFA57F0049388F /* SentryCrashCxaThrowSwapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryCrashCxaThrowSwapper.h; sourceTree = "<group>"; };
1231+
6292585A2DAFA5F70049388F /* SentryCrashCxaThrowSwapper.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = SentryCrashCxaThrowSwapper.c; sourceTree = "<group>"; };
1232+
6292585C2DAFA8290049388F /* SentryCrashMach-O.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryCrashMach-O.h"; sourceTree = "<group>"; };
1233+
6292585D2DAFA8290049388F /* SentryCrashMach-O.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = "SentryCrashMach-O.c"; sourceTree = "<group>"; };
12221234
6293F5742D422A8A002BC3BD /* SentryStacktraceCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryStacktraceCodable.swift; sourceTree = "<group>"; };
12231235
62950F0F29E7FE0100A42624 /* SentryTransactionContextTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTransactionContextTests.swift; sourceTree = "<group>"; };
12241236
629690522AD3E060000185FA /* SentryReachabilitySwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryReachabilitySwiftTests.swift; sourceTree = "<group>"; };
@@ -3002,6 +3014,10 @@
30023014
7B883F48253D714C00879E62 /* SentryCrashUUIDConversion.c */,
30033015
71F11CDEF5952DF5CC69AC74 /* SentryCrashUUIDConversion.h */,
30043016
7B31C290277B04A000337126 /* SentryCrashPlatformSpecificDefines.h */,
3017+
629258582DAFA57F0049388F /* SentryCrashCxaThrowSwapper.h */,
3018+
6292585A2DAFA5F70049388F /* SentryCrashCxaThrowSwapper.c */,
3019+
6292585C2DAFA8290049388F /* SentryCrashMach-O.h */,
3020+
6292585D2DAFA8290049388F /* SentryCrashMach-O.c */,
30053021
);
30063022
path = Tools;
30073023
sourceTree = "<group>";
@@ -3070,6 +3086,8 @@
30703086
0ADC33EF28D9BE690078D980 /* TestSentryUIDeviceWrapper.swift */,
30713087
7B984A9E28E572AF001F4BEE /* CrashReport.swift */,
30723088
7BF69E062987D1FE002EBCA4 /* SentryCrashDoctorTests.swift */,
3089+
621655652DB12A8900810504 /* SentryCrashMach-OTests.m */,
3090+
628B45332DB8D5E700934391 /* SentryCrashCxaThrowSwapper_Tests.mm */,
30733091
629258542DAF91940049388F /* SentryCrashStackCursorSelfThreadTests.swift */,
30743092
);
30753093
path = SentryCrash;
@@ -4515,6 +4533,7 @@
45154533
7BFC169B2524995700FF6266 /* SentryMessage.h in Headers */,
45164534
7B18DE4028D9F748004845C6 /* SentryNSNotificationCenterWrapper.h in Headers */,
45174535
03F84D1E27DD414C008FE43F /* SentryBacktrace.hpp in Headers */,
4536+
629258592DAFA57F0049388F /* SentryCrashCxaThrowSwapper.h in Headers */,
45184537
63AA76991EB9C1C200D153DE /* SentryDefines.h in Headers */,
45194538
D86B6835294348A400B8B1FC /* SentryAttachment+Private.h in Headers */,
45204539
84AF45A629A7FFA500FBB177 /* SentryProfiledTracerConcurrency.h in Headers */,
@@ -4707,6 +4726,7 @@
47074726
62A456E32B0370AA003F19A1 /* SentryUIEventTrackerTransactionMode.h in Headers */,
47084727
63FE714B20DA4C1100CDBAE8 /* SentryCrashString.h in Headers */,
47094728
7BCFBD6D2681D0A900BC27D8 /* SentryCrashScopeObserver.h in Headers */,
4729+
6292585E2DAFA8290049388F /* SentryCrashMach-O.h in Headers */,
47104730
63FE715320DA4C1100CDBAE8 /* SentryCrashObjCApple.h in Headers */,
47114731
63FE710120DA4C1000CDBAE8 /* SentryCrashDate.h in Headers */,
47124732
7B4E24FC251C97B500060D68 /* SentrySession.h in Headers */,
@@ -5060,6 +5080,7 @@
50605080
62C97D3A2CC64E6B00DDA204 /* SentryUncaughtNSExceptions.m in Sources */,
50615081
03F84D3727DD4191008FE43F /* SentrySamplingProfiler.cpp in Sources */,
50625082
8453421628BE8A9500C22EEC /* SentrySpanStatus.m in Sources */,
5083+
6292585B2DAFA5F70049388F /* SentryCrashCxaThrowSwapper.c in Sources */,
50635084
7B08A3472924CF9C0059603A /* SentryMetricKitIntegration.m in Sources */,
50645085
623FD9022D3FA5E000803EDA /* SentryFrameCodable.swift in Sources */,
50655086
62BDDD122D51FD540024CCD1 /* SentryThreadCodable.swift in Sources */,
@@ -5361,6 +5382,7 @@
53615382
D820CDB72BB1895F00BA339D /* SentrySessionReplayIntegration.m in Sources */,
53625383
632F43521F581D5400A18A36 /* SentryCrashExceptionApplication.m in Sources */,
53635384
620379DD2AFE1432005AC0C1 /* SentryBuildAppStartSpans.m in Sources */,
5385+
6292585F2DAFA8290049388F /* SentryCrashMach-O.c in Sources */,
53645386
7B77BE3727EC8460003C9020 /* SentryDiscardReasonMapper.m in Sources */,
53655387
63FE712520DA4C1000CDBAE8 /* SentryCrashSignalInfo.c in Sources */,
53665388
63FE70F320DA4C1000CDBAE8 /* SentryCrashMonitor_Signal.c in Sources */,
@@ -5375,6 +5397,7 @@
53755397
8ED3D306264DFE700049393B /* SwiftDescriptorTests.swift in Sources */,
53765398
7BFC16AD2524BCE700FF6266 /* SentryMessageTests.swift in Sources */,
53775399
7BF6505F292B77EC00BBA5A8 /* SentryMetricKitIntegrationTests.swift in Sources */,
5400+
628B45342DB8D5E700934391 /* SentryCrashCxaThrowSwapper_Tests.mm in Sources */,
53785401
629690532AD3E060000185FA /* SentryReachabilitySwiftTests.swift in Sources */,
53795402
7BA61CC6247CFC5F00C130A8 /* SentryCrashDefaultBinaryImageProviderTests.swift in Sources */,
53805403
7BBC827925DFD7D7005F1ED8 /* SentryInAppLogicTests.swift in Sources */,
@@ -5430,6 +5453,7 @@
54305453
D8FFE50C2703DBB400607131 /* SwizzlingCallTests.swift in Sources */,
54315454
7BFAA6E7297AA16A00E7E02E /* SentryCrashMonitor_CppException_Tests.mm in Sources */,
54325455
9286059929A50BAB00F96038 /* SentryGeoTests.swift in Sources */,
5456+
621655662DB12A8900810504 /* SentryCrashMach-OTests.m in Sources */,
54335457
D8B76B0828081461000A58C4 /* TestSentryScreenShot.swift in Sources */,
54345458
A8AFFCD22907DA7600967CD7 /* SentryHttpStatusCodeRangeTests.swift in Sources */,
54355459
7BE2C7F8257000A4003B66C7 /* SentryTestIntegration.m in Sources */,

Sources/Sentry/SentryCrashIntegration.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#import "SentryCrashC.h"
55
#import "SentryCrashIntegrationSessionHandler.h"
6+
#import "SentryCrashMonitor_CPPException.h"
67
#include "SentryCrashMonitor_Signal.h"
78
#import "SentryCrashWrapper.h"
89
#import "SentryDispatchQueueWrapper.h"
@@ -13,6 +14,7 @@
1314
#import "SentrySDK+Private.h"
1415
#import "SentryScope+Private.h"
1516
#import "SentrySpan+Private.h"
17+
#import "SentrySwift.h"
1618
#import "SentryTracer.h"
1719
#import "SentryWatchdogTerminationLogic.h"
1820
#import <SentryAppStateManager.h>
@@ -119,7 +121,8 @@ - (BOOL)installWithOptions:(nonnull SentryOptions *)options
119121

120122
[self startCrashHandler:options.cacheDirectoryPath
121123
enableSigtermReporting:enableSigtermReporting
122-
enableReportingUncaughtExceptions:enableUncaughtNSExceptionReporting];
124+
enableReportingUncaughtExceptions:enableUncaughtNSExceptionReporting
125+
enableCppExceptionsV2:options.experimental.enableUnhandledCPPExceptionsV2];
123126

124127
[self configureScope];
125128

@@ -138,6 +141,7 @@ - (SentryIntegrationOption)integrationOptions
138141
- (void)startCrashHandler:(NSString *)cacheDirectory
139142
enableSigtermReporting:(BOOL)enableSigtermReporting
140143
enableReportingUncaughtExceptions:(BOOL)enableReportingUncaughtExceptions
144+
enableCppExceptionsV2:(BOOL)enableCppExceptionsV2
141145
{
142146
void (^block)(void) = ^{
143147
BOOL canSendReports = NO;
@@ -165,6 +169,10 @@ - (void)startCrashHandler:(NSString *)cacheDirectory
165169
}
166170
#endif // TARGET_OS_OSX
167171

172+
if (enableCppExceptionsV2) {
173+
sentrycrashcm_cppexception_enable_swap_cxa_throw();
174+
}
175+
168176
// We need to send the crashed event together with the crashed session in the same envelope
169177
// to have proper statistics in release health. To achieve this we need both synchronously
170178
// in the hub. The crashed event is converted from a SentryCrashReport to an event in

Sources/Sentry/include/SentryCompiler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@
237237
#define NEVER_INLINE
238238
#endif
239239

240+
/* KEEP_FUNCTION_IN_STACKTRACE */
241+
#define KEEP_FUNCTION_IN_STACKTRACE __attribute__((disable_tail_calls))
242+
243+
#define THWART_TAIL_CALL_OPTIMISATION __asm__ __volatile__("");
244+
240245
/* NO_RETURN */
241246

242247
#if !defined(NO_RETURN) && COMPILER(GCC_COMPATIBLE)

0 commit comments

Comments
 (0)