Skip to content

Commit effea5c

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

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

stdlib/public/Backtracing/Backtrace.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,12 @@ public struct Backtrace: CustomStringConvertible, Sendable {
492492
if let match = try? mapRegex.wholeMatch(in: line) {
493493
let path = stripWhitespace(match.pathname)
494494
if match.inode == "0" || path == "" {
495+
print("[A] \(line)")
495496
continue
496497
}
497498
guard let start = Address(match.start, radix: 16),
498499
let end = Address(match.end, radix: 16) else {
500+
print("[B] \(line)")
499501
continue
500502
}
501503

@@ -506,9 +508,13 @@ public struct Backtrace: CustomStringConvertible, Sendable {
506508
mappedFiles[path] = AddressRange(low: start,
507509
high: end)
508510
}
511+
} else {
512+
print("[C] \(line)")
509513
}
510514
}
511515

516+
print("Mapped files: \(mappedFiles)")
517+
512518
// Look for ELF headers in the process' memory
513519
typealias Source = MemoryImageSource<M>
514520
let source = Source(with: reader)
@@ -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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ public struct SymbolicatedBacktrace: CustomStringConvertible {
479479
where: { address >= $0.baseAddress
480480
&& address < $0.endOfText }
481481
) {
482+
482483
let relativeAddress = address - FileImageSource.Address(theImages[imageNdx].baseAddress)
483484
var symbol: Symbol = Symbol(imageIndex: imageNdx,
484485
imageName: theImages[imageNdx].name,

test/Backtracing/Images.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -parse-as-library -g -Onone -o %t/Images
3+
// RUN: %target-codesign %t/Images
4+
// RUN: %target-run %t/Images | %FileCheck %s
5+
6+
// UNSUPPORTED: use_os_stdlib
7+
// UNSUPPORTED: back_deployment_runtime
8+
// REQUIRES: executable_test
9+
// REQUIRES: backtracing
10+
// REQUIRES: OS=linux-gnu
11+
12+
import _Backtracing
13+
14+
func kablam() {
15+
kerpow()
16+
}
17+
18+
func kerpow() {
19+
whap()
20+
}
21+
22+
func whap() {
23+
zonk()
24+
}
25+
26+
func zonk() {
27+
splat()
28+
}
29+
30+
func splat() {
31+
pow()
32+
}
33+
34+
func pow() {
35+
let images = Backtrace.captureImages()
36+
37+
print(images)
38+
39+
// CHECK: frobble
40+
}
41+
42+
@main
43+
struct Images {
44+
static func main() {
45+
kablam()
46+
}
47+
}

0 commit comments

Comments
 (0)