Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix symbolicating arm64e #91

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ on:

jobs:
build:
runs-on: macos-14
runs-on: macos-15

steps:
- 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_16.0.app/Contents/Developer'
- name: Show destinations
run: xcodebuild -scheme ETTrace -showdestinations
- name: Build ETTrace for iOS Simulator
Expand All @@ -31,4 +31,4 @@ jobs:
- 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
run: xcodebuild build -scheme ETTrace -sdk xrsimulator -destination 'generic/platform=visionOS Simulator' ONLY_ACTIVE_ARCH=NO
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ on:

jobs:
release:
runs-on: macos-14
runs-on: macos-15

steps:
- 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
Loading