Class: DEBUGGER__::UI_TcpServer

Inherits:
UI_ServerBase show all
Defined in:
lib/debug/server.rb

Instance Attribute Summary

Attributes inherited from UI_ServerBase

#reader_thread

Instance Method Summary collapse

Methods inherited from UI_ServerBase

#activate, #after_fork_parent, #ask, #check_cookie, #cleanup_reader, #deactivate, #greeting, #parse_option, #pause, #process, #puts, #quit, #readline, #remote?, #setup_interrupt, #sigurg_overridden?, #sock, #vscode_setup, #width

Methods inherited from UI_Base

#event, #flush, #ignore_output_on_suspend?

Constructor Details

#initialize(host: nil, port: nil) ⇒ UI_TcpServer

Returns a new instance of UI_TcpServer.



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/debug/server.rb', line 384

def initialize host: nil, port: nil
  @local_addr = nil
  @host = host || CONFIG[:host]
  @port_save_file = nil
  @port = begin
    port_str = (port && port.to_s) || CONFIG[:port] || raise("Specify listening port by RUBY_DEBUG_PORT environment variable.")
    case port_str
    when /\A\d+\z/
      port_str.to_i
    when /\A(\d+):(.+)\z/
      @port_save_file = $2
      $1.to_i
    else
      raise "Specify digits for port number"
    end
  end
  @uuid = nil # for CDP

  super()
end

Instance Method Details

#acceptObject



419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/debug/server.rb', line 419

def accept
  retry_cnt = 0
  super # for fork

  begin
    Socket.tcp_server_sockets @host, @port do |socks|
      @local_addr = socks.first.local_address # Change this part if `socks` are multiple.
      rdbg = File.expand_path('../../exe/rdbg', __dir__)
      DEBUGGER__.warn "Debugger can attach via TCP/IP (#{@local_addr.inspect_sockaddr})"

      if @port_save_file
        File.write(@port_save_file, "#{socks[0].local_address.ip_port.to_s}\n")
        DEBUGGER__.warn "Port is saved into #{@port_save_file}"
      end

      DEBUGGER__.info "      With rdbg, use the following command line:\n      #\n      #   \#{rdbg} --attach \#{@local_addr.ip_address} \#{@local_addr.ip_port}\n      #\n      EOS\n\n      case CONFIG[:open]\n      when 'chrome'\n        chrome_setup\n      when 'vscode'\n        vscode_setup @local_addr.inspect_sockaddr\n      end\n\n      Socket.accept_loop(socks) do |sock, client|\n        @client_addr = client\n        yield @sock_for_fork = sock\n      end\n    end\n  rescue Errno::EADDRINUSE\n    if retry_cnt < 10\n      retry_cnt += 1\n      sleep 0.1\n      retry\n    else\n      raise\n    end\n  rescue Terminate\n    # OK\n  rescue => e\n    $stderr.puts e.inspect, e.message\n    pp e.backtrace\n    exit\n  end\nensure\n  @sock_for_fork = nil\n\n  if @port_save_file && File.exist?(@port_save_file)\n    File.unlink(@port_save_file)\n  end\nend\n"

#chrome_setupObject



405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/debug/server.rb', line 405

def chrome_setup
  require_relative 'server_cdp'

  @uuid = SecureRandom.uuid
  unless @chrome_pid = UI_CDP.setup_chrome(@local_addr.inspect_sockaddr, @uuid)
    DEBUGGER__.warn "      With Chrome browser, type the following URL in the address-bar:\n\n         devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=\#{@local_addr.inspect_sockaddr}/\#{@uuid}\n\n      EOS\n  end\nend\n"