Sha256: 8c248149f78e8d8d9b3d7c3a9124c11240a41629bbb24b5fdeab98c929c9a300

Contents?: true

Size: 1.87 KB

Versions: 18

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

require "socket"
require "byebug/processors/control_processor"
require "byebug/remote/server"
require "byebug/remote/client"

#
# Remote debugging functionality.
#
module Byebug
  # Port number used for remote debugging
  PORT = 8989 unless defined?(PORT)

  class << self
    # If in remote mode, wait for the remote connection
    attr_accessor :wait_connection

    # The actual port that the server is started at
    def actual_port
      server.actual_port
    end

    # The actual port that the control server is started at
    def actual_control_port
      control.actual_port
    end

    #
    # Interrupts the current thread
    #
    def interrupt
      current_context.interrupt
    end

    #
    # Starts the remote server main thread
    #
    def start_server(host = nil, port = PORT)
      start_control(host, port.zero? ? 0 : port + 1)

      server.start(host, port)
    end

    #
    # Starts the remote server control thread
    #
    def start_control(host = nil, port = PORT + 1)
      control.start(host, port)
    end

    #
    # Connects to the remote byebug
    #
    def start_client(host = "localhost", port = PORT)
      client.start(host, port)
    end

    def parse_host_and_port(host_port_spec)
      location = host_port_spec.split(":")
      location[1] ? [location[0], location[1].to_i] : ["localhost", location[0]]
    end

    private

    def client
      @client ||= Remote::Client.new(Context.interface)
    end

    def server
      @server ||= Remote::Server.new(wait_connection: wait_connection) do |s|
        Context.interface = RemoteInterface.new(s)
      end
    end

    def control
      @control ||= Remote::Server.new(wait_connection: false) do |s|
        context = Byebug.current_context
        interface = RemoteInterface.new(s)

        ControlProcessor.new(context, interface).process_commands
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 8 rubygems

Version Path
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/byebug-10.0.2/lib/byebug/remote.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/byebug-10.0.2/lib/byebug/remote.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/byebug-10.0.2/lib/byebug/remote.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/byebug-11.0.1/lib/byebug/remote.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/byebug-11.0.1/lib/byebug/remote.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/byebug-11.0.1/lib/byebug/remote.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/byebug-11.0.1/lib/byebug/remote.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/byebug-10.0.2/lib/byebug/remote.rb
byebug-11.0.1 lib/byebug/remote.rb
byebug-11.0.0 lib/byebug/remote.rb
jets-0.5.5 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/remote.rb
jets-0.5.4 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/remote.rb
jets-0.5.3 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/remote.rb
jets-0.5.2 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/remote.rb
jets-0.5.1 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/remote.rb
byebug-10.0.2 lib/byebug/remote.rb
byebug-10.0.1 lib/byebug/remote.rb
byebug-10.0.0 lib/byebug/remote.rb