Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/debug/server_dap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/protocol/disconnect_dap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/support/protocol_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down