Refactor: use FindGoroutine
Use proc.(*Process).FindGoroutine in proc.(*Process).SwitchGoroutine and debugger.(*Debugger).Stacktrace. That method did not exist when those were originally written.
This commit is contained in:
parent
a6391c1f76
commit
5ba0435382
19
proc/proc.go
19
proc/proc.go
@ -428,20 +428,19 @@ func (dbp *Process) SwitchThread(tid int) error {
|
||||
|
||||
// Change from current thread to the thread running the specified goroutine
|
||||
func (dbp *Process) SwitchGoroutine(gid int) error {
|
||||
gs, err := dbp.GoroutinesInfo()
|
||||
g, err := dbp.FindGoroutine(gid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, g := range gs {
|
||||
if g.Id == gid {
|
||||
if g.thread != nil {
|
||||
return dbp.SwitchThread(g.thread.Id)
|
||||
}
|
||||
dbp.SelectedGoroutine = g
|
||||
return nil
|
||||
}
|
||||
if g == nil {
|
||||
// user specified -1 and SelectedGoroutine is nil
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("could not find goroutine %d", gid)
|
||||
if g.thread != nil {
|
||||
return dbp.SwitchThread(g.thread.Id)
|
||||
}
|
||||
dbp.SelectedGoroutine = g
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns an array of G structures representing the information
|
||||
|
@ -456,38 +456,19 @@ func (d *Debugger) Goroutines() ([]*api.Goroutine, error) {
|
||||
|
||||
func (d *Debugger) Stacktrace(goroutineId, depth int, full bool) ([]api.Stackframe, error) {
|
||||
var rawlocs []proc.Stackframe
|
||||
var err error
|
||||
|
||||
if goroutineId < 0 {
|
||||
if d.process.SelectedGoroutine != nil {
|
||||
rawlocs, err = d.process.GoroutineStacktrace(d.process.SelectedGoroutine, depth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
rawlocs, err = d.process.CurrentThread.Stacktrace(depth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
g, err := d.process.FindGoroutine(goroutineId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if g == nil {
|
||||
rawlocs, err = d.process.CurrentThread.Stacktrace(depth)
|
||||
} else {
|
||||
gs, err := d.process.GoroutinesInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, g := range gs {
|
||||
if g.Id == goroutineId {
|
||||
rawlocs, err = d.process.GoroutineStacktrace(g, depth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if rawlocs == nil {
|
||||
return nil, fmt.Errorf("Unknown goroutine id %d\n", goroutineId)
|
||||
}
|
||||
rawlocs, err = d.process.GoroutineStacktrace(g, depth)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return d.convertStacktrace(rawlocs, full)
|
||||
|
Loading…
Reference in New Issue
Block a user