Skip to content

Commit

Permalink
Addresses can use full UInt64
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Oct 19, 2022
1 parent 36231d6 commit dda79ae
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 11 deletions.
12 changes: 6 additions & 6 deletions Sources/Meter/CallStackTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public struct Binary: Codable, Hashable {

public struct Frame: Codable, Hashable {
public var binaryUUID: UUID?
public var offsetIntoBinaryTextSegment: Int?
public var offsetIntoBinaryTextSegment: UInt64?
public var sampleCount: Int?
public var binaryName: String?
public var address: Int
public var address: UInt64
public var subFrames: [Frame]?
public var symbolInfo: [SymbolInfo]?

public init(binaryUUID: UUID? = nil, offsetIntoBinaryTextSegment: Int? = nil, sampleCount: Int? = nil, binaryName: String? = nil, address: Int, subFrames: [Frame]?, symbolInfo: [SymbolInfo]? = nil) {
public init(binaryUUID: UUID? = nil, offsetIntoBinaryTextSegment: UInt64? = nil, sampleCount: Int? = nil, binaryName: String? = nil, address: UInt64, subFrames: [Frame]?, symbolInfo: [SymbolInfo]? = nil) {
self.binaryUUID = binaryUUID
self.offsetIntoBinaryTextSegment = offsetIntoBinaryTextSegment
self.sampleCount = sampleCount
Expand Down Expand Up @@ -82,12 +82,12 @@ public struct Frame: Codable, Hashable {
return nil
}

let loadAddress = withOffsetAsLoadAddress ? offset : address - offset
let loadAddress = withOffsetAsLoadAddress ? offset : address - offset
let size = address - loadAddress + 1

return Binary(uuid: uuid,
loadAddress: loadAddress,
approximateSize: size,
loadAddress: Int(loadAddress),
approximateSize: Int(size),
name: binaryName)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Meter/DlfcnSymbolicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ extension DlfcnSymbolicator: Symbolicator {
return []
}

let loadAddress = Int(bitPattern: loadedImage.header)
let loadAddress = Int(bitPattern: loadedImage.header)
let relativeAddress = address - target.loadAddress
let processAddress = loadAddress + relativeAddress

Expand Down
5 changes: 3 additions & 2 deletions Sources/Meter/ExceptionInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ extension NSException {
}

let subFrames = [frame].compactMap({ $0 })
let offset = binary.map { UInt64($0.loadAddress) }

frame = Frame(binaryUUID: binary?.uuid,
offsetIntoBinaryTextSegment: binary?.loadAddress,
offsetIntoBinaryTextSegment: offset,
binaryName: binary?.name,
address: addr,
address: UInt64(addr),
subFrames: subFrames,
symbolInfo: [info.symbolInfo])
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Meter/Symbolicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public extension Symbolicator {
let subframes = frame.subFrames ?? []
let symSubframes = subframes.map({ symbolicate(frame: $0, withOffsetAsLoadAddress: withOffsetAsLoadAddress) })

let addr = frame.address
let addr = Int(frame.address)
let target = frame.symbolicationTarget(withOffsetAsLoadAddress: withOffsetAsLoadAddress)
let info = target.map({ symbolicate(address: addr, in: $0) }) ?? []

Expand Down
45 changes: 45 additions & 0 deletions Tests/MeterTests/DiagnosticTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,49 @@ class DiagnosticTests: XCTestCase {
XCTAssertEqual(frames[31].address, 6795285912)
#endif
}

func testVeryLargeAddress() throws {
let value = """
{
"timeStampEnd" : "2022-10-07 14:41:00",
"timeStampBegin" : "2022-10-07 14:41:00",
"hangDiagnostics" : [
{
"version" : "1.0.0",
"callStackTree" : {
"callStacks" : [
{
"threadAttributed" : true,
"callStackRootFrames" : [
{
"binaryUUID" : "1A111731-DB37-3138-BB6A-4F8CC7551374",
"offsetIntoBinaryTextSegment" : 239784,
"sampleCount" : 434,
"subFrames" : [],
"binaryName" : "kernel.release.t8103",
"address" : 18446741874824079528
}
]
}
],
"callStackPerThread" : true
},
"diagnosticMetaData" : {
"appBuildVersion" : "1",
"appVersion" : "1.0.0",
"regionFormat" : "US",
"hangDuration" : "7 sec",
"osVersion" : "macOS 13.0 (22A5358e)",
"deviceType" : "Macmini9,1",
"bundleIdentifier" : "x.y.x",
"platformArchitecture" : "arm64e"
}
}
]
}
"""
let data = try XCTUnwrap(value.data(using: .utf8))

XCTAssertNoThrow(try DiagnosticPayload.from(data: data))
}
}
2 changes: 1 addition & 1 deletion Tests/MeterTests/SymbolicationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ final class SymbolicationTests: XCTestCase {
let symbolInfoB = SymbolInfo(symbol: "symbolB", offset: 10)
let symbolInfoA = SymbolInfo(symbol: "symbolA", offset: 10)

let mockResults = [frameB.address: [symbolInfoB], frameA.address: [symbolInfoA]]
let mockResults = [Int(frameB.address): [symbolInfoB], Int(frameA.address): [symbolInfoA]]

let mockSymbolicator = MockSymbolicator { addr, _ in
return mockResults[addr]!
Expand Down

0 comments on commit dda79ae

Please sign in to comment.