Skip to content

Commit 6138992

Browse files
committed
[Backtracing] Fix a couple of Linux specific issues.
Linux gives the main thread a name based on the process name, and also we need to tolerate an extra slash on the `<compiler-generated>` filename for some reason. rdar://121430255
1 parent b85bf05 commit 6138992

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

stdlib/public/libexec/swift-backtrace/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ Generate a backtrace for the parent process.
606606
while fd < 0 && (errno == EEXIST || errno == EINTR) {
607607
if errno != EINTR {
608608
ndx += 1
609+
filename = "\(args.outputPath)/\(name)-\(pid)-\(now.tv_sec).\(now.tv_nsec)-\(ndx).\(ext)"
609610
}
610-
filename = "\(args.outputPath)/\(name)-\(pid)-\(now.tv_sec).\(now.tv_nsec)-\(ndx).\(ext)"
611611
fd = open(filename, O_RDWR|O_CREAT|O_EXCL, 0o644)
612612
}
613613

test/Backtracing/JSON.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ struct Crash {
8585

8686
// CHECK-NEXT: "threads": [
8787
// CHECK-NEXT: {
88-
// CHECK-NEXT: "crashed": true,
88+
89+
// On Linux there's a name here
90+
91+
// CHECK: "crashed": true,
8992
// CHECK-NEXT: "registers": {
9093
// CHECK-NEXT: "{{.*}}": "0x{{[0-9a-f]+}}",
9194

@@ -180,7 +183,7 @@ struct Crash {
180183
// CHECK-NEXT: "description": "static Crash.$main() + [[OFFSET]]",
181184
// CHECK-NEXT: "image": "Crash",
182185
// CHECK-NEXT: "sourceLocation": {
183-
// CHECK-NEXT: "file": "{{/?}}<compiler-generated>",
186+
// CHECK-NEXT: "file": "{{/*}}<compiler-generated>",
184187
// CHECK-NEXT: "line": 0,
185188
// CHECK-NEXT: "column": 0
186189
// CHECK-NEXT: }
@@ -218,8 +221,8 @@ struct Crash {
218221
// Maybe multiple images before this one
219222

220223
// CHECK: "name": "Crash",
221-
// CHECK-NEXT: "buildId": "{{([0-9a-f][0-9a-f])+}}",
222-
// CHECK-NEXT: "path": "{{.*}}/Crash",
224+
// "buildId": ... is optional
225+
// CHECK: "path": "{{.*}}/Crash",
223226
// CHECK-NEXT: "baseAddress": "0x{{[0-9a-f]+}}",
224227
// CHECK-NEXT: "endOfText": "0x{{[0-9a-f]+}}"
225228
// CHECK-NEXT: }

test/Backtracing/JSONAsync.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ struct JSONAsync {
166166
// CHECK-NEXT: "offset": [[OFFSET:[0-9]+]],
167167
// CHECK-NEXT: "image": "JSONAsync",
168168
// CHECK-NEXT: "sourceLocation": {
169-
// CHECK-NEXT: "file": "{{/?}}<compiler-generated>",
169+
// CHECK-NEXT: "file": "{{/*}}<compiler-generated>",
170170
// CHECK-NEXT: "line": 0,
171171
// CHECK-NEXT: "column": 0
172172
// CHECK-NEXT: }
@@ -179,7 +179,7 @@ struct JSONAsync {
179179
// CHECK-NEXT: "offset": [[OFFSET:[0-9]+]],
180180
// CHECK-NEXT: "image": "JSONAsync",
181181
// CHECK-NEXT: "sourceLocation": {
182-
// CHECK-NEXT: "file": "{{/?}}<compiler-generated>",
182+
// CHECK-NEXT: "file": "{{/*}}<compiler-generated>",
183183
// CHECK-NEXT: "line": 0,
184184
// CHECK-NEXT: "column": 0
185185
// CHECK-NEXT: }
@@ -206,8 +206,8 @@ struct JSONAsync {
206206
// Maybe multiple images before this one
207207

208208
// CHECK: "name": "JSONAsync",
209-
// CHECK-NEXT: "buildId": "{{([0-9a-f][0-9a-f])+}}",
210-
// CHECK-NEXT: "path": "{{.*}}/JSONAsync",
209+
// "buildId": ... is optional
210+
// CHECK: "path": "{{.*}}/JSONAsync",
211211
// CHECK-NEXT: "baseAddress": "0x{{[0-9a-f]+}}",
212212
// CHECK-NEXT: "endOfText": "0x{{[0-9a-f]+}}"
213213
// CHECK-NEXT: }

0 commit comments

Comments
 (0)