From d635cdff2ba48529ec3394746918c0b600575b75 Mon Sep 17 00:00:00 2001 From: Maxime Epain Date: Tue, 18 Jan 2022 13:54:40 +0100 Subject: [PATCH] RUMM-1883 Report binary image with no UUID --- .../CrashReport.swift | 31 +++++++++---------- .../DDCrashReportExporter.swift | 2 +- Tests/DatadogCrashReportingTests/Mocks.swift | 2 +- .../DDCrashReportExporterTests.swift | 11 +++++++ 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Sources/DatadogCrashReporting/PLCrashReporterIntegration/CrashReport.swift b/Sources/DatadogCrashReporting/PLCrashReporterIntegration/CrashReport.swift index 3cc41cd13f..25510743e1 100644 --- a/Sources/DatadogCrashReporting/PLCrashReporterIntegration/CrashReport.swift +++ b/Sources/DatadogCrashReporting/PLCrashReporterIntegration/CrashReport.swift @@ -91,7 +91,7 @@ internal struct BinaryImageInfo { } /// The UUID of this image. - var uuid: String + var uuid: String? /// The name of this image (referenced by "library name" in the stack frame). var imageName: String /// If its a system library image. @@ -232,14 +232,12 @@ extension ThreadInfo { extension BinaryImageInfo { init?(from imageInfo: PLCrashReportBinaryImageInfo) { - guard let imagePath = imageInfo.imageName, - let imageUUID = imageInfo.hasImageUUID ? imageInfo.imageUUID : nil else { - // We can drop this image as it won't be useful for symbolication - both - // "image name" and "uuid" are necessary. + guard let imagePath = imageInfo.imageName else { + // We can drop this image as it won't be useful for symbolication return nil } - self.uuid = imageUUID + self.uuid = imageInfo.imageUUID self.imageName = URL(fileURLWithPath: imagePath).lastPathComponent #if targetEnvironment(simulator) @@ -303,18 +301,17 @@ extension BinaryImageInfo.CodeType { extension StackFrame { init(from stackFrame: PLCrashReportStackFrameInfo, number: Int, in crashReport: PLCrashReport) { - if let image = crashReport.image(forAddress: stackFrame.instructionPointer), - let imageInfo = BinaryImageInfo(from: image) { - self.libraryName = imageInfo.imageName - self.libraryBaseAddress = imageInfo.imageBaseAddress - } else { - // Without "library name" and its "base address" symbolication will not be possible, - // but the presence of this frame in the stack will be still relevant. - self.libraryName = nil - self.libraryBaseAddress = nil - } - self.number = number self.instructionPointer = stackFrame.instructionPointer + + // Without "library name" and its "base address" symbolication will not be possible, + // but the presence of this frame in the stack will be still relevant. + let image = crashReport.image(forAddress: stackFrame.instructionPointer) + + self.libraryBaseAddress = image?.imageBaseAddress + + if let imagePath = image?.imageName { + self.libraryName = URL(fileURLWithPath: imagePath).lastPathComponent + } } } diff --git a/Sources/DatadogCrashReporting/PLCrashReporterIntegration/DDCrashReportExporter.swift b/Sources/DatadogCrashReporting/PLCrashReporterIntegration/DDCrashReportExporter.swift index d4737c8ae2..4e243f8c1f 100644 --- a/Sources/DatadogCrashReporting/PLCrashReporterIntegration/DDCrashReportExporter.swift +++ b/Sources/DatadogCrashReporting/PLCrashReporterIntegration/DDCrashReportExporter.swift @@ -150,7 +150,7 @@ internal struct DDCrashReportExporter { return DDCrashReport.BinaryImage( libraryName: image.imageName, - uuid: image.uuid, + uuid: image.uuid ?? unavailable, architecture: image.codeType?.architectureName ?? unavailable, isSystemLibrary: image.isSystemImage, loadAddress: loadAddressHex, diff --git a/Tests/DatadogCrashReportingTests/Mocks.swift b/Tests/DatadogCrashReportingTests/Mocks.swift index 849926897d..de2b8928ed 100644 --- a/Tests/DatadogCrashReportingTests/Mocks.swift +++ b/Tests/DatadogCrashReportingTests/Mocks.swift @@ -252,7 +252,7 @@ extension ThreadInfo { extension BinaryImageInfo { static func mockWith( - uuid: String = .mockAny(), + uuid: String? = .mockAny(), imageName: String = .mockAny(), isSystemImage: Bool = .random(), architectureName: String? = .mockAny(), diff --git a/Tests/DatadogCrashReportingTests/PLCrashReporterIntegration/DDCrashReportExporterTests.swift b/Tests/DatadogCrashReportingTests/PLCrashReporterIntegration/DDCrashReportExporterTests.swift index 9641a0df66..31ac798ab3 100644 --- a/Tests/DatadogCrashReportingTests/PLCrashReporterIntegration/DDCrashReportExporterTests.swift +++ b/Tests/DatadogCrashReportingTests/PLCrashReporterIntegration/DDCrashReportExporterTests.swift @@ -275,6 +275,17 @@ class DDCrashReportExporterTests: XCTestCase { } } + func testExportingBinaryImageWhenUUIDIsUnavailable() { + // Given + crashReport.binaryImages = [.mockWith(uuid: nil)] + + // When + let exportedImages = exporter.export(crashReport).binaryImages + + // Then + XCTAssertEqual(exportedImages.first?.uuid, "???") + } + func testExportingBinaryImageAddressRange() throws { let randomImageLoadAddress: UInt64 = .mockRandom() let randomImageSize: UInt64 = .mockRandom()