2017-04-21 06:55:53 +00:00
|
|
|
package native
|
2016-01-15 05:26:54 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-02-09 06:24:14 +00:00
|
|
|
"unsafe"
|
2017-04-17 21:13:00 +00:00
|
|
|
|
2017-04-21 06:55:53 +00:00
|
|
|
"github.com/derekparker/delve/pkg/proc"
|
2018-10-18 08:15:36 +00:00
|
|
|
"github.com/derekparker/delve/pkg/proc/winutil"
|
2016-01-15 05:26:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SetPC sets the RIP register to the value specified by `pc`.
|
2018-05-04 17:31:45 +00:00
|
|
|
func (thread *Thread) SetPC(pc uint64) error {
|
2018-10-18 08:15:36 +00:00
|
|
|
context := winutil.NewCONTEXT()
|
2016-02-17 10:23:17 +00:00
|
|
|
context.ContextFlags = _CONTEXT_ALL
|
2016-01-15 05:26:54 +00:00
|
|
|
|
2016-02-17 10:23:17 +00:00
|
|
|
err := _GetThreadContext(thread.os.hThread, context)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-01-15 05:26:54 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 10:23:17 +00:00
|
|
|
context.Rip = pc
|
2016-01-15 05:26:54 +00:00
|
|
|
|
2016-02-17 10:23:17 +00:00
|
|
|
return _SetThreadContext(thread.os.hThread, context)
|
2016-01-15 05:26:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-04 17:31:45 +00:00
|
|
|
// SetSP sets the RSP register to the value specified by `sp`.
|
|
|
|
func (thread *Thread) SetSP(sp uint64) error {
|
2018-10-18 08:15:36 +00:00
|
|
|
context := winutil.NewCONTEXT()
|
2018-05-04 17:31:45 +00:00
|
|
|
context.ContextFlags = _CONTEXT_ALL
|
|
|
|
|
|
|
|
err := _GetThreadContext(thread.os.hThread, context)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
context.Rsp = sp
|
|
|
|
|
|
|
|
return _SetThreadContext(thread.os.hThread, context)
|
|
|
|
}
|
|
|
|
|
2018-07-31 16:32:30 +00:00
|
|
|
func (thread *Thread) SetDX(dx uint64) error {
|
2018-10-18 08:15:36 +00:00
|
|
|
context := winutil.NewCONTEXT()
|
2018-07-31 16:32:30 +00:00
|
|
|
context.ContextFlags = _CONTEXT_ALL
|
|
|
|
|
|
|
|
err := _GetThreadContext(thread.os.hThread, context)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
context.Rdx = dx
|
|
|
|
|
|
|
|
return _SetThreadContext(thread.os.hThread, context)
|
|
|
|
}
|
|
|
|
|
2017-04-21 06:55:53 +00:00
|
|
|
func registers(thread *Thread, floatingPoint bool) (proc.Registers, error) {
|
2018-10-18 08:15:36 +00:00
|
|
|
context := winutil.NewCONTEXT()
|
2016-01-15 05:26:54 +00:00
|
|
|
|
2016-02-17 10:23:17 +00:00
|
|
|
context.ContextFlags = _CONTEXT_ALL
|
|
|
|
err := _GetThreadContext(thread.os.hThread, context)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-01-15 05:26:54 +00:00
|
|
|
}
|
|
|
|
|
2016-02-09 06:24:14 +00:00
|
|
|
var threadInfo _THREAD_BASIC_INFORMATION
|
2016-02-17 10:23:17 +00:00
|
|
|
status := _NtQueryInformationThread(thread.os.hThread, _ThreadBasicInformation, uintptr(unsafe.Pointer(&threadInfo)), uint32(unsafe.Sizeof(threadInfo)), nil)
|
2016-02-09 06:24:14 +00:00
|
|
|
if !_NT_SUCCESS(status) {
|
2016-02-17 10:23:17 +00:00
|
|
|
return nil, fmt.Errorf("NtQueryInformationThread failed: it returns 0x%x", status)
|
2016-01-15 05:26:54 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 08:15:36 +00:00
|
|
|
return winutil.NewAMD64Registers(context, uint64(threadInfo.TebBaseAddress), floatingPoint), nil
|
2016-01-15 05:26:54 +00:00
|
|
|
}
|