diff --git a/lib/debug/server_dap.rb b/lib/debug/server_dap.rb index 907db2d1f..3b7101951 100644 --- a/lib/debug/server_dap.rb +++ b/lib/debug/server_dap.rb @@ -313,11 +313,14 @@ def process_request req # `launch` runs on debuggee on the same file system UI_DAP.local_fs_map_set req.dig('arguments', 'localfs') || req.dig('arguments', 'localfsMap') || true @nonstop = true + @attached = false load_extensions req when 'attach' send_response req + # The debuggee was already running; a later restart must not kill it (debug#1184). + @attached = true UI_DAP.local_fs_map_set req.dig('arguments', 'localfs') || req.dig('arguments', 'localfsMap') if req.dig('arguments', 'nonstop') == true @@ -395,6 +398,10 @@ def process_request req when 'disconnect' terminate = args.fetch("terminateDebuggee", false) + # VS Code's Restart sends terminateDebuggee together with restart. + # An attached process was not started by this session, so restart + # only drops the connection (debug#1184). + terminate = false if args["restart"] && @attached SESSION.clear_all_breakpoints send_response req diff --git a/test/protocol/disconnect_dap_test.rb b/test/protocol/disconnect_dap_test.rb index 61109da2e..296f49cf9 100644 --- a/test/protocol/disconnect_dap_test.rb +++ b/test/protocol/disconnect_dap_test.rb @@ -37,6 +37,17 @@ def test_disconnect_with_terminateDebuggee_kills_debuggee end end + def test_restart_with_terminateDebuggee_keeps_attached_debuggee_alive + run_protocol_scenario PROGRAM, cdp: false do + req_dap_disconnect(terminate_debuggee: true, restart: true) + attach_to_dap_server + assert_reattached + # suspends the debuggee so it'll take the later requests (include terminate) + suspend_debugee + req_terminate_debuggee + end + end + private def suspend_debugee diff --git a/test/support/protocol_test_case.rb b/test/support/protocol_test_case.rb index 78e0b5bb0..bf17f5316 100644 --- a/test/support/protocol_test_case.rb +++ b/test/support/protocol_test_case.rb @@ -69,8 +69,8 @@ def attach_to_cdp_server end end - def req_dap_disconnect(terminate_debuggee:) - send_dap_request 'disconnect', restart: false, terminateDebuggee: terminate_debuggee + def req_dap_disconnect(terminate_debuggee:, restart: false) + send_dap_request 'disconnect', restart: restart, terminateDebuggee: terminate_debuggee close_reader end