debug 1.2.3 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebbeeac4c437bdefb9c0115008b705debb189b6332ee9ea056fd469c323c7149
4
- data.tar.gz: 7a6abfb0490eaa49ec118efe89e50c51111be291a0b342fca930c3887a66aa72
3
+ metadata.gz: 7316cec0879fc91787183e28cad0bbc4a1f819eb7d3ee4530a28b2ee173877e9
4
+ data.tar.gz: e37f36b72d3aec5fed4559c78474358c487e3c1748a732984a42331c2a96191a
5
5
  SHA512:
6
- metadata.gz: 7bfb31a8b9b5fc882c20c28992ecdc501d4a11a8088023664ef2d590385e7ba3a8f756b92b74c607b0148e7e6710c213a14659ce8f33e10b261ee4031993582d
7
- data.tar.gz: ad174799dd193021f845e971e08c19cc8c31bb915ee603659c33299c4a5e21d9bdf2e7687dfb1da75e0e573442fdc116b343d8caa7e54550ae62fbeea1ed6165
6
+ metadata.gz: 51ba70e0a9b9c73170080a0e428edf178aa98aceb409e8d4b69ea16eb36796467852c07ba38c103cbac8f7e0861119d40d1e6272d5d002ac472ec2b92801a5b5
7
+ data.tar.gz: 8e02dc629e83151c4a1b744ed3dcd9262e57d1c6dad012bfa1f42410636f9f467a189aa3579abad419e443c943c39930729305311456b06c4fc0a562ef49827c
data/CONTRIBUTING.md CHANGED
@@ -206,17 +206,15 @@ end
206
206
  #### gentest options
207
207
  You can get more information about `gentest` here.
208
208
 
209
- The default method name is `test_foo` and the class name is `FooTest`. The file name will be `[Lowercase letters with "Test" removed from the class name]_test.rb`.
210
- ```shell
211
- # run without any options(test method name will be `test_foo`, class name will be `FooTest`, file name will be `foo_test.rb`)
212
- $ bin/gentest target.rb
213
- # specify the class name(test method name will be `test_foo`, class name will be `StepTest`, file name will be `step_test.rb`)
214
- $ bin/gentest target.rb -c StepTest
215
- # specify the method name(test method name will be `test_step`, class name will be `FooTest`, file name will be `foo_test.rb`)
216
- $ bin/gentest target.rb -m test_step
217
- # specify class name and method name(test method name will be `test_step`, class name will be `StepTest`, file name will be `step_test.rb`.)
218
- $ bin/gentest target.rb -c StepTest -m test_step
219
- ```
209
+ The default method name is `test_#{some integer numbers}`, the class name is `FooTest`, and the file name will be `foo_test.rb`.
210
+ The following table shows examples of the gentest options.
211
+
212
+ | Command | Description | File | Class | Method |
213
+ | --- | --- | --- | --- | --- |
214
+ | `$ bin/gentest target.rb` | Run without any options | `foo_test.rb` | `FooTest` | `test_#{some integer numbers}` |
215
+ | `$ bin/gentest target.rb -c step` | Specify the class name | `step_test.rb` | `StepTest` | `test_#{some integer numbers}` |
216
+ | `$ bin/gentest target.rb -m test_step` | Specify the method name | `foo_test.rb` | `FooTest` | `test_step` |
217
+ | `$ bin/gentest target.rb -c step -m test_step` | Specify the class name and the method name | `step_test.rb` | `StepTest` | `test_step` |
220
218
 
221
219
  ## To Update README
222
220
 
