Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUMM-1492: Fix isSystemImage detection #563

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,12 @@ extension BinaryImageInfo {

self.uuid = imageUUID
self.imageName = URL(string: imagePath)?.lastPathComponent
// NOTE: RUMM-1492 refer to JIRA ticket or `CrashReportTests.swift` to see imagePath examples
self.isSystemImage = !imagePath.contains("/Bundle/Application/") || imagePath.contains("/Contents/Developer/Platforms/")

#if targetEnvironment(simulator)
self.isSystemImage = Self.isPathSystemImageInSimulator(imagePath)
#else
self.isSystemImage = Self.isPathSystemImageInDevice(imagePath)
#endif

if let codeType = imageInfo.codeType {
self.codeType = CodeType(from: codeType)
Expand All @@ -254,6 +258,17 @@ extension BinaryImageInfo {
self.imageBaseAddress = imageInfo.imageBaseAddress
self.imageSize = imageInfo.imageSize
}

static func isPathSystemImageInSimulator(_ path: String) -> Bool {
// in simulator, example system image path: ~/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/...
return path.contains("/Contents/Developer/Platforms/")
}

static func isPathSystemImageInDevice(_ path: String) -> Bool {
// in device, example user image path: .../containers/Bundle/Application/0000/Example.app/Frameworks/...
let isUserImage = path.contains("/Bundle/Application/")
return !isUserImage
}
}

extension BinaryImageInfo.CodeType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,37 @@ class CrashReportTests: XCTestCase {
XCTAssertEqual(threadInfo.stackFrames.count, mockStackFrames.count)
}

private let systemImagePaths_device = [
"/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
"/usr/lib/system/libdyld.dylib"
]
private let systemImagePaths_simulator = [
"/Users/john.appleseed/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"
]
private let userImagePaths_device = [
"/private/var/containers/Bundle/Application/0000/Example.app/Example",
"/private/var/containers/Bundle/Application/0000/Example.app/Frameworks/DatadogCrashReporting.framework/DatadogCrashReporting"
]
private let userImagePaths_simulator = [
"/Users/john.appleseed/Library/Developer/CoreSimulator/Devices/0000/data/Containers/Bundle/Application/0000/Example.app/Example",
"/Users/john.appleseed/Library/Developer/Xcode/DerivedData/Datadog-abcd/Build/Products/Release-iphonesimulator/DatadogCrashReporting.framework/DatadogCrashReporting"
]

func testItDetectsSystemImages() throws {
for systemImagePath in systemImagePaths_device {
XCTAssertTrue(BinaryImageInfo.isPathSystemImageInDevice(systemImagePath), "\(systemImagePath) is a system image")
}
for systemImagePath in systemImagePaths_simulator {
XCTAssertTrue(BinaryImageInfo.isPathSystemImageInSimulator(systemImagePath), "\(systemImagePath) is a system image")
}
for userImagePath in userImagePaths_device {
XCTAssertFalse(BinaryImageInfo.isPathSystemImageInDevice(userImagePath), "\(userImagePath) is an user image")
}
for userImagePath in userImagePaths_simulator {
XCTAssertFalse(BinaryImageInfo.isPathSystemImageInSimulator(userImagePath), "\(userImagePath) is an user image")
}
}

func testItReadsBinaryImageInfo() throws {
func mock(with imagePath: URL) -> PLCrashReportMock.BinaryImageInfo {
let mock = PLCrashReportMock.BinaryImageInfo()
Expand All @@ -220,20 +251,13 @@ class CrashReportTests: XCTestCase {
}

// Given
let systemImagePathString = [
"/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
"/usr/lib/system/libdyld.dylib",
"/Users/john.appleseed/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"
].randomElement()!
let systemImagePath = URL(string: systemImagePathString)!

let userImagePathString = [
"/private/var/containers/Bundle/Application/0000/Example.app/Example",
"/private/var/containers/Bundle/Application/0000/Example.app/Frameworks/DatadogCrashReporting.framework/DatadogCrashReporting",
"/Users/john.appleseed/Library/Developer/CoreSimulator/Devices/0000/data/Containers/Bundle/Application/0000/Example.app/Example",
"/Users/john.appleseed/Library/Developer/Xcode/DerivedData/Datadog-abcd/Build/Products/Release-iphonesimulator/DatadogCrashReporting.framework/DatadogCrashReporting"
].randomElement()!
let userImagePath = URL(string: userImagePathString)!
#if targetEnvironment(simulator)
let systemImagePath = URL(string: systemImagePaths_simulator.randomElement()!)!
let userImagePath = URL(string: userImagePaths_simulator.randomElement()!)!
#else
let systemImagePath = URL(string: systemImagePaths_device.randomElement()!)!
let userImagePath = URL(string: userImagePaths_device.randomElement()!)!
#endif

let mockSystemImage = mock(with: systemImagePath)
let mockUserImage = mock(with: userImagePath)
Expand Down