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
|
// Change from current thread to the thread running the specified goroutine
|
||||||
func (dbp *Process) SwitchGoroutine(gid int) error {
|
func (dbp *Process) SwitchGoroutine(gid int) error {
|
||||||
gs, err := dbp.GoroutinesInfo()
|
g, err := dbp.FindGoroutine(gid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, g := range gs {
|
if g == nil {
|
||||||
if g.Id == gid {
|
// user specified -1 and SelectedGoroutine is nil
|
||||||
if g.thread != nil {
|
return nil
|
||||||
return dbp.SwitchThread(g.thread.Id)
|
|
||||||
}
|
|
||||||
dbp.SelectedGoroutine = g
|
|
||||||
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
|
// 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) {
|
func (d *Debugger) Stacktrace(goroutineId, depth int, full bool) ([]api.Stackframe, error) {
|
||||||
var rawlocs []proc.Stackframe
|
var rawlocs []proc.Stackframe
|
||||||
var err error
|
|
||||||
|
|
||||||
if goroutineId < 0 {
|
g, err := d.process.FindGoroutine(goroutineId)
|
||||||
if d.process.SelectedGoroutine != nil {
|
if err != nil {
|
||||||
rawlocs, err = d.process.GoroutineStacktrace(d.process.SelectedGoroutine, depth)
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
|
||||||
}
|
if g == nil {
|
||||||
} else {
|
rawlocs, err = d.process.CurrentThread.Stacktrace(depth)
|
||||||
rawlocs, err = d.process.CurrentThread.Stacktrace(depth)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
gs, err := d.process.GoroutinesInfo()
|
rawlocs, err = d.process.GoroutineStacktrace(g, depth)
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return d.convertStacktrace(rawlocs, full)
|
return d.convertStacktrace(rawlocs, full)
|
||||||
|
Loading…
Reference in New Issue
Block a user