Skip to content

Commit d73e036

Browse files
jpnurmiclaude
andcommitted
fix(ios): preload Cocoa crash handlers for managed runtime interop
- Build sentry-cocoa with SENTRY_CRASH_MANAGED_RUNTIME to preload signal handlers and exclude EXC_BAD_ACCESS/EXC_ARITHMETIC from Mach monitoring - Call PrivateSentrySDKOnly.IgnoreNextSignal(SIGABRT) from MarshalManagedException to prevent duplicate native crash events - Update iOS integration tests to expect no duplicate events (#3954) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c92e06f commit d73e036

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

integration-test/ios.Tests.ps1

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ Describe 'iOS app (<tfm>, <configuration>)' -ForEach @(
9999

100100
$result.HasErrors() | Should -BeFalse
101101
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.ApplicationException`""
102-
# TODO: fix redundant SIGABRT (#3954)
103-
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGABRT`"" } | Should -Throw
104-
{ $result.Envelopes() | Should -HaveCount 1 } | Should -Throw
102+
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"(EXC_[A-Z_]+|SIG[A-Z]+)`""
103+
$result.Envelopes() | Should -HaveCount 1
105104
}
106105

107106
It 'captures native crash (<configuration>)' {
@@ -112,7 +111,7 @@ Describe 'iOS app (<tfm>, <configuration>)' -ForEach @(
112111
}
113112

114113
$result.HasErrors() | Should -BeFalse
115-
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"EXC_[A-Z_]+`""
114+
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"(EXC_[A-Z_]+|SIG[A-Z]+)`""
116115
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.\w+Exception`""
117116
$result.Envelopes() | Should -HaveCount 1
118117
}
@@ -126,12 +125,7 @@ Describe 'iOS app (<tfm>, <configuration>)' -ForEach @(
126125

127126
$result.HasErrors() | Should -BeFalse
128127
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.NullReferenceException`""
129-
# TODO: fix redundant EXC_BAD_ACCESS in Release (#3954)
130-
if ($configuration -eq 'Release') {
131-
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"EXC_BAD_ACCESS`"" } | Should -Throw
132-
} else {
133-
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"EXC_BAD_ACCESS`""
134-
$result.Envelopes() | Should -HaveCount 1
135-
}
128+
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"(EXC_[A-Z_]+|SIG[A-Z]+)`""
129+
$result.Envelopes() | Should -HaveCount 1
136130
}
137131
}

scripts/build-sentry-cocoa.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@ xcodebuild archive -project Sentry.xcodeproj \
5050
-sdk "$ios_sdk" \
5151
-archivePath ./Carthage/output-ios.xcarchive \
5252
SKIP_INSTALL=NO \
53-
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
53+
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
54+
GCC_PREPROCESSOR_DEFINITIONS='$(inherited) SENTRY_CRASH_MANAGED_RUNTIME=1'
5455
./scripts/remove-architectures.sh ./Carthage/output-ios.xcarchive arm64e
5556
xcodebuild archive -project Sentry.xcodeproj \
5657
-scheme Sentry \
5758
-configuration Release \
5859
-sdk "$ios_simulator_sdk" \
5960
-archivePath ./Carthage/output-iossimulator.xcarchive \
6061
SKIP_INSTALL=NO \
61-
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
62+
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
63+
GCC_PREPROCESSOR_DEFINITIONS='$(inherited) SENTRY_CRASH_MANAGED_RUNTIME=1'
6264
xcodebuild -create-xcframework \
6365
-framework ./Carthage/output-ios.xcarchive/Products/Library/Frameworks/Sentry.framework \
6466
-framework ./Carthage/output-iossimulator.xcarchive/Products/Library/Frameworks/Sentry.framework \
@@ -73,7 +75,8 @@ xcodebuild archive -project Sentry.xcodeproj \
7375
-destination 'generic/platform=macOS,variant=Mac Catalyst' \
7476
-archivePath ./Carthage/output-maccatalyst.xcarchive \
7577
SKIP_INSTALL=NO \
76-
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
78+
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
79+
GCC_PREPROCESSOR_DEFINITIONS='$(inherited) SENTRY_CRASH_MANAGED_RUNTIME=1'
7780
./scripts/remove-architectures.sh ./Carthage/output-maccatalyst.xcarchive arm64e
7881
xcodebuild -create-xcframework \
7982
-framework ./Carthage/output-maccatalyst.xcarchive/Products/Library/Frameworks/Sentry.framework \

src/Sentry/Platforms/Cocoa/RuntimeMarshalManagedExceptionIntegration.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ internal void Handle(object sender, MarshalManagedExceptionEventArgs e)
4343

4444
// This is likely a terminal exception so try to send the crash report before shutting down
4545
_hub?.Flush();
46+
47+
// The Xamarin runtime will call abort() after this handler returns, which raises
48+
// SIGABRT. Tell SentryCrash to ignore it on this thread so we don't get a duplicate
49+
// native crash event for a managed exception we've already captured.
50+
const int SIGABRT = 6;
51+
SentryCocoaHybridSdk.IgnoreNextSignal(SIGABRT);
4652
}
4753
}
4854
}

0 commit comments

Comments
 (0)