From 890cde3d4c766d8b918ad945501257fd1ddd3ba8 Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Wed, 14 Jul 2021 17:32:46 -0400 Subject: [PATCH] service/dap: send terminated event when disconnecting (#2587) * service/dap: send terminated event when disconnecting If the program terminates while disconnecting, either because it was killed or otherwise, send a terminated event. --- cmd/dlv/dlv_test.go | 1 + service/dap/server.go | 4 ++++ service/dap/server_test.go | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/cmd/dlv/dlv_test.go b/cmd/dlv/dlv_test.go index 2c5b23a7..479ac40e 100644 --- a/cmd/dlv/dlv_test.go +++ b/cmd/dlv/dlv_test.go @@ -637,6 +637,7 @@ func TestDap(t *testing.T) { client := daptest.NewClient(listenAddr) client.DisconnectRequest() client.ExpectDisconnectResponse(t) + client.ExpectTerminatedEvent(t) if _, err := client.ReadMessage(); err != io.EOF { t.Errorf("got %q, want \"EOF\"\n", err) } diff --git a/service/dap/server.go b/service/dap/server.go index cec104ad..ad639f70 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -972,6 +972,10 @@ func (s *Server) onDisconnectRequest(request *dap.DisconnectRequest) { } else { s.send(&dap.DisconnectResponse{Response: *newResponse(request.Request)}) } + // The debugging session has ended, so we send a terminated event. + s.send(&dap.TerminatedEvent{ + Event: *newEvent("terminated"), + }) } // stopDebugSession is called from Stop (main goroutine) and diff --git a/service/dap/server_test.go b/service/dap/server_test.go index 23084425..7bd15878 100644 --- a/service/dap/server_test.go +++ b/service/dap/server_test.go @@ -246,6 +246,7 @@ func TestLaunchStopOnEntry(t *testing.T) { if dResp.Seq != 0 || dResp.RequestSeq != 13 { t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=13", dResp) } + client.ExpectTerminatedEvent(t) }) } @@ -377,6 +378,7 @@ func TestAttachStopOnEntry(t *testing.T) { client.CheckOutputEvent(t, msg) msg = expectMessageFilterStopped(t, client) client.CheckDisconnectResponse(t, msg) + client.ExpectTerminatedEvent(t) // If this call to KeepAlive isn't here there's a chance that stdout will // be garbage collected (since it is no longer alive long before this @@ -452,6 +454,7 @@ func TestContinueOnEntry(t *testing.T) { if dResp.Seq != 0 || dResp.RequestSeq != 8 { t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=8", dResp) } + client.ExpectTerminatedEvent(t) }) } @@ -591,6 +594,7 @@ func TestPreSetBreakpoint(t *testing.T) { client.ExpectOutputEventProcessExited(t, 0) client.ExpectOutputEventDetaching(t) client.ExpectDisconnectResponse(t) + client.ExpectTerminatedEvent(t) }) } @@ -3854,6 +3858,7 @@ func runDebugSessionWithBPs(t *testing.T, client *daptest.Client, cmd string, cm client.ExpectOutputEventDetachingKill(t) } client.ExpectDisconnectResponse(t) + client.ExpectTerminatedEvent(t) return } client.ContinueRequest(1) @@ -3872,6 +3877,7 @@ func runDebugSessionWithBPs(t *testing.T, client *daptest.Client, cmd string, cm client.ExpectOutputEventDetachingKill(t) } client.ExpectDisconnectResponse(t) + client.ExpectTerminatedEvent(t) } // runDebugSession is a helper for executing the standard init and shutdown @@ -3996,6 +4002,7 @@ func runNoDebugDebugSession(t *testing.T, client *daptest.Client, cmdRequest fun client.ExpectTerminatedEvent(t) client.DisconnectRequestWithKillOption(true) client.ExpectDisconnectResponse(t) + client.ExpectTerminatedEvent(t) } func TestLaunchTestRequest(t *testing.T) {