提交 a19bca22 编写于 作者: A Alessandro Arzilli 提交者: Derek Parker

proc/native/windows: inline PtraceDetach delete ptrace_windows.go (#903)

Windows doesn't actually have ptrace.

Fixes #778
上级 50f63823
......@@ -370,19 +370,7 @@ func (dbp *Process) FindBreakpoint(pc uint64) (*proc.Breakpoint, bool) {
}
// Returns a new Process struct.
func initializeDebugProcess(dbp *Process, path string, attach bool) (*Process, error) {
if attach {
var err error
dbp.execPtraceFunc(func() { err = PtraceAttach(dbp.pid) })
if err != nil {
return nil, err
}
_, _, err = dbp.wait(dbp.pid, 0)
if err != nil {
return nil, err
}
}
func initializeDebugProcess(dbp *Process, path string) (*Process, error) {
process, err := os.FindProcess(dbp.pid)
if err != nil {
return nil, err
......
......@@ -116,7 +116,7 @@ func Launch(cmd []string, wd string) (*Process, error) {
}
dbp.os.initialized = true
dbp, err = initializeDebugProcess(dbp, argv0Go, false)
dbp, err = initializeDebugProcess(dbp, argv0Go)
if err != nil {
return nil, err
}
......@@ -142,7 +142,17 @@ func Attach(pid int) (*Process, error) {
dbp.os.initialized = true
return initializeDebugProcess(dbp, "", true)
var err error
dbp.execPtraceFunc(func() { err = PtraceAttach(dbp.pid) })
if err != nil {
return nil, err
}
_, _, err = dbp.wait(dbp.pid, 0)
if err != nil {
return nil, err
}
return initializeDebugProcess(dbp, "")
}
// Kill kills the process.
......
......@@ -73,12 +73,24 @@ func Launch(cmd []string, wd string) (*Process, error) {
if err != nil {
return nil, fmt.Errorf("waiting for target execve failed: %s", err)
}
return initializeDebugProcess(dbp, process.Path, false)
return initializeDebugProcess(dbp, process.Path)
}
// Attach to an existing process with the given PID.
func Attach(pid int) (*Process, error) {
return initializeDebugProcess(New(pid), "", true)
dbp := New(pid)
var err error
dbp.execPtraceFunc(func() { err = PtraceAttach(dbp.pid) })
if err != nil {
return nil, err
}
_, _, err = dbp.wait(dbp.pid, 0)
if err != nil {
return nil, err
}
return initializeDebugProcess(dbp, "")
}
// Kill kills the target process.
......
......@@ -114,7 +114,7 @@ func newDebugProcess(dbp *Process, exepath string) (*Process, error) {
return nil, err
}
return initializeDebugProcess(dbp, exepath, false)
return initializeDebugProcess(dbp, exepath)
}
// findExePath searches for process pid, and returns its executable path.
......@@ -451,7 +451,7 @@ func (dbp *Process) detach(kill bool) error {
}
}
}
return PtraceDetach(dbp.pid, 0)
return _DebugActiveProcessStop(uint32(dbp.pid))
}
func killProcess(pid int) error {
......
package native
import (
"fmt"
)
func PtraceAttach(pid int) error {
return fmt.Errorf("not implemented: PtraceAttach")
}
func PtraceDetach(tid, sig int) error {
return _DebugActiveProcessStop(uint32(tid))
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册