forked from go-delve/delve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
threads_linux.go
82 lines (71 loc) · 1.92 KB
/
threads_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package proc
import (
"fmt"
sys "golang.org/x/sys/unix"
)
// Not actually used, but necessary
// to be defined.
type OSSpecificDetails struct {
registers sys.PtraceRegs
}
func (t *Thread) Halt() error {
if stopped(t.Id) {
return nil
}
err := sys.Tgkill(t.dbp.Pid, t.Id, sys.SIGSTOP)
if err != nil {
return fmt.Errorf("Halt err %s %d", err, t.Id)
}
_, _, err = wait(t.Id, 0)
if err != nil {
return fmt.Errorf("wait err %s %d", err, t.Id)
}
return nil
}
func (t *Thread) resume() (err error) {
t.dbp.execPtraceFunc(func() { err = PtraceCont(t.Id, 0) })
return
}
func (t *Thread) singleStep() (err error) {
t.dbp.execPtraceFunc(func() { err = sys.PtraceSingleStep(t.Id) })
if err != nil {
return err
}
_, _, err = wait(t.Id, 0)
return err
}
func (t *Thread) blocked() bool {
// TODO(dp) cache the func pc to remove this lookup
pc, _ := t.PC()
fn := t.dbp.goSymTable.PCToFunc(pc)
if fn != nil && ((fn.Name == "runtime.futex") || (fn.Name == "runtime.usleep") || (fn.Name == "runtime.clone")) {
return true
}
return false
}
func (thread *Thread) saveRegisters() (Registers, error) {
var err error
thread.dbp.execPtraceFunc(func() { err = sys.PtraceGetRegs(thread.Id, &thread.os.registers) })
if err != nil {
return nil, fmt.Errorf("could not save register contents")
}
return &Regs{&thread.os.registers}, nil
}
func (thread *Thread) restoreRegisters() (err error) {
thread.dbp.execPtraceFunc(func() { err = sys.PtraceSetRegs(thread.Id, &thread.os.registers) })
return
}
func writeMemory(thread *Thread, 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
}
func readMemory(thread *Thread, addr uintptr, data []byte) (read int, err error) {
if len(data) == 0 {
return
}
thread.dbp.execPtraceFunc(func() { read, err = sys.PtracePeekData(thread.Id, addr, data) })
return
}