Class: Byebug::DAP::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/byebug/dap/server.rb

Overview

Byebug DAP Server

Instance Method Summary collapse

Constructor Details

#initialize(capture: true, forward: true) ⇒ Server

Create a new server.

Parameters:

  • capture (Boolean) (defaults to: true)

    if ‘true`, the debugee’s STDOUT and STDERR will be captured

  • forward (Boolean) (defaults to: true)

    if ‘false`, the debugee’s STDOUT and STDERR will be supressed



8
9
10
11
12
13
14
15
# File 'lib/byebug/dap/server.rb', line 8

def initialize(capture: true, forward: true)
  @started = false
  @mu = Mutex.new
  @cond = ConditionVariable.new
  @configured = false
  @capture = capture
  @forward = forward
end

Instance Method Details

#start(host, port = 0) ⇒ Server

Starts the server. Calls #start_stdio if ‘host == :stdio`. Calls #start_unix with `port` if `host == :unix`. Calls #start_tcp with `host` and `port` otherwise.

Parameters:

  • host

    ‘:stdio`, `:unix`, or the TCP host name

  • port (defaults to: 0)

    the Unix socket path or TCP port

Returns:



23
24
25
26
27
28
29
30
31
32
# File 'lib/byebug/dap/server.rb', line 23

def start(host, port = 0)
  case host
  when :stdio
    start_stdio
  when :unix
    start_unix port
  else
    start_tcp host, port
  end
end

#start_stdioServer

Starts the server using STDIN and STDOUT to communicate.

Returns:



59
60
61
62
63
64
65
66
67
# File 'lib/byebug/dap/server.rb', line 59

def start_stdio
  return if @started
  @started = true

  stream = STDIO.new
  STDIN.close
  @ios = CapturedIO.new(false, @forward) if @capture
  launch stream
end

#start_tcp(host, port) ⇒ Server

Starts the server, listening on a TCP socket.

Parameters:

  • host (std:String)

    the IP to listen on

  • port (std:Number)

    the port to listen on

Returns:



38
39
40
41
42
43
44
# File 'lib/byebug/dap/server.rb', line 38

def start_tcp(host, port)
  return if @started
  @started = true

  @ios = CapturedIO.new(@forward, @forward) if @capture
  launch_accept TCPServer.new(host, port)
end

#start_unix(socket) ⇒ Server

Starts the server, listening on a Unix socket.

Parameters:

  • socket (std:String)

    the Unix socket path

Returns:



49
50
51
52
53
54
55
# File 'lib/byebug/dap/server.rb', line 49

def start_unix(socket)
  return if @started
  @started = true

  @ios = CapturedIO.new(@forward, @forward) if @capture
  launch_accept UNIXServer.new(socket)
end

#wait_for_clientObject

Blocks until a client connects and begins debugging.



70
71
72
73
74
75
76
77
78
# File 'lib/byebug/dap/server.rb', line 70

def wait_for_client
  @mu.synchronize do
    loop do
      return if @configured

      @cond.wait(@mu)
    end
  end
end