delve
delve copied to clipboard
Is it a bug here when setting breakpoints at return address of multiple functions
trafficstars
func setBreakpoint(t *Session, ctx callContext, tracepoint bool, argstr string) ([]*api.Breakpoint, error) {
...
switch t := loc.(type) {
case *locspec.NormalLocationSpec:
shouldSetReturnBreakpoints = t.LineOffset == -1 && t.FuncBase != nil
case *locspec.RegexLocationSpec:
shouldSetReturnBreakpoints = true
}
if tracepoint && shouldSetReturnBreakpoints && locs[0].Function != nil {
for i := range locs {
if locs[i].Function == nil {
continue
}
// here, if we use RegexLocationSpec for multiple functions,
// is `locs[0].Function.Name()` a bug here?
addrs, err := t.client.(*rpc2.RPCClient).FunctionReturnLocations(locs[0].Function.Name())
if err != nil {
return nil, err
}
for j := range addrs {
_, err = t.client.CreateBreakpoint(&api.Breakpoint{
Addr: addrs[j],
TraceReturn: true,
Line: -1,
LoadArgs: &ShortLoadConfig,
})
if err != nil {
return nil, err
}
}
}
}
return created, nil
}
```go
Yes, it does look like a bug, I think it should be locs[i] and the nilness check should be inside the loop and also be on locs[i].