From 9ba19c0b7719b25ffdccb097ed021e5aaadc87dc Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Tue, 29 Nov 2022 15:43:42 +0100 Subject: [PATCH] fix: Reporting crashes when restarting the SDK (#2440) The SDK did not report crashes after restarting the SDK. This is fixed by restoring the SentryCrashMonitors when installing SentryCrash after uninstalling it. --- CHANGELOG.md | 1 + Samples/iOS-Swift/iOS-Swift/AppDelegate.swift | 10 +- .../iOS-Swift/Base.lproj/Main.storyboard | 62 +++++--- .../iOS-Swift/iOS-Swift/ViewController.swift | 7 + .../iOS-Swift/iOS13-Swift/AppDelegate.swift | 38 +++-- Sentry.xcodeproj/project.pbxproj | 4 + Sources/Sentry/SentryCrashIntegration.m | 4 +- Sources/Sentry/SentryCrashWrapper.m | 9 +- Sources/Sentry/include/SentryCrashWrapper.h | 6 +- .../SentryCrashInstallation+Private.h | 14 ++ .../Installations/SentryCrashInstallation.h | 5 + .../Installations/SentryCrashInstallation.m | 28 ++-- .../Recording/Monitors/SentryCrashMonitor.c | 8 +- .../Recording/Monitors/SentryCrashMonitor.h | 10 +- .../SentryCrashMonitor_MachException.c | 62 ++++++-- .../SentryCrashMonitor_MachException.h | 7 + Sources/SentryCrash/Recording/SentryCrash.h | 21 ++- Sources/SentryCrash/Recording/SentryCrash.m | 120 ++++++++------ Sources/SentryCrash/Recording/SentryCrashC.c | 48 +----- Sources/SentryCrash/Recording/SentryCrashC.h | 9 +- .../Recording/SentryCrashCachedData.c | 6 + .../Recording/SentryCrashCachedData.h | 1 + .../Recording/Tools/SentryCrashLogger.c | 31 ---- .../Recording/Tools/SentryCrashLogger.h | 11 -- .../Tools/SentryCrashMachineContext.c | 36 +---- .../Tools/SentryCrashMachineContext.h | 6 - .../TestNSNotificationCenterWrapper.swift | 16 +- ...SentryNetworkTrackerIntegrationTests.swift | 2 + .../SentryCrashIntegrationTests.swift | 4 +- .../SentryCrashInstallationTests.m | 146 ++++++++++++++++++ .../SentryCrash/SentryCrashLogger_Tests.m | 25 --- .../SentryThreadInspectorTests.swift | 2 +- .../SentryCrash/TestSentryCrashWrapper.h | 2 +- .../SentryCrash/TestSentryCrashWrapper.m | 6 +- 34 files changed, 467 insertions(+), 300 deletions(-) create mode 100644 Tests/SentryTests/SentryCrash/SentryCrashInstallationTests.m diff --git a/CHANGELOG.md b/CHANGELOG.md index 47db1c614c..84a8c470d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- Reporting crashes when restarting the SDK (#2440) - Core data span status with error (#2439) ## 7.31.2 diff --git a/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift b/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift index 69290edc2b..203c22620c 100644 --- a/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift +++ b/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift @@ -7,9 +7,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? static let defaultDSN = "https://6cc9bae94def43cab8444a99e0031c28@o447951.ingest.sentry.io/5428557" - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - + + static func startSentry() { // For testing purposes, we want to be able to change the DSN and store it to disk. In a real app, you shouldn't need this behavior. let dsn = DSNStorage.shared.getDSN() ?? AppDelegate.defaultDSN DSNStorage.shared.saveDSN(dsn: dsn) @@ -45,6 +44,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let httpStatusCodeRange = HttpStatusCodeRange(min: 400, max: 599) options.failedRequestStatusCodes = [ httpStatusCodeRange ] } + } + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + + AppDelegate.startSentry() if #available(iOS 14.0, *) { metricKit.receiveReports() diff --git a/Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard b/Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard index 0ed14a09ab..029585c65a 100644 --- a/Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard +++ b/Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -18,13 +18,13 @@ - + - + - + + + - +