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:
parent
d925f6b719
commit
897d5c4288
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user