debugger: CreateBreakpoint should delete existing breakpoints (#1892)

Fixes a bug introduced by the logical breakpoint change, where creating
the same breakpoint twice deletes the breakpoint.
This commit is contained in:
Alessandro Arzilli 2020-02-25 21:29:20 +01:00 committed by GitHub
parent d925f6b719
commit 897d5c4288
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

@ -487,6 +487,9 @@ func createLogicalBreakpoint(p proc.Process, addrs []uint64, requestedBp *api.Br
}
}
if err != nil {
if isBreakpointExistsErr(err) {
return nil, err
}
for _, bp := range bps {
if bp == nil {
continue
@ -502,6 +505,11 @@ func createLogicalBreakpoint(p proc.Process, addrs []uint64, requestedBp *api.Br
return createdBp[0], nil // we created a single logical breakpoint, the slice here will always have len == 1
}
func isBreakpointExistsErr(err error) bool {
_, r := err.(proc.BreakpointExistsError)
return r
}
// AmendBreakpoint will update the breakpoint with the matching ID.
func (d *Debugger) AmendBreakpoint(amend *api.Breakpoint) error {
d.processMutex.Lock()

@ -1836,3 +1836,35 @@ func TestIssue1787(t *testing.T) {
}
})
}
func TestDoubleCreateBreakpoint(t *testing.T) {
withTestClient2("testnextprog", t, func(c service.Client) {
_, err := c.CreateBreakpoint(&api.Breakpoint{FunctionName: "main.main", Line: 1, Name: "firstbreakpoint", Tracepoint: true})
assertNoError(err, t, "CreateBreakpoint 1")
bps, err := c.ListBreakpoints()
assertNoError(err, t, "ListBreakpoints 1")
t.Logf("breakpoints before second call:")
for _, bp := range bps {
t.Logf("\t%v", bp)
}
numBreakpoints := len(bps)
_, err = c.CreateBreakpoint(&api.Breakpoint{FunctionName: "main.main", Line: 1, Name: "secondbreakpoint", Tracepoint: true})
assertError(err, t, "CreateBreakpoint 2") // breakpoint exists
bps, err = c.ListBreakpoints()
assertNoError(err, t, "ListBreakpoints 2")
t.Logf("breakpoints after second call:")
for _, bp := range bps {
t.Logf("\t%v", bp)
}
if len(bps) != numBreakpoints {
t.Errorf("wrong number of breakpoints, got %d expected %d", len(bps), numBreakpoints)
}
})
}