Skip to content

Commit

Permalink
service/dap: send continued event before step response (go-delve#2594)
Browse files Browse the repository at this point in the history
* service/dap: send continued event before step response

Send the continued event before the step response to make sure that there is no time where the client believes that only a single thread is running.

Updates golang/vscode-go#1617

* move to helper
  • Loading branch information
suzmue authored Jul 20, 2021
1 parent 38aaf27 commit 776b86f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
14 changes: 7 additions & 7 deletions service/dap/daptest/gen/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions service/dap/daptest/resp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 16 additions & 12 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1510,24 +1510,37 @@ func (s *Server) onAttachRequest(request *dap.AttachRequest) {
// onNextRequest handles 'next' request.
// This is a mandatory request to support.
func (s *Server) onNextRequest(request *dap.NextRequest, asyncSetupDone chan struct{}) {
s.send(&dap.NextResponse{Response: *newResponse(request.Request)})
s.sendStepResponse(request.Arguments.ThreadId, &dap.NextResponse{Response: *newResponse(request.Request)})
s.doStepCommand(api.Next, request.Arguments.ThreadId, asyncSetupDone)
}

// onStepInRequest handles 'stepIn' request
// This is a mandatory request to support.
func (s *Server) onStepInRequest(request *dap.StepInRequest, asyncSetupDone chan struct{}) {
s.send(&dap.StepInResponse{Response: *newResponse(request.Request)})
s.sendStepResponse(request.Arguments.ThreadId, &dap.StepInResponse{Response: *newResponse(request.Request)})
s.doStepCommand(api.Step, request.Arguments.ThreadId, asyncSetupDone)
}

// onStepOutRequest handles 'stepOut' request
// This is a mandatory request to support.
func (s *Server) onStepOutRequest(request *dap.StepOutRequest, asyncSetupDone chan struct{}) {
s.send(&dap.StepOutResponse{Response: *newResponse(request.Request)})
s.sendStepResponse(request.Arguments.ThreadId, &dap.StepOutResponse{Response: *newResponse(request.Request)})
s.doStepCommand(api.StepOut, request.Arguments.ThreadId, asyncSetupDone)
}

func (s *Server) sendStepResponse(threadId int, message dap.Message) {
// All of the threads will be continued by this request, so we need to send
// a continued event so the UI can properly reflect the current state.
s.send(&dap.ContinuedEvent{
Event: *newEvent("continued"),
Body: dap.ContinuedEventBody{
ThreadId: threadId,
AllThreadsContinued: true,
},
})
s.send(message)
}

func stoppedGoroutineID(state *api.DebuggerState) (id int) {
if state.SelectedGoroutine != nil {
id = state.SelectedGoroutine.ID
Expand All @@ -1544,15 +1557,6 @@ func stoppedGoroutineID(state *api.DebuggerState) (id int) {
// due to an error, so the server is ready to receive new requests.
func (s *Server) doStepCommand(command string, threadId int, asyncSetupDone chan struct{}) {
defer s.asyncCommandDone(asyncSetupDone)
// All of the threads will be continued by this request, so we need to send
// a continued event so the UI can properly reflect the current state.
s.send(&dap.ContinuedEvent{
Event: *newEvent("continued"),
Body: dap.ContinuedEventBody{
ThreadId: threadId,
AllThreadsContinued: true,
},
})
_, err := s.debugger.Command(&api.DebuggerCommand{Name: api.SwitchGoroutine, GoroutineID: threadId}, nil)
if err != nil {
s.log.Errorf("Error switching goroutines while stepping: %v", err)
Expand Down

0 comments on commit 776b86f

Please sign in to comment.