Skip to content

Commit

Permalink
Fix symbolicating arm64e
Browse files Browse the repository at this point in the history
  • Loading branch information
noahsmartin committed Sep 26, 2024
1 parent 9f4bd57 commit eb084e8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Xcode select
run: sudo xcode-select -s '/Applications/Xcode_15.2.app/Contents/Developer'
run: sudo xcode-select -s '/Applications/Xcode_15.4.app/Contents/Developer'
- name: Show destinations
run: xcodebuild -scheme ETTrace -showdestinations
- name: Build ETTrace for iOS Simulator
Expand All @@ -28,7 +28,7 @@ jobs:
run: xcodebuild build -scheme ETTrace -sdk appletvos -destination 'generic/platform=tvOS' ONLY_ACTIVE_ARCH=NO
- name: Build ETTrace for tvOS Simulator
run: xcodebuild build -scheme ETTrace -sdk appletvsimulator -destination 'generic/platform=tvOS Simulator' ONLY_ACTIVE_ARCH=NO
- name: Build ETTrace for visionOS Simulator
run: xcodebuild build -scheme ETTrace -sdk xrsimulator -destination 'generic/platform=visionOS Simulator' ONLY_ACTIVE_ARCH=NO
- name: Build ETTrace for visionOS
run: xcodebuild build -scheme ETTrace -sdk xros -destination 'generic/platform=visionOS' ONLY_ACTIVE_ARCH=NO
- name: Build ETTrace for visionOS Simulator
run: xcodebuild build -scheme ETTrace -sdk xrsimulator -destination 'generic/platform=visionOS Simulator' ONLY_ACTIVE_ARCH=NO
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Xcode select
run: sudo xcode-select -s '/Applications/Xcode_15.2.app/Contents/Developer'
run: sudo xcode-select -s '/Applications/Xcode_15.4.app/Contents/Developer'
- name: Setup Signing Certificate
uses: apple-actions/import-codesign-certs@v2
with:
Expand Down
35 changes: 28 additions & 7 deletions ETTrace/Symbolicator/Symbolicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class StackSymbolicator {
group.enter()
queue.async {
if let dSym = self.dsymForLib(lib) {
let addrToSym = Self.addrToSymForBinary(dSym, addrs)
let addrToSym = Self.addrToSymForBinary(dSym, self.archForBinary(dSym), addrs)
stateLock.lock()
libToAddrToSym[lib.path] = addrToSym
stateLock.unlock()
Expand Down Expand Up @@ -145,15 +145,28 @@ public class StackSymbolicator {
return addrs
}

private static func addrToSymForBinary(_ binary: String, _ addrs: Set<UInt64>) -> [UInt64: String] {
private func archForBinary(_ binary: String) -> String {
let archsStr = try? processWithOutput("/usr/bin/lipo", args: ["-archs", binary])
let archs = archsStr?.split(separator: " ").map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } ?? []
let trimmedArch = self.arch.trimmingCharacters(in: .whitespacesAndNewlines)
if archs.contains(trimmedArch) {
return trimmedArch
}
if trimmedArch == "arm64e" && archs.contains("arm64") {
return "arm64"
}
return archs.first ?? trimmedArch
}

private static func addrToSymForBinary(_ binary: String, _ arch: String, _ addrs: Set<UInt64>) -> [UInt64: String] {
let addrsArray = Array(addrs)
let addrsFile = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)!.path

let addition: UInt64 = 0x1000000 // atos can fail when the load address is 0, so add extra
let strs = addrsArray.map { String($0 + addition, radix: 16) }
try! strs.joined(separator: "\n").write(toFile: addrsFile, atomically: true, encoding: .utf8)

let symsStr = try? processWithOutput("/usr/bin/atos", args: ["-l", String(addition, radix: 16), "-o", binary, "-f", addrsFile])
let symsStr = try? processWithOutput("/usr/bin/atos", args: ["-l", String(addition, radix: 16), "-o", binary, "-f", addrsFile, "-arch", arch])

let syms = symsStr!.split(separator: "\n").enumerated().map { (idx, sym) -> (UInt64, String?) in
let trimmed = sym.trimmingCharacters(in: .whitespacesAndNewlines)
Expand Down Expand Up @@ -189,7 +202,11 @@ public class StackSymbolicator {
formatSymbolCache[sym] = result
return result
}


private static func fileIfExists(_ path: String) -> String? {
FileManager.default.fileExists(atPath: path) ? path : nil
}

private func dsymForLib(_ lib: LoadedLibrary) -> String? {
let libPath = lib.path

Expand Down Expand Up @@ -222,9 +239,13 @@ public class StackSymbolicator {
// Get symbols from device support dir
let searchFolder = "\(FileManager.default.homeDirectoryForCurrentUser.path)/Library/Developer/Xcode/iOS DeviceSupport"
let directories = (try? FileManager.default.contentsOfDirectory(atPath: searchFolder)) ?? []

for folder in directories where folder.contains(osBuild) && folder.hasSuffix(arch){
return "\(searchFolder)/\(folder)/Symbols\(libPath)"

// First look for matching os and arch, then just matching os
for folder in directories where folder.contains(osBuild) && folder.hasSuffix(arch) {
return Self.fileIfExists("\(searchFolder)/\(folder)/Symbols\(libPath)")
}
for folder in directories where folder.contains(osBuild) {
return Self.fileIfExists("\(searchFolder)/\(folder)/Symbols\(libPath)")
}
return nil
} else {
Expand Down

0 comments on commit eb084e8

Please sign in to comment.