Skip to content

Commit

Permalink
Merge pull request #724 from DataDog/maxep/RUMM-1883/report-invalid-i…
Browse files Browse the repository at this point in the history
…mages

RUMM-1883 Report binary image with no UUID
  • Loading branch information
maxep authored Jan 19, 2022
2 parents 744191c + d635cdf commit 85f9785
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Tests/DatadogCrashReportingTests/Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 85f9785

Please sign in to comment.