delve/proc/threads_linux.go

88 lines
2.0 KiB
Go
Raw Normal View History

2015-06-12 19:49:23 +00:00
package proc
2015-01-14 02:37:10 +00:00
import (
"fmt"
sys "golang.org/x/sys/unix"
)
// Not actually used, but necessary
// to be defined.
type OSSpecificDetails struct {
registers sys.PtraceRegs
}
2015-01-14 02:37:10 +00:00
func (t *Thread) halt() (err error) {
err = sys.Tgkill(t.dbp.Pid, t.Id, sys.SIGSTOP)
2015-01-14 02:37:10 +00:00
if err != nil {
err = fmt.Errorf("halt err %s on thread %d", err, t.Id)
return
2015-01-14 02:37:10 +00:00
}
_, _, err = t.dbp.wait(t.Id, 0)
2015-01-14 02:37:10 +00:00
if err != nil {
err = fmt.Errorf("wait err %s on thread %d", err, t.Id)
return
2015-01-14 02:37:10 +00:00
}
return
}
func (thread *Thread) stopped() bool {
state := status(thread.Id, thread.dbp.comm)
return state == STATUS_TRACE_STOP
2015-01-14 02:37:10 +00:00
}
func (t *Thread) resume() (err error) {
t.running = true
t.dbp.execPtraceFunc(func() { err = PtraceCont(t.Id, 0) })
return
2015-01-14 02:37:10 +00:00
}
func (t *Thread) singleStep() (err error) {
t.dbp.execPtraceFunc(func() { err = sys.PtraceSingleStep(t.Id) })
2015-02-27 23:11:13 +00:00
if err != nil {
2015-01-14 02:37:10 +00:00
return err
}
_, _, err = t.dbp.wait(t.Id, 0)
2015-01-14 02:37:10 +00:00
return err
}
2015-06-12 19:51:23 +00:00
func (t *Thread) blocked() bool {
2015-04-23 15:40:33 +00:00
pc, _ := t.PC()
fn := t.dbp.goSymTable.PCToFunc(pc)
2015-02-28 14:05:37 +00:00
if fn != nil && ((fn.Name == "runtime.futex") || (fn.Name == "runtime.usleep") || (fn.Name == "runtime.clone")) {
2015-02-27 23:11:13 +00:00
return true
}
return false
}
2015-06-12 19:51:23 +00:00
func (thread *Thread) saveRegisters() (Registers, error) {
var err error
thread.dbp.execPtraceFunc(func() { err = sys.PtraceGetRegs(thread.Id, &thread.os.registers) })
if err != nil {
2015-05-04 22:31:13 +00:00
return nil, fmt.Errorf("could not save register contents")
}
return &Regs{&thread.os.registers}, nil
2015-01-14 02:37:10 +00:00
}
func (thread *Thread) restoreRegisters() (err error) {
thread.dbp.execPtraceFunc(func() { err = sys.PtraceSetRegs(thread.Id, &thread.os.registers) })
return
2015-01-14 02:37:10 +00:00
}
2015-08-02 02:43:03 +00:00
func (thread *Thread) writeMemory(addr uintptr, data []byte) (written int, err error) {
if len(data) == 0 {
return
}
thread.dbp.execPtraceFunc(func() { written, err = sys.PtracePokeData(thread.Id, addr, data) })
return
}
2015-08-02 02:43:03 +00:00
func (thread *Thread) readMemory(addr uintptr, size int) (data []byte, err error) {
if size == 0 {
return
}
2015-08-02 02:43:03 +00:00
data = make([]byte, size)
2015-08-02 04:06:34 +00:00
thread.dbp.execPtraceFunc(func() { _, err = sys.PtracePeekData(thread.Id, addr, data) })
return
}