From 5ece8d3b6964f38731bf8dd00d5aa8f3ecd58f67 Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Tue, 2 Dec 2014 10:15:51 -0600 Subject: [PATCH] Use allm info to attach to existing threads This remove reliance on the procfs for figuring out what threads are already active when we attach to a running process. The allm linked list will be present to matter what OS we're on, whereas procfs will not be present everywhere. This is the first in a series of steps to support more platforms. --- proctl/proctl_linux_amd64.go | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/proctl/proctl_linux_amd64.go b/proctl/proctl_linux_amd64.go index 78cef7b5..ba012233 100644 --- a/proctl/proctl_linux_amd64.go +++ b/proctl/proctl_linux_amd64.go @@ -80,7 +80,25 @@ func (bpe BreakPointExistsError) Error() string { } func Attach(pid int) (*DebuggedProcess, error) { - return newDebugProcess(pid, true) + dbp, err := newDebugProcess(pid, true) + if err != nil { + return nil, err + } + // Attach to all currently active threads. + allm, err := dbp.CurrentThread.AllM() + if err != nil { + return nil, err + } + for _, m := range allm { + if m.procid == 0 { + continue + } + _, err := dbp.AttachThread(m.procid) + if err != nil { + return nil, err + } + } + return dbp, nil } func Launch(cmd []string) (*DebuggedProcess, error) { @@ -135,14 +153,6 @@ func newDebugProcess(pid int, attach bool) (*DebuggedProcess, error) { return nil, err } - // Attach to all currently active threads. - for _, tid := range threadIds(pid) { - _, err := dbp.AttachThread(tid) - if err != nil { - return nil, err - } - } - return &dbp, nil }