Skip to content

Commit

Permalink
Match behavior for recent OSes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Dec 13, 2022
1 parent 4fdce4a commit 6d39f09
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Sources/Meter/ExceptionInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,32 @@ extension NSException {

var frame: Frame? = nil

// both greating the DynamicLibraryInfo and calling makeBinary are
// both creating the DynamicLibraryInfo and calling makeBinary are
// expensive. Use a simple cache to avoid one of those operations.

for addr in addresses.reversed() {
let info = DynamicLibraryInfo(address: addr) ?? DynamicLibraryInfo()

let binary = binaryMap[info.loadAddress] ?? info.makeBinary()
let loadAddress = binary?.loadAddress ?? info.loadAddress

if binary != nil && info.loadAddress > 0 {
binaryMap[info.loadAddress] = binary
}

let subFrames = [frame].compactMap({ $0 })

// have to account for the change in recent platforms to make this an actual offset
let offset: Int

if #available(macOS 13, iOS 16, *) {
offset = addr - loadAddress
} else {
offset = loadAddress
}

frame = Frame(binaryUUID: binary?.uuid,
offsetIntoBinaryTextSegment: binary?.loadAddress,
offsetIntoBinaryTextSegment: offset,
binaryName: binary?.name,
address: UInt64(addr),
subFrames: subFrames,
Expand Down

0 comments on commit 6d39f09

Please sign in to comment.