service/dap: fix backend parsing in replay mode (#2618)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
This commit is contained in:
parent
f1edc45f75
commit
aaed14ffcb
@ -772,6 +772,20 @@ func (s *Server) onLaunchRequest(request *dap.LaunchRequest) {
|
||||
return
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
if mode == "replay" {
|
||||
traceDirPath, _ := request.Arguments["traceDirPath"].(string)
|
||||
|
||||
@ -891,20 +905,6 @@ 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)
|
||||
|
||||
|
||||
@ -4753,19 +4753,33 @@ func TestBadLaunchRequests(t *testing.T) {
|
||||
client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "noDebug": true, "cwd": "dir/invalid"})
|
||||
checkFailedToLaunch(client.ExpectErrorResponse(t)) // invalid directory, the error message is system-dependent.
|
||||
|
||||
// Bad parameters on "replay" and "core" modes
|
||||
// Bad "replay" parameters
|
||||
// These errors come from dap layer
|
||||
client.LaunchRequestWithArgs(map[string]interface{}{"mode": "replay", "traceDirPath": ""})
|
||||
checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t),
|
||||
"Failed to launch: The 'traceDirPath' attribute is missing in debug configuration.")
|
||||
client.LaunchRequestWithArgs(map[string]interface{}{"mode": "core", "coreFilePath": ""})
|
||||
checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t),
|
||||
"Failed to launch: The program attribute is missing in debug configuration.")
|
||||
client.LaunchRequestWithArgs(map[string]interface{}{"mode": "replay", "program": fixture.Source, "traceDirPath": ""})
|
||||
checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t),
|
||||
"Failed to launch: The 'traceDirPath' attribute is missing in debug configuration.")
|
||||
// These errors come from debugger layer
|
||||
if _, err := exec.LookPath("rr"); err != nil {
|
||||
client.LaunchRequestWithArgs(map[string]interface{}{"mode": "replay", "backend": "ignored", "traceDirPath": ".."})
|
||||
checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t),
|
||||
"Failed to launch: backend unavailable")
|
||||
}
|
||||
|
||||
// Bad "core" parameters
|
||||
// These errors come from dap layer
|
||||
client.LaunchRequestWithArgs(map[string]interface{}{"mode": "core", "coreFilePath": ""})
|
||||
checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t),
|
||||
"Failed to launch: The program attribute is missing in debug configuration.")
|
||||
client.LaunchRequestWithArgs(map[string]interface{}{"mode": "core", "program": fixture.Source, "coreFilePath": ""})
|
||||
checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t),
|
||||
"Failed to launch: The 'coreFilePath' attribute is missing in debug configuration.")
|
||||
// These errors come from debugger layer
|
||||
client.LaunchRequestWithArgs(map[string]interface{}{"mode": "core", "backend": "ignored", "program": fixture.Source, "coreFilePath": fixture.Source})
|
||||
checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t),
|
||||
"Failed to launch: unrecognized core format")
|
||||
|
||||
// We failed to launch the program. Make sure shutdown still works.
|
||||
client.DisconnectRequest()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user