From 04543efaa717c9d26259928fc34144273e8fb431 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 8 Jul 2022 23:32:54 +0900 Subject: [PATCH 1/2] support `rdbg -n --attach` * Attach with `-n` option doesn't stop the debuggee process. * Introduce `parse_option` method for an extensible greeting message. * Show the debuggee information at connecting. --- lib/debug/client.rb | 5 ++++- lib/debug/server.rb | 31 ++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/debug/client.rb b/lib/debug/client.rb index 056dd5cd0..7b59745c8 100644 --- a/lib/debug/client.rb +++ b/lib/debug/client.rb @@ -121,7 +121,10 @@ def initialize argv @width = IO.console_size[1] @width = 80 if @width == 0 - send "version: #{VERSION} width: #{@width} cookie: #{CONFIG[:cookie]}" + send "version: #{VERSION} " + + "width: #{@width} " + + "cookie: #{CONFIG[:cookie] || '-'} " + + "nonstop: #{CONFIG[:nonstop] ? 'true' : 'false'}" end def deactivate diff --git a/lib/debug/server.rb b/lib/debug/server.rb index 67a73144f..4f15707b3 100644 --- a/lib/debug/server.rb +++ b/lib/debug/server.rb @@ -107,6 +107,24 @@ def check_cookie c end end + def parse_option params + case params.strip + when /width:\s+(\d+)/ + @width = $1.to_i + parse_option $~.post_match + when /cookie:\s+(\S+)/ + check_cookie $1 if $1 != '-' + parse_option $~.post_match + when /nonstop: (true|false)/ + @need_pause_at_first = false if $1 == 'true' + parse_option $~.post_match + when /(.+):(.+)/ + raise GreetingError, "Unkown option: #{params}" + else + # OK + end + end + def greeting case g = @sock.gets when /^info cookie:\s+(.*)$/ @@ -117,16 +135,18 @@ def greeting @sock.close raise GreetingError, "HEAD request" - when /^version:\s+(.+)\s+width: (\d+) cookie:\s+(.*)$/ - v, w, c = $1, $2, $3 + when /^version:\s+(\S+)\s+(.+)$/ + v, params = $1, $2 + # TODO: protocol version if v != VERSION raise GreetingError, "Incompatible version (server:#{VERSION} and client:#{$1})" end + parse_option(params) - check_cookie c - - @width = w.to_i + puts "DEBUGGER (client): Connected. PID:#{Process.pid}, $0:#{$0}" + puts "DEBUGGER (client): Type `Ctrl-C` to enter the debug console." unless @need_pause_at_first + puts when /^Content-Length: (\d+)/ require_relative 'server_dap' @@ -136,6 +156,7 @@ def greeting @repl = false @need_pause_at_first = false dap_setup @sock.read($1.to_i) + when /^GET \/.* HTTP\/1.1/ require_relative 'server_cdp' From 9a176d5129d4ec68220b58cb76706aa3753c78fd Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 8 Jul 2022 23:40:31 +0900 Subject: [PATCH 2/2] v1.6.0dev1 Greeting format is changed so we need to upodate the version. --- lib/debug/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/debug/version.rb b/lib/debug/version.rb index 8c38ff1fa..6031ee989 100644 --- a/lib/debug/version.rb +++ b/lib/debug/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module DEBUGGER__ - VERSION = "1.5.0" + VERSION = "1.6.0dev1" end