Skip to content

Commit 4ad370a

Browse files
committed
[Backtracing][WIP] Add some debug to track down problem in Linux CI.
1 parent 7fcd48a commit 4ad370a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

stdlib/public/Backtracing/Backtrace.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,10 @@ public struct Backtrace: CustomStringConvertible, Sendable {
472472
path = "/proc/self/maps"
473473
}
474474

475+
print("Capturing images by reading \(path)")
476+
475477
guard let procMaps = readString(from: path) else {
478+
print("Failed to read \(path)")
476479
return []
477480
}
478481

@@ -486,6 +489,9 @@ public struct Backtrace: CustomStringConvertible, Sendable {
486489
/#
487490
let lines = procMaps.split(separator: "\n")
488491

492+
print("Read \(lines.count) from \(path):")
493+
print(procMaps)
494+
489495
// Find all the mapped files and get high/low ranges
490496
var mappedFiles: [Substring:AddressRange] = [:]
491497
for line in lines {
@@ -547,6 +553,7 @@ public struct Backtrace: CustomStringConvertible, Sendable {
547553
var endOfText: Address = range.low
548554

549555
if let image = try? Elf32Image(source: subSource) {
556+
print("\(path) is an ELF32 image")
550557
theUUID = image.uuid
551558

552559
for hdr in image.programHeaders {
@@ -556,6 +563,7 @@ public struct Backtrace: CustomStringConvertible, Sendable {
556563
}
557564
}
558565
} else if let image = try? Elf64Image(source: subSource) {
566+
print("\(path) is an ELF64 image")
559567
theUUID = image.uuid
560568

561569
for hdr in image.programHeaders {
@@ -566,6 +574,7 @@ public struct Backtrace: CustomStringConvertible, Sendable {
566574
}
567575
} else {
568576
// Not a valid ELF image
577+
print("\(path) is not an ELF image")
569578
continue
570579
}
571580

stdlib/public/Backtracing/SymbolicatedBacktrace.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,17 @@ public struct SymbolicatedBacktrace: CustomStringConvertible {
473473
// number programs once per frame, whereas we could just run them once
474474
// for all the addresses we're interested in.
475475

476+
print("Images: \(theImages)")
477+
476478
for frame in backtrace.frames {
477479
let address = FileImageSource.Address(frame.adjustedProgramCounter)
478480
if let imageNdx = theImages.firstIndex(
479481
where: { address >= $0.baseAddress
480482
&& address < $0.endOfText }
481483
) {
484+
print("\(hex(address)): checking image \(imageNdx) \(theImages[imageNdx].name)")
485+
print("\(hex(address)): path is \(theImages[imageNdx].path)")
486+
482487
let relativeAddress = address - FileImageSource.Address(theImages[imageNdx].baseAddress)
483488
var symbol: Symbol = Symbol(imageIndex: imageNdx,
484489
imageName: theImages[imageNdx].name,
@@ -491,16 +496,20 @@ public struct SymbolicatedBacktrace: CustomStringConvertible {
491496
if elf32Image == nil && elf64Image == nil {
492497
if let source = try? FileImageSource(path: theImages[imageNdx].path) {
493498
if let elfImage = try? Elf32Image(source: source) {
499+
print("\(hex(address)): found an ELF32 image")
494500
elf32Image = elfImage
495501
elf32Cache[imageNdx] = elfImage
496502
} else if let elfImage = try? Elf64Image(source: source) {
503+
print("\(hex(address)): found an ELF64 image")
497504
elf64Image = elfImage
498505
elf64Cache[imageNdx] = elfImage
499506
}
500507
}
501508
}
502509

503510
if let theSymbol = elf32Image?.lookupSymbol(address: relativeAddress) {
511+
print("\(hex(address)): found \(theSymbol.name) in ELF32")
512+
504513
var location = try? elf32Image!.sourceLocation(for: relativeAddress)
505514

506515
for inline in elf32Image!.inlineCallSites(at: relativeAddress) {
@@ -524,6 +533,8 @@ public struct SymbolicatedBacktrace: CustomStringConvertible {
524533
offset: theSymbol.offset,
525534
sourceLocation: location)
526535
} else if let theSymbol = elf64Image?.lookupSymbol(address: relativeAddress) {
536+
print("\(hex(address)): found \(theSymbol.name) in ELF64")
537+
527538
var location = try? elf64Image!.sourceLocation(for: relativeAddress)
528539

529540
for inline in elf64Image!.inlineCallSites(at: relativeAddress) {
@@ -547,6 +558,8 @@ public struct SymbolicatedBacktrace: CustomStringConvertible {
547558
offset: theSymbol.offset,
548559
sourceLocation: location)
549560
} else {
561+
print("\(hex(address)): symbol lookup failed")
562+
550563
symbol = Symbol(imageIndex: imageNdx,
551564
imageName: theImages[imageNdx].name,
552565
rawName: "<unknown>",
@@ -558,6 +571,8 @@ public struct SymbolicatedBacktrace: CustomStringConvertible {
558571
continue
559572
}
560573

574+
print("\(hex(address)): address not found in image")
575+
561576
frames.append(Frame(captured: frame, symbol: nil))
562577
}
563578
#else

0 commit comments

Comments
 (0)