File: ptrace_linux.go

package info (click to toggle)
delve 1.24.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,092 kB
  • sloc: ansic: 111,943; sh: 169; asm: 141; makefile: 43; python: 23
file content (43 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package native

import (
	"syscall"

	sys "golang.org/x/sys/unix"
)

// ptraceAttach executes the sys.PtraceAttach call.
func ptraceAttach(pid int) error {
	return sys.PtraceAttach(pid)
}

// ptraceDetach calls ptrace(PTRACE_DETACH).
func ptraceDetach(tid, sig int) error {
	_, _, err := sys.Syscall6(sys.SYS_PTRACE, sys.PTRACE_DETACH, uintptr(tid), 1, uintptr(sig), 0, 0)
	if err != syscall.Errno(0) {
		return err
	}
	return nil
}

// ptraceCont executes ptrace PTRACE_CONT
func ptraceCont(tid, sig int) error {
	return sys.PtraceCont(tid, sig)
}

// ptraceSingleStep executes ptrace PTRACE_SINGLESTEP
func ptraceSingleStep(pid, sig int) error {
	_, _, e1 := sys.Syscall6(sys.SYS_PTRACE, uintptr(sys.PTRACE_SINGLESTEP), uintptr(pid), uintptr(0), uintptr(sig), 0, 0)
	if e1 != 0 {
		return e1
	}
	return nil
}

// remoteIovec is like golang.org/x/sys/unix.Iovec but uses uintptr for the
// base field instead of *byte so that we can use it with addresses that
// belong to the target process.
type remoteIovec struct {
	base uintptr
	len  uintptr
}