Skip to content

Commit 503cd00

Browse files
committed
support rdbg -n --attach
* Attach with `-n` option doesn't stop the debuggee process. * Introduce `parse_option` method for an extensible greeting message. * Show the debuggee information at connecting.
1 parent d847e20 commit 503cd00

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

lib/debug/client.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ def initialize argv
121121
@width = IO.console_size[1]
122122
@width = 80 if @width == 0
123123

124-
send "version: #{VERSION} width: #{@width} cookie: #{CONFIG[:cookie]}"
124+
send "version: #{VERSION} " +
125+
"width: #{@width} " +
126+
"cookie: #{CONFIG[:cookie] || '-'} " +
127+
"nonstop: #{CONFIG[:nonstop] ? 'true' : 'false'}"
125128
end
126129

127130
def deactivate

lib/debug/server.rb

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,24 @@ def check_cookie c
107107
end
108108
end
109109

110+
def parse_option params
111+
case params.strip
112+
when /width:\s+(\d+)/
113+
@width = $1.to_i
114+
parse_option $~.post_match
115+
when /cookie:\s+(\S+)/
116+
check_cookie $1 if $1 != '-'
117+
parse_option $~.post_match
118+
when /nonstop: (true|false)/
119+
@need_pause_at_first = false if $1 == 'true'
120+
parse_option $~.post_match
121+
when /(.+):(.+)/
122+
raise GreetingError, "Unkown option: #{params}"
123+
else
124+
# OK
125+
end
126+
end
127+
110128
def greeting
111129
case g = @sock.gets
112130
when /^info cookie:\s+(.*)$/
@@ -117,16 +135,18 @@ def greeting
117135
@sock.close
118136
raise GreetingError, "HEAD request"
119137

120-
when /^version:\s+(.+)\s+width: (\d+) cookie:\s+(.*)$/
121-
v, w, c = $1, $2, $3
138+
when /^version:\s+(\S+)\s+(.+)$/
139+
v, params = $1, $2
140+
122141
# TODO: protocol version
123142
if v != VERSION
124143
raise GreetingError, "Incompatible version (server:#{VERSION} and client:#{$1})"
125144
end
145+
parse_option(params)
126146

127-
check_cookie c
128-
129-
@width = w.to_i
147+
puts "DEBUGGER (client): Connected. PID:#{Process.pid}, $0:#{$0}"
148+
puts "DEBUGGER (client): Type `Ctrl-C` to enter the debug console." unless @need_pause_at_first
149+
puts
130150

131151
when /^Content-Length: (\d+)/
132152
require_relative 'server_dap'
@@ -136,6 +156,7 @@ def greeting
136156
@repl = false
137157
@need_pause_at_first = false
138158
dap_setup @sock.read($1.to_i)
159+
139160
when /^GET \/.* HTTP\/1.1/
140161
require_relative 'server_cdp'
141162

0 commit comments

Comments
 (0)