service/dap: add modes comments (TODO from PR/2367) (#2575)

Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
This commit is contained in:
polinasok 2021-07-18 11:06:52 -07:00 committed by GitHub
parent af378d396f
commit 4e78f7f391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -952,16 +952,34 @@ func (s *Server) stopNoDebugProcess() {
s.noDebugProcess = nil s.noDebugProcess = nil
} }
// TODO(polina): support "remote" mode // Launch debug sessions support the following modes:
func isValidLaunchMode(launchMode interface{}) bool { // -- [DEFAULT] "debug" - builds and launches debugger for specified program (similar to 'dlv debug')
switch launchMode { // Required args: program
// Optional args with default: output, cwd, noDebug
// Optional args: buildFlags, args
// -- "test" - builds and launches debugger for specified test (similar to 'dlv test')
// same args as above
// -- "exec" - launches debugger for precompiled binary (similar to 'dlv exec')
// Required args: program
// Optional args with default: cwd, noDebug
// Optional args: args
// TODO(pull/2367): add "replay", "core"
func isValidLaunchMode(mode interface{}) bool {
switch mode {
case "exec", "debug", "test": case "exec", "debug", "test":
return true return true
} }
return false return false
} }
// Attach debug sessions support the following modes:
// -- [DEFAULT] "local" -- attaches debugger to a local running process
// Required args: processId
// TODO(polina): support "remote" mode
func isValidAttachMode(mode interface{}) bool {
return mode == "local"
}
// onDisconnectRequest handles the DisconnectRequest. Per the DAP spec, // onDisconnectRequest handles the DisconnectRequest. Per the DAP spec,
// it disconnects the debuggee and signals that the debug adaptor // it disconnects the debuggee and signals that the debug adaptor
// (in our case this TCP server) can be terminated. // (in our case this TCP server) can be terminated.
@ -1436,6 +1454,14 @@ func (s *Server) onAttachRequest(request *dap.AttachRequest) {
if !ok || mode == "" { if !ok || mode == "" {
mode = "local" mode = "local"
} }
if !isValidAttachMode(mode) {
// TODO(polina): support 'remote' mode that expects a non-nil debugger
s.sendErrorResponse(request.Request,
FailedToAttach, "Failed to attach",
fmt.Sprintf("Unsupported 'mode' value %q in debug configuration", mode))
return
}
if mode == "local" { if mode == "local" {
pid, ok := request.Arguments["processId"].(float64) pid, ok := request.Arguments["processId"].(float64)
if !ok || pid == 0 { if !ok || pid == 0 {
@ -1473,12 +1499,6 @@ func (s *Server) onAttachRequest(request *dap.AttachRequest) {
s.sendErrorResponse(request.Request, FailedToAttach, "Failed to attach", err.Error()) s.sendErrorResponse(request.Request, FailedToAttach, "Failed to attach", err.Error())
return return
} }
} else {
// TODO(polina): support 'remote' mode with 'host' and 'port'
s.sendErrorResponse(request.Request,
FailedToAttach, "Failed to attach",
fmt.Sprintf("Unsupported 'mode' value %q in debug configuration", mode))
return
} }
// Notify the client that the debugger is ready to start accepting // Notify the client that the debugger is ready to start accepting
// configuration requests for setting breakpoints, etc. The client // configuration requests for setting breakpoints, etc. The client