1 require 'debugger/interface'
6 class Server < Interface
7 REMOTE_DEBUG_PORT = 1098
9 class ClientQuitError < RuntimeError; end
11 def initialize(port=REMOTE_DEBUG_PORT, host=nil)
14 Debugger.instance.interface = self
18 # Begins listening on the configured host/port for debugger commands
20 @server = @host ? TCPServer.open(@host, @port) : TCPServer.open(@port)
21 @server.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, [1].pack("i"))
24 addrs = @server.addr[2..-1].uniq
26 STDOUT.puts "*** Debugger listening on #{addrs.collect{|a|"#{a}:#{@port}"}.join(' ')}"
28 # Wait for a debugger client to connect
29 @client = @server.accept
30 STDOUT.puts "*** Debugger client connected from #{@client.peeraddr[2]}:#{@client.peeraddr[1]}"
33 # Debugger callback implementation for getting debug commands from a user
34 def process_commands(dbg, thread, ctxt, bp_list)
37 while line = @client.gets # read a line at a time
40 STDOUT.puts "[#{Time.now}]: #{line}"
41 output = process_command(dbg, line)
42 @client.puts CGI::escape(output.to_s)
48 STDOUT.puts "*** EOF on socket - client disconnected"
53 STDOUT.puts "*** Client disconnected"
55 STDERR.puts e.awesome_backtrace
64 # Closes the connection to the client
67 @client.puts 'finished'
69 @client.close # close socket on error
74 STDOUT.puts "*** Debug server finished"