Method: Debugger.start_control

Defined in:
lib/ruby-debug-ide.rb

.start_control(host, port, notify_dispatcher) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ruby-debug-ide.rb', line 102

def start_control(host, port, notify_dispatcher)
  raise "Debugger is not started" unless started?
  return if @control_thread
  @control_thread = DebugThread.new do
    begin
      # 127.0.0.1 seemingly works with all systems and with IPv6 as well.
      # "localhost" and nil have problems on some systems.
      host ||= '127.0.0.1'
      server = TCPServer.new(host, port)
      print_greeting_msg(host, port)
      notify_dispatcher(port) if notify_dispatcher

      while (session = server.accept)
        $stderr.puts "Connected from #{session.peeraddr[2]}" if Debugger.cli_debug
        dispatcher = ENV['IDE_PROCESS_DISPATCHER']
        if dispatcher
          ENV['IDE_PROCESS_DISPATCHER'] = "#{session.peeraddr[2]}:#{dispatcher}" unless dispatcher.include?(":")
          ENV['DEBUGGER_HOST'] = host
        end
        begin
          @interface = RemoteInterface.new(session)
          self.handler = EventProcessor.new(interface)
          IdeControlCommandProcessor.new(interface).process_commands
        rescue StandardError, ScriptError => ex
          bt = ex.backtrace
          $stderr.printf "#{Process.pid}: Exception in DebugThread loop: #{ex.message}(#{ex.class})\nBacktrace:\n#{bt ? bt.join("\n  from: ") : "<none>"}\n"
          exit 1
        end
      end
    rescue
      bt = $!.backtrace
      $stderr.printf "Fatal exception in DebugThread loop: #{$!.message}\nBacktrace:\n#{bt ? bt.join("\n  from: ") : "<none>"}\n"
      exit 2
    end
  end
end