Skip to content

SwiftInspectLinux: re-order initialization #81000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions tools/swift-inspect/Sources/SwiftInspectLinux/PTrace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,25 @@ public struct PTrace: ~Copyable {
// process by calling cont().
// NOTE: clients must use withPTracedProcess instead of direct initialization.
fileprivate init(_ pid: pid_t) throws {
guard ptrace_attach(pid) != -1 else {
throw PTraceError.operationFailure(PTRACE_ATTACH, pid: pid)
self.pid = pid

guard ptrace_attach(self.pid) != -1 else {
throw PTraceError.operationFailure(PTRACE_ATTACH, pid: self.pid)
}

while true {
var status: CInt = 0
let result = waitpid(pid, &status, 0)
let result = waitpid(self.pid, &status, 0)
if result == -1 {
if get_errno() == EINTR { continue }
throw PTraceError.waitFailure(pid: pid)
throw PTraceError.waitFailure(pid: self.pid)
}

precondition(pid == result, "waitpid returned unexpected value \(result)")
precondition(self.pid == result,
"waitpid returned unexpected value \(result)")

if wIfStopped(status) { break }
}

self.pid = pid
}

deinit { _ = ptrace_detach(self.pid) }
Expand Down