From b4d41386105b266304d8a3704bc72a103d511c22 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Wed, 23 Nov 2022 07:06:41 +0900 Subject: [PATCH] `open` conifg *Deprecate* `open_frontend` and add `open` configuration. It is consistent with `rdbg --open` option. `RUBY_DEBUG_OPEN` is also introduced. For example, ``` $ RUBY_DEBUG_OPEN=true ruby -r debug script.rb ``` opens the debug port remotely. --- README.md | 2 +- exe/rdbg | 2 +- lib/debug/config.rb | 23 ++++++++++++++++++++--- lib/debug/server.rb | 4 ++-- lib/debug/session.rb | 19 +++++++++++-------- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 7313f1f2a..8ca1f7a1a 100644 --- a/README.md +++ b/README.md @@ -494,6 +494,7 @@ config set no_color true * `RUBY_DEBUG_SAVE_HISTORY` (`save_history`): maximum save history lines (default: 10000) * REMOTE + * `RUBY_DEBUG_OPEN` (`open`): Open remote port (same as `rdbg --open` option) * `RUBY_DEBUG_PORT` (`port`): TCP/IP remote debugging: port * `RUBY_DEBUG_HOST` (`host`): TCP/IP remote debugging: host (default: 127.0.0.1) * `RUBY_DEBUG_SOCK_PATH` (`sock_path`): UNIX Domain Socket remote debugging: socket path @@ -501,7 +502,6 @@ config set no_color true * `RUBY_DEBUG_LOCAL_FS_MAP` (`local_fs_map`): Specify local fs map * `RUBY_DEBUG_SKIP_BP` (`skip_bp`): Skip breakpoints if no clients are attached (default: false) * `RUBY_DEBUG_COOKIE` (`cookie`): Cookie for negotiation - * `RUBY_DEBUG_OPEN_FRONTEND` (`open_frontend`): frontend used by open command (vscode, chrome, default: rdbg). * `RUBY_DEBUG_CHROME_PATH` (`chrome_path`): Platform dependent path of Chrome (For more information, See [here](https://github.com/ruby/debug/pull/334/files#diff-5fc3d0a901379a95bc111b86cf0090b03f857edfd0b99a0c1537e26735698453R55-R64)) * OBSOLETE diff --git a/exe/rdbg b/exe/rdbg index af230a1d0..52b93d8ce 100755 --- a/exe/rdbg +++ b/exe/rdbg @@ -10,7 +10,7 @@ when :start require 'rbconfig' libpath = File.join(File.expand_path(File.dirname(__dir__)), 'lib/debug') - start_mode = config[:remote] ? "open" : 'start' + start_mode = config[:open] ? "open" : 'start' cmd = config[:command] ? ARGV.shift : (ENV['RUBY'] || RbConfig.ruby) if defined?($:.resolve_feature_path) diff --git a/lib/debug/config.rb b/lib/debug/config.rb index ff660b7fc..70ca12487 100644 --- a/lib/debug/config.rb +++ b/lib/debug/config.rb @@ -39,6 +39,7 @@ module DEBUGGER__ save_history: ['RUBY_DEBUG_SAVE_HISTORY',"BOOT: maximum save history lines", :int, "10000"], # remote setting + open: ['RUBY_DEBUG_OPEN', "REMOTE: Open remote port (same as `rdbg --open` option)"], port: ['RUBY_DEBUG_PORT', "REMOTE: TCP/IP remote debugging: port"], host: ['RUBY_DEBUG_HOST', "REMOTE: TCP/IP remote debugging: host", :string, "127.0.0.1"], sock_path: ['RUBY_DEBUG_SOCK_PATH', "REMOTE: UNIX Domain Socket remote debugging: socket path"], @@ -46,7 +47,6 @@ module DEBUGGER__ local_fs_map: ['RUBY_DEBUG_LOCAL_FS_MAP', "REMOTE: Specify local fs map", :path_map], skip_bp: ['RUBY_DEBUG_SKIP_BP', "REMOTE: Skip breakpoints if no clients are attached", :bool, 'false'], cookie: ['RUBY_DEBUG_COOKIE', "REMOTE: Cookie for negotiation"], - open_frontend: ['RUBY_DEBUG_OPEN_FRONTEND',"REMOTE: frontend used by open command (vscode, chrome, default: rdbg)."], chrome_path: ['RUBY_DEBUG_CHROME_PATH', "REMOTE: Platform dependent path of Chrome (For more information, See [here](https://github.com/ruby/debug/pull/334/files#diff-5fc3d0a901379a95bc111b86cf0090b03f857edfd0b99a0c1537e26735698453R55-R64))"], # obsolete @@ -298,8 +298,25 @@ def self.parse_argv argv 'If TCP/IP options are not given, a UNIX domain socket will be used.', 'If FRONTEND is given, prepare for the FRONTEND.', 'Now rdbg, vscode and chrome is supported.') do |f| - config[:remote] = true - config[:open_frontend] = f.downcase if f + + case f # some format patterns are not documented yet + when nil + config[:open] = true + when /\A\d\z/ + config[:open] = true + config[:port] = f.to_i + when /\A(\S+):(\d+)\z/ + config[:open] = true + config[:host] = $1 + config[:port] = $2.to_i + when 'tcp' + config[:open] = true + config[:port] ||= 0 + when 'vscode', 'chrome', 'cdp' + config[:open] = f&.downcase + else + raise "Unknown option for --open: #{f}" + end end o.on('--sock-path=SOCK_PATH', 'UNIX Domain socket path') do |path| config[:sock_path] = path diff --git a/lib/debug/server.rb b/lib/debug/server.rb index f382b05b6..25445fb9e 100644 --- a/lib/debug/server.rb +++ b/lib/debug/server.rb @@ -437,7 +437,7 @@ def accept # EOS - case CONFIG[:open_frontend] + case CONFIG[:open] when 'chrome' chrome_setup when 'vscode' @@ -494,7 +494,7 @@ def accept end ::DEBUGGER__.warn "Debugger can attach via UNIX domain socket (#{@sock_path})" - vscode_setup @sock_path if CONFIG[:open_frontend] == 'vscode' + vscode_setup @sock_path if CONFIG[:open] == 'vscode' begin Socket.unix_server_loop @sock_path do |sock, client| diff --git a/lib/debug/session.rb b/lib/debug/session.rb index b35e173be..b83479390 100644 --- a/lib/debug/session.rb +++ b/lib/debug/session.rb @@ -1042,10 +1042,10 @@ def register_default_command when 'tcp' ::DEBUGGER__.open_tcp host: CONFIG[:host], port: (CONFIG[:port] || 0), nonstop: true when 'vscode' - CONFIG[:open_frontend] = 'vscode' + CONFIG[:open] = 'vscode' ::DEBUGGER__.open nonstop: true when 'chrome', 'cdp' - CONFIG[:open_frontend] = 'chrome' + CONFIG[:open] = 'chrome' ::DEBUGGER__.open_tcp host: CONFIG[:host], port: (CONFIG[:port] || 0), nonstop: true else raise "Unknown arg: #{arg}" @@ -2105,19 +2105,22 @@ def self.require_location def self.start nonstop: false, **kw CONFIG.set_config(**kw) - unless defined? SESSION - require_relative 'local' - initialize_session{ UI_LocalConsole.new } + if CONFIG[:open] + open nonstop: nonstop, **kw + else + unless defined? SESSION + require_relative 'local' + initialize_session{ UI_LocalConsole.new } + end + setup_initial_suspend unless nonstop end - - setup_initial_suspend unless nonstop end def self.open host: nil, port: CONFIG[:port], sock_path: nil, sock_dir: nil, nonstop: false, **kw CONFIG.set_config(**kw) require_relative 'server' - if port || CONFIG[:open_frontend] == 'chrome' || (!::Addrinfo.respond_to?(:unix)) + if port || CONFIG[:open] == 'chrome' || (!::Addrinfo.respond_to?(:unix)) open_tcp host: host, port: (port || 0), nonstop: nonstop else open_unix sock_path: sock_path, sock_dir: sock_dir, nonstop: nonstop