
* tests: misc test fixes for go1.14 - math.go is now ambiguous due to changes to the go runtime so specify that we mean our own math.go in _fixtures - go list -m requires vendor-mode to be disabled so pass '-mod=' to it in case user has GOFLAGS=-mod=vendor - update version of go/packages, required to work with go 1.14 (and executed go mod vendor) - Increased goroutine migration in one development version of Go 1.14 revealed a problem with TestCheckpoints in command_test.go and rr_test.go. The tests were always wrong because Restart(checkpoint) doesn't change the current thread but we can't assume that when the checkpoint was taken the current goroutine was running on the same thread. * goversion: update maximum supported version * Makefile: disable testing lldb-server backend on linux with Go 1.14 There seems to be some incompatibility with lldb-server version 6.0.0 on linux and Go 1.14. * proc/gdbserial: better handling of signals - if multiple signals are received simultaneously propagate all of them to the target threads instead of only one. - debugserver will drop an interrupt request if a target thread simultaneously receives a signal, handle this situation. * dwarf/line: normalize backslashes for windows executables Starting with Go 1.14 the compiler sometimes emits backslashes as well as forward slashes in debug_line, normalize everything to / for conformity with the behavior of previous versions. * proc/native: partial support for Windows async preempt mechanism See https://github.com/golang/go/issues/36494 for a description of why full support for 1.14 under windows is problematic. * proc/native: disable Go 1.14 async preemption on Windows See https://github.com/golang/go/issues/36494
175 lines
3.9 KiB
Go
175 lines
3.9 KiB
Go
package native
|
|
|
|
import (
|
|
"errors"
|
|
"syscall"
|
|
|
|
sys "golang.org/x/sys/windows"
|
|
|
|
"github.com/go-delve/delve/pkg/proc"
|
|
"github.com/go-delve/delve/pkg/proc/winutil"
|
|
)
|
|
|
|
// WaitStatus is a synonym for the platform-specific WaitStatus
|
|
type WaitStatus sys.WaitStatus
|
|
|
|
// OSSpecificDetails holds information specific to the Windows
|
|
// operating system / kernel.
|
|
type OSSpecificDetails struct {
|
|
hThread syscall.Handle
|
|
}
|
|
|
|
func (t *Thread) singleStep() error {
|
|
context := winutil.NewCONTEXT()
|
|
context.ContextFlags = _CONTEXT_ALL
|
|
|
|
// Set the processor TRAP flag
|
|
err := _GetThreadContext(t.os.hThread, context)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
context.EFlags |= 0x100
|
|
|
|
err = _SetThreadContext(t.os.hThread, context)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
suspendcnt := 0
|
|
|
|
// If a thread simultaneously hits a breakpoint and is suspended by the Go
|
|
// runtime it will have a suspend count greater than 1 and to actually take
|
|
// a single step we have to resume it multiple times here.
|
|
// We keep a counter of how many times it was suspended so that after
|
|
// single-stepping we can re-suspend it the corrent number of times.
|
|
for {
|
|
n, err := _ResumeThread(t.os.hThread)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
suspendcnt++
|
|
if n == 1 {
|
|
break
|
|
}
|
|
}
|
|
|
|
for {
|
|
var tid, exitCode int
|
|
t.dbp.execPtraceFunc(func() {
|
|
tid, exitCode, err = t.dbp.waitForDebugEvent(waitBlocking | waitSuspendNewThreads)
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if tid == 0 {
|
|
t.dbp.postExit()
|
|
return proc.ErrProcessExited{Pid: t.dbp.pid, Status: exitCode}
|
|
}
|
|
|
|
if t.dbp.os.breakThread == t.ID {
|
|
break
|
|
}
|
|
|
|
t.dbp.execPtraceFunc(func() {
|
|
err = _ContinueDebugEvent(uint32(t.dbp.pid), uint32(t.dbp.os.breakThread), _DBG_CONTINUE)
|
|
})
|
|
}
|
|
|
|
for i := 0; i < suspendcnt; i++ {
|
|
_, err = _SuspendThread(t.os.hThread)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
t.dbp.execPtraceFunc(func() {
|
|
err = _ContinueDebugEvent(uint32(t.dbp.pid), uint32(t.ID), _DBG_CONTINUE)
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Unset the processor TRAP flag
|
|
err = _GetThreadContext(t.os.hThread, context)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
context.EFlags &= ^uint32(0x100)
|
|
|
|
return _SetThreadContext(t.os.hThread, context)
|
|
}
|
|
|
|
func (t *Thread) resume() error {
|
|
var err error
|
|
t.dbp.execPtraceFunc(func() {
|
|
//TODO: Note that we are ignoring the thread we were asked to continue and are continuing the
|
|
//thread that we last broke on.
|
|
err = _ContinueDebugEvent(uint32(t.dbp.pid), uint32(t.ID), _DBG_CONTINUE)
|
|
})
|
|
return err
|
|
}
|
|
|
|
func (t *Thread) Blocked() bool {
|
|
// TODO: Probably incorrect - what are the runtime functions that
|
|
// indicate blocking on Windows?
|
|
regs, err := t.Registers(false)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
pc := regs.PC()
|
|
fn := t.BinInfo().PCToFunc(pc)
|
|
if fn == nil {
|
|
return false
|
|
}
|
|
switch fn.Name {
|
|
case "runtime.kevent", "runtime.usleep":
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Stopped returns whether the thread is stopped at the operating system
|
|
// level. On windows this always returns true.
|
|
func (t *Thread) Stopped() bool {
|
|
return true
|
|
}
|
|
|
|
func (t *Thread) WriteMemory(addr uintptr, data []byte) (int, error) {
|
|
if t.dbp.exited {
|
|
return 0, proc.ErrProcessExited{Pid: t.dbp.pid}
|
|
}
|
|
if len(data) == 0 {
|
|
return 0, nil
|
|
}
|
|
var count uintptr
|
|
err := _WriteProcessMemory(t.dbp.os.hProcess, addr, &data[0], uintptr(len(data)), &count)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return int(count), nil
|
|
}
|
|
|
|
var ErrShortRead = errors.New("short read")
|
|
|
|
func (t *Thread) ReadMemory(buf []byte, addr uintptr) (int, error) {
|
|
if t.dbp.exited {
|
|
return 0, proc.ErrProcessExited{Pid: t.dbp.pid}
|
|
}
|
|
if len(buf) == 0 {
|
|
return 0, nil
|
|
}
|
|
var count uintptr
|
|
err := _ReadProcessMemory(t.dbp.os.hProcess, addr, &buf[0], uintptr(len(buf)), &count)
|
|
if err == nil && count != uintptr(len(buf)) {
|
|
err = ErrShortRead
|
|
}
|
|
return int(count), err
|
|
}
|
|
|
|
func (t *Thread) restoreRegisters(savedRegs proc.Registers) error {
|
|
return _SetThreadContext(t.os.hThread, savedRegs.(*winutil.AMD64Registers).Context)
|
|
}
|