github.com/undoio/delve@v1.9.0/pkg/proc/native/ptrace_linux.go (about)

     1  package native
     2  
     3  import (
     4  	"syscall"
     5  
     6  	sys "golang.org/x/sys/unix"
     7  )
     8  
     9  // ptraceAttach executes the sys.PtraceAttach call.
    10  func ptraceAttach(pid int) error {
    11  	return sys.PtraceAttach(pid)
    12  }
    13  
    14  // ptraceDetach calls ptrace(PTRACE_DETACH).
    15  func ptraceDetach(tid, sig int) error {
    16  	_, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PTRACE_DETACH, uintptr(tid), 1, uintptr(sig), 0, 0)
    17  	if err != syscall.Errno(0) {
    18  		return err
    19  	}
    20  	return nil
    21  }
    22  
    23  // ptraceCont executes ptrace PTRACE_CONT
    24  func ptraceCont(tid, sig int) error {
    25  	return sys.PtraceCont(tid, sig)
    26  }
    27  
    28  // ptraceSingleStep executes ptrace PTRACE_SINGLESTEP
    29  func ptraceSingleStep(pid, sig int) error {
    30  	_, _, e1 := sys.Syscall6(sys.SYS_PTRACE, uintptr(sys.PTRACE_SINGLESTEP), uintptr(pid), uintptr(0), uintptr(sig), 0, 0)
    31  	if e1 != 0 {
    32  		return e1
    33  	}
    34  	return nil
    35  }
    36  
    37  // remoteIovec is like golang.org/x/sys/unix.Iovec but uses uintptr for the
    38  // base field instead of *byte so that we can use it with addresses that
    39  // belong to the target process.
    40  type remoteIovec struct {
    41  	base uintptr
    42  	len  uintptr
    43  }