2019-10-24 14:49:27 +00:00
|
|
|
|
package native
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"syscall"
|
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
|
|
sys "golang.org/x/sys/unix"
|
|
|
|
|
|
2020-12-14 17:39:01 +00:00
|
|
|
|
"github.com/go-delve/delve/pkg/proc/amd64util"
|
2019-10-24 14:49:27 +00:00
|
|
|
|
)
|
|
|
|
|
|
2020-03-26 12:05:09 +00:00
|
|
|
|
// ptraceGetRegset returns floating point registers of the specified thread
|
2019-10-24 14:49:27 +00:00
|
|
|
|
// using PTRACE.
|
|
|
|
|
// See amd64_linux_fetch_inferior_registers in gdb/amd64-linux-nat.c.html
|
|
|
|
|
// and amd64_supply_xsave in gdb/amd64-tdep.c.html
|
|
|
|
|
// and Section 13.1 (and following) of Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1: Basic Architecture
|
2020-12-14 17:39:01 +00:00
|
|
|
|
func ptraceGetRegset(tid int) (regset amd64util.AMD64Xstate, err error) {
|
2019-10-24 14:49:27 +00:00
|
|
|
|
_, _, err = syscall.Syscall6(syscall.SYS_PTRACE, sys.PTRACE_GETFPREGS, uintptr(tid), uintptr(0), uintptr(unsafe.Pointer(®set.AMD64PtraceFpRegs)), 0, 0)
|
|
|
|
|
if err == syscall.Errno(0) || err == syscall.ENODEV {
|
|
|
|
|
// ignore ENODEV, it just means this CPU doesn't have X87 registers (??)
|
|
|
|
|
err = nil
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 17:39:01 +00:00
|
|
|
|
xstateargs := make([]byte, amd64util.AMD64XstateMaxSize())
|
|
|
|
|
iov := sys.Iovec{Base: &xstateargs[0], Len: uint64(len(xstateargs))}
|
2019-10-24 14:49:27 +00:00
|
|
|
|
_, _, err = syscall.Syscall6(syscall.SYS_PTRACE, sys.PTRACE_GETREGSET, uintptr(tid), _NT_X86_XSTATE, uintptr(unsafe.Pointer(&iov)), 0, 0)
|
|
|
|
|
if err != syscall.Errno(0) {
|
2021-01-29 21:39:33 +00:00
|
|
|
|
if err == syscall.ENODEV || err == syscall.EIO || err == syscall.EINVAL {
|
2019-10-24 14:49:27 +00:00
|
|
|
|
// ignore ENODEV, it just means this CPU or kernel doesn't support XSTATE, see https://github.com/go-delve/delve/issues/1022
|
|
|
|
|
// also ignore EIO, it means that we are running on an old kernel (pre 2.6.34) and PTRACE_GETREGSET is not implemented
|
2021-01-29 21:39:33 +00:00
|
|
|
|
// also ignore EINVAL, it means the kernel itself does not support the NT_X86_XSTATE argument (but does support PTRACE_GETREGSET)
|
2019-10-24 14:49:27 +00:00
|
|
|
|
err = nil
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
} else {
|
|
|
|
|
err = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
regset.Xsave = xstateargs[:iov.Len]
|
2020-12-14 17:39:01 +00:00
|
|
|
|
err = amd64util.AMD64XstateRead(regset.Xsave, false, ®set)
|
2019-10-24 14:49:27 +00:00
|
|
|
|
return
|
2020-03-26 12:05:09 +00:00
|
|
|
|
}
|