Skip to content

Commit d75e115

Browse files
committed
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.
1 parent 4e3d9d3 commit d75e115

File tree

5 files changed

+35
-15
lines changed

5 files changed

+35
-15
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,14 @@ config set no_color true
494494
* `RUBY_DEBUG_SAVE_HISTORY` (`save_history`): maximum save history lines (default: 10000)
495495

496496
* REMOTE
497+
* `RUBY_DEBUG_OPEN` (`open`): Open remote port (same as `rdbg --open` option)
497498
* `RUBY_DEBUG_PORT` (`port`): TCP/IP remote debugging: port
498499
* `RUBY_DEBUG_HOST` (`host`): TCP/IP remote debugging: host (default: 127.0.0.1)
499500
* `RUBY_DEBUG_SOCK_PATH` (`sock_path`): UNIX Domain Socket remote debugging: socket path
500501
* `RUBY_DEBUG_SOCK_DIR` (`sock_dir`): UNIX Domain Socket remote debugging: socket directory
501502
* `RUBY_DEBUG_LOCAL_FS_MAP` (`local_fs_map`): Specify local fs map
502503
* `RUBY_DEBUG_SKIP_BP` (`skip_bp`): Skip breakpoints if no clients are attached (default: false)
503504
* `RUBY_DEBUG_COOKIE` (`cookie`): Cookie for negotiation
504-
* `RUBY_DEBUG_OPEN_FRONTEND` (`open_frontend`): frontend used by open command (vscode, chrome, default: rdbg).
505505
* `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))
506506

507507
* OBSOLETE

exe/rdbg

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ when :start
1010
require 'rbconfig'
1111

1212
libpath = File.join(File.expand_path(File.dirname(__dir__)), 'lib/debug')
13-
start_mode = config[:remote] ? "open" : 'start'
13+
start_mode = config[:open] ? "open" : 'start'
1414
cmd = config[:command] ? ARGV.shift : (ENV['RUBY'] || RbConfig.ruby)
1515

1616
if defined?($:.resolve_feature_path)

lib/debug/config.rb

+20-3
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ module DEBUGGER__
3939
save_history: ['RUBY_DEBUG_SAVE_HISTORY',"BOOT: maximum save history lines", :int, "10000"],
4040

4141
# remote setting
42+
open: ['RUBY_DEBUG_OPEN', "REMOTE: Open remote port (same as `rdbg --open` option)"],
4243
port: ['RUBY_DEBUG_PORT', "REMOTE: TCP/IP remote debugging: port"],
4344
host: ['RUBY_DEBUG_HOST', "REMOTE: TCP/IP remote debugging: host", :string, "127.0.0.1"],
4445
sock_path: ['RUBY_DEBUG_SOCK_PATH', "REMOTE: UNIX Domain Socket remote debugging: socket path"],
4546
sock_dir: ['RUBY_DEBUG_SOCK_DIR', "REMOTE: UNIX Domain Socket remote debugging: socket directory"],
4647
local_fs_map: ['RUBY_DEBUG_LOCAL_FS_MAP', "REMOTE: Specify local fs map", :path_map],
4748
skip_bp: ['RUBY_DEBUG_SKIP_BP', "REMOTE: Skip breakpoints if no clients are attached", :bool, 'false'],
4849
cookie: ['RUBY_DEBUG_COOKIE', "REMOTE: Cookie for negotiation"],
49-
open_frontend: ['RUBY_DEBUG_OPEN_FRONTEND',"REMOTE: frontend used by open command (vscode, chrome, default: rdbg)."],
5050
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))"],
5151

5252
# obsolete
@@ -298,8 +298,25 @@ def self.parse_argv argv
298298
'If TCP/IP options are not given, a UNIX domain socket will be used.',
299299
'If FRONTEND is given, prepare for the FRONTEND.',
300300
'Now rdbg, vscode and chrome is supported.') do |f|
301-
config[:remote] = true
302-
config[:open_frontend] = f.downcase if f
301+
302+
case f # some format patterns are not documented yet
303+
when nil
304+
config[:open] = true
305+
when /\A\d\z/
306+
config[:open] = true
307+
config[:port] = f.to_i
308+
when /\A(\S+):(\d+)\z/
309+
config[:open] = true
310+
config[:host] = $1
311+
config[:port] = $2.to_i
312+
when 'tcp'
313+
config[:open] = true
314+
config[:port] ||= 0
315+
when 'vscode', 'chrome', 'cdp'
316+
config[:open] = f&.downcase
317+
else
318+
raise "Unknown option for --open: #{f}"
319+
end
303320
end
304321
o.on('--sock-path=SOCK_PATH', 'UNIX Domain socket path') do |path|
305322
config[:sock_path] = path

lib/debug/server.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def accept
437437
#
438438
EOS
439439

440-
case CONFIG[:open_frontend]
440+
case CONFIG[:open]
441441
when 'chrome'
442442
chrome_setup
443443
when 'vscode'
@@ -494,7 +494,7 @@ def accept
494494
end
495495

496496
::DEBUGGER__.warn "Debugger can attach via UNIX domain socket (#{@sock_path})"
497-
vscode_setup @sock_path if CONFIG[:open_frontend] == 'vscode'
497+
vscode_setup @sock_path if CONFIG[:open] == 'vscode'
498498

499499
begin
500500
Socket.unix_server_loop @sock_path do |sock, client|

lib/debug/session.rb

+11-8
Original file line numberDiff line numberDiff line change
@@ -1042,10 +1042,10 @@ def register_default_command
10421042
when 'tcp'
10431043
::DEBUGGER__.open_tcp host: CONFIG[:host], port: (CONFIG[:port] || 0), nonstop: true
10441044
when 'vscode'
1045-
CONFIG[:open_frontend] = 'vscode'
1045+
CONFIG[:open] = 'vscode'
10461046
::DEBUGGER__.open nonstop: true
10471047
when 'chrome', 'cdp'
1048-
CONFIG[:open_frontend] = 'chrome'
1048+
CONFIG[:open] = 'chrome'
10491049
::DEBUGGER__.open_tcp host: CONFIG[:host], port: (CONFIG[:port] || 0), nonstop: true
10501050
else
10511051
raise "Unknown arg: #{arg}"
@@ -2105,19 +2105,22 @@ def self.require_location
21052105
def self.start nonstop: false, **kw
21062106
CONFIG.set_config(**kw)
21072107

2108-
unless defined? SESSION
2109-
require_relative 'local'
2110-
initialize_session{ UI_LocalConsole.new }
2108+
if CONFIG[:open]
2109+
open nonstop: nonstop, **kw
2110+
else
2111+
unless defined? SESSION
2112+
require_relative 'local'
2113+
initialize_session{ UI_LocalConsole.new }
2114+
end
2115+
setup_initial_suspend unless nonstop
21112116
end
2112-
2113-
setup_initial_suspend unless nonstop
21142117
end
21152118

21162119
def self.open host: nil, port: CONFIG[:port], sock_path: nil, sock_dir: nil, nonstop: false, **kw
21172120
CONFIG.set_config(**kw)
21182121
require_relative 'server'
21192122

2120-
if port || CONFIG[:open_frontend] == 'chrome' || (!::Addrinfo.respond_to?(:unix))
2123+
if port || CONFIG[:open] == 'chrome' || (!::Addrinfo.respond_to?(:unix))
21212124
open_tcp host: host, port: (port || 0), nonstop: nonstop
21222125
else
21232126
open_unix sock_path: sock_path, sock_dir: sock_dir, nonstop: nonstop

0 commit comments

Comments
 (0)