delve/proc/threads_linux.go

77 lines
1.6 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
2015-06-12 19:51:23 +00:00
func (t *Thread) Halt() error {
2015-01-14 02:37:10 +00:00
if stopped(t.Id) {
return nil
}
err := sys.Tgkill(t.dbp.Pid, t.Id, sys.SIGSTOP)
2015-01-14 02:37:10 +00:00
if err != nil {
2015-02-27 23:11:13 +00:00
return fmt.Errorf("Halt err %s %d", err, t.Id)
2015-01-14 02:37:10 +00:00
}
2015-02-28 03:35:26 +00:00
_, _, err = wait(t.Id, 0)
2015-01-14 02:37:10 +00:00
if err != nil {
2015-02-27 23:11:13 +00:00
return fmt.Errorf("wait err %s %d", err, t.Id)
2015-01-14 02:37:10 +00:00
}
return nil
}
2015-06-12 19:51:23 +00:00
func (t *Thread) resume() error {
2015-02-27 23:11:13 +00:00
return PtraceCont(t.Id, 0)
2015-01-14 02:37:10 +00:00
}
2015-06-12 19:51:23 +00:00
func (t *Thread) singleStep() error {
2015-01-14 02:37:10 +00:00
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
}
2015-02-27 23:11:13 +00:00
_, _, err = 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-02-27 23:11:13 +00:00
// TODO(dp) cache the func pc to remove this lookup
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) {
if err := sys.PtraceGetRegs(thread.Id, &thread.os.registers); 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
}
2015-06-12 19:51:23 +00:00
func (thread *Thread) restoreRegisters() error {
2015-04-23 16:40:20 +00:00
return sys.PtraceSetRegs(thread.Id, &thread.os.registers)
2015-01-14 02:37:10 +00:00
}
2015-06-12 19:51:23 +00:00
func writeMemory(thread *Thread, addr uintptr, data []byte) (int, error) {
if len(data) == 0 {
return 0, nil
}
2015-04-23 16:40:20 +00:00
return sys.PtracePokeData(thread.Id, addr, data)
}
2015-06-12 19:51:23 +00:00
func readMemory(thread *Thread, addr uintptr, data []byte) (int, error) {
if len(data) == 0 {
return 0, nil
}
2015-04-23 16:40:20 +00:00
return sys.PtracePeekData(thread.Id, addr, data)
}