diff --git a/cmd/dlv/cmds/commands.go b/cmd/dlv/cmds/commands.go index 2f8ec18d..e11bdd12 100644 --- a/cmd/dlv/cmds/commands.go +++ b/cmd/dlv/cmds/commands.go @@ -422,6 +422,9 @@ func dapCmd(cmd *cobra.Command, args []string) { if continueOnStart { fmt.Fprintf(os.Stderr, "Warning: continue ignored with dap; specify via launch/attach request instead\n") } + if backend != "default" { + fmt.Fprintf(os.Stderr, "Warning: backend ignored with dap; specify via launch/attach request instead\n") + } if buildFlags != "" { fmt.Fprintf(os.Stderr, "Warning: build flags ignored with dap; specify via launch/attach request instead\n") } diff --git a/service/dap/server.go b/service/dap/server.go index 761d4dbd..59d27f1b 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -843,6 +843,20 @@ func (s *Server) onLaunchRequest(request *dap.LaunchRequest) { } } + backend, ok := request.Arguments["backend"] + if ok { + backendParsed, ok := backend.(string) + if !ok { + s.sendErrorResponse(request.Request, + FailedToLaunch, "Failed to launch", + fmt.Sprintf("'backend' attribute '%v' in debug configuration is not a string.", backend)) + return + } + s.config.Debugger.Backend = backendParsed + } else { + s.config.Debugger.Backend = "default" + } + s.config.ProcessArgs = append([]string{program}, targetArgs...) s.config.Debugger.WorkingDir = filepath.Dir(program) @@ -1436,6 +1450,20 @@ func (s *Server) onAttachRequest(request *dap.AttachRequest) { s.sendErrorResponse(request.Request, FailedToAttach, "Failed to attach", err.Error()) return } + backend, ok := request.Arguments["backend"] + if ok { + backendParsed, ok := backend.(string) + if !ok { + s.sendErrorResponse(request.Request, + FailedToAttach, "Failed to attach", + fmt.Sprintf("'backend' attribute '%v' in debug configuration is not a string.", backend)) + return + } + s.config.Debugger.Backend = backendParsed + } else { + s.config.Debugger.Backend = "default" + } + func() { s.mu.Lock() defer s.mu.Unlock() // Make sure to unlock in case of panic that will become internal error diff --git a/service/dap/server_test.go b/service/dap/server_test.go index 08872dcb..71ded520 100644 --- a/service/dap/server_test.go +++ b/service/dap/server_test.go @@ -22,7 +22,6 @@ import ( protest "github.com/go-delve/delve/pkg/proc/test" "github.com/go-delve/delve/service" "github.com/go-delve/delve/service/dap/daptest" - "github.com/go-delve/delve/service/debugger" "github.com/google/go-dap" ) @@ -73,9 +72,6 @@ func startDapServer(t *testing.T) *daptest.Client { server := NewServer(&service.Config{ Listener: listener, DisconnectChan: disconnectChan, - Debugger: debugger.Config{ - Backend: "default", - }, }) server.Run() // Give server time to start listening for clients @@ -284,7 +280,7 @@ func TestAttachStopOnEntry(t *testing.T) { // 2 >> attach, << initialized, << attach client.AttachRequest( - map[string]interface{}{"mode": "local", "processId": cmd.Process.Pid, "stopOnEntry": true}) + map[string]interface{}{"mode": "local", "processId": cmd.Process.Pid, "stopOnEntry": true, "backend": "default"}) initEvent := client.ExpectInitializedEvent(t) if initEvent.Seq != 0 { t.Errorf("\ngot %#v\nwant Seq=0", initEvent) @@ -869,7 +865,7 @@ func TestScopesAndVariablesRequests(t *testing.T) { // Launch func() { client.LaunchRequestWithArgs(map[string]interface{}{ - "mode": "exec", "program": fixture.Path, "showGlobalVariables": true, + "mode": "exec", "program": fixture.Path, "showGlobalVariables": true, "backend": "default", }) }, // Breakpoints are set within the program @@ -4683,6 +4679,18 @@ func TestBadLaunchRequests(t *testing.T) { checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t), "Failed to launch: 'buildFlags' attribute '123' in debug configuration is not a string.") + // Bad "backend" + client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "backend": 123}) + checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t), + "Failed to launch: 'backend' attribute '123' in debug configuration is not a string.") + client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "backend": "foo"}) + checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t), + "Failed to launch: could not launch process: unknown backend \"foo\"") + client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "backend": ""}) + checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t), + "Failed to launch: could not launch process: unknown backend \"\"") + + // Bad "substitutePath" client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "substitutePath": 123}) checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t), "Failed to launch: 'substitutePath' attribute '123' in debug configuration is not a []{'from': string, 'to': string}") @@ -4698,6 +4706,8 @@ func TestBadLaunchRequests(t *testing.T) { client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "substitutePath": []interface{}{map[string]interface{}{"from": "path1", "to": 123}}}) checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t), "Failed to launch: 'substitutePath' attribute '[map[from:path1 to:123]]' in debug configuration is not a []{'from': string, 'to': string}") + + // Bad "cwd" client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "cwd": 123}) checkFailedToLaunchWithMessage(client.ExpectErrorResponse(t), "Failed to launch: 'cwd' attribute '123' in debug configuration is not a string.") @@ -4736,7 +4746,7 @@ func TestBadLaunchRequests(t *testing.T) { } checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t), "Failed to launch: Build error: Check the debug console for details.") - // Bad "wd". + // Bad "cwd" client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "noDebug": false, "cwd": "dir/invalid"}) checkFailedToLaunch(client.ExpectErrorResponse(t)) // invalid directory, the error message is system-dependent. client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "noDebug": true, "cwd": "dir/invalid"}) @@ -4838,7 +4848,18 @@ func TestBadAttachRequest(t *testing.T) { t.Errorf("Id got %d, want 8888", er.Body.Error.Id) } - // We failed to launch the program. Make sure shutdown still works. + // Bad "backend" + client.AttachRequest(map[string]interface{}{"mode": "local", "processId": 1, "backend": 123}) + checkFailedToAttachWithMessage(client.ExpectInvisibleErrorResponse(t), + "Failed to attach: 'backend' attribute '123' in debug configuration is not a string.") + client.AttachRequest(map[string]interface{}{"mode": "local", "processId": 1, "backend": "foo"}) + checkFailedToAttachWithMessage(client.ExpectInvisibleErrorResponse(t), + "Failed to attach: could not attach to pid 1: unknown backend \"foo\"") + client.AttachRequest(map[string]interface{}{"mode": "local", "processId": 1, "backend": ""}) + checkFailedToAttachWithMessage(client.ExpectInvisibleErrorResponse(t), + "Failed to attach: could not attach to pid 1: unknown backend \"\"") + + // We failed to attach to the program. Make sure shutdown still works. client.DisconnectRequest() dresp := client.ExpectDisconnectResponse(t) if dresp.RequestSeq != seqCnt {