diff --git a/OneSignal-KMP-SDK b/OneSignal-KMP-SDK index b5c7bbeabf..b27ea1f5b3 160000 --- a/OneSignal-KMP-SDK +++ b/OneSignal-KMP-SDK @@ -1 +1 @@ -Subproject commit b5c7bbeabfa0fdcae036af4f726ac6e6817d0b0d +Subproject commit b27ea1f5b3a7eab850ecc4ff2c34b8924ac75ad2 diff --git a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj index 8e8c9bb7a5..ffe36526f5 100644 --- a/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj +++ b/iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj @@ -738,6 +738,8 @@ DEFB3E672BB735B500E65DAD /* OSStubLiveActivities.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFB3E662BB735B500E65DAD /* OSStubLiveActivities.swift */; }; ECD9DF65FB98056806A43541 /* OSIdentityVerificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C4EAEA1BC62D8FC57927511 /* OSIdentityVerificationService.swift */; }; FD1F1FCA05D555623DD53B54 /* OSUserJwtRepo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A8BBA843AFC81A4940CF7CC /* OSUserJwtRepo.swift */; }; + 3C5059A12FD0000000000003 /* CrashTestExceptionRaiser.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C5059A12FD0000000000001 /* CrashTestExceptionRaiser.m */; }; + 3C5059A12FD0000000000005 /* OSLogCrashAttributionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C5059A12FD0000000000004 /* OSLogCrashAttributionTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -2013,6 +2015,9 @@ C3E5A1D7F2B9461EB8D4A6C2 /* ExecutorRequestAgingTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = ExecutorRequestAgingTests.swift; sourceTree = ""; }; FF4B19D1EC31C0750F13065A /* OSIamFetchReadyConditionTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSIamFetchReadyConditionTests.swift; sourceTree = ""; }; FFBB451F692A15639A1A08AE /* OSOperationRepoIdentityVerificationTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSOperationRepoIdentityVerificationTests.swift; sourceTree = ""; }; + 3C5059A12FD0000000000001 /* CrashTestExceptionRaiser.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = CrashTestExceptionRaiser.m; sourceTree = ""; }; + 3C5059A12FD0000000000002 /* OneSignalOSCoreTests-Bridging-Header.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "OneSignalOSCoreTests-Bridging-Header.h"; sourceTree = ""; }; + 3C5059A12FD0000000000004 /* OSLogCrashAttributionTests.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = OSLogCrashAttributionTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -2786,6 +2791,9 @@ 5B053FB92CAE07EB002F30C4 /* OneSignalOSCoreTests */ = { isa = PBXGroup; children = ( + 3C5059A12FD0000000000004 /* OSLogCrashAttributionTests.swift */, + 3C5059A12FD0000000000001 /* CrashTestExceptionRaiser.m */, + 3C5059A12FD0000000000002 /* OneSignalOSCoreTests-Bridging-Header.h */, 5BC1DE672C90C23E00CA8807 /* OSConsistencyManagerTests.swift */, 3C427AC8301BB28A0059B8B7 /* OSOperationRepoFlushTests.swift */, B5481A0100000000000000A7 /* OSRequestRetryBackoffTests.swift */, @@ -4920,6 +4928,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 3C5059A12FD0000000000005 /* OSLogCrashAttributionTests.swift in Sources */, + 3C5059A12FD0000000000003 /* CrashTestExceptionRaiser.m in Sources */, 5B053FC32CAE0843002F30C4 /* OSConsistencyManagerTests.swift in Sources */, 3C23A21F2FCE0AA1001D32E3 /* OSResilientStorageTests.swift in Sources */, 3C23A21D2FCE0A83001D32E3 /* OSModelStoreRefreshTests.swift in Sources */, @@ -5844,7 +5854,7 @@ MARKETING_VERSION = 1.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalOSCore; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -5924,7 +5934,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalOSCore; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -7204,6 +7214,7 @@ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; + OTHER_CFLAGS = "$(inherited) -fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalLiveActivities; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -7278,6 +7289,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; + OTHER_CFLAGS = "$(inherited) -fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalLiveActivities; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -7346,6 +7358,7 @@ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; + OTHER_CFLAGS = "$(inherited) -fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalLiveActivities; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -7408,6 +7421,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_OBJC_BRIDGING_HEADER = "OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UnitTestApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/UnitTestApp"; @@ -7469,6 +7483,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_OBJC_BRIDGING_HEADER = "OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -7524,6 +7539,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_OBJC_BRIDGING_HEADER = "OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UnitTestApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/UnitTestApp"; @@ -7603,7 +7619,10 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - OTHER_CFLAGS = "-fembed-bitcode"; + OTHER_CFLAGS = ( + "-fembed-bitcode", + "-fno-optimize-sibling-calls", + ); OTHER_LDFLAGS = ""; PRODUCT_NAME = OneSignal; SKIP_INSTALL = YES; @@ -7649,7 +7668,7 @@ ); MACH_O_TYPE = mh_dylib; MTL_ENABLE_DEBUG_INFO = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = "com.onesignal.OneSignal-Dynamic"; @@ -7807,7 +7826,10 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - OTHER_CFLAGS = "-fembed-bitcode"; + OTHER_CFLAGS = ( + "-fembed-bitcode", + "-fno-optimize-sibling-calls", + ); OTHER_LDFLAGS = ""; PRODUCT_NAME = OneSignal; SKIP_INSTALL = YES; @@ -7855,7 +7877,7 @@ MACH_O_TYPE = mh_dylib; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = "com.onesignal.OneSignal-Dynamic"; @@ -8013,7 +8035,10 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - OTHER_CFLAGS = "-fembed-bitcode"; + OTHER_CFLAGS = ( + "-fembed-bitcode", + "-fno-optimize-sibling-calls", + ); OTHER_LDFLAGS = ""; PRODUCT_NAME = OneSignal; SKIP_INSTALL = YES; @@ -8061,7 +8086,7 @@ MACH_O_TYPE = mh_dylib; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; OTHER_LDFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = "com.onesignal.OneSignal-Dynamic"; @@ -8275,7 +8300,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; "OTHER_LDFLAGS[sdk=iphoneos*]" = ( "$(inherited)", @@ -8354,7 +8379,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalExtension; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -8418,7 +8443,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalOutcomes; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -8480,7 +8505,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalUser; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -8540,7 +8565,7 @@ MARKETING_VERSION = 1.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalUser; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -8607,7 +8632,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalUser; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -8679,7 +8704,7 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; "OTHER_LDFLAGS[sdk=iphoneos*]" = ( "$(inherited)", @@ -8771,7 +8796,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; "OTHER_LDFLAGS[sdk=iphoneos*]" = ( "$(inherited)", @@ -8846,7 +8871,7 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalExtension; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -8913,7 +8938,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; OTHER_CPLUSPLUSFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalExtension; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -8973,7 +8998,7 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalOutcomes; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9039,7 +9064,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalOutcomes; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9245,7 +9270,7 @@ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalLocation; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9313,7 +9338,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalLocation; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9375,7 +9400,7 @@ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalLocation; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9435,7 +9460,7 @@ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalInAppMessages; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9503,7 +9528,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalInAppMessages; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9565,7 +9590,7 @@ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalInAppMessages; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9638,7 +9663,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalOSCore; PRODUCT_NAME = OneSignalOSCore; SKIP_INSTALL = YES; @@ -9801,7 +9826,7 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalNotifications; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9867,7 +9892,7 @@ MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalNotifications; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -9928,7 +9953,7 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = ""; + OTHER_CFLAGS = "-fno-optimize-sibling-calls"; PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.OneSignalNotifications; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Logging/OSLogCrashHandler.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Logging/OSLogCrashHandler.swift index a406fb41d8..142db0d940 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Logging/OSLogCrashHandler.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/Logging/OSLogCrashHandler.swift @@ -27,6 +27,7 @@ import Darwin import Foundation +import MachO import OneSignalCore @_implementationOnly import OneSignalKMP @@ -41,6 +42,40 @@ struct OSResolvedStackFrame: Equatable { let symbolName: String? } +/// The Mach-O image this framework's own code was linked into. +struct OSOwnImage: Equatable { + let path: String? + + /// True once SDK code sits in the host's main executable. Every frame then reports that + /// same image, and the symbol fallback cannot stand in: release builds strip the local + /// symbols that name our ObjC methods and Swift functions, so `dladdr` reports none. + let sharesHostExecutable: Bool + + static let resolved: OSOwnImage = { + var info = Dl_info() + let selfAddress = unsafeBitCast( + osLogUncaughtExceptionHandler as OSExceptionHandler, + to: UnsafeRawPointer.self + ) + guard dladdr(selfAddress, &info) != 0, let ownBase = info.dli_fbase else { + // Keep the narrower behavior: capturing every host crash is a worse failure than + // the drop this guards against, and a lookup inside our own image does not fail. + return OSOwnImage(path: nil, sharesHostExecutable: false) + } + // Find the executable by filetype, not by index. Inserted libraries take the low + // indices: XCTest, Main Thread Checker and the simulator shims all land ahead of it. + let mainExecutable = (0..<_dyld_image_count()) + .lazy + .compactMap { _dyld_get_image_header($0) } + .first { $0.pointee.filetype == UInt32(MH_EXECUTE) } + .map { UnsafeRawPointer($0) } + return OSOwnImage( + path: info.dli_fname.map { String(cString: $0) }, + sharesHostExecutable: UnsafeRawPointer(ownBase) == mainExecutable + ) + }() +} + /// Prints KMP diagnostics with `NSLog`, honoring the console log level without going through /// `OneSignalLog` (listeners, alert UI, remote telemetry). Each caller documents why it cannot /// afford that path. @@ -110,11 +145,13 @@ final class OSLogCrashHandler: ILogCrashHandler { private static var inactivePreviousHandler: OSExceptionHandler? private let reporter: ILogCrashReporter + private let ownImage: OSOwnImage private var previousExceptionHandler: OSExceptionHandler? private var isInitialized = false - init(reporter: ILogCrashReporter) { + init(reporter: ILogCrashReporter, ownImage: OSOwnImage = .resolved) { self.reporter = reporter + self.ownImage = ownImage } func initialize() { @@ -165,14 +202,18 @@ final class OSLogCrashHandler: ILogCrashHandler { stackSymbols: [String], resolvedFrames: [OSResolvedStackFrame] ) { - guard Self.isOneSignalAtFault(resolvedFrames) else { + let isAtFault = Self.isOneSignalAtFault(resolvedFrames, ownImage: ownImage) + // Dropping is only safe where a OneSignal frame would have been recognizable. Where it + // would not, a false negative is indistinguishable from "no crashes happened". + guard isAtFault || ownImage.sharesHostExecutable else { previousExceptionHandler?(exception) return } capture( exceptionType: exception.name.rawValue, exceptionMessage: exception.reason ?? exception.description, - stacktrace: stackSymbols.joined(separator: "\n") + stacktrace: stackSymbols.joined(separator: "\n"), + attributed: isAtFault ) previousExceptionHandler?(exception) } @@ -180,13 +221,15 @@ final class OSLogCrashHandler: ILogCrashHandler { private func capture( exceptionType: String, exceptionMessage: String, - stacktrace: String + stacktrace: String, + attributed: Bool ) { let crash = CrashData( threadName: Self.currentThreadName, exceptionType: exceptionType, exceptionMessage: exceptionMessage, - stacktrace: stacktrace + stacktrace: stacktrace, + attributed: attributed ) do { try reporter.saveCrash(crash: crash) @@ -233,7 +276,10 @@ final class OSLogCrashHandler: ILogCrashHandler { } } - static func isOneSignalAtFault(_ frames: [OSResolvedStackFrame]) -> Bool { + static func isOneSignalAtFault( + _ frames: [OSResolvedStackFrame], + ownImage: OSOwnImage = .resolved + ) -> Bool { frames.contains { frame in guard let imagePath = frame.imagePath, !isSystemImage(imagePath) else { @@ -242,10 +288,19 @@ final class OSLogCrashHandler: ILogCrashHandler { if oneSignalModules.contains(imageName(from: imagePath)) { return true } + let isOwnImage = imagePath == ownImage.path + // Our image identifies us only while it is ours alone. Shared with the host, every + // frame matches it and the attribution tag would always read true. + if isOwnImage, !ownImage.sharesHostExecutable { + return true + } guard let symbolName = frame.symbolName else { return false } - return isOneSignalSymbol(symbolName) + return isOneSignalSymbol( + symbolName, + allowsClassPrefix: isOwnImage && ownImage.sharesHostExecutable + ) } } @@ -273,12 +328,14 @@ final class OSLogCrashHandler: ILogCrashHandler { path.contains("/System/Library/") || path.contains("/usr/lib/") } - private static func isOneSignalSymbol(_ symbol: String) -> Bool { + private static func isOneSignalSymbol(_ symbol: String, allowsClassPrefix: Bool) -> Bool { let symbolWithoutLeadingUnderscores = symbol.drop(while: { $0 == "_" }) - if symbolWithoutLeadingUnderscores.hasPrefix("-[OneSignal") - || symbolWithoutLeadingUnderscores.hasPrefix("+[OneSignal") - || symbolWithoutLeadingUnderscores.hasPrefix("onesignal_") - || symbolWithoutLeadingUnderscores.contains("kfun:com.onesignal.") { + if symbolWithoutLeadingUnderscores.hasPrefix("onesignal_") + || symbolWithoutLeadingUnderscores.contains("kfun:com.onesignal.") + || isOneSignalObjCMethod( + symbolWithoutLeadingUnderscores, + allowsClassPrefix: allowsClassPrefix + ) { return true } guard let module = swiftModuleName(from: String(symbolWithoutLeadingUnderscores)) else { @@ -287,6 +344,26 @@ final class OSLogCrashHandler: ILogCrashHandler { return oneSignalModules.contains(module) } + /// Both halves of an `-[Class selector]` symbol can identify us: most of the ObjC surface + /// uses the `OS` prefix rather than `OneSignal`, and swizzled categories land on system + /// classes where only the selector names us (`-[UIApplication setOneSignalDelegate:]`). + /// + /// `allowsClassPrefix` is false outside the image we share with the host, where a bare `OS` + /// would claim unrelated classes such as Aliyun's `-[OSSClient ...]`. + private static func isOneSignalObjCMethod( + _ symbol: Substring, + allowsClassPrefix: Bool + ) -> Bool { + guard symbol.hasPrefix("-[") || symbol.hasPrefix("+[") else { + return false + } + let method = symbol.dropFirst(2) + if method.range(of: "onesignal", options: .caseInsensitive) != nil { + return true + } + return allowsClassPrefix && method.hasPrefix("OS") + } + private static func swiftModuleName(from symbol: String) -> String? { guard symbol.hasPrefix("$s") else { return nil diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/CrashTestExceptionRaiser.m b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/CrashTestExceptionRaiser.m new file mode 100644 index 0000000000..10f597e8ce --- /dev/null +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/CrashTestExceptionRaiser.m @@ -0,0 +1,41 @@ +/* + Modified MIT License + + Copyright 2026 OneSignal + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + 1. The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + 2. All copies of substantial portions of the Software may only be used in connection + with services provided by OneSignal. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +#import "OneSignalOSCoreTests-Bridging-Header.h" + +@implementation CrashTestExceptionRaiser + ++ (nullable NSException *)exceptionRaisedBy:(void (^)(void))block { + @try { + block(); + } @catch (NSException *exception) { + return exception; + } + return nil; +} + +@end diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashAttributionTests.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashAttributionTests.swift new file mode 100644 index 0000000000..42997309a7 --- /dev/null +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashAttributionTests.swift @@ -0,0 +1,208 @@ +/* + Modified MIT License + + Copyright 2026 OneSignal + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + 1. The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + 2. All copies of substantial portions of the Software may only be used in connection + with services provided by OneSignal. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +import Foundation +@testable import OneSignalOSCore +import XCTest + +final class OSLogCrashAttributionTests: XCTestCase { + func testIgnoresOneSignalSubstringOutsideModuleField() { + XCTAssertFalse( + isOneSignal([frame(appPath, symbol: "OneSignalNotificationCallback")]) + ) + } + func testRecognizesKnownOneSignalModule() { + XCTAssertTrue(isOneSignal([dynamicFrame("OneSignalNotifications")])) + } + func testRecognizesOneSignalKMPModule() { + XCTAssertTrue(isOneSignal([dynamicFrame("OneSignalKMP")])) + } + func testRecognizesOneSignalCallbackBelowHostThrowingFrame() { + XCTAssertTrue( + isOneSignal([ + frame(appPath, symbol: "HostCallback"), + dynamicFrame("OneSignalCore", symbol: "OneSignalCallback") + ]) + ) + } + func testRecognizesFoundationOriginatedOneSignalCrash() { + XCTAssertTrue( + isOneSignal([ + frame("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"), + frame("/usr/lib/libobjc.A.dylib"), + frame("/System/Library/Frameworks/Foundation.framework/Foundation"), + dynamicFrame("OneSignalCore") + ]) + ) + } + func testRecognizesStaticFoundationOriginatedOneSignalCrash() { + XCTAssertTrue( + isOneSignal([ + frame("/System/Library/Frameworks/Foundation.framework/Foundation"), + frame(appPath, symbol: "-[OneSignalUserDefaults saveCodeableDataForKey:withValue:]") + ]) + ) + } + func testRecognizesStaticSwiftOneSignalModule() { + XCTAssertTrue( + isOneSignal([ + frame(appPath, symbol: "_$s13OneSignalUser19OSPropertyOperationC7execute") + ]) + ) + } + func testRecognizesStaticKotlinOneSignalSymbol() { + XCTAssertTrue( + isOneSignal([ + frame(appPath, symbol: "kfun:com.onesignal.logger.LogCrashReporter.saveCrash") + ]) + ) + } + func testRecognizesStaticNotificationProcessingStack() { + XCTAssertTrue( + isOneSignal([ + frame(appPath, symbol: "finishProcessingNotification"), + frame(appPath, symbol: "onesignal_Log") + ]) + ) + } + func testRecognizesStaticOSPrefixedObjCClass() { + XCTAssertTrue( + isOneSignal([ + frame(appPath, symbol: "-[OSNotificationsManager handleNotificationAction:]") + ]) + ) + XCTAssertTrue( + isOneSignal([frame(appPath, symbol: "+[OSMessagingController sharedInstance]")]) + ) + } + func testRecognizesStaticSwizzledCategoryOnSystemClass() { + XCTAssertTrue( + isOneSignal([frame(appPath, symbol: "-[UIApplication setOneSignalDelegate:]")]) + ) + XCTAssertTrue( + isOneSignal([ + frame( + appPath, + symbol: "-[UNUserNotificationCenter onesignalRequestAuthorizationWithOptions:" + + "completionHandler:]" + ) + ]) + ) + } + func testIgnoresUnrelatedObjCMethod() { + XCTAssertFalse( + isOneSignal([frame(appPath, symbol: "-[AppDelegate application:didFinishLaunching:]")]) + ) + } + func testIgnoresGenericOSSymbol() { + XCTAssertFalse(isOneSignal([frame(appPath, symbol: "OSPropertyOperationExecutor")])) + } + + func testIgnoresOneSignalSymbolInSystemImage() { + XCTAssertFalse( + isOneSignal([frame("/usr/lib/libExample.dylib", symbol: "onesignal_Log")]) + ) + } + + func testSkipsSimulatorSystemImage() { + XCTAssertTrue( + isOneSignal([ + frame( + "/Library/Developer/CoreSimulator/Volumes/iOS/RuntimeRoot/" + + "System/Library/Frameworks/Foundation.framework/Foundation", + symbol: "onesignal_Log" + ), + dynamicFrame("OneSignalOSCore") + ]) + ) + } + + /// Our image names us only while it is ours alone. Once it is the host binary every frame + /// matches it, which would tag crashes we cannot attribute as if we had. + func testIgnoresHostFramesWhenSdkSharesTheHostImage() { + XCTAssertFalse(isOneSignal([frame(appPath)])) + } + func testRecognizesRepackagedFrameworkByOwnImage() { + let repackaged = OSOwnImage(path: frameworkPath("VendorWrapper"), sharesHostExecutable: false) + XCTAssertTrue( + isOneSignal([frame(frameworkPath("VendorWrapper"))], ownImage: repackaged) + ) + } + func testIgnoresThirdPartyOSPrefixedClass() { + XCTAssertFalse( + isOneSignal([ + frame(frameworkPath("AliyunOSS"), symbol: "-[OSSClient putObject:]") + ]) + ) + } + func testIgnoresOSPrefixedClassOutsideTheSharedHostImage() { + XCTAssertFalse( + isOneSignal( + [frame(appPath, symbol: "-[OSNotificationsManager handleNotificationAction:]")], + ownImage: dynamicallyLinked + ) + ) + } + + func testIgnoresUnresolvedAndEmptyStacks() { + XCTAssertFalse( + isOneSignal([OSResolvedStackFrame(imagePath: nil, symbolName: "onesignal_Log")]) + ) + XCTAssertFalse(isOneSignal([])) + } + + /// Every `appPath` case above models static linking, where our code sits in the host binary. + private func isOneSignal( + _ frames: [OSResolvedStackFrame], + ownImage: OSOwnImage = staticallyLinked + ) -> Bool { + OSLogCrashHandler.isOneSignalAtFault(frames, ownImage: ownImage) + } + + private func frame(_ imagePath: String, symbol: String? = nil) -> OSResolvedStackFrame { + OSResolvedStackFrame(imagePath: imagePath, symbolName: symbol) + } + + private func dynamicFrame(_ module: String, symbol: String? = nil) -> OSResolvedStackFrame { + frame(frameworkPath(module), symbol: symbol) + } +} + +private let appPath = "/private/var/containers/Bundle/Application/App/ExampleApp" + +private func frameworkPath(_ module: String) -> String { + "/private/var/containers/Bundle/Application/App/Frameworks/\(module).framework/\(module)" +} + +/// SDK compiled into the host binary, so no frame's image can tell our code from the app's. +private let staticallyLinked = OSOwnImage(path: appPath, sharesHostExecutable: true) + +/// SDK shipped as its own framework, the shape every current integration uses. +private let dynamicallyLinked = OSOwnImage( + path: frameworkPath("OneSignalOSCore"), + sharesHostExecutable: false +) diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashHandlerTests.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashHandlerTests.swift index 475ef5bf57..17eeee4bf7 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashHandlerTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLogCrashHandlerTests.swift @@ -83,118 +83,91 @@ final class OSLogCrashHandlerTests: XCTestCase { XCTAssertTrue(try FileManager.default.contentsOfDirectory(atPath: temporaryDirectory.path).isEmpty) } - private func frame(_ imagePath: String, symbol: String? = nil) -> OSResolvedStackFrame { - OSResolvedStackFrame(imagePath: imagePath, symbolName: symbol) + /// Drives the installed handler with the addresses the runtime captured at a real throw, so + /// attribution runs on `dladdr` output rather than frames the test supplied. + func testCapturesExceptionThrownThroughOneSignalFrame() throws { + try assertCapture(1, for: raisedThroughOneSignalFrame()) } -} -final class OSLogCrashAttributionTests: XCTestCase { - func testIgnoresOneSignalSubstringOutsideModuleField() { - XCTAssertFalse( - isOneSignal([frame(appPath, symbol: "OneSignalNotificationCallback")]) - ) - } - func testRecognizesKnownOneSignalModule() { - XCTAssertTrue(isOneSignal([dynamicFrame("OneSignalNotifications")])) - } - func testRecognizesOneSignalKMPModule() { - XCTAssertTrue(isOneSignal([dynamicFrame("OneSignalKMP")])) + func testIgnoresExceptionThrownEntirelyInHostFrames() throws { + try assertCapture(0, for: raisedInHostFrame()) } - func testRecognizesOneSignalCallbackBelowHostThrowingFrame() { - XCTAssertTrue( - isOneSignal([ - frame(appPath, symbol: "HostCallback"), - dynamicFrame("OneSignalCore", symbol: "OneSignalCallback") - ]) - ) - } - func testRecognizesFoundationOriginatedOneSignalCrash() { - XCTAssertTrue( - isOneSignal([ - frame("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"), - frame("/usr/lib/libobjc.A.dylib"), - frame("/System/Library/Frameworks/Foundation.framework/Foundation"), - dynamicFrame("OneSignalCore") - ]) - ) - } - func testRecognizesStaticFoundationOriginatedOneSignalCrash() { - XCTAssertTrue( - isOneSignal([ - frame("/System/Library/Frameworks/Foundation.framework/Foundation"), - frame(appPath, symbol: "-[OneSignalUserDefaults saveCodeableDataForKey:withValue:]") - ]) - ) - } - func testRecognizesStaticSwiftOneSignalModule() { - XCTAssertTrue( - isOneSignal([ - frame(appPath, symbol: "_$s13OneSignalUser19OSPropertyOperationC7execute") - ]) - ) - } - func testRecognizesStaticKotlinOneSignalSymbol() { - XCTAssertTrue( - isOneSignal([ - frame(appPath, symbol: "kfun:com.onesignal.logger.LogCrashReporter.saveCrash") - ]) - ) - } - func testRecognizesStaticNotificationProcessingStack() { - XCTAssertTrue( - isOneSignal([ - frame(appPath, symbol: "finishProcessingNotification"), - frame(appPath, symbol: "onesignal_Log") - ]) + + /// Where SDK code shares the host executable, no frame can name us, so dropping would hide + /// every one of our crashes behind a stack that looks like the host's. The real image path + /// matters here: matching on it would tag these as ours and defeat the server-side filter. + func testCapturesHostFramesUnattributedWhenSdkSharesTheHostImage() throws { + let reporter = RecordingCrashReporter() + try assertCapture( + 1, + for: raisedInHostFrame(), + ownImage: OSOwnImage(path: Self.testBundleImagePath, sharesHostExecutable: true), + reporter: reporter ) - } - func testIgnoresGenericOSSymbol() { - XCTAssertFalse(isOneSignal([frame(appPath, symbol: "OSPropertyOperationExecutor")])) + + XCTAssertEqual(reporter.saved.map(\.attributed), [false]) } - func testIgnoresOneSignalSymbolInSystemImage() { - XCTAssertFalse( - isOneSignal([frame("/usr/lib/libExample.dylib", symbol: "onesignal_Log")]) - ) + func testCapturesExceptionThroughOneSignalFrameAsAttributed() throws { + let reporter = RecordingCrashReporter() + try assertCapture(1, for: raisedThroughOneSignalFrame(), reporter: reporter) + + XCTAssertEqual(reporter.saved.map(\.attributed), [true]) } - func testSkipsSimulatorSystemImage() { - XCTAssertTrue( - isOneSignal([ - frame( - "/Library/Developer/CoreSimulator/Volumes/iOS/RuntimeRoot/" - + "System/Library/Frameworks/Foundation.framework/Foundation", - symbol: "onesignal_Log" - ), - dynamicFrame("OneSignalOSCore") - ]) + /// The image the raised frames resolve to, standing in for a host binary the SDK was + /// linked into. + private static let testBundleImagePath: String? = + class_getImageName(CrashTestExceptionRaiser.self).map { String(cString: $0) } + + /// `OSConsoleLogger` hands `write` a frame inside OneSignalOSCore, which is the only seam + /// here that puts SDK code between the throw and the test bundle. + private func raisedThroughOneSignalFrame() -> NSException? { + let logger = OSConsoleLogger( + consoleLogLevel: { .LL_VERBOSE }, + write: { _ in + NSException(name: NSExceptionName("RaisedException"), reason: "boom").raise() + } ) + return CrashTestExceptionRaiser.exceptionRaised { logger.error(message: "boom") } } - func testIgnoresUnresolvedAndEmptyStacks() { - XCTAssertFalse( - isOneSignal([OSResolvedStackFrame(imagePath: nil, symbolName: "onesignal_Log")]) - ) - XCTAssertFalse(isOneSignal([])) + private func raisedInHostFrame() -> NSException? { + CrashTestExceptionRaiser.exceptionRaised { + NSException(name: NSExceptionName("RaisedException"), reason: "boom").raise() + } } - private let appPath = "/private/var/containers/Bundle/Application/App/ExampleApp" + private func assertCapture( + _ expected: Int, + for raised: NSException?, + ownImage: OSOwnImage = .resolved, + reporter: RecordingCrashReporter? = nil, + file: StaticString = #filePath, + line: UInt = #line + ) throws { + let exception = try XCTUnwrap(raised, file: file, line: line) + XCTAssertFalse(exception.callStackReturnAddresses.isEmpty, file: file, line: line) + + let handler = makeCrashHandler(ownImage: ownImage, reporter: reporter) + let originalHandler = NSGetUncaughtExceptionHandler() + NSSetUncaughtExceptionHandler(osLogCrashTestExceptionHandler) + defer { NSSetUncaughtExceptionHandler(originalHandler) } + handler.initialize() + defer { handler.unregister() } + + OSLogCrashHandler.handleActive(exception) - private func isOneSignal(_ frames: [OSResolvedStackFrame]) -> Bool { - OSLogCrashHandler.isOneSignalAtFault(frames) + let captured = try reporter?.saved.count + ?? FileManager.default.contentsOfDirectory(atPath: temporaryDirectory.path) + .filter { $0.hasSuffix(".otlp") } + .count + XCTAssertEqual(captured, expected, file: file, line: line) } private func frame(_ imagePath: String, symbol: String? = nil) -> OSResolvedStackFrame { OSResolvedStackFrame(imagePath: imagePath, symbolName: symbol) } - - private func dynamicFrame(_ module: String, symbol: String? = nil) -> OSResolvedStackFrame { - frame( - "/private/var/containers/Bundle/Application/App/Frameworks/" - + "\(module).framework/\(module)", - symbol: symbol - ) - } } extension OSLogCrashHandlerTests { @@ -332,7 +305,13 @@ extension OSLogCrashHandlerTests { XCTAssertEqual(started, ["first", "second"]) } - private func makeCrashHandler() -> OSLogCrashHandler { + private func makeCrashHandler( + ownImage: OSOwnImage = .resolved, + reporter recording: RecordingCrashReporter? = nil + ) -> OSLogCrashHandler { + if let recording { + return OSLogCrashHandler(reporter: recording, ownImage: ownImage) + } let store = FileLogStore(rootPath: temporaryDirectory.path) let telemetry = LoggerFactory.shared.createCrashLocalTelemetry( platformProvider: makePlatformProvider(), @@ -342,7 +321,7 @@ extension OSLogCrashHandlerTests { crashTelemetry: telemetry, logger: OSConsoleLogger() ) - return OSLogCrashHandler(reporter: reporter) + return OSLogCrashHandler(reporter: reporter, ownImage: ownImage) } private func makePlatformProvider() -> OSLoggerPlatformProvider { @@ -359,6 +338,20 @@ extension OSLogCrashHandlerTests { } +/// Captures the `CrashData` the handler builds, so tests can read the attribution tag without +/// decoding an OTLP payload. +private final class RecordingCrashReporter: NSObject, ILogCrashReporter { + private(set) var saved: [CrashData] = [] + + func saveCrash(crash: CrashData) throws { + saved.append(crash) + } + + func saveNonFatal(crash: CrashData) throws { + saved.append(crash) + } +} + private typealias TestSignalHandler = @convention(c) (Int32) -> Void private typealias TestExceptionHandler = @convention(c) (NSException) -> Void private let exceptionHandlerCallLock = NSLock() diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLoggerAdaptersTests.swift b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLoggerAdaptersTests.swift index 3c382a252b..98bbde5fdb 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLoggerAdaptersTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OSLoggerAdaptersTests.swift @@ -351,7 +351,8 @@ final class OSLoggerAdaptersTests: XCTestCase { threadName: "test", exceptionType: "TestError", exceptionMessage: "test message", - stacktrace: "test stack" + stacktrace: "test stack", + attributed: true ) _ = try reporter.saveNonFatal(crash: crash) diff --git a/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h new file mode 100644 index 0000000000..579b3b55d3 --- /dev/null +++ b/iOS_SDK/OneSignalSDK/OneSignalOSCoreTests/OneSignalOSCoreTests-Bridging-Header.h @@ -0,0 +1,17 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface CrashTestExceptionRaiser : NSObject + +/// Returns the exception `block` raised, with the return addresses the runtime captured at the +/// throw. Swift cannot catch an `NSException`, so the `@try` has to live here. ++ (nullable NSException *)exceptionRaisedBy:(void (^)(void))block; + +@end + +NS_ASSUME_NONNULL_END