Skip to content

Commit 9d19068

Browse files
committed
Assume loopback server address is localfs
We can assume listening loopback address should be localfs. fix #598 (comment)
1 parent 32eba51 commit 9d19068

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

lib/debug/server.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def vscode_setup debug_port
353353

354354
class UI_TcpServer < UI_ServerBase
355355
def initialize host: nil, port: nil
356-
@addr = nil
356+
@local_addr = nil
357357
@host = host || CONFIG[:host] || '127.0.0.1'
358358
@port_save_file = nil
359359
@port = begin
@@ -375,11 +375,11 @@ def initialize host: nil, port: nil
375375
def chrome_setup
376376
require_relative 'server_cdp'
377377

378-
unless @chrome_pid = UI_CDP.setup_chrome(@addr)
378+
unless @chrome_pid = UI_CDP.setup_chrome(@local_addr.inspect_sockaddr)
379379
DEBUGGER__.warn <<~EOS
380380
With Chrome browser, type the following URL in the address-bar:
381381
382-
devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=#{@addr}/#{SecureRandom.uuid}
382+
devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=#{@local_addr.inspect_sockaddr}/#{SecureRandom.uuid}
383383
384384
EOS
385385
end
@@ -391,9 +391,9 @@ def accept
391391

392392
begin
393393
Socket.tcp_server_sockets @host, @port do |socks|
394-
@addr = socks[0].local_address.inspect_sockaddr # Change this part if `socks` are multiple.
394+
@local_addr = socks.first.local_address # Change this part if `socks` are multiple.
395395
rdbg = File.expand_path('../../exe/rdbg', __dir__)
396-
DEBUGGER__.warn "Debugger can attach via TCP/IP (#{@addr})"
396+
DEBUGGER__.warn "Debugger can attach via TCP/IP (#{@local_addr.inspect_sockaddr})"
397397

398398
if @port_save_file
399399
File.write(@port_save_file, "#{socks[0].local_address.ip_port.to_s}\n")
@@ -403,15 +403,15 @@ def accept
403403
DEBUGGER__.info <<~EOS
404404
With rdbg, use the following command line:
405405
#
406-
# #{rdbg} --attach #{@addr.split(':').join(' ')}
406+
# #{rdbg} --attach #{@local_addr.ip_address} #{@local_addr.ip_port}
407407
#
408408
EOS
409409

410410
case CONFIG[:open_frontend]
411411
when 'chrome'
412412
chrome_setup
413413
when 'vscode'
414-
vscode_setup @addr
414+
vscode_setup @local_addr.inspect_sockaddr
415415
end
416416

417417
Socket.accept_loop(socks) do |sock, client|

lib/debug/server_cdp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def process
346346
send_event 'Runtime.executionContextCreated',
347347
context: {
348348
id: SecureRandom.hex(16),
349-
origin: "http://#{@addr}",
349+
origin: "http://#{@local_addr.inspect_sockaddr}",
350350
name: ''
351351
}
352352
when 'Runtime.getIsolateId'

lib/debug/server_dap.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ def self.local_fs_set
8383
def dap_setup bytes
8484
CONFIG.set_config no_color: true
8585
@seq = 0
86-
UI_DAP.local_fs_set if self.kind_of?(UI_UnixDomainServer)
86+
87+
case self
88+
when UI_UnixDomainServer
89+
UI_DAP.local_fs_set
90+
when UI_TcpServer
91+
UI_DAP.local_fs_set if @local_addr.ipv4_loopback? || @local_addr.ipv6_loopback?
92+
end
8793

8894
show_protocol :>, bytes
8995
req = JSON.load(bytes)

0 commit comments

Comments
 (0)