
Previously either the terminal client or the debugger service would either lock main goroutine to a thread or provide a locked goroutine to run _all_ DebuggedProcess functions in. This is unnecessary because only ptrace functions need to be run from the same thread that originated the PT_ATTACH request. Here we use a specific thread-locked goroutine to service any ptrace request. That goroutine is also responsible for the initial spawning / attaching of the process, since it must be responsible for the PT_ATTACH request.
38 lines
665 B
Go
38 lines
665 B
Go
package proc
|
|
|
|
import sys "golang.org/x/sys/unix"
|
|
|
|
type Regs struct {
|
|
regs *sys.PtraceRegs
|
|
}
|
|
|
|
func (r *Regs) PC() uint64 {
|
|
return r.regs.PC()
|
|
}
|
|
|
|
func (r *Regs) SP() uint64 {
|
|
return r.regs.Rsp
|
|
}
|
|
|
|
func (r *Regs) CX() uint64 {
|
|
return r.regs.Rcx
|
|
}
|
|
|
|
func (r *Regs) SetPC(thread *Thread, pc uint64) (err error) {
|
|
r.regs.SetPC(pc)
|
|
thread.dbp.execPtraceFunc(func() { err = sys.PtraceSetRegs(thread.Id, r.regs) })
|
|
return
|
|
}
|
|
|
|
func registers(thread *Thread) (Registers, error) {
|
|
var (
|
|
regs sys.PtraceRegs
|
|
err error
|
|
)
|
|
thread.dbp.execPtraceFunc(func() { err = sys.PtraceGetRegs(thread.Id, ®s) })
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &Regs{®s}, nil
|
|
}
|