Skip to content

Commit bc07600

Browse files
authored
Merge pull request #81000 from compnerd/reorder
SwiftInspectLinux: re-order initialization
2 parents 9218458 + 0b953ad commit bc07600

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)