From e00670b9018d273c67ec4fc93244c98597e4aa83 Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Fri, 24 Sep 2021 16:18:28 -0600 Subject: [PATCH] service/debugger: return correct exit status on manual halt (#2674) * service/dap: add test for nonzero exit status --- service/dap/server.go | 2 ++ service/dap/server_test.go | 29 +++++++++++++++++++++++++++++ service/debugger/debugger.go | 5 +++++ 3 files changed, 36 insertions(+) diff --git a/service/dap/server.go b/service/dap/server.go index ed6b602a..ba9d4f4f 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -1024,6 +1024,8 @@ func (s *Server) stopDebugSession(killProcess bool) error { s.log.Debug("halt returned state: ", exited) } if exited != nil { + // TODO(suzmue): log exited error when the process exits, which may have been before + // halt was called. s.logToConsole(exited.Error()) s.logToConsole("Detaching") } else if killProcess { diff --git a/service/dap/server_test.go b/service/dap/server_test.go index 1962c7d6..b9173001 100644 --- a/service/dap/server_test.go +++ b/service/dap/server_test.go @@ -4330,6 +4330,35 @@ func TestLaunchRequestOutputPath(t *testing.T) { }) } +func TestExitNonZeroStatus(t *testing.T) { + runTest(t, "pr1055", func(client *daptest.Client, fixture protest.Fixture) { + client.InitializeRequest() + client.ExpectInitializeResponseAndCapabilities(t) + + client.LaunchRequest("exec", fixture.Path, !stopOnEntry) + client.ExpectInitializedEvent(t) + client.ExpectLaunchResponse(t) + + client.ConfigurationDoneRequest() + client.ExpectConfigurationDoneResponse(t) + + client.ExpectTerminatedEvent(t) + + client.DisconnectRequest() + // Check that the process exit status is 2. + oep := client.ExpectOutputEventProcessExited(t, 2) + if oep.Body.Category != "console" { + t.Errorf("\ngot %#v\nwant Category='console'", oep) + } + oed := client.ExpectOutputEventDetaching(t) + if oed.Body.Category != "console" { + t.Errorf("\ngot %#v\nwant Category='console'", oed) + } + client.ExpectDisconnectResponse(t) + client.ExpectTerminatedEvent(t) + }) +} + func TestNoDebug_GoodExitStatus(t *testing.T) { runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) { runNoDebugSession(t, client, func() { diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index 8db021fa..e3dcb62d 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -1130,6 +1130,11 @@ func (d *Debugger) Command(command *api.DebuggerCommand, resumeNotify chan struc d.recordMutex.Lock() if d.stopRecording == nil { err = d.target.RequestManualStop() + // The error returned from d.target.Valid will have more context + // about the exited process. + if _, valErr := d.target.Valid(); valErr != nil { + err = valErr + } } d.recordMutex.Unlock() } -- GitLab