mirror of
https://github.com/go-delve/delve.git
synced 2025-11-01 03:42:59 +08:00
More cleanup
This commit is contained in:
@ -51,11 +51,6 @@ func Attach(pid int) (*DebuggedProcess, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Attach to all currently active threads.
|
|
||||||
// TODO(dp) doing this in newDebugProcess already for mach
|
|
||||||
if err := dbp.updateThreadList(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return dbp, nil
|
return dbp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,6 @@ func (dbp *DebuggedProcess) updateThreadList() error {
|
|||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
kret C.kern_return_t
|
kret C.kern_return_t
|
||||||
th *ThreadContext
|
|
||||||
count = C.thread_count(C.task_t(dbp.os.task))
|
count = C.thread_count(C.task_t(dbp.os.task))
|
||||||
)
|
)
|
||||||
if count == -1 {
|
if count == -1 {
|
||||||
@ -74,7 +73,7 @@ func (dbp *DebuggedProcess) updateThreadList() error {
|
|||||||
}
|
}
|
||||||
list := make([]uint32, count)
|
list := make([]uint32, count)
|
||||||
|
|
||||||
// TODO(dp) might be better to malloc mem in C and them free it here
|
// TODO(dp) might be better to malloc mem in C and then free it here
|
||||||
// instead of getting count above and passing in a slice
|
// instead of getting count above and passing in a slice
|
||||||
kret = C.get_threads(C.task_t(dbp.os.task), unsafe.Pointer(&list[0]))
|
kret = C.get_threads(C.task_t(dbp.os.task), unsafe.Pointer(&list[0]))
|
||||||
if kret != C.KERN_SUCCESS {
|
if kret != C.KERN_SUCCESS {
|
||||||
@ -85,17 +84,15 @@ func (dbp *DebuggedProcess) updateThreadList() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, port := range list {
|
for _, port := range list {
|
||||||
th, err = dbp.addThread(int(port), false)
|
if _, ok := dbp.Threads[int(port)]; !ok {
|
||||||
if err != nil {
|
fmt.Println("new thread spawned", port)
|
||||||
return err
|
_, err = dbp.addThread(int(port), false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(dp) account for GOMAXPROCS=1 or attaching to pid
|
|
||||||
if count == 1 {
|
|
||||||
dbp.CurrentThread = th
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +112,9 @@ func (dbp *DebuggedProcess) addThread(port int, attach bool) (*ThreadContext, er
|
|||||||
}
|
}
|
||||||
dbp.Threads[port] = thread
|
dbp.Threads[port] = thread
|
||||||
thread.os.thread_act = C.thread_act_t(port)
|
thread.os.thread_act = C.thread_act_t(port)
|
||||||
|
if dbp.CurrentThread == nil {
|
||||||
|
dbp.CurrentThread = thread
|
||||||
|
}
|
||||||
return thread, nil
|
return thread, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,11 +169,6 @@ func (dbp *DebuggedProcess) obtainGoSymbols(exe *macho.File, wg *sync.WaitGroup)
|
|||||||
dbp.GoSymTable = tab
|
dbp.GoSymTable = tab
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(darwin) IMPLEMENT ME
|
|
||||||
func stopped(pid int) bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dbp *DebuggedProcess) findExecutable() (*macho.File, error) {
|
func (dbp *DebuggedProcess) findExecutable() (*macho.File, error) {
|
||||||
pathptr, err := C.find_executable(C.int(dbp.Pid))
|
pathptr, err := C.find_executable(C.int(dbp.Pid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -203,23 +203,6 @@ func (dbp *DebuggedProcess) obtainGoSymbols(exe *elf.File, wg *sync.WaitGroup) {
|
|||||||
dbp.GoSymTable = tab
|
dbp.GoSymTable = tab
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(dp) seems like it could be unneccessary
|
|
||||||
func addNewThread(dbp *DebuggedProcess, cloner, cloned int) error {
|
|
||||||
fmt.Println("new thread spawned", cloned)
|
|
||||||
|
|
||||||
th, err := dbp.addThread(cloned, false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = th.Continue()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("could not continue new thread %d %s", cloned, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return dbp.Threads[cloner].Continue()
|
|
||||||
}
|
|
||||||
|
|
||||||
func stopped(pid int) bool {
|
func stopped(pid int) bool {
|
||||||
f, err := os.Open(fmt.Sprintf("/proc/%d/stat", pid))
|
f, err := os.Open(fmt.Sprintf("/proc/%d/stat", pid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -257,14 +240,27 @@ func trapWait(dbp *DebuggedProcess, pid int) (int, *sys.WaitStatus, error) {
|
|||||||
if status.StopSignal() == sys.SIGTRAP && status.TrapCause() == sys.PTRACE_EVENT_CLONE {
|
if status.StopSignal() == sys.SIGTRAP && status.TrapCause() == sys.PTRACE_EVENT_CLONE {
|
||||||
// A traced thread has cloned a new thread, grab the pid and
|
// A traced thread has cloned a new thread, grab the pid and
|
||||||
// add it to our list of traced threads.
|
// add it to our list of traced threads.
|
||||||
tid, err := sys.PtraceGetEventMsg(wpid)
|
cloned, err := sys.PtraceGetEventMsg(wpid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, nil, fmt.Errorf("could not get event message: %s", err)
|
return -1, nil, fmt.Errorf("could not get event message: %s", err)
|
||||||
}
|
}
|
||||||
err = addNewThread(dbp, wpid, int(tid))
|
|
||||||
|
fmt.Println("new thread spawned", cloned)
|
||||||
|
|
||||||
|
th, err := dbp.addThread(cloned, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, nil, err
|
return -1, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = th.Continue()
|
||||||
|
if err != nil {
|
||||||
|
return -1, nil, fmt.Errorf("could not continue new thread %d %s", cloned, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = dbp.Threads[cloner].Continue()
|
||||||
|
if err != nil {
|
||||||
|
return -1, nil, fmt.Errorf("could not continue new thread %d %s", cloned, err)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if status.StopSignal() == sys.SIGTRAP {
|
if status.StopSignal() == sys.SIGTRAP {
|
||||||
|
|||||||
@ -12,7 +12,6 @@ type OSSpecificDetails struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *ThreadContext) Halt() error {
|
func (t *ThreadContext) Halt() error {
|
||||||
// TODO(dp) may be able to just task_suspend instead of suspending individual threads
|
|
||||||
var kret C.kern_return_t
|
var kret C.kern_return_t
|
||||||
kret = C.thread_suspend(t.os.thread_act)
|
kret = C.thread_suspend(t.os.thread_act)
|
||||||
if kret != C.KERN_SUCCESS {
|
if kret != C.KERN_SUCCESS {
|
||||||
@ -49,7 +48,6 @@ func (t *ThreadContext) resume() error {
|
|||||||
|
|
||||||
func (t *ThreadContext) blocked() bool {
|
func (t *ThreadContext) blocked() bool {
|
||||||
// TODO(dp) cache the func pc to remove this lookup
|
// TODO(dp) cache the func pc to remove this lookup
|
||||||
// TODO(dp) check err
|
|
||||||
pc, _ := t.CurrentPC()
|
pc, _ := t.CurrentPC()
|
||||||
fn := t.Process.GoSymTable.PCToFunc(pc)
|
fn := t.Process.GoSymTable.PCToFunc(pc)
|
||||||
if fn != nil && ((fn.Name == "runtime.mach_semaphore_wait") || (fn.Name == "runtime.usleep")) {
|
if fn != nil && ((fn.Name == "runtime.mach_semaphore_wait") || (fn.Name == "runtime.usleep")) {
|
||||||
|
|||||||
@ -40,7 +40,6 @@ func (t *ThreadContext) singleStep() error {
|
|||||||
|
|
||||||
func (t *ThreadContext) blocked() bool {
|
func (t *ThreadContext) blocked() bool {
|
||||||
// TODO(dp) cache the func pc to remove this lookup
|
// TODO(dp) cache the func pc to remove this lookup
|
||||||
// TODO(dp) check err
|
|
||||||
pc, _ := t.CurrentPC()
|
pc, _ := t.CurrentPC()
|
||||||
fn := t.Process.GoSymTable.PCToFunc(pc)
|
fn := t.Process.GoSymTable.PCToFunc(pc)
|
||||||
if fn != nil && ((fn.Name == "runtime.futex") || (fn.Name == "runtime.usleep") || (fn.Name == "runtime.clone")) {
|
if fn != nil && ((fn.Name == "runtime.futex") || (fn.Name == "runtime.usleep") || (fn.Name == "runtime.clone")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user