class SporkDebugger::PreloadState
def connect_rdebug_client(port = Debugger::PORT)
def connect_rdebug_client(port = Debugger::PORT) puts "\n\n - Debug Session Started - \n\n\n" begin Debugger.start_client(SporkDebugger::HOST, port) rescue Errno::EPIPE, Errno::ECONNRESET, Errno::ECONNREFUSED end puts "\n\n - Debug Session Terminated - \n\n\n" end
def debugger(steps = 1)
def debugger(steps = 1) SporkDebugger.instance.prepare_debugger debugger_without_spork_hook end
def finish
def finish @tcp_service.close; @tcp_service = nil; end
def initialize
def initialize Spork.each_run { install_hook } listen_for_connection_signals end
def install_hook
def install_hook Kernel.class_eval do alias :debugger_without_spork_hook :debugger def debugger(steps = 1) SporkDebugger.instance.prepare_debugger debugger_without_spork_hook end end end
def listen_for_connection_signals
def listen_for_connection_signals @port = SporkDebugger::DEFAULT_PORT begin @tcp_service = TCPServer.new(SporkDebugger::HOST, @port) rescue Errno::EADDRINUSE @port += 1 retry end Thread.new { main_loop } end
def main_loop
def main_loop while @tcp_service do socket = @tcp_service.accept port = Marshal.load(socket) Marshal.dump(true, socket) connect_rdebug_client(port) socket.close end rescue => e puts "error: #{e.class} - #{e}" end
def transition_to_each_run_state
def transition_to_each_run_state finish SporkDebugger::EachRunState.new(@port) end