Skip to content

Commit ae2c157

Browse files
committed
Allow starting debug server without opening apps
1 parent ab937ac commit ae2c157

File tree

5 files changed

+41
-18
lines changed

5 files changed

+41
-18
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ d => 4
138138
[1, 2, 3, 4]
139139
```
140140

141-
### Invoke the program from the debugger as a traditional debuggers
141+
### Invoke the program from the debugger as a traditional debugger
142142

143143
If you don't want to modify the source code, you can set breakpoints with a debug command `break` (`b` for short).
144144
Using `rdbg` command (or `bundle exec rdbg`) to launch the program without any modifications, you can run the program with the debugger.
@@ -253,7 +253,7 @@ Examples:
253253
* `rdbg -c -- bundle exec rake test`
254254
* `rdbg -c -- ruby target.rb` is same as `rdbg target.rb`
255255

256-
NOTE: `--` is needed to separate the command line options for `rdbg` and invoking command. For example, `rdbg -c rake -T` is recognized like `rdbg -c -T -- rake`. It should be `rdbg -c -- rake -T`.
256+
NOTE: `--` is needed to separate the command line options for `rdbg` from the invoked command. For example, `rdbg -c rake -T` is recognized like `rdbg -c -T -- rake`. It should be `rdbg -c -- rake -T`.
257257

258258
NOTE: If you want to use bundler (`bundle` command), you need to write `gem debug` line in your `Gemfile`.
259259

@@ -358,15 +358,20 @@ $ RUBY_DEBUG_PORT=12345 ruby target.rb
358358

359359
### Integration with external debugger frontend
360360

361-
You can attach with external debugger frontend with VSCode and Chrome.
361+
You can start a debugging session for an external debugger frontend using:
362362

363-
```
363+
```shell
364364
$ rdbg --open=[frontend] target.rb
365365
```
366366

367-
will open a debug port and `[frontend]` can attach to the port.
367+
The currently available frontends are:
368368

369-
Also `open` command allows opening the debug port.
369+
| Flag | Frontend |
370+
|------|----------|
371+
| <nobr>`--open=vscode`</nobr> | Starts a DAP session and automatically opens Visual Studio Code. |
372+
| <nobr>`--open=dap`</nobr> | Starts a debug adapter protocol (DAP) session, _without_ opening Visual Studio code. This allows for another DAP client to connect instead.
373+
| <nobr>`--open=chrome`</nobr> | Starts a CDP session and automatically opens Chrome. |
374+
| <nobr>`--open=cdp`</nobr> | Starts a Chrome debug protocol (CDP) session, _without_ opening Chrome. This allows for another CDP client to connect instead.
370375

371376
#### VSCode integration
372377

lib/debug/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def self.parse_argv argv
324324
when 'tcp'
325325
config[:open] = true
326326
config[:port] ||= 0
327-
when 'vscode', 'chrome', 'cdp'
327+
when 'vscode', 'dap', 'chrome', 'cdp'
328328
config[:open] = f&.downcase
329329
else
330330
raise "Unknown option for --open: #{f}"

lib/debug/server.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@ def after_fork_parent
376376
# do nothing
377377
end
378378

379-
def vscode_setup debug_port
379+
def vscode_setup debug_port, launch_vscode: true
380380
require_relative 'server_dap'
381-
UI_DAP.setup debug_port
381+
UI_DAP.setup debug_port if launch_vscode
382382
end
383383
end
384384

@@ -442,8 +442,10 @@ def accept
442442
case CONFIG[:open]
443443
when 'chrome'
444444
chrome_setup
445+
when 'dap-server' # Start in Debug Adapter Protocol mode without launching Visual Studio Code
446+
vscode_setup @local_addr.inspect_sockaddr, launch_vscode: false
445447
when 'vscode'
446-
vscode_setup @local_addr.inspect_sockaddr
448+
vscode_setup @local_addr.inspect_sockaddr, launch_vscode: true
447449
end
448450

449451
Socket.accept_loop(socks) do |sock, client|
@@ -496,7 +498,12 @@ def accept
496498
end
497499

