debug 1.6.3 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/debug/local.rb CHANGED
@@ -13,23 +13,28 @@ module DEBUGGER__
13
13
  false
14
14
  end
15
15
 
16
- def activate session, on_fork: false
17
- unless CONFIG[:no_sigint_hook]
18
- prev_handler = trap(:SIGINT){
19
- if session.active?
20
- ThreadClient.current.on_trap :SIGINT
21
- end
22
- }
23
- session.intercept_trap_sigint_start prev_handler
24
- end
16
+ def activate_sigint
17
+ prev_handler = trap(:SIGINT){
18
+ if SESSION.active?
19
+ ThreadClient.current.on_trap :SIGINT
20
+ end
21
+ }
22
+ SESSION.intercept_trap_sigint_start prev_handler
25
23
  end
26
24
 
27
- def deactivate
25
+ def deactivate_sigint
28
26
  if SESSION.intercept_trap_sigint?
29
27
  prev = SESSION.intercept_trap_sigint_end
30
28
  trap(:SIGINT, prev)
31
29
  end
30
+ end
31
+
32
+ def activate session, on_fork: false
33
+ activate_sigint unless CONFIG[:no_sigint_hook]
34
+ end
32
35
 
36
+ def deactivate
37
+ deactivate_sigint
33
38
  @console.deactivate
34
39
  end
35
40
 
@@ -42,6 +47,7 @@ module DEBUGGER__
42
47
  end
43
48
 
44
49
  def quit n
50
+ yield
45
51
  exit n
46
52
  end
47
53
 
data/lib/debug/open.rb CHANGED
File without changes
File without changes
data/lib/debug/prelude.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  return if ENV['RUBY_DEBUG_ENABLE'] == '0'
4
- return if defined?(::DEBUGGER__)
4
+ return if defined?(::DEBUGGER__::Session)
5
5
 
6
6
  # Put the following line in your login script (e.g. ~/.bash_profile) with modified path:
7
7
  #
data/lib/debug/server.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'socket'
4
- require 'etc'
5
4
  require_relative 'config'
6
5
  require_relative 'version'
7
6
 
@@ -22,6 +21,7 @@ module DEBUGGER__
22
21
 
23
22
  class Terminate < StandardError; end
24
23
  class GreetingError < StandardError; end
24
+ class RetryConnection < StandardError; end
25
25
 
26
26
  def deactivate
27
27
  @reader_thread.raise Terminate
@@ -78,6 +78,8 @@ module DEBUGGER__
78
78
  next
79
79
  rescue Terminate
80
80
  raise # should catch at outer scope
81
+ rescue RetryConnection
82
+ next
81
83
  rescue => e
82
84
  DEBUGGER__.warn "ReaderThreadError: #{e}"
83
85
  pp e.backtrace
@@ -128,6 +130,8 @@ module DEBUGGER__
128
130
  def greeting
129
131
  case g = @sock.gets
130
132
  when /^info cookie:\s+(.*)$/
133
+ require 'etc'
134
+
131
135
  check_cookie $1
132
136
  @sock.puts "PID: #{Process.pid}, $0: #{$0}"
133
137
  @sock.puts "debug #{VERSION} on #{RUBY_DESCRIPTION}"
@@ -140,7 +144,8 @@ module DEBUGGER__
140
144
 
141
145
  # TODO: protocol version
142
146
  if v != VERSION
143
- raise GreetingError, "Incompatible version (server:#{VERSION} and client:#{$1})"
147
+ @sock.puts msg = "out DEBUGGER: Incompatible version (server:#{VERSION} and client:#{$1})"
148
+ raise GreetingError, msg
144
149
  end
145
150
  parse_option(params)
146
151
 
@@ -157,16 +162,13 @@ module DEBUGGER__
157
162
  @need_pause_at_first = false
158
163
  dap_setup @sock.read($1.to_i)
159
164
 
160
- when /^GET \/.* HTTP\/1.1/
165
+ when /^GET\s\/json\sHTTP\/1.1/, /^GET\s\/json\/version\sHTTP\/1.1/, /^GET\s\/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}\sHTTP\/1.1/
166
+ # The reason for not using @uuid here is @uuid is nil if users run debugger without `--open=chrome`.
167
+
161
168
  require_relative 'server_cdp'
162
169
 
163
170
  self.extend(UI_CDP)
