service/debugger: refactor state/collectBreakpointInfo for TargetGroup (#3064)
Change service/debugger.(*Debugger).state and collectBreakpointInfo methods so that they work with TargetGroup. Updates #2551 when running custom builds abstraction on '5660f9a4'.
This commit is contained in:
parent
3de29a88f8
commit
65cfd25787
@ -547,10 +547,10 @@ func (d *Debugger) State(nowait bool) (*api.DebuggerState, error) {
|
|||||||
|
|
||||||
d.targetMutex.Lock()
|
d.targetMutex.Lock()
|
||||||
defer d.targetMutex.Unlock()
|
defer d.targetMutex.Unlock()
|
||||||
return d.state(nil)
|
return d.state(nil, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Debugger) state(retLoadCfg *proc.LoadConfig) (*api.DebuggerState, error) {
|
func (d *Debugger) state(retLoadCfg *proc.LoadConfig, withBreakpointInfo bool) (*api.DebuggerState, error) {
|
||||||
if _, err := d.target.Valid(); err != nil {
|
if _, err := d.target.Valid(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -585,6 +585,13 @@ func (d *Debugger) state(retLoadCfg *proc.LoadConfig) (*api.DebuggerState, error
|
|||||||
th.ReturnValues = api.ConvertVars(thread.Common().ReturnValues(*retLoadCfg))
|
th.ReturnValues = api.ConvertVars(thread.Common().ReturnValues(*retLoadCfg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if withBreakpointInfo {
|
||||||
|
err := d.collectBreakpointInformation(th, thread)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
state.Threads = append(state.Threads, th)
|
state.Threads = append(state.Threads, th)
|
||||||
if thread.ThreadID() == tgt.CurrentThread().ThreadID() {
|
if thread.ThreadID() == tgt.CurrentThread().ThreadID() {
|
||||||
state.CurrentThread = th
|
state.CurrentThread = th
|
||||||
@ -1320,13 +1327,10 @@ func (d *Debugger) Command(command *api.DebuggerCommand, resumeNotify chan struc
|
|||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
state, stateErr := d.state(api.LoadConfigToProc(command.ReturnInfoLoadConfig))
|
state, stateErr := d.state(api.LoadConfigToProc(command.ReturnInfoLoadConfig), withBreakpointInfo)
|
||||||
if stateErr != nil {
|
if stateErr != nil {
|
||||||
return state, stateErr
|
return state, stateErr
|
||||||
}
|
}
|
||||||
if withBreakpointInfo {
|
|
||||||
err = d.collectBreakpointInformation(state)
|
|
||||||
}
|
|
||||||
for _, th := range state.Threads {
|
for _, th := range state.Threads {
|
||||||
if th.Breakpoint != nil && th.Breakpoint.TraceReturn {
|
if th.Breakpoint != nil && th.Breakpoint.TraceReturn {
|
||||||
for _, v := range th.BreakpointInfo.Arguments {
|
for _, v := range th.BreakpointInfo.Arguments {
|
||||||
@ -1343,32 +1347,27 @@ func (d *Debugger) Command(command *api.DebuggerCommand, resumeNotify chan struc
|
|||||||
return state, err
|
return state, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Debugger) collectBreakpointInformation(state *api.DebuggerState) error {
|
func (d *Debugger) collectBreakpointInformation(apiThread *api.Thread, thread proc.Thread) error {
|
||||||
//TODO(aarzilli): this doesn't work when there are multiple targets because the state.Threads slice will contain threads from all targets, not just d.target .Selected
|
if apiThread.Breakpoint == nil || apiThread.BreakpointInfo != nil {
|
||||||
|
|
||||||
if state == nil {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range state.Threads {
|
bp := apiThread.Breakpoint
|
||||||
if state.Threads[i].Breakpoint == nil || state.Threads[i].BreakpointInfo != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
bp := state.Threads[i].Breakpoint
|
|
||||||
bpi := &api.BreakpointInfo{}
|
bpi := &api.BreakpointInfo{}
|
||||||
state.Threads[i].BreakpointInfo = bpi
|
apiThread.BreakpointInfo = bpi
|
||||||
|
|
||||||
|
tgt := d.target.TargetForThread(thread)
|
||||||
|
|
||||||
if bp.Goroutine {
|
if bp.Goroutine {
|
||||||
g, err := proc.GetG(d.target.Selected.CurrentThread())
|
g, err := proc.GetG(thread)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
bpi.Goroutine = api.ConvertGoroutine(d.target.Selected, g)
|
bpi.Goroutine = api.ConvertGoroutine(tgt, g)
|
||||||
}
|
}
|
||||||
|
|
||||||
if bp.Stacktrace > 0 {
|
if bp.Stacktrace > 0 {
|
||||||
rawlocs, err := proc.ThreadStacktrace(d.target.Selected.CurrentThread(), bp.Stacktrace)
|
rawlocs, err := proc.ThreadStacktrace(thread, bp.Stacktrace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1378,17 +1377,12 @@ func (d *Debugger) collectBreakpointInformation(state *api.DebuggerState) error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thread, found := d.target.Selected.FindThread(state.Threads[i].ID)
|
|
||||||
if !found {
|
|
||||||
return fmt.Errorf("could not find thread %d", state.Threads[i].ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(bp.Variables) == 0 && bp.LoadArgs == nil && bp.LoadLocals == nil {
|
if len(bp.Variables) == 0 && bp.LoadArgs == nil && bp.LoadLocals == nil {
|
||||||
// don't try to create goroutine scope if there is nothing to load
|
// don't try to create goroutine scope if there is nothing to load
|
||||||
continue
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := proc.GoroutineScope(d.target.Selected, thread)
|
s, err := proc.GoroutineScope(tgt, thread)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1414,8 +1408,6 @@ func (d *Debugger) collectBreakpointInformation(state *api.DebuggerState) error
|
|||||||
bpi.Locals = api.ConvertVars(locals)
|
bpi.Locals = api.ConvertVars(locals)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user