module Byebug
def self.attach
Starts byebug, and stops at the first line of user's code.
def self.attach require "byebug/core" unless started? self.mode = :attached start run_init_script end current_context.step_out(3, true) end
def self.handle_post_mortem
prompt back to the user before program termination.
Saves information about the unhandled exception and gives a byebug
def self.handle_post_mortem return unless raised_exception context = raised_exception.__bb_context PostMortemProcessor.new(context).at_line end
def self.load_settings
def self.load_settings Dir.glob(File.join(__dir__, "settings", "*.rb")).each do |file| require file end constants.grep(/[a-z]Setting/).map do |name| setting = const_get(name).new Byebug::Setting.settings[setting.to_sym] = setting end end
def self.spawn(host = "localhost", port = nil)
def self.spawn(host = "localhost", port = nil) require "byebug/core" self.wait_connection = true start_server(host, port || PORT) end
def actual_control_port
def actual_control_port control.actual_port end
def actual_port
def actual_port server.actual_port end
def client
def client @client ||= Remote::Client.new(Context.interface) end
def control
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
def interrupt
Interrupts the current thread
def interrupt current_context.interrupt end
def parse_host_and_port(host_port_spec)
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
def rc_dirs
- Note: - Files will be loaded in the order specified here.
def rc_dirs [ENV["HOME"], Dir.pwd].compact.uniq end
def run_init_script
are debugging, in the directory where you invoke byebug.
generic in your home directory, and another, specific to the program you
from your home directory. Thus, you can have more than one init file, one
working directory. This is only done if the current directory is different
Reads and executes the commands from init file (if any) in the current
Runs normal byebug initialization scripts.
def run_init_script rc_dirs.each do |dir| rc_file = File.expand_path(File.join(dir, init_file)) next unless File.exist?(rc_file) run_rc_file(rc_file) end end
def run_rc_file(rc_file)
Runs a initialization script file
def run_rc_file(rc_file) interface = ScriptInterface.new(rc_file) ScriptProcessor.new(nil, interface).process_commands end
def server
def server @server ||= Remote::Server.new(wait_connection: wait_connection) do |s| Context.interface = RemoteInterface.new(s) end end
def start_client(host = "localhost", port = PORT)
Connects to the remote byebug
def start_client(host = "localhost", port = PORT) client.start(host, port) end
def start_control(host = nil, port = PORT + 1)
Starts the remote server control thread
def start_control(host = nil, port = PORT + 1) control.start(host, port) end
def start_server(host = nil, port = PORT)
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