Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open config #826

Merged
merged 1 commit into from
Nov 23, 2022
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,14 @@ 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
* `RUBY_DEBUG_SOCK_DIR` (`sock_dir`): UNIX Domain Socket remote debugging: socket directory
* `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
Expand Down
2 changes: 1 addition & 1 deletion exe/rdbg
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 20 additions & 3 deletions lib/debug/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ 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"],
sock_dir: ['RUBY_DEBUG_SOCK_DIR', "REMOTE: UNIX Domain Socket remote debugging: socket directory"],
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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/debug/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def accept
#
EOS

case CONFIG[:open_frontend]
case CONFIG[:open]
when 'chrome'
chrome_setup
when 'vscode'
Expand Down Expand Up @@ -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|
Expand Down
19 changes: 11 additions & 8 deletions lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down