
Changes implementations of proc.Registers interface and the op.DwarfRegisters struct so that floating point registers can be loaded only when they are needed. Removes the floatingPoint parameter from proc.Thread.Registers. This accomplishes three things: 1. it simplifies the proc.Thread.Registers interface 2. it makes it impossible to accidentally create a broken set of saved registers or of op.DwarfRegisters by accidentally calling Registers(false) 3. it improves general performance of Delve by avoiding to load floating point registers as much as possible Floating point registers are loaded under two circumstances: 1. When the Slice method is called with floatingPoint == true 2. When the Copy method is called Benchmark before: BenchmarkConditionalBreakpoints-4 1 4327350142 ns/op Benchmark after: BenchmarkConditionalBreakpoints-4 1 3852642917 ns/op Updates #1549
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package native
|
|
|
|
import (
|
|
"fmt"
|
|
"unsafe"
|
|
|
|
"github.com/go-delve/delve/pkg/proc"
|
|
"github.com/go-delve/delve/pkg/proc/winutil"
|
|
)
|
|
|
|
// SetPC sets the RIP register to the value specified by `pc`.
|
|
func (thread *nativeThread) SetPC(pc uint64) error {
|
|
context := winutil.NewCONTEXT()
|
|
context.ContextFlags = _CONTEXT_ALL
|
|
|
|
err := _GetThreadContext(thread.os.hThread, context)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
context.Rip = pc
|
|
|
|
return _SetThreadContext(thread.os.hThread, context)
|
|
}
|
|
|
|
// SetSP sets the RSP register to the value specified by `sp`.
|
|
func (thread *nativeThread) SetSP(sp uint64) error {
|
|
context := winutil.NewCONTEXT()
|
|
context.ContextFlags = _CONTEXT_ALL
|
|
|
|
err := _GetThreadContext(thread.os.hThread, context)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
context.Rsp = sp
|
|
|
|
return _SetThreadContext(thread.os.hThread, context)
|
|
}
|
|
|
|
func (thread *nativeThread) SetDX(dx uint64) error {
|
|
context := winutil.NewCONTEXT()
|
|
context.ContextFlags = _CONTEXT_ALL
|
|
|
|
err := _GetThreadContext(thread.os.hThread, context)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
context.Rdx = dx
|
|
|
|
return _SetThreadContext(thread.os.hThread, context)
|
|
}
|
|
|
|
func registers(thread *nativeThread) (proc.Registers, error) {
|
|
context := winutil.NewCONTEXT()
|
|
|
|
context.ContextFlags = _CONTEXT_ALL
|
|
err := _GetThreadContext(thread.os.hThread, context)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var threadInfo _THREAD_BASIC_INFORMATION
|
|
status := _NtQueryInformationThread(thread.os.hThread, _ThreadBasicInformation, uintptr(unsafe.Pointer(&threadInfo)), uint32(unsafe.Sizeof(threadInfo)), nil)
|
|
if !_NT_SUCCESS(status) {
|
|
return nil, fmt.Errorf("NtQueryInformationThread failed: it returns 0x%x", status)
|
|
}
|
|
|
|
return winutil.NewAMD64Registers(context, uint64(threadInfo.TebBaseAddress)), nil
|
|
}
|