498500
::DEBUGGER__.warn "Debugger can attach via UNIX domain socket (#{@sock_path})"
499-
vscode_setup @sock_path if CONFIG[:open] == 'vscode'
501+
case CONFIG[:open]
502+
when 'dap-server' # Start in Debug Adapter Protocol mode without launching Visual Studio Code
503+
vscode_setup @sock_path, launch_vscode: false
504+
when 'vscode'
505+
vscode_setup @sock_path, launch_vscode: true
506+
end
500507

501508
begin
502509
Socket.unix_server_loop @sock_path do |sock, client|

lib/debug/session.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,9 +1118,15 @@ def register_default_command
11181118
when 'vscode'
11191119
CONFIG[:open] = 'vscode'
11201120
::DEBUGGER__.open nonstop: true
1121-
when 'chrome', 'cdp'
1121+
when 'dap'
1122+
CONFIG[:open] = 'dap'
1123+
::DEBUGGER__.open nonstop: true
1124+
when 'chrome'
11221125
CONFIG[:open] = 'chrome'
11231126
::DEBUGGER__.open_tcp host: CONFIG[:host], port: (CONFIG[:port] || 0), nonstop: true
1127+
when 'cdp'
1128+
CONFIG[:open] = 'cdp'
1129+
::DEBUGGER__.open_tcp host: CONFIG[:host], port: (CONFIG[:port] || 0), nonstop: true
11241130
else
11251131
raise "Unknown arg: #{arg}"
11261132
end

misc/README.md.erb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ d => 4
138138
[1, 2, 3, 4]
139139
```
140140

141-
### Invoke the program from the debugger as a traditional debuggers
141+
### Invoke the program from the debugger as a traditional debugger
142142

143143
If you don't want to modify the source code, you can set breakpoints with a debug command `break` (`b` for short).
144144
Using `rdbg` command (or `bundle exec rdbg`) to launch the program without any modifications, you can run the program with the debugger.
@@ -253,7 +253,7 @@ Examples:
253253
* `rdbg -c -- bundle exec rake test`
254254
* `rdbg -c -- ruby target.rb` is same as `rdbg target.rb`
255255

256-
NOTE: `--` is needed to separate the command line options for `rdbg` and invoking command. For example, `rdbg -c rake -T` is recognized like `rdbg -c -T -- rake`. It should be `rdbg -c -- rake -T`.
256+
NOTE: `--` is needed to separate the command line options for `rdbg` from the invoked command. For example, `rdbg -c rake -T` is recognized like `rdbg -c -T -- rake`. It should be `rdbg -c -- rake -T`.
257257

258258
NOTE: If you want to use bundler (`bundle` command), you need to write `gem debug` line in your `Gemfile`.
259259

@@ -358,15 +358,20 @@ $ RUBY_DEBUG_PORT=12345 ruby target.rb
358358

359359
### Integration with external debugger frontend
360360

361-
You can attach with external debugger frontend with VSCode and Chrome.
361+
You can start a debugging session for an external debugger frontend using:
362362

363-
```
363+
```shell
364364
$ rdbg --open=[frontend] target.rb
365365
```
366366

367-
will open a debug port and `[frontend]` can attach to the port.
367+
The currently available frontends are:
368368

369-
Also `open` command allows opening the debug port.
369+
| Flag | Frontend |
370+
|------|----------|
371+
| <nobr>`--open=vscode`</nobr> | Starts a DAP session and automatically opens Visual Studio Code. |
372+
| <nobr>`--open=dap`</nobr> | Starts a debug adapter protocol (DAP) session, _without_ opening Visual Studio code. This allows for another DAP client to connect instead.
373+
| <nobr>`--open=chrome`</nobr> | Starts a CDP session and automatically opens Chrome. |
374+
| <nobr>`--open=cdp`</nobr> | Starts a Chrome debug protocol (CDP) session, _without_ opening Chrome. This allows for another CDP client to connect instead.
370375

371376
#### VSCode integration
372377

0 commit comments

Comments
 (0)