module Byebug

def self.settings


:force_stepping - stepping command always move to the new line
source code
:reload_source_on_change - makes 'list' command always display up-to-date
stack
:frame_class_names - displays method's class name when showing frame
:frame_full_path - displays full paths when showing frame stack
an exception
:stack_trace_on_error - shows full stack trace if eval command results in
:autoirb - automatically calls 'irb' command on breakpoint
not recognized as a byebug command
:autoeval - evaluates input in the current binding if it's
:autolist - automatically calls 'list' command on breakpoint

byebug settings. These settings are available:
Use Byebug.settings[] and Byebug.settings[]= methods to query and set
Returns ths settings object.
#
def self.settings
  Command.settings
end

def add_breakpoint(file, line, expr=nil)

Parameters:
  • expr (String) --
  • line (Fixnum) --
  • file (String) --
def add_breakpoint(file, line, expr=nil)
  breakpoint = Breakpoint.new(file, line, expr)
  breakpoints << breakpoint
  breakpoint
end

def interface=(value)

def interface=(value)
  handler.interface = value
end

def interrupt


Interrupts the current thread
def interrupt
  current_context.interrupt
end

def interrupt_last


Interrupts the last debugged thread
def interrupt_last
  if context = last_context
    return nil unless context.thread.alive?
    context.interrupt
  end
  context
end

def line_at(filename, line_number)

@return "\n" if there was a problem. Leaking blanks are stripped off.
Get line +line_number+ from file named +filename+.
def line_at(filename, line_number)
  @reload_on_change = nil unless defined?(@reload_on_change)
  line = LineCache::getline(filename, line_number, @reload_on_change)
  return "\n" unless line
  return "#{line.gsub(/^\s+/, '').chomp}"
end

def remove_breakpoint(id)

def remove_breakpoint(id)
  Breakpoint.remove breakpoints, id
end

def run_init_script(out = handler.interface)


program you are debugging, in the directory where you invoke byebug.
file, one generic in your home directory, and another, specific to the
different from your home directory. Thus, you can have more than one init
working directory. This is only done if the current directory is
Reads and executes the commands from init file (if any) in the current

Runs normal byebug initialization scripts.
#
def run_init_script(out = handler.interface)
  cwd_script  = File.expand_path(File.join(".", INITFILE))
  run_script(cwd_script, out) if File.exists?(cwd_script)
  home_script = File.expand_path(File.join(ENV['HOME'].to_s, INITFILE))
  if File.exists?(home_script) and cwd_script != home_script
     run_script(home_script, out)
  end
end

def run_script(file, out = handler.interface, verbose=false)


Runs a script file
#
def run_script(file, out = handler.interface, verbose=false)
  interface = ScriptInterface.new(File.expand_path(file), out)
  processor = ControlCommandProcessor.new(interface)
  processor.process_commands(verbose)
end

def source_reload

def source_reload
  Object.send(:remove_const, "SCRIPT_LINES__") if Object.const_defined?("SCRIPT_LINES__")
  Object.const_set("SCRIPT_LINES__", {})
  LineCache::clear_file_cache
end

def start(options={}, &block)


can't be unset.
uncaught exception. Once post-mortem debugging is set, it
:post_mortem - true if you want to enter post-mortem debugging on an
the (first) call.
saved, you should make sure it hasn't been changed before
is set to true the values will get set. Since ARGV is
make a byebug restart possible. Only the first time :init
:init - true if you want to save ARGV and some other variables to
+options+ is a hash used to set various debugging options.

many times as you called Byebug.start method.
Note that if you want to stop byebug, you must call Byebug.stop as

Byebug.start's have no effect and you can't use this inside byebug itself.
Also, byebug only allows one invocation of byebug at a time; nested

Byebug.start{byebug; foo} # Stop inside of foo

will probably want to have a call to Byebug.byebug. For example:
executed it stops byebug with Byebug.stop method. Inside the block you
If a block is given, it starts byebug and yields block. When the block is

already started.
If it's called without a block it returns +true+, unless byebug was

Byebug.start(options) { ... } -> obj
Byebug.start(options) -> bool
def start(options={}, &block)
  options = Byebug::DEFAULT_START_SETTINGS.merge(options)
  if options[:init]
    Byebug.const_set('ARGV', ARGV.clone) unless defined? Byebug::ARGV
    Byebug.const_set('PROG_SCRIPT', $0) unless defined? Byebug::PROG_SCRIPT
    Byebug.const_set('INITIAL_DIR', Dir.pwd) unless defined? Byebug::INITIAL_DIR
  end
  Byebug.tracing = options[:tracing] unless options[:tracing].nil?
  if Byebug.started?
    retval = block && block.call(self)
  else
    retval = Byebug._start(&block)
  end
  #if options[:post_mortem]
  #  post_mortem
  #end
  return retval
end

def start_client(host = 'localhost', port = PORT)


Connects to the remote byebug
def start_client(host = 'localhost', port = PORT)
  require "socket"
  interface = Byebug::LocalInterface.new
  socket = TCPSocket.new(host, port)
  puts "Connected."
  catch(:exit) do
    while (line = socket.gets)
      case line
      when /^PROMPT (.*)$/
        input = interface.read_command($1)
        throw :exit unless input
        socket.puts input
      when /^CONFIRM (.*)$/
        input = interface.confirm($1)
        throw :exit unless input
        socket.puts input
      else
        print line
      end
    end
  end
  socket.close
end

def start_control(host = nil, ctrl_port = PORT + 1) # :nodoc:

:nodoc:
def start_control(host = nil, ctrl_port = PORT + 1) # :nodoc:
  return @ctrl_port if defined?(@control_thread) && @control_thread
  server = TCPServer.new(host, ctrl_port)
  @ctrl_port = server.addr[1]
  @control_thread = DebugThread.new do
    while (session = server.accept)
      interface = RemoteInterface.new(session)
      processor = ControlCommandProcessor.new(interface)
      processor.process_commands
    end
  end
  @ctrl_port
end

def start_remote(host = nil, port = PORT)


Starts a remote byebug.
def start_remote(host = nil, port = PORT)
  return if @thread
  self.interface = nil
  start
  if port.kind_of?(Array)
    cmd_port, ctrl_port = port
  else
    cmd_port, ctrl_port = port, port + 1
  end
  ctrl_port = start_control(host, ctrl_port)
  yield if block_given?
  mutex = Mutex.new
  proceed = ConditionVariable.new
  server = TCPServer.new(host, cmd_port)
  @cmd_port = cmd_port = server.addr[1]
  @thread = DebugThread.new do
    while (session = server.accept)
      self.interface = RemoteInterface.new(session)
      if wait_connection
        mutex.synchronize do
          proceed.signal
        end
      end
    end
  end
  if wait_connection
    mutex.synchronize do
      proceed.wait(mutex)
    end
  end
end