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

Allow starting debug server without opening apps #995

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ d => 4
[1, 2, 3, 4]
```

### Invoke the program from the debugger as a traditional debuggers
### Invoke the program from the debugger as a traditional debugger

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

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`.
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`.

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

Expand Down Expand Up @@ -358,15 +358,20 @@ $ RUBY_DEBUG_PORT=12345 ruby target.rb

### Integration with external debugger frontend

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

```
```shell
$ rdbg --open=[frontend] target.rb
```

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

Also `open` command allows opening the debug port.
| Flag | Frontend |
|------|----------|
| <nobr>`--open=vscode`</nobr> | Starts a DAP session and automatically opens Visual Studio Code. |
| <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.
| <nobr>`--open=chrome`</nobr> | Starts a CDP session and automatically opens Chrome. |
| <nobr>`--open=cdp`</nobr> | Starts a Chrome debug protocol (CDP) session, _without_ opening Chrome. This allows for another CDP client to connect instead.

#### VSCode integration

Expand Down
2 changes: 1 addition & 1 deletion lib/debug/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def self.parse_argv argv
when 'tcp'
config[:open] = true
config[:port] ||= 0
when 'vscode', 'chrome', 'cdp'
when 'vscode', 'dap', 'chrome', 'cdp'
config[:open] = f&.downcase
else
raise "Unknown option for --open: #{f}"
Expand Down
15 changes: 11 additions & 4 deletions lib/debug/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ def after_fork_parent
# do nothing
end

def vscode_setup debug_port
def vscode_setup debug_port, launch_vscode: true
require_relative 'server_dap'
UI_DAP.setup debug_port
UI_DAP.setup debug_port if launch_vscode
end
end

Expand Down Expand Up @@ -442,8 +442,10 @@ def accept
case CONFIG[:open]
when 'chrome'
chrome_setup
when 'dap-server' # Start in Debug Adapter Protocol mode without launching Visual Studio Code
vscode_setup @local_addr.inspect_sockaddr, launch_vscode: false
when 'vscode'
vscode_setup @local_addr.inspect_sockaddr
vscode_setup @local_addr.inspect_sockaddr, launch_vscode: true
end

Socket.accept_loop(socks) do |sock, client|
Expand Down Expand Up @@ -496,7 +498,12 @@ def accept
end

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

begin
Socket.unix_server_loop @sock_path do |sock, client|
Expand Down
8 changes: 7 additions & 1 deletion lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1118,9 +1118,15 @@ def register_default_command
when 'vscode'
CONFIG[:open] = 'vscode'
::DEBUGGER__.open nonstop: true
when 'chrome', 'cdp'
when 'dap'
CONFIG[:open] = 'dap'
::DEBUGGER__.open nonstop: true
when 'chrome'
CONFIG[:open] = 'chrome'
::DEBUGGER__.open_tcp host: CONFIG[:host], port: (CONFIG[:port] || 0), nonstop: true
when 'cdp'
CONFIG[:open] = 'cdp'
::DEBUGGER__.open_tcp host: CONFIG[:host], port: (CONFIG[:port] || 0), nonstop: true
else
raise "Unknown arg: #{arg}"
end
Expand Down
17 changes: 11 additions & 6 deletions misc/README.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ d => 4
[1, 2, 3, 4]
```

### Invoke the program from the debugger as a traditional debuggers
### Invoke the program from the debugger as a traditional debugger

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

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`.
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`.

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

Expand Down Expand Up @@ -358,15 +358,20 @@ $ RUBY_DEBUG_PORT=12345 ruby target.rb

### Integration with external debugger frontend

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

```
```shell
$ rdbg --open=[frontend] target.rb
```

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

Also `open` command allows opening the debug port.
| Flag | Frontend |
|------|----------|
| <nobr>`--open=vscode`</nobr> | Starts a DAP session and automatically opens Visual Studio Code. |
| <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.
| <nobr>`--open=chrome`</nobr> | Starts a CDP session and automatically opens Chrome. |
| <nobr>`--open=cdp`</nobr> | Starts a Chrome debug protocol (CDP) session, _without_ opening Chrome. This allows for another CDP client to connect instead.

#### VSCode integration

Expand Down