data/README.md CHANGED
@@ -11,7 +11,9 @@ New debug.rb has several advantages:
11
11
  * [Remote debugging](#remote-debugging): Support remote debugging natively.
12
12
  * UNIX domain socket
13
13
  * TCP/IP
14
- * VSCode/DAP integration ([VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg))
14
+ * Integration with rich debugger frontend
15
+ * VSCode/DAP ([VSCode rdbg Ruby Debugger - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=KoichiSasada.vscode-rdbg))
16
+ * Chrome DevTools
15
17
  * Extensible: application can introduce debugging support with several ways:
16
18
  * By `rdbg` command
17
19
  * By loading libraries with `-r` command line option
@@ -336,6 +338,97 @@ By default, UNIX domain socket is used for the debugging port. To use TCP/IP, yo
336
338
  $ RUBY_DEBUG_PORT=12345 ruby target.rb
337
339
  ```
338
340
 
341
+ ### Integration with external debugger frontend
342
+
343
+ You can attach with external debugger frontend with VSCode and Chrome.
344
+
345
+ ```
346
+ $ rdbg --open=[frontend] target.rb
347
+ ```
348
+
349
+ will open a debug port and `[frontned]` can attache to the port.
350
+
351
+ Also `open` command allows opening the debug port.
352
+
353
+ #### VSCode integration
354
+
355
+ If you don't run a debuggee Ruby process on VSCode, you can attach with VSCode later with the following steps.
356
+
357
+ `rdbg --open=vscode` opens the debug port and tries to invoke the VSCode (`code` command).
358
+
359
+ ```
360
+ $ rdbg --open=vscode target.rb
361
+ DEBUGGER: Debugger can attach via UNIX domain socket (/tmp/ruby-debug-sock-1000/ruby-debug-ko1-27706)
362
+ DEBUGGER: wait for debugger connection...
363
+ Launching: code /tmp/ruby-debug-vscode-20211014-27706-gd7e85/ /tmp/ruby-debug-vscode-20211014-27706-gd7e85/README.rb
364
+ DEBUGGER: Connected.
365
+ ```
366
+
367
+ And it tries to invoke the new VSCode window and VSCode starts attaching to the debuggee Ruby program automatically.
368
+
369
+ You can also use `open vscode` command in REPL.
370
+
371
+ ```
372
+ $ rdbg target.rb
373
+ [1, 8] in target.rb
374
+ 1|
375
+ => 2| p a = 1
376
+ 3| p b = 2
377
+ 4| p c = 3
378
+ 5| p d = 4
379
+ 6| p e = 5
380
+ 7|
381
+ 8| __END__
382
+ =>#0 <main> at target.rb:2
383
+ (rdbg) open vscode # command
384
+ DEBUGGER: wait for debugger connection...
385
+ DEBUGGER: Debugger can attach via UNIX domain socket (/tmp/ruby-debug-sock-1000/ruby-debug-ko1-28337)
386
+ Launching: code /tmp/ruby-debug-vscode-20211014-28337-kg9dm/ /tmp/ruby-debug-vscode-20211014-28337-kg9dm/README.rb
387
+ DEBUGGER: Connected.
388
+ ```
389
+
390
+ If the machine which runs the Ruby process doesn't have a `code` command, the following message will be shown:
391
+
392
+ ```
393
+ (rdbg) open vscode
394
+ DEBUGGER: wait for debugger connection...
395
+ DEBUGGER: Debugger can attach via UNIX domain socket (/tmp/ruby-debug-sock-1000/ruby-debug-ko1-455)
396
+ Launching: code /tmp/ruby-debug-vscode-20211014-455-gtjpwi/ /tmp/ruby-debug-vscode-20211014-455-gtjpwi/README.rb
397
+ DEBUGGER: Can not invoke the command.
398
+ Use the command-line on your terminal (with modification if you need).
399
+
400
+ code /tmp/ruby-debug-vscode-20211014-455-gtjpwi/ /tmp/ruby-debug-vscode-20211014-455-gtjpwi/README.rb
401
+
402
+ If your application is running on a SSH remote host, please try:
403
+
404
+ code --remote ssh-remote+[SSH hostname] /tmp/ruby-debug-vscode-20211014-455-gtjpwi/ /tmp/ruby-debug-vscode-20211014-455-gtjpwi/README.rb
405
+
406
+ ```
407
+
408
+ and try to use proposed commands.
409
+
410
+ Note that you can attach with `rdbg --attach` and continue REPL debugging.
411
+
412
+ #### Chrome DevTool integration
413
+
414
+ With `rdbg --open=chrome` command will shows the following message.
415
+
416
+ ```
417
+ $ rdbg target.rb --open=chrome
418
+ DEBUGGER: Debugger can attach via TCP/IP (127.0.0.1:43633)
419
+ DEBUGGER: With Chrome browser, type the following URL in the address-bar:
420
+
421
+ devtools://devtools/bundled/inspector.html?ws=127.0.0.1:43633
422
+
423
+ DEBUGGER: wait for debugger connection...
424
+ ```
425
+
426
+ Type `devtools://devtools/bundled/inspector.html?ws=127.0.0.1:43633` in the address-bar on Chrome browser, and you can continue the debugging with chrome browser.
427
+
428
+ Also `open chrome` command works like `open vscode`.
429
+
430
+ For more information about how to use Chrome debugging, you might want to read [here](https://developer.chrome.com/docs/devtools/)
431
+
339
432
  ## Configuration
340
433
 
341
434
  You can configure the debugger's behavior with debug commands and environment variables.
@@ -367,7 +460,7 @@ config set no_color true
367
460
  * `RUBY_DEBUG_SKIP_NOSRC` (`skip_nosrc`): Skip on no source code lines (default: false)
368
461
  * `RUBY_DEBUG_KEEP_ALLOC_SITE` (`keep_alloc_site`): Keep allocation site and p, pp shows it (default: false)
369
462
  * `RUBY_DEBUG_POSTMORTEM` (`postmortem`): Enable postmortem debug (default: false)
370
- * `RUBY_DEBUG_PARENT_ON_FORK` (`parent_on_fork`): Keep debugging parent process on fork (default: false)
463
+ * `RUBY_DEBUG_FORK_MODE` (`fork_mode`): Control which process activates a debugger after fork (both/parent/child) (default: both)
371
464
  * `RUBY_DEBUG_SIGDUMP_SIG` (`sigdump_sig`): Sigdump signal (default: disabled)
372
465
 
373
466
  * BOOT
@@ -376,6 +469,8 @@ config set no_color true
376
469
  * `RUBY_DEBUG_INIT_SCRIPT` (`init_script`): debug command script path loaded at first stop
377
470
  * `RUBY_DEBUG_COMMANDS` (`commands`): debug commands invoked at first stop. commands should be separated by ';;'
378
471
  * `RUBY_DEBUG_NO_RC` (`no_rc`): ignore loading ~/.rdbgrc(.rb)
472
+ * `RUBY_DEBUG_HISTORY_FILE` (`history_file`): history file (default: ~/.rdbg_history)
473
+ * `RUBY_DEBUG_SAVE_HISTORY` (`save_history`): maximum save history lines (default: 10,000)
379
474
 
380
475
  * REMOTE
381
476
  * `RUBY_DEBUG_PORT` (`port`): TCP/IP remote debugging: port
@@ -383,6 +478,10 @@ config set no_color true
383
478
  * `RUBY_DEBUG_SOCK_PATH` (`sock_path`): UNIX Domain Socket remote debugging: socket path
384
479
  * `RUBY_DEBUG_SOCK_DIR` (`sock_dir`): UNIX Domain Socket remote debugging: socket directory
385
480
  * `RUBY_DEBUG_COOKIE` (`cookie`): Cookie for negotiation
481
+ * `RUBY_DEBUG_OPEN_FRONTEND` (`open_frontend`): frontend used by open command (vscode, chrome, default: rdbg).
482
+
483
+ * OBSOLETE
484
+ * `RUBY_DEBUG_PARENT_ON_FORK` (`parent_on_fork`): Keep debugging parent process on fork (default: false)
386
485
 
387
486
  ### Initial scripts
388
487
 
@@ -596,6 +695,15 @@ The `<...>` notation means the argument.
596
695
  * Set <name> to default.
597
696
  * `source <file>`
598
697
  * Evaluate lines in `<file>` as debug commands.
698
+ * `open`
699
+ * open debuggee port on UNIX domain socket and wait for attaching.
700
+ * Note that `open` command is EXPERIMENTAL.
701
+ * `open [<host>:]<port>`
702
+ * open debuggee port on TCP/IP with given `[<host>:]<port>` and wait for attaching.
703
+ * `open vscode`
704
+ * open debuggee port for VSCode and launch VSCode if available.
705
+ * `open chrome`
706
+ * open debuggee port for Chrome and wait for attaching.
599
707
 
600
708
  ### Help
601
709
 
@@ -698,9 +806,10 @@ Debug console mode:
698
806
  The first argument should be a command name in $PATH.
699
807
  Example: 'rdbg -c bundle exec rake test'
700
808
 
701
- -O, --open Start remote debugging with opening the network port.
702
- If TCP/IP options are not given,
703
- a UNIX domain socket will be used.
809
+ -O, --open=[FRONTEND] Start remote debugging with opening the network port.
810
+ If TCP/IP options are not given, a UNIX domain socket will be used.
811
+ If FRONTEND is given, prepare for the FRONTEND.
812
+ Now rdbg, vscode and chrome is supported.
704
813
  --sock-path=SOCK_PATH UNIX Domain socket path
705
814
  --port=PORT Listening TCP/IP port
706
815
  --host=HOST Listening TCP/IP host
@@ -716,6 +825,7 @@ Debug console mode:
716
825
  'rdbg -O target.rb foo bar' starts and accepts attaching with UNIX domain socket.
717
826
  'rdbg -O --port 1234 target.rb foo bar' starts accepts attaching with TCP/IP localhost:1234.
718
827
  'rdbg -O --port 1234 -- -r foo -e bar' starts accepts attaching with TCP/IP localhost:1234.
828
+ 'rdbg target.rb -O chrome --port 1234' starts and accepts connecting from Chrome Devtools with localhost:1234.
719
829
 
720
830
  Attach mode:
721
831
  -A, --attach Attach to debuggee process.
@@ -750,3 +860,4 @@ Please also check the [contributing guideline](/CONTRIBUTING.md).
750
860
  # Acknowledgement
751
861
 
752
862
  * Some tests are based on [deivid-rodriguez/byebug: Debugging in Ruby 2](https://github.com/deivid-rodriguez/byebug)
863
+ * Several codes in `server_cdp.rb` are based on [geoffreylitt/ladybug: Visual Debugger](https://github.com/geoffreylitt/ladybug)
data/ext/debug/debug.c CHANGED
@@ -2,7 +2,7 @@
2
2
  #include "ruby/ruby.h"
3
3
  #include "ruby/debug.h"
4
4
  #include "ruby/encoding.h"
5
-
5
+ #include "debug_version.h"
6
6
  //
7
7
  static VALUE rb_mDebugger;
8
8
 
@@ -64,7 +64,7 @@ di_body(const rb_debug_inspector_t *dc, void *ptr)
64
64
 
65
65
  if (!NIL_P(iseq)) {
66
66
  VALUE path = iseq_realpath(iseq);
67
- if (!NIL_P(path) && str_start_with(path, skip_path_prefix)) continue;
67
+ if (!NIL_P(path) && !NIL_P(skip_path_prefix) && str_start_with(path, skip_path_prefix)) continue;
68
68
  }
69
69
 
70
70
  loc = RARRAY_AREF(locs, i);
@@ -130,5 +130,6 @@ Init_debug(void)
130
130
  rb_define_singleton_method(rb_mDebugger, "capture_frames", capture_frames, 1);
131
131
  rb_define_singleton_method(rb_mDebugger, "frame_depth", frame_depth, 0);
132
132
  rb_define_singleton_method(rb_mDebugger, "create_method_added_tracker", create_method_added_tracker, 0);
133
+ rb_define_const(rb_mDebugger, "SO_VERSION", rb_str_new2(RUBY_DEBUG_VERSION));
133
134
  Init_iseq_collector();
134
135
  }
data/ext/debug/extconf.rb CHANGED
@@ -1,2 +1,4 @@
1
1
  require 'mkmf'
2
+ require_relative '../../lib/debug/version'
3
+ File.write("debug_version.h", "#define RUBY_DEBUG_VERSION \"#{DEBUGGER__::VERSION}\"\n")
2
4
  create_makefile 'debug/debug'
data/lib/debug/client.rb CHANGED
@@ -21,6 +21,18 @@ module DEBUGGER__
21
21
  when 'list-socks'
22
22
  cleanup_unix_domain_sockets
23
23
  puts list_connections
24
+ when 'init'
25
+ if ARGV.shift == '-'
26
+ puts <<~EOS
27
+ export RUBYOPT="-r #{__dir__}/prelude $(RUBYOPT)"
28
+ EOS
29
+ else
30
+ puts <<~EOS
31
+ # add the following lines in your .bash_profile
32
+
33
+ eval "$(rdbg init -)"
34
+ EOS
35
+ end
24
36
  else
25
37
  raise "Unknown utility: #{name}"
26
38
  end
@@ -31,6 +43,7 @@ module DEBUGGER__
31
43
  if /(\d+)$/ =~ file
32
44
  begin
33
45
  Process.kill(0, $1.to_i)
46
+ rescue Errno::EPERM
34
47
  rescue Errno::ESRCH
35
48
  File.unlink(file)
36
49
  end
@@ -44,17 +57,15 @@ module DEBUGGER__
44
57
  end
45
58
 
46
59
  def initialize argv
60
+ @multi_process = false
61
+ @pid = nil
47
62
  @console = Console.new
48
63
 
49
64
  case argv.size
50
65
  when 0
51
66
  connect_unix
52
67
  when 1
53
- case arg = argv.shift
54
- when /-h/, /--help/
55
- help
56
- exit
57
- when /\A\d+\z/
68
+ if /\A\d+\z/ =~ (arg = argv.shift.strip)
58
69
  connect_tcp nil, arg.to_i
59
70
  else
60
71
  connect_unix arg
@@ -67,13 +78,20 @@ module DEBUGGER__
67
78
 
68
79
  @width = IO.console_size[1]
69
80
  @width = 80 if @width == 0
70
- @width_changed = false
71
81
 
72
82
  send "version: #{VERSION} width: #{@width} cookie: #{CONFIG[:cookie]}"
73
83
  end
74
84
 
85
+ def deactivate
86
+ @console.deactivate if @console
87
+ end
88
+
75
89
  def readline
76
- @console.readline "(rdbg:remote) "
90
+ if @multi_process
91
+ @console.readline "(rdbg:remote\##{@pid}) "
92
+ else
93
+ @console.readline "(rdbg:remote) "
94
+ end
77
95
  end
78
96
 
79
97
  def connect_unix name = nil
@@ -118,15 +136,19 @@ module DEBUGGER__
118
136
  }
119
137
  trap(:SIGWINCH){
120
138
  @width = IO.console_size[1]
121
- @width_changed = true
122
139
  }
123
140
 
124
141
  while line = @s.gets
125
142
  p recv: line if $VERBOSE
126
143
  case line
144
+
127
145
  when /^out (.*)/
128
146
  puts "#{$1}"
129
- when /^input/
147
+
148
+ when /^input (.+)/
149
+ pid = $1
150
+ @multi_process = true if @pid && @pid != pid
151
+ @pid = pid
130
152
  prev_trap = trap(:SIGINT, 'DEFAULT')
131
153
 
132
154
  begin
@@ -138,18 +160,16 @@ module DEBUGGER__
138
160
  end
139
161
 
140
162
  line = (line || 'quit').strip
163
+ send "command #{pid} #{@width} #{line}"
141
164
 
142
- if @width_changed
143
- @width_changed = false
144
- send "width #{@width}"
145
- end
165
+ when /^ask (\d+) (.*)/
166
+ pid = $1
167
+ print $2
168
+ send "answer #{pid} #{gets || ''}"
146
169
 
147
- send "command #{line}"
148
- when /^ask (.*)/
149
- print $1
150
- send "answer #{gets || ''}"
151
170
  when /^quit/
152
171
  raise 'quit'
172
+
153
173
  else
154
174
  puts "(unknown) #{line.inspect}"
155
175
  end
@@ -157,6 +177,8 @@ module DEBUGGER__
157
177
  rescue
158
178
  STDERR.puts "disconnected (#{$!})"
159
179
  exit
180
+ ensure
181
+ deactivate
160
182
  end
161
183
  end
162
184
  end
data/lib/debug/config.rb CHANGED
@@ -24,7 +24,7 @@ module DEBUGGER__
24
24
  skip_nosrc: ['RUBY_DEBUG_SKIP_NOSRC', "CONTROL: Skip on no source code lines (default: false)", :bool],
25
25
  keep_alloc_site:['RUBY_DEBUG_KEEP_ALLOC_SITE',"CONTROL: Keep allocation site and p, pp shows it (default: false)", :bool],
26
26
  postmortem: ['RUBY_DEBUG_POSTMORTEM', "CONTROL: Enable postmortem debug (default: false)", :bool],
27
- parent_on_fork: ['RUBY_DEBUG_PARENT_ON_FORK', "CONTROL: Keep debugging parent process on fork (default: false)", :bool],
27
+ fork_mode: ['RUBY_DEBUG_FORK_MODE', "CONTROL: Control which process activates a debugger after fork (both/parent/child) (default: both)", :forkmode],
28
28
  sigdump_sig: ['RUBY_DEBUG_SIGDUMP_SIG', "CONTROL: Sigdump signal (default: disabled)"],
29
29
 
30
30
  # boot setting
@@ -33,13 +33,19 @@ module DEBUGGER__
33
33
  init_script: ['RUBY_DEBUG_INIT_SCRIPT', "BOOT: debug command script path loaded at first stop"],
34
34
  commands: ['RUBY_DEBUG_COMMANDS', "BOOT: debug commands invoked at first stop. commands should be separated by ';;'"],
35
35
  no_rc: ['RUBY_DEBUG_NO_RC', "BOOT: ignore loading ~/.rdbgrc(.rb)", :bool],
36
+ history_file: ['RUBY_DEBUG_HISTORY_FILE',"BOOT: history file (default: ~/.rdbg_history)"],
37
+ save_history: ['RUBY_DEBUG_SAVE_HISTORY',"BOOT: maximum save history lines (default: 10,000)"],
36
38
 
37
39
  # remote setting
38
- port: ['RUBY_DEBUG_PORT', "REMOTE: TCP/IP remote debugging: port"],
39
- host: ['RUBY_DEBUG_HOST', "REMOTE: TCP/IP remote debugging: host (localhost if not given)"],
40
- sock_path: ['RUBY_DEBUG_SOCK_PATH', "REMOTE: UNIX Domain Socket remote debugging: socket path"],
41
- sock_dir: ['RUBY_DEBUG_SOCK_DIR', "REMOTE: UNIX Domain Socket remote debugging: socket directory"],
42
- cookie: ['RUBY_DEBUG_COOKIE', "REMOTE: Cookie for negotiation"],
40
+ port: ['RUBY_DEBUG_PORT', "REMOTE: TCP/IP remote debugging: port"],
41
+ host: ['RUBY_DEBUG_HOST', "REMOTE: TCP/IP remote debugging: host (localhost if not given)"],
42
+ sock_path: ['RUBY_DEBUG_SOCK_PATH', "REMOTE: UNIX Domain Socket remote debugging: socket path"],
43
+ sock_dir: ['RUBY_DEBUG_SOCK_DIR', "REMOTE: UNIX Domain Socket remote debugging: socket directory"],
44
+ cookie: ['RUBY_DEBUG_COOKIE', "REMOTE: Cookie for negotiation"],
45
+ open_frontend: ['RUBY_DEBUG_OPEN_FRONTEND',"REMOTE: frontend used by open command (vscode, chrome, default: rdbg)."],
46
+
47
+ # obsolete
48
+ parent_on_fork: ['RUBY_DEBUG_PARENT_ON_FORK', "OBSOLETE: Keep debugging parent process on fork (default: false)", :bool],
43
49
  }.freeze
44
50
 
45
51
  CONFIG_MAP = CONFIG_SET.map{|k, (ev, desc)| [k, ev]}.to_h.freeze
@@ -57,6 +63,10 @@ module DEBUGGER__
57
63
  update self.class.parse_argv(argv)
58
64
  end
59
65
 
66
+ def inspect
67
+ config.inspect
68
+ end
69
+
60
70
  def [](key)
61
71
  config[key]
62
72
  end
@@ -79,7 +89,7 @@ module DEBUGGER__
79
89
  end
80
90
 
81
91
  def append_config key, val
82
- conf = self.config.dup
92
+ conf = config.dup
83
93
 
84
94
  if CONFIG_SET[key]
85
95
  if CONFIG_SET[key][2] == :path
@@ -187,6 +197,13 @@ module DEBUGGER__
187
197
  else
188
198
  raise "Unknown loglevel: #{valstr}"
189
199
  end
200
+ when :forkmode
201
+ case sym = valstr.to_sym
202
+ when :parent, :child, :both, nil
203
+ sym
204
+ else
205
+ raise "unknown fork mode: #{sym}"
206
+ end
190
207
  when :path # array of String
191
208
  valstr.split(/:/).map{|e|
192
209
  if /\A\/(.+)\/\z/ =~ e
@@ -255,10 +272,12 @@ module DEBUGGER__
255
272
 
256
273
  o.separator ''
257
274
 
258
- o.on('-O', '--open', 'Start remote debugging with opening the network port.',
259
- 'If TCP/IP options are not given,',
260
- 'a UNIX domain socket will be used.') do
275
+ o.on('-O', '--open=[FRONTEND]', 'Start remote debugging with opening the network port.',
276
+ 'If TCP/IP options are not given, a UNIX domain socket will be used.',
277
+ 'If FRONTEND is given, prepare for the FRONTEND.',
278
+ 'Now rdbg, vscode and chrome is supported.') do |f|
261
279
  config[:remote] = true
280
+ config[:open_frontend] = f.downcase if f
262
281
  end
263
282
  o.on('--sock-path=SOCK_PATH', 'UNIX Domain socket path') do |path|
264
283
  config[:sock_path] = path
@@ -286,6 +305,7 @@ module DEBUGGER__
286
305
  o.separator " '#{rdbg} -O target.rb foo bar' starts and accepts attaching with UNIX domain socket."
287
306
  o.separator " '#{rdbg} -O --port 1234 target.rb foo bar' starts accepts attaching with TCP/IP localhost:1234."
288
307
  o.separator " '#{rdbg} -O --port 1234 -- -r foo -e bar' starts accepts attaching with TCP/IP localhost:1234."
308
+ o.separator " '#{rdbg} target.rb -O chrome --port 1234' starts and accepts connecting from Chrome Devtools with localhost:1234."
289
309
 
290
310
  o.separator ''
291
311
  o.separator 'Attach mode:'
@@ -351,38 +371,54 @@ module DEBUGGER__
351
371
 
352
372
  ## Unix domain socket configuration
353
373
 
354
- def self.unix_domain_socket_dir
374
+ def self.check_dir_authority path
375
+ fs = File.stat(path)
376
+
377
+ unless (dir_uid = fs.uid) == (uid = Process.uid)
378
+ raise "#{path} uid is #{dir_uid}, but Process.uid is #{uid}"
379
+ end
380
+ unless (dir_mode = fs.mode) == 040700 # 4: dir, 7:rwx
381
+ raise "#{path}'s mode is #{dir_mode.to_s(8)} (should be 040700)"
382
+ end
383
+
384
+ path
385
+ end
386
+
387
+ def self.unix_domain_socket_tmpdir
355
388
  require 'tmpdir'
356
389
 
357
- case
358
- when path = CONFIG[:sock_dir]
359
- when path = ENV['XDG_RUNTIME_DIR']
360
- when tmpdir = Dir.tmpdir
390
+ if tmpdir = Dir.tmpdir
361
391
  path = File.join(tmpdir, "ruby-debug-sock-#{Process.uid}")
362
392
 
363
- if File.exist?(path)
364
- fs = File.stat(path)
365
- unless (dir_uid = fs.uid) == (uid = Process.uid)
366
- raise "#{path} uid is #{dir_uid}, but Process.uid is #{uid}"
367
- end
368
- unless (dir_mode = fs.mode) == 040700 # 4: dir, 7:rwx
369
- raise "#{path}'s mode is #{dir_mode.to_s(8)} (should be 040700)"
370
- end
371
- else
393
+ unless File.exist?(path)
372
394
  d = Dir.mktmpdir
373
395
  File.rename(d, path)
374
396
  end
375
- when home = ENV['HOME']
397
+
398
+ check_dir_authority(path)
399
+ end
400
+ end
401
+
402
+ def self.unix_domain_socket_homedir
403
+ if home = ENV['HOME']
376
404
  path = File.join(home, '.ruby-debug-sock')
377
405
 
378
- case
379
- when !File.exist?(path)
406
+ unless File.exist?(path)
380
407
  Dir.mkdir(path, 0700)
381
- when !File.directory?(path)
382
- raise "#{path} is not a directory."
383
408
  end
409
+
410
+ check_dir_authority(path)
411
+ end
412
+ end
413
+
414
+ def self.unix_domain_socket_dir
415
+ case
416
+ when path = CONFIG[:sock_dir]
417
+ when path = ENV['XDG_RUNTIME_DIR']
418
+ when path = unix_domain_socket_tmpdir
419
+ when path = unix_domain_socket_homedir
384
420
  else
385
- raise 'specify RUBY_DEBUG_SOCK_DIR environment variable for UNIX domain socket directory.'
421
+ raise 'specify RUBY_DEBUG_SOCK_DIR environment variable.'
386
422
  end
387
423
 
388
424
  path