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

     1  package native
     2  
     3  import (
     4  	"syscall"
     5  	"unsafe"
     6  
     7  	sys "golang.org/x/sys/unix"
     8  
     9  	"github.com/undoio/delve/pkg/proc/amd64util"
    10  )
    11  
    12  // ptraceGetRegset returns floating point registers of the specified thread
    13  // using PTRACE.
    14  // See amd64_linux_fetch_inferior_registers in gdb/amd64-linux-nat.c.html
    15  // and amd64_supply_xsave in gdb/amd64-tdep.c.html
    16  // and Section 13.1 (and following) of Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1: Basic Architecture
    17  func ptraceGetRegset(tid int) (regset amd64util.AMD64Xstate, err error) {
    18  	_, _, err = syscall.Syscall6(syscall.SYS_PTRACE, sys.PTRACE_GETFPREGS, uintptr(tid), uintptr(0), uintptr(unsafe.Pointer(&regset.AMD64PtraceFpRegs)), 0, 0)
    19  	if err == syscall.Errno(0) || err == syscall.ENODEV {
    20  		// ignore ENODEV, it just means this CPU doesn't have X87 registers (??)
    21  		err = nil
    22  	}
    23  
    24  	xstateargs := make([]byte, amd64util.AMD64XstateMaxSize())
    25  	iov := sys.Iovec{Base: &xstateargs[0], Len: uint64(len(xstateargs))}
    26  	_, _, err = syscall.Syscall6(syscall.SYS_PTRACE, sys.PTRACE_GETREGSET, uintptr(tid), _NT_X86_XSTATE, uintptr(unsafe.Pointer(&iov)), 0, 0)
    27  	if err != syscall.Errno(0) {
    28  		if err == syscall.ENODEV || err == syscall.EIO || err == syscall.EINVAL {
    29  			// ignore ENODEV, it just means this CPU or kernel doesn't support XSTATE, see https://github.com/go-delve/delve/issues/1022
    30  			// also ignore EIO, it means that we are running on an old kernel (pre 2.6.34) and PTRACE_GETREGSET is not implemented
    31  			// also ignore EINVAL, it means the kernel itself does not support the NT_X86_XSTATE argument (but does support PTRACE_GETREGSET)
    32  			err = nil
    33  		}
    34  		return
    35  	} else {
    36  		err = nil
    37  	}
    38  
    39  	regset.Xsave = xstateargs[:iov.Len]
    40  	err = amd64util.AMD64XstateRead(regset.Xsave, false, &regset)
    41  	return
    42  }