diff --git a/proc/proc.go b/proc/proc.go index b5575e434f..69f34f413b 100644 --- a/proc/proc.go +++ b/proc/proc.go @@ -4,6 +4,7 @@ import ( "debug/dwarf" "debug/gosym" "encoding/binary" + "errors" "fmt" "go/constant" "os" @@ -408,22 +409,18 @@ func (dbp *Process) pickCurrentThread(trapthread *Thread) error { return dbp.SwitchThread(trapthread.ID) } -// Step will continue the debugged process for exactly -// one instruction. +// Step will continue the current thread for exactly +// one instruction. This method affects only the thread +// asssociated with the selected goroutine. All other +// threads will remain stopped. func (dbp *Process) Step() (err error) { - fn := func() error { - for _, th := range dbp.Threads { - if th.blocked() || !th.canStep() { - continue - } - if err := th.Step(); err != nil { - return err - } - } - return nil + if dbp.SelectedGoroutine == nil { + return errors.New("cannot single step: no selected goroutine") } - - return dbp.run(fn) + if dbp.SelectedGoroutine.thread == nil { + return fmt.Errorf("cannot single step: no thread associated with goroutine %d", dbp.SelectedGoroutine.ID) + } + return dbp.run(dbp.SelectedGoroutine.thread.Step) } // SwitchThread changes from current thread to the thread specified by `tid`. diff --git a/proc/threads_darwin.go b/proc/threads_darwin.go index 30fc8df8f4..90ff9d0123 100644 --- a/proc/threads_darwin.go +++ b/proc/threads_darwin.go @@ -89,10 +89,6 @@ func (t *Thread) stopped() bool { return C.thread_blocked(t.os.threadAct) > C.int(0) } -func (t *Thread) canStep() bool { - return true -} - func (t *Thread) writeMemory(addr uintptr, data []byte) (int, error) { if len(data) == 0 { return 0, nil diff --git a/proc/threads_linux.go b/proc/threads_linux.go index c4b6474965..88a89adcf7 100644 --- a/proc/threads_linux.go +++ b/proc/threads_linux.go @@ -39,10 +39,6 @@ func (t *Thread) resume() (err error) { return } -func (thread *Thread) canStep() bool { - return true -} - func (t *Thread) singleStep() (err error) { for { t.dbp.execPtraceFunc(func() { err = sys.PtraceSingleStep(t.ID) }) diff --git a/proc/threads_windows.go b/proc/threads_windows.go index fb5ec4e5e0..c82fc7be18 100644 --- a/proc/threads_windows.go +++ b/proc/threads_windows.go @@ -134,10 +134,6 @@ func (t *Thread) stopped() bool { return true } -func (t *Thread) canStep() bool { - return t.dbp.os.breakThread == t.ID -} - func (t *Thread) writeMemory(addr uintptr, data []byte) (int, error) { var ( vmData = C.LPCVOID(unsafe.Pointer(&data[0])) diff --git a/terminal/command.go b/terminal/command.go index 9620ef4fd4..093a392f00 100644 --- a/terminal/command.go +++ b/terminal/command.go @@ -235,6 +235,8 @@ func goroutines(t *Term, argstr string) error { fgl = fglRuntimeCurrent case "-g": fgl = fglGo + case "": + // nothing to do default: return fmt.Errorf("wrong argument: '%s'", args[0]) }