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:
Alessandro Arzilli 2022-08-09 19:03:45 +02:00 committed by GitHub
parent 3de29a88f8
commit 65cfd25787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -547,10 +547,10 @@ func (d *Debugger) State(nowait bool) (*api.DebuggerState, error) {
d.targetMutex.Lock()
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 {
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))
}
if withBreakpointInfo {
err := d.collectBreakpointInformation(th, thread)
if err != nil {
return nil, err
}
}
state.Threads = append(state.Threads, th)
if thread.ThreadID() == tgt.CurrentThread().ThreadID() {
state.CurrentThread = th
@ -1320,13 +1327,10 @@ func (d *Debugger) Command(command *api.DebuggerCommand, resumeNotify chan struc
}
return nil, err
}
state, stateErr := d.state(api.LoadConfigToProc(command.ReturnInfoLoadConfig))
state, stateErr := d.state(api.LoadConfigToProc(command.ReturnInfoLoadConfig), withBreakpointInfo)
if stateErr != nil {
return state, stateErr
}
if withBreakpointInfo {
err = d.collectBreakpointInformation(state)
}
for _, th := range state.Threads {
if th.Breakpoint != nil && th.Breakpoint.TraceReturn {
for _, v := range th.BreakpointInfo.Arguments {
@ -1343,32 +1347,27 @@ func (d *Debugger) Command(command *api.DebuggerCommand, resumeNotify chan struc
return state, err
}
func (d *Debugger) collectBreakpointInformation(state *api.DebuggerState) 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 state == nil {
func (d *Debugger) collectBreakpointInformation(apiThread *api.Thread, thread proc.Thread) error {
if apiThread.Breakpoint == nil || apiThread.BreakpointInfo != nil {
return nil
}
for i := range state.Threads {
if state.Threads[i].Breakpoint == nil || state.Threads[i].BreakpointInfo != nil {
continue
}
bp := state.Threads[i].Breakpoint
bp := apiThread.Breakpoint
bpi := &api.BreakpointInfo{}
state.Threads[i].BreakpointInfo = bpi
apiThread.BreakpointInfo = bpi
tgt := d.target.TargetForThread(thread)
if bp.Goroutine {
g, err := proc.GetG(d.target.Selected.CurrentThread())
g, err := proc.GetG(thread)
if err != nil {
return err
}
bpi.Goroutine = api.ConvertGoroutine(d.target.Selected, g)
bpi.Goroutine = api.ConvertGoroutine(tgt, g)
}
if bp.Stacktrace > 0 {
rawlocs, err := proc.ThreadStacktrace(d.target.Selected.CurrentThread(), bp.Stacktrace)
rawlocs, err := proc.ThreadStacktrace(thread, bp.Stacktrace)
if err != nil {
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 {
// 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 {
return err
}
@ -1414,8 +1408,6 @@ func (d *Debugger) collectBreakpointInformation(state *api.DebuggerState) error
bpi.Locals = api.ConvertVars(locals)
}
}
}
return nil
}