mirror of
https://github.com/go-delve/delve.git
synced 2025-10-30 02:07:58 +08:00
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
This commit is contained in:
committed by
Hashrocket Workstation
parent
0d08380555
commit
58de1f7c85
@ -2,12 +2,12 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
sys "golang.org/x/sys/unix"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/derekparker/delve/command"
|
"github.com/derekparker/delve/command"
|
||||||
"github.com/derekparker/delve/goreadline"
|
"github.com/derekparker/delve/goreadline"
|
||||||
@ -49,7 +49,7 @@ func Run(run bool, pid int, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch := make(chan os.Signal)
|
ch := make(chan os.Signal)
|
||||||
signal.Notify(ch, syscall.SIGINT)
|
signal.Notify(ch, sys.SIGINT)
|
||||||
go func() {
|
go func() {
|
||||||
for _ = range ch {
|
for _ = range ch {
|
||||||
if dbp.Running() {
|
if dbp.Running() {
|
||||||
@ -105,7 +105,7 @@ func handleExit(dbp *proctl.DebuggedProcess, status int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Detaching from process...")
|
fmt.Println("Detaching from process...")
|
||||||
err := syscall.PtraceDetach(dbp.Process.Pid)
|
err := sys.PtraceDetach(dbp.Process.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
die(2, "Could not detach", err)
|
die(2, "Could not detach", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,20 +11,20 @@ package goreadline
|
|||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
sys "golang.org/x/sys/unix"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
C.rl_catch_sigwinch = 0
|
C.rl_catch_sigwinch = 0
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, syscall.SIGWINCH)
|
signal.Notify(c, sys.SIGWINCH)
|
||||||
go func() {
|
go func() {
|
||||||
for sig := range c {
|
for sig := range c {
|
||||||
switch sig {
|
switch sig {
|
||||||
case syscall.SIGWINCH:
|
case sys.SIGWINCH:
|
||||||
Resize()
|
Resize()
|
||||||
default:
|
default:
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import "C"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
sys "golang.org/x/sys/unix"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
@ -44,7 +45,7 @@ func (bpe BreakPointExistsError) Error() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func PtracePokeUser(tid int, off, addr uintptr) error {
|
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) {
|
if err != syscall.Errno(0) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import (
|
|||||||
"debug/dwarf"
|
"debug/dwarf"
|
||||||
"debug/gosym"
|
"debug/gosym"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
sys "golang.org/x/sys/unix"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -122,8 +123,8 @@ func (dbp *DebuggedProcess) AttachThread(tid int) (*ThreadContext, error) {
|
|||||||
return thread, nil
|
return thread, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := syscall.PtraceAttach(tid)
|
err := sys.PtraceAttach(tid)
|
||||||
if err != nil && err != syscall.EPERM {
|
if err != nil && err != sys.EPERM {
|
||||||
// Do not return err if err == EPERM,
|
// Do not return err if err == EPERM,
|
||||||
// we may already be tracing this thread due to
|
// we may already be tracing this thread due to
|
||||||
// PTRACE_O_TRACECLONE. We will surely blow up later
|
// PTRACE_O_TRACECLONE. We will surely blow up later
|
||||||
@ -200,7 +201,7 @@ func (dbp *DebuggedProcess) RequestManualStop() {
|
|||||||
if stopped(th.Id) {
|
if stopped(th.Id) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
syscall.Tgkill(dbp.Pid, th.Id, syscall.SIGSTOP)
|
sys.Tgkill(dbp.Pid, th.Id, sys.SIGSTOP)
|
||||||
}
|
}
|
||||||
dbp.running = false
|
dbp.running = false
|
||||||
}
|
}
|
||||||
@ -234,7 +235,7 @@ func (dbp *DebuggedProcess) ClearByLocation(loc string) (*BreakPoint, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns the status of the current main thread context.
|
// 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
|
return dbp.CurrentThread.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,7 +314,7 @@ func (dbp *DebuggedProcess) Next() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := th.Next()
|
err := th.Next()
|
||||||
if err != nil && err != syscall.ESRCH {
|
if err != nil && err != sys.ESRCH {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -389,7 +390,7 @@ func (pe ProcessExitedError) Error() string {
|
|||||||
return fmt.Sprintf("process %d has exited", pe.pid)
|
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 {
|
for {
|
||||||
wpid, status, err := wait(pid, 0)
|
wpid, status, err := wait(pid, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -404,17 +405,17 @@ func trapWait(dbp *DebuggedProcess, pid int) (int, *syscall.WaitStatus, error) {
|
|||||||
if status.Exited() && wpid == dbp.Pid {
|
if status.Exited() && wpid == dbp.Pid {
|
||||||
return -1, status, ProcessExitedError{wpid}
|
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)
|
err = addNewThread(dbp, wpid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, nil, err
|
return -1, nil, err
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if status.StopSignal() == syscall.SIGTRAP {
|
if status.StopSignal() == sys.SIGTRAP {
|
||||||
return wpid, status, nil
|
return wpid, status, nil
|
||||||
}
|
}
|
||||||
if status.StopSignal() == syscall.SIGSTOP && dbp.halt {
|
if status.StopSignal() == sys.SIGSTOP && dbp.halt {
|
||||||
return -1, nil, ManualStopError{}
|
return -1, nil, ManualStopError{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -477,11 +478,11 @@ func stopTheWorld(dbp *DebuggedProcess) error {
|
|||||||
if stopped(th.Id) {
|
if stopped(th.Id) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err := syscall.Tgkill(dbp.Pid, th.Id, syscall.SIGSTOP)
|
err := sys.Tgkill(dbp.Pid, th.Id, sys.SIGSTOP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pid, _, err := wait(th.Id, syscall.WNOHANG)
|
pid, _, err := wait(th.Id, sys.WNOHANG)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("wait err %s %d", err, pid)
|
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 {
|
func addNewThread(dbp *DebuggedProcess, pid int) error {
|
||||||
// A traced thread has cloned a new thread, grab the pid and
|
// A traced thread has cloned a new thread, grab the pid and
|
||||||
// add it to our list of traced threads.
|
// add it to our list of traced threads.
|
||||||
msg, err := syscall.PtraceGetEventMsg(pid)
|
msg, err := sys.PtraceGetEventMsg(pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not get event message: %s", err)
|
return fmt.Errorf("could not get event message: %s", err)
|
||||||
}
|
}
|
||||||
@ -504,12 +505,12 @@ func addNewThread(dbp *DebuggedProcess, pid int) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = syscall.PtraceCont(int(msg), 0)
|
err = sys.PtraceCont(int(msg), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not continue new thread %d %s", msg, err)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("could not continue stopped thread %d %s", pid, err)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func wait(pid, options int) (int, *syscall.WaitStatus, error) {
|
func wait(pid, options int) (int, *sys.WaitStatus, error) {
|
||||||
var status syscall.WaitStatus
|
var status sys.WaitStatus
|
||||||
wpid, err := syscall.Wait4(pid, &status, syscall.WALL|options, nil)
|
wpid, err := sys.Wait4(pid, &status, sys.WALL|options, nil)
|
||||||
return wpid, &status, err
|
return wpid, &status, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package proctl
|
|||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"syscall"
|
sys "golang.org/x/sys/unix"
|
||||||
|
|
||||||
"github.com/derekparker/delve/dwarf/frame"
|
"github.com/derekparker/delve/dwarf/frame"
|
||||||
)
|
)
|
||||||
@ -13,7 +13,7 @@ import (
|
|||||||
type ThreadContext struct {
|
type ThreadContext struct {
|
||||||
Id int
|
Id int
|
||||||
Process *DebuggedProcess
|
Process *DebuggedProcess
|
||||||
Status *syscall.WaitStatus
|
Status *sys.WaitStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
type Registers interface {
|
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
|
// 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 {
|
if err != nil {
|
||||||
return fmt.Errorf("step failed: %s", err.Error())
|
return fmt.Errorf("step failed: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
package proctl
|
package proctl
|
||||||
|
|
||||||
import "syscall"
|
import sys "golang.org/x/sys/unix"
|
||||||
|
|
||||||
type Regs struct {
|
type Regs struct {
|
||||||
regs *syscall.PtraceRegs
|
regs *sys.PtraceRegs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Regs) PC() uint64 {
|
func (r *Regs) PC() uint64 {
|
||||||
@ -16,12 +16,12 @@ func (r *Regs) SP() uint64 {
|
|||||||
|
|
||||||
func (r *Regs) SetPC(tid int, pc uint64) error {
|
func (r *Regs) SetPC(tid int, pc uint64) error {
|
||||||
r.regs.SetPC(pc)
|
r.regs.SetPC(pc)
|
||||||
return syscall.PtraceSetRegs(tid, r.regs)
|
return sys.PtraceSetRegs(tid, r.regs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func registers(tid int) (Registers, error) {
|
func registers(tid int) (Registers, error) {
|
||||||
var regs syscall.PtraceRegs
|
var regs sys.PtraceRegs
|
||||||
err := syscall.PtraceGetRegs(tid, ®s)
|
err := sys.PtraceGetRegs(tid, ®s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -29,11 +29,11 @@ func registers(tid int) (Registers, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func writeMemory(tid int, addr uintptr, data []byte) (int, 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) {
|
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 {
|
func clearHardwareBreakpoint(reg, tid int) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user