Sha256: 834d78e4ce791d571ca9c16b3bfe15f7069c5fff5737e311a2ab2852110c9fee
Contents?: true
Size: 1.97 KB
Versions: 4
Compression:
Stored size: 1.97 KB
Contents
module Debugger module MultiProcess class << self def pre_child require "socket" require "ostruct" host = '127.0.0.1' port = find_free_port(host) options = OpenStruct.new( 'frame_bind' => false, 'host' => host, 'load_mode' => false, 'port' => port, 'stop' => false, 'tracing' => false, 'int_handler' => true ) acceptor_host, acceptor_port = ENV['IDE_PROCESS_DISPATCHER'].split(":") acceptor_host, acceptor_port = '127.0.0.1', acceptor_host unless acceptor_port connected = false 3.times do |i| begin s = TCPSocket.open(acceptor_host, acceptor_port) s.print(port) s.close connected = true start_debugger(options) return rescue => bt $stderr.puts "#{Process.pid}: connection failed(#{i+1})" $stderr.puts "Exception: #{bt}" $stderr.puts bt.backtrace.map { |l| "\t#{l}" }.join("\n") sleep 0.3 end unless connected end end def start_debugger(options) if Debugger.started? #we're in forked child, only need to restart control thread Debugger.breakpoints.clear Debugger.control_thread = nil Debugger.start_control(options.host, options.port) end if options.int_handler # install interruption handler trap('INT') { Debugger.interrupt_last } end # set options Debugger.keep_frame_binding = options.frame_bind Debugger.tracing = options.tracing Debugger.prepare_debugger(options) end def find_free_port(host) server = TCPServer.open(host, 0) port = server.addr[1] server.close port end end end end
Version data entries
4 entries across 4 versions & 1 rubygems