Module: Debugger

Defined in:
lib/rack-debug/debugger.rb

Constant Summary collapse

DEFAULT_SOCKET_PATH =
File.join(Dir.getwd, 'tmp', 'sockets', 'debugger')

Class Method Summary collapse

Class Method Details

.start_unix_socket_client(socket_path) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/rack-debug/debugger.rb', line 70

def start_unix_socket_client(socket_path)
  socket_path ||= DEFAULT_SOCKET_PATH

  require "socket"
  interface = Debugger::LocalInterface.new
  socket = UNIXSocket.new(socket_path + '.server')
  puts "Connected."

  catch(:exit) do
    while (line = socket.gets)
      case line
      when /^PROMPT (.*)$/
        input = interface.read_command($1)
        throw :exit unless input
        socket.puts input
      when /^CONFIRM (.*)$/
        input = interface.confirm($1)
        throw :exit unless input
        socket.puts input
      else
        print line
      end
    end
  end
  socket.close
end

.start_unix_socket_control(socket_path) ⇒ Object

:nodoc:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rack-debug/debugger.rb', line 53

def start_unix_socket_control(socket_path) # :nodoc:
  raise "Debugger is not started" unless started?
  return if defined?(@control_thread) && @control_thread

  socket_path ||= DEFAULT_SOCKET_PATH

  File.unlink(socket_path) if File.exists?(socket_path)
  @control_thread = DebugThread.new do
    server = UNIXServer.open(socket_path)
    while (session = server.accept)
      interface = RemoteInterface.new(session)
      processor = ControlCommandProcessor.new(interface)
      processor.process_commands
    end
  end
end

.start_unix_socket_remote(socket_path, post_mortem = false) ⇒ Object Also known as: start_unix_socket_server



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rack-debug/debugger.rb', line 11

def start_unix_socket_remote(socket_path, post_mortem = false)
  return if @thread
  return if started?

  socket_path ||= DEFAULT_SOCKET_PATH

  self.interface = nil
  start
  self.post_mortem if post_mortem

  FileUtils.mkdir_p(File.dirname(socket_path))

  server_path  = "#{socket_path}.server"
  control_path = "#{socket_path}.control"

  start_unix_socket_control(control_path)

  yield if block_given?

  mutex = Mutex.new
  proceed = ConditionVariable.new

  File.unlink(server_path) if File.exists?(server_path)
  @thread = DebugThread.new do
    server = UNIXServer.open(server_path)
    while (session = server.accept)
      self.interface = RemoteInterface.new(session)
      if wait_connection
        mutex.synchronize do
          proceed.signal
        end
      end
    end
  end
  if wait_connection
    mutex.synchronize do
      proceed.wait(mutex)
    end
  end
end