未验证 提交 09798471 编写于 作者: S Suzy Mueller 提交者: GitHub

service/dap: do not send a halt request if the debuggee is not running (#2686)

updates go-delve/delve#2685
上级 5d158820
......@@ -1568,10 +1568,12 @@ func (s *Server) doStepCommand(command string, threadId int, asyncSetupDone chan
// onPauseRequest handles 'pause' request.
// This is a mandatory request to support.
func (s *Server) onPauseRequest(request *dap.PauseRequest) {
_, err := s.debugger.Command(&api.DebuggerCommand{Name: api.Halt}, nil)
if err != nil {
s.sendErrorResponse(request.Request, UnableToHalt, "Unable to halt execution", err.Error())
return
if s.debugger.IsRunning() {
_, err := s.debugger.Command(&api.DebuggerCommand{Name: api.Halt}, nil)
if err != nil {
s.sendErrorResponse(request.Request, UnableToHalt, "Unable to halt execution", err.Error())
return
}
}
s.send(&dap.PauseResponse{Response: *newResponse(request.Request)})
// No need to send any event here.
......
......@@ -2296,6 +2296,64 @@ func TestSetBreakpoint(t *testing.T) {
})
}
func TestPauseAtStop(t *testing.T) {
runTest(t, "loopprog", func(client *daptest.Client, fixture protest.Fixture) {
runDebugSessionWithBPs(t, client, "launch",
// Launch
func() {
client.LaunchRequest("exec", fixture.Path, !stopOnEntry)
},
// Set breakpoints
fixture.Source, []int{16},
[]onBreakpoint{{
execute: func() {
checkStop(t, client, 1, "main.main", 16)
client.SetBreakpointsRequest(fixture.Source, []int{6, 8})
expectSetBreakpointsResponse(t, client, []Breakpoint{{6, fixture.Source, true, ""}, {8, fixture.Source, true, ""}})
// Send a pause request while stopped on a cleared breakpoint.
client.PauseRequest(1)
client.ExpectPauseResponse(t)
client.ContinueRequest(1)
client.ExpectContinueResponse(t)
client.ExpectStoppedEvent(t)
checkStop(t, client, 1, "main.loop", 6)
// Send a pause request while stopped on a breakpoint.
client.PauseRequest(1)
client.ExpectPauseResponse(t)
client.ContinueRequest(1)
client.ExpectContinueResponse(t)
se := client.ExpectStoppedEvent(t)
if se.Body.Reason != "breakpoint" {
t.Errorf("got %#v, expected breakpoint", se)
}
checkStop(t, client, 1, "main.loop", 8)
// Send a pause request while stopped after stepping.
client.NextRequest(1)
client.ExpectNextResponse(t)
client.ExpectStoppedEvent(t)
checkStop(t, client, 1, "main.loop", 9)
client.PauseRequest(1)
client.ExpectPauseResponse(t)
client.ContinueRequest(1)
client.ExpectContinueResponse(t)
client.ExpectStoppedEvent(t)
checkStop(t, client, 1, "main.loop", 8)
},
// The program has an infinite loop, so we must kill it by disconnecting.
disconnect: true,
}})
})
}
func checkHitBreakpointIds(t *testing.T, se *dap.StoppedEvent, reason string, id int) {
if se.Body.ThreadId != 1 || se.Body.Reason != reason || len(se.Body.HitBreakpointIds) != 1 || se.Body.HitBreakpointIds[0] != id {
t.Errorf("got %#v, want Reason=%q, ThreadId=1, HitBreakpointIds=[]int{%d}", se, reason, id)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册