Skip to content

Commit 0b953ad

Browse files
committed
SwiftInspectLinux: re-order initialization
It seems that a recent change to the compiler will now optimize the initializer and then the SIL verifier will fail due to the unintialized member when the initializer is throwing and will never return without initializing the member unless the initialization fails.
1 parent f7bf701 commit 0b953ad

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

tools/swift-inspect/Sources/SwiftInspectLinux/PTrace.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,25 @@ public struct PTrace: ~Copyable {
3333
// process by calling cont().
3434
// NOTE: clients must use withPTracedProcess instead of direct initialization.
3535
fileprivate init(_ pid: pid_t) throws {
36-
guard ptrace_attach(pid) != -1 else {
37-
throw PTraceError.operationFailure(PTRACE_ATTACH, pid: pid)
36+
self.pid = pid
37+
38+
guard ptrace_attach(self.pid) != -1 else {
39+
throw PTraceError.operationFailure(PTRACE_ATTACH, pid: self.pid)
3840
}
3941

4042
while true {
4143
var status: CInt = 0
42-
let result = waitpid(pid, &status, 0)
44+
let result = waitpid(self.pid, &status, 0)
4345
if result == -1 {
4446
if get_errno() == EINTR { continue }
45-
throw PTraceError.waitFailure(pid: pid)
47+
throw PTraceError.waitFailure(pid: self.pid)
4648
}
4749

48-
precondition(pid == result, "waitpid returned unexpected value \(result)")
50+
precondition(self.pid == result,
51+
"waitpid returned unexpected value \(result)")
4952

5053
if wIfStopped(status) { break }
5154
}
52-
53-
self.pid = pid
5455
}
5556

5657
deinit { _ = ptrace_detach(self.pid) }

0 commit comments

Comments
 (0)