Sha256: 2702cdaeb08f3a6e516914e1fd4189f3e05708448b0d36b798411cf20089b76c

Contents?: true

Size: 1.45 KB

Versions: 23

Compression:

Stored size: 1.45 KB

Contents

module Debugger
  module MultiProcess
    class << self
      def pre_child

        require 'socket'
        require 'ostruct'

        host = ENV['DEBUGGER_HOST']
        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,
            'cli_debug'   => (ENV['DEBUGGER_CLI_DEBUG'] == 'true'),
            'notify_dispatcher' => true
        )

        start_debugger(options)
      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, options.notify_dispatcher)
        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.cli_debug = options.cli_debug

        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

23 entries across 23 versions & 1 rubygems

Version Path
ruby-debug-ide-0.6.1.beta2 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.6.0 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.6.0.beta1 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.5.0 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.33 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.32 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.31 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.30 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.29 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.28 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.27 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.26 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.25 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.24 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.24.beta5 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.24.beta4 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.23 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.23.beta11 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.23.beta10 lib/ruby-debug-ide/multiprocess/pre_child.rb
ruby-debug-ide-0.4.23.beta9 lib/ruby-debug-ide/multiprocess/pre_child.rb