diff --git a/stdlib/public/Backtracing/Backtrace.swift b/stdlib/public/Backtracing/Backtrace.swift index 3481a5e61e95b..52ac292250333 100644 --- a/stdlib/public/Backtracing/Backtrace.swift +++ b/stdlib/public/Backtracing/Backtrace.swift @@ -472,7 +472,10 @@ public struct Backtrace: CustomStringConvertible, Sendable { path = "/proc/self/maps" } + print("Capturing images by reading \(path)") + guard let procMaps = readString(from: path) else { + print("Failed to read \(path)") return [] } @@ -486,6 +489,9 @@ public struct Backtrace: CustomStringConvertible, Sendable { /# let lines = procMaps.split(separator: "\n") + print("Read \(lines.count) from \(path):") + print(procMaps) + // Find all the mapped files and get high/low ranges var mappedFiles: [Substring:AddressRange] = [:] for line in lines { @@ -547,6 +553,7 @@ public struct Backtrace: CustomStringConvertible, Sendable { var endOfText: Address = range.low if let image = try? Elf32Image(source: subSource) { + print("\(path) is an ELF32 image") theUUID = image.uuid for hdr in image.programHeaders { @@ -556,6 +563,7 @@ public struct Backtrace: CustomStringConvertible, Sendable { } } } else if let image = try? Elf64Image(source: subSource) { + print("\(path) is an ELF64 image") theUUID = image.uuid for hdr in image.programHeaders { @@ -566,6 +574,7 @@ public struct Backtrace: CustomStringConvertible, Sendable { } } else { // Not a valid ELF image + print("\(path) is not an ELF image") continue } diff --git a/stdlib/public/Backtracing/SymbolicatedBacktrace.swift b/stdlib/public/Backtracing/SymbolicatedBacktrace.swift index bc5e7c4f5aaba..694e245ab9f4d 100644 --- a/stdlib/public/Backtracing/SymbolicatedBacktrace.swift +++ b/stdlib/public/Backtracing/SymbolicatedBacktrace.swift @@ -473,12 +473,17 @@ public struct SymbolicatedBacktrace: CustomStringConvertible { // number programs once per frame, whereas we could just run them once // for all the addresses we're interested in. + print("Images: \(theImages)") + for frame in backtrace.frames { let address = FileImageSource.Address(frame.adjustedProgramCounter) if let imageNdx = theImages.firstIndex( where: { address >= $0.baseAddress && address < $0.endOfText } ) { + print("\(hex(address)): checking image \(imageNdx) \(theImages[imageNdx].name)") + print("\(hex(address)): path is \(theImages[imageNdx].path)") + let relativeAddress = address - FileImageSource.Address(theImages[imageNdx].baseAddress) var symbol: Symbol = Symbol(imageIndex: imageNdx, imageName: theImages[imageNdx].name, @@ -491,9 +496,11 @@ public struct SymbolicatedBacktrace: CustomStringConvertible { if elf32Image == nil && elf64Image == nil { if let source = try? FileImageSource(path: theImages[imageNdx].path) { if let elfImage = try? Elf32Image(source: source) { + print("\(hex(address)): found an ELF32 image") elf32Image = elfImage elf32Cache[imageNdx] = elfImage } else if let elfImage = try? Elf64Image(source: source) { + print("\(hex(address)): found an ELF64 image") elf64Image = elfImage elf64Cache[imageNdx] = elfImage } @@ -501,6 +508,8 @@ public struct SymbolicatedBacktrace: CustomStringConvertible { } if let theSymbol = elf32Image?.lookupSymbol(address: relativeAddress) { + print("\(hex(address)): found \(theSymbol.name) in ELF32") + var location = try? elf32Image!.sourceLocation(for: relativeAddress) for inline in elf32Image!.inlineCallSites(at: relativeAddress) { @@ -524,6 +533,8 @@ public struct SymbolicatedBacktrace: CustomStringConvertible { offset: theSymbol.offset, sourceLocation: location) } else if let theSymbol = elf64Image?.lookupSymbol(address: relativeAddress) { + print("\(hex(address)): found \(theSymbol.name) in ELF64") + var location = try? elf64Image!.sourceLocation(for: relativeAddress) for inline in elf64Image!.inlineCallSites(at: relativeAddress) { @@ -547,6 +558,8 @@ public struct SymbolicatedBacktrace: CustomStringConvertible { offset: theSymbol.offset, sourceLocation: location) } else { + print("\(hex(address)): symbol lookup failed") + symbol = Symbol(imageIndex: imageNdx, imageName: theImages[imageNdx].name, rawName: "", @@ -558,6 +571,8 @@ public struct SymbolicatedBacktrace: CustomStringConvertible { continue } + print("\(hex(address)): address not found in image") + frames.append(Frame(captured: frame, symbol: nil)) } #else