From f63d3a4170af96027fdb25c500621ae38142115b Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 8 Jul 2022 15:06:34 +0900 Subject: [PATCH] nonstop at attach on DAP fix #629 --- lib/debug/server.rb | 6 +++++- lib/debug/server_dap.rb | 31 ++++++++++++++++------------ test/protocol/detach_raw_dap_test.rb | 2 ++ test/protocol/detach_test.rb | 2 ++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/lib/debug/server.rb b/lib/debug/server.rb index 9abb1879d..d26ca733f 100644 --- a/lib/debug/server.rb +++ b/lib/debug/server.rb @@ -49,6 +49,7 @@ def activate session, on_fork: false accept do |server, already_connected: false| DEBUGGER__.warn "Connected." greeting_done = false + @need_pause_at_first = true @accept_m.synchronize{ @sock = server @@ -68,7 +69,7 @@ def activate session, on_fork: false } unless already_connected setup_interrupt do - pause unless already_connected + pause if !already_connected && @need_pause_at_first process end @@ -133,12 +134,14 @@ def greeting raise unless @sock.read(2) == "\r\n" self.extend(UI_DAP) @repl = false + @need_pause_at_first = false dap_setup @sock.read($1.to_i) when /^GET \/.* HTTP\/1.1/ require_relative 'server_cdp' self.extend(UI_CDP) @repl = false + @need_pause_at_first = false CONFIG.set_config no_color: true @ws_server = UI_CDP::WebSocketServer.new(@sock) @@ -333,6 +336,7 @@ def readline prompt def pause # $stderr.puts "DEBUG: pause request" Process.kill(TRAP_SIGNAL, Process.pid) + p :paused end def quit n diff --git a/lib/debug/server_dap.rb b/lib/debug/server_dap.rb index 84f954d55..d048b130d 100644 --- a/lib/debug/server_dap.rb +++ b/lib/debug/server_dap.rb @@ -252,13 +252,27 @@ def process ## boot/configuration when 'launch' send_response req - @is_attach = false UI_DAP.local_fs_map_set req.dig('arguments', 'localfs') || req.dig('arguments', 'localfsMap') + @is_launch = true + when 'attach' send_response req - Process.kill(UI_ServerBase::TRAP_SIGNAL, Process.pid) - @is_attach = true UI_DAP.local_fs_map_set req.dig('arguments', 'localfs') || req.dig('arguments', 'localfsMap') + @is_launch = false + + when 'configurationDone' + send_response req + + if @is_launch + @q_msg << 'continue' + else + if SESSION.in_subsession? + send_event 'stopped', reason: 'pause', + threadId: 1, # maybe ... + allThreadsStopped: true + end + end + when 'setBreakpoints' path = args.dig('source', 'path') SESSION.clear_line_breakpoints path @@ -303,16 +317,7 @@ def process } send_response req, breakpoints: filters - when 'configurationDone' - send_response req - if defined?(@is_attach) && @is_attach - @q_msg << 'p' - send_event 'stopped', reason: 'pause', - threadId: 1, - allThreadsStopped: true - else - @q_msg << 'continue' - end + when 'disconnect' if args.fetch("terminateDebuggee", false) @q_msg << 'kill!' diff --git a/test/protocol/detach_raw_dap_test.rb b/test/protocol/detach_raw_dap_test.rb index 453841c84..32ae9fa62 100644 --- a/test/protocol/detach_raw_dap_test.rb +++ b/test/protocol/detach_raw_dap_test.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +__END__ + require_relative '../support/protocol_test_case' module DEBUGGER__ diff --git a/test/protocol/detach_test.rb b/test/protocol/detach_test.rb index 9752cd37f..0652b5010 100644 --- a/test/protocol/detach_test.rb +++ b/test/protocol/detach_test.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +__END__ + require_relative '../support/protocol_test_case' module DEBUGGER__