Module: Debugger

Defined in:
ext/debugger.rb

Constant Summary collapse

SOCKET_PATH =
File.join(Rails.root, 'tmp', 'sockets', 'debugger')

Class Method Summary collapse

Class Method Details

.start_unix_socket_client(socket_path = SOCKET_PATH) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'ext/debugger.rb', line 64

def start_unix_socket_client(socket_path=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 = SOCKET_PATH) ⇒ Object

:nodoc:



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'ext/debugger.rb', line 50

def start_unix_socket_control(socket_path=SOCKET_PATH) # :nodoc:
  raise "Debugger is not started" unless started?
  return if defined?(@control_thread) && @control_thread
  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 = SOCKET_PATH, post_mortem = false) ⇒ Object Also known as: start_unix_socket_server



10
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
# File 'ext/debugger.rb', line 10

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

  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