From 58de1f7c85dbe585cda52f11b1e85812414f7f8f Mon Sep 17 00:00:00 2001 From: Paul Sbarra Date: Sun, 25 Jan 2015 17:16:18 -0600 Subject: [PATCH] migrate to go.sys subrepository As of go version 1.4 the standard library syscall package is "locked down" and code outside of the standard library is recommended to migrate to the go.sys subrepository. Reference: https://golang.org/s/go1.4-syscall --- client/cli/cli.go | 6 +++--- goreadline/goreadline.go | 6 +++--- proctl/breakpoints_linux_amd64.go | 3 ++- proctl/proctl.go | 35 ++++++++++++++++--------------- proctl/threads.go | 8 +++---- proctl/threads_linux_amd64.go | 14 ++++++------- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/client/cli/cli.go b/client/cli/cli.go index d1304bb0..1576f7a3 100644 --- a/client/cli/cli.go +++ b/client/cli/cli.go @@ -2,12 +2,12 @@ package cli import ( "fmt" + sys "golang.org/x/sys/unix" "io" "os" "os/exec" "os/signal" "strings" - "syscall" "github.com/derekparker/delve/command" "github.com/derekparker/delve/goreadline" @@ -49,7 +49,7 @@ func Run(run bool, pid int, args []string) { } ch := make(chan os.Signal) - signal.Notify(ch, syscall.SIGINT) + signal.Notify(ch, sys.SIGINT) go func() { for _ = range ch { if dbp.Running() { @@ -105,7 +105,7 @@ func handleExit(dbp *proctl.DebuggedProcess, status int) { } fmt.Println("Detaching from process...") - err := syscall.PtraceDetach(dbp.Process.Pid) + err := sys.PtraceDetach(dbp.Process.Pid) if err != nil { die(2, "Could not detach", err) } diff --git a/goreadline/goreadline.go b/goreadline/goreadline.go index f5c7eebc..0a1d5e55 100644 --- a/goreadline/goreadline.go +++ b/goreadline/goreadline.go @@ -11,20 +11,20 @@ package goreadline */ import "C" import ( + sys "golang.org/x/sys/unix" "os" "os/signal" - "syscall" "unsafe" ) func init() { C.rl_catch_sigwinch = 0 c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGWINCH) + signal.Notify(c, sys.SIGWINCH) go func() { for sig := range c { switch sig { - case syscall.SIGWINCH: + case sys.SIGWINCH: Resize() default: diff --git a/proctl/breakpoints_linux_amd64.go b/proctl/breakpoints_linux_amd64.go index 441baa79..1b1af237 100644 --- a/proctl/breakpoints_linux_amd64.go +++ b/proctl/breakpoints_linux_amd64.go @@ -16,6 +16,7 @@ import "C" import ( "fmt" + sys "golang.org/x/sys/unix" "syscall" "unsafe" ) @@ -44,7 +45,7 @@ func (bpe BreakPointExistsError) Error() string { } func PtracePokeUser(tid int, off, addr uintptr) error { - _, _, err := syscall.Syscall6(syscall.SYS_PTRACE, syscall.PTRACE_POKEUSR, uintptr(tid), uintptr(off), uintptr(addr), 0, 0) + _, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PTRACE_POKEUSR, uintptr(tid), uintptr(off), uintptr(addr), 0, 0) if err != syscall.Errno(0) { return err } diff --git a/proctl/proctl.go b/proctl/proctl.go index 1abc0ce9..d9a75aac 100644 --- a/proctl/proctl.go +++ b/proctl/proctl.go @@ -6,6 +6,7 @@ import ( "debug/dwarf" "debug/gosym" "fmt" + sys "golang.org/x/sys/unix" "os" "os/exec" "path/filepath" @@ -122,8 +123,8 @@ func (dbp *DebuggedProcess) AttachThread(tid int) (*ThreadContext, error) { return thread, nil } - err := syscall.PtraceAttach(tid) - if err != nil && err != syscall.EPERM { + err := sys.PtraceAttach(tid) + if err != nil && err != sys.EPERM { // Do not return err if err == EPERM, // we may already be tracing this thread due to // PTRACE_O_TRACECLONE. We will surely blow up later @@ -200,7 +201,7 @@ func (dbp *DebuggedProcess) RequestManualStop() { if stopped(th.Id) { continue } - syscall.Tgkill(dbp.Pid, th.Id, syscall.SIGSTOP) + sys.Tgkill(dbp.Pid, th.Id, sys.SIGSTOP) } dbp.running = false } @@ -234,7 +235,7 @@ func (dbp *DebuggedProcess) ClearByLocation(loc string) (*BreakPoint, error) { } // Returns the status of the current main thread context. -func (dbp *DebuggedProcess) Status() *syscall.WaitStatus { +func (dbp *DebuggedProcess) Status() *sys.WaitStatus { return dbp.CurrentThread.Status } @@ -313,7 +314,7 @@ func (dbp *DebuggedProcess) Next() error { } err := th.Next() - if err != nil && err != syscall.ESRCH { + if err != nil && err != sys.ESRCH { return err } } @@ -389,7 +390,7 @@ func (pe ProcessExitedError) Error() string { return fmt.Sprintf("process %d has exited", pe.pid) } -func trapWait(dbp *DebuggedProcess, pid int) (int, *syscall.WaitStatus, error) { +func trapWait(dbp *DebuggedProcess, pid int) (int, *sys.WaitStatus, error) { for { wpid, status, err := wait(pid, 0) if err != nil { @@ -404,17 +405,17 @@ func trapWait(dbp *DebuggedProcess, pid int) (int, *syscall.WaitStatus, error) { if status.Exited() && wpid == dbp.Pid { return -1, status, ProcessExitedError{wpid} } - if status.StopSignal() == syscall.SIGTRAP && status.TrapCause() == syscall.PTRACE_EVENT_CLONE { + if status.StopSignal() == sys.SIGTRAP && status.TrapCause() == sys.PTRACE_EVENT_CLONE { err = addNewThread(dbp, wpid) if err != nil { return -1, nil, err } continue } - if status.StopSignal() == syscall.SIGTRAP { + if status.StopSignal() == sys.SIGTRAP { return wpid, status, nil } - if status.StopSignal() == syscall.SIGSTOP && dbp.halt { + if status.StopSignal() == sys.SIGSTOP && dbp.halt { return -1, nil, ManualStopError{} } } @@ -477,11 +478,11 @@ func stopTheWorld(dbp *DebuggedProcess) error { if stopped(th.Id) { continue } - err := syscall.Tgkill(dbp.Pid, th.Id, syscall.SIGSTOP) + err := sys.Tgkill(dbp.Pid, th.Id, sys.SIGSTOP) if err != nil { return err } - pid, _, err := wait(th.Id, syscall.WNOHANG) + pid, _, err := wait(th.Id, sys.WNOHANG) if err != nil { return fmt.Errorf("wait err %s %d", err, pid) } @@ -493,7 +494,7 @@ func stopTheWorld(dbp *DebuggedProcess) error { func addNewThread(dbp *DebuggedProcess, pid int) error { // A traced thread has cloned a new thread, grab the pid and // add it to our list of traced threads. - msg, err := syscall.PtraceGetEventMsg(pid) + msg, err := sys.PtraceGetEventMsg(pid) if err != nil { return fmt.Errorf("could not get event message: %s", err) } @@ -504,12 +505,12 @@ func addNewThread(dbp *DebuggedProcess, pid int) error { return err } - err = syscall.PtraceCont(int(msg), 0) + err = sys.PtraceCont(int(msg), 0) if err != nil { return fmt.Errorf("could not continue new thread %d %s", msg, err) } - err = syscall.PtraceCont(pid, 0) + err = sys.PtraceCont(pid, 0) if err != nil { return fmt.Errorf("could not continue stopped thread %d %s", pid, err) } @@ -517,8 +518,8 @@ func addNewThread(dbp *DebuggedProcess, pid int) error { return nil } -func wait(pid, options int) (int, *syscall.WaitStatus, error) { - var status syscall.WaitStatus - wpid, err := syscall.Wait4(pid, &status, syscall.WALL|options, nil) +func wait(pid, options int) (int, *sys.WaitStatus, error) { + var status sys.WaitStatus + wpid, err := sys.Wait4(pid, &status, sys.WALL|options, nil) return wpid, &status, err } diff --git a/proctl/threads.go b/proctl/threads.go index 543410da..049736de 100644 --- a/proctl/threads.go +++ b/proctl/threads.go @@ -3,7 +3,7 @@ package proctl import ( "encoding/binary" "fmt" - "syscall" + sys "golang.org/x/sys/unix" "github.com/derekparker/delve/dwarf/frame" ) @@ -13,7 +13,7 @@ import ( type ThreadContext struct { Id int Process *DebuggedProcess - Status *syscall.WaitStatus + Status *sys.WaitStatus } type Registers interface { @@ -91,7 +91,7 @@ func (thread *ThreadContext) Continue() error { } } - return syscall.PtraceCont(thread.Id, 0) + return sys.PtraceCont(thread.Id, 0) } // Single steps this thread a single instruction, ensuring that @@ -122,7 +122,7 @@ func (thread *ThreadContext) Step() (err error) { }() } - err = syscall.PtraceSingleStep(thread.Id) + err = sys.PtraceSingleStep(thread.Id) if err != nil { return fmt.Errorf("step failed: %s", err.Error()) } diff --git a/proctl/threads_linux_amd64.go b/proctl/threads_linux_amd64.go index 618689d0..a508d934 100644 --- a/proctl/threads_linux_amd64.go +++ b/proctl/threads_linux_amd64.go @@ -1,9 +1,9 @@ package proctl -import "syscall" +import sys "golang.org/x/sys/unix" type Regs struct { - regs *syscall.PtraceRegs + regs *sys.PtraceRegs } func (r *Regs) PC() uint64 { @@ -16,12 +16,12 @@ func (r *Regs) SP() uint64 { func (r *Regs) SetPC(tid int, pc uint64) error { r.regs.SetPC(pc) - return syscall.PtraceSetRegs(tid, r.regs) + return sys.PtraceSetRegs(tid, r.regs) } func registers(tid int) (Registers, error) { - var regs syscall.PtraceRegs - err := syscall.PtraceGetRegs(tid, ®s) + var regs sys.PtraceRegs + err := sys.PtraceGetRegs(tid, ®s) if err != nil { return nil, err } @@ -29,11 +29,11 @@ func registers(tid int) (Registers, error) { } func writeMemory(tid int, addr uintptr, data []byte) (int, error) { - return syscall.PtracePokeData(tid, addr, data) + return sys.PtracePokeData(tid, addr, data) } func readMemory(tid int, addr uintptr, data []byte) (int, error) { - return syscall.PtracePeekData(tid, addr, data) + return sys.PtracePeekData(tid, addr, data) } func clearHardwareBreakpoint(reg, tid int) error {