164
- @repl = false
165
- @need_pause_at_first = false
166
- CONFIG.set_config no_color: true
167
-
168
- @ws_server = UI_CDP::WebSocketServer.new(@sock)
169
- @ws_server.handshake
171
+ send_chrome_response g
170
172
  else
171
173
  raise GreetingError, "Unknown greeting message: #{g}"
172
174
  end
@@ -174,17 +176,17 @@ module DEBUGGER__
174
176
 
175
177
  def process
176
178
  while true
177
- DEBUGGER__.info "sleep IO.select"
178
- r = IO.select([@sock])
179
- DEBUGGER__.info "wakeup IO.select"
179
+ DEBUGGER__.debug{ "sleep IO.select" }
180
+ _r = IO.select([@sock])
181
+ DEBUGGER__.debug{ "wakeup IO.select" }
180
182
 
181
183
  line = @session.process_group.sync do
182
184
  unless IO.select([@sock], nil, nil, 0)
183
- DEBUGGER__.info "UI_Server can not read"
185
+ DEBUGGER__.debug{ "UI_Server can not read" }
184
186
  break :can_not_read
185
187
  end
186
188
  @sock.gets&.chomp.tap{|line|
187
- DEBUGGER__.info "UI_Server received: #{line}"
189
+ DEBUGGER__.debug{ "UI_Server received: #{line}" }
188
190
  }
189
191
  end
190
192
 
@@ -340,12 +342,12 @@ module DEBUGGER__
340
342
  if @repl
341
343
  raise "not in subsession, but received: #{line.inspect}" unless @session.in_subsession?
342
344
  line = "input #{Process.pid}"
343
- DEBUGGER__.info "send: #{line}"
345
+ DEBUGGER__.debug{ "send: #{line}" }
344
346
  s.puts line
345
347
  end
346
348
  sleep 0.01 until @q_msg
347
349
  @q_msg.pop.tap{|msg|
348
- DEBUGGER__.info "readline: #{msg.inspect}"
350
+ DEBUGGER__.debug{ "readline: #{msg.inspect}" }
349
351
  }
350
352
  end || 'continue')
351
353
 
@@ -361,7 +363,7 @@ module DEBUGGER__
361
363
  Process.kill(TRAP_SIGNAL, Process.pid)
362
364
  end
363
365
 
364
- def quit n
366
+ def quit n, &_b
365
367
  # ignore n
366
368
  sock do |s|
367
369
  s.puts "quit"
@@ -395,6 +397,7 @@ module DEBUGGER__
395
397
  raise "Specify digits for port number"
396
398
  end
397
399
  end
400
+ @uuid = nil # for CDP
398
401
 
399
402
  super()
400
403
  end
@@ -402,11 +405,12 @@ module DEBUGGER__
402
405
  def chrome_setup
403
406
  require_relative 'server_cdp'
404
407
 
405
- unless @chrome_pid = UI_CDP.setup_chrome(@local_addr.inspect_sockaddr)
408
+ @uuid = SecureRandom.uuid
409
+ unless @chrome_pid = UI_CDP.setup_chrome(@local_addr.inspect_sockaddr, @uuid)
406
410
  DEBUGGER__.warn <<~EOS
407
411
  With Chrome browser, type the following URL in the address-bar:
408
412
 
409
- devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=#{@local_addr.inspect_sockaddr}/#{SecureRandom.uuid}
413
+ devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=#{@local_addr.inspect_sockaddr}/#{@uuid}
410
414
 
411
415
  EOS
412
416
  end
@@ -434,7 +438,7 @@ module DEBUGGER__
434
438
  #
435
439
  EOS
436
440
 
437
- case CONFIG[:open_frontend]
441
+ case CONFIG[:open]
438
442
  when 'chrome'
439
443
  chrome_setup
440
444
  when 'vscode'
@@ -491,7 +495,7 @@ module DEBUGGER__
491
495
  end
492
496
 
493
497
  ::DEBUGGER__.warn "Debugger can attach via UNIX domain socket (#{@sock_path})"
494
- vscode_setup @sock_path if CONFIG[:open_frontend] == 'vscode'
498
+ vscode_setup @sock_path if CONFIG[:open] == 'vscode'
495
499
 
496
500
  begin
497
501
  Socket.unix_server_loop @sock_path do |sock, client|