mirror of
https://github.com/go-delve/delve.git
synced 2025-10-29 01:27:16 +08:00
proc: Single step only "current" thread
Instead of the `step` command single stepping every thread, instead only step the "current" thread. This fixes a few issues surrounding single stepping, and simplifies the logic. The original concerns around only stepping a single thread (with regard to coordination) are invalid and generally non-issues.
This commit is contained in:
25
proc/proc.go
25
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() {
|
||||
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`.
|
||||
|
||||
Reference in New Issue
Block a user