class Byebug::Runner
Responsible for starting the debugger when started from the command line.
Attributes
Special working modes that don't actually start the debugger.
Signals that we should run rc scripts before program starts
Signals that we should exit after the debugged program is finished.
Special working modes that don't actually start the debugger.
Signals that we should stop before program starts
Special working modes that don't actually start the debugger.
Public Class Methods
@param stop [Boolean] Whether the runner should stop right before starting the program.
@param quit [Boolean] Whether the runner should quit right after finishing the program.
# File lib/byebug/runner.rb, line 47 def initialize(stop = true, quit = true) @stop = stop @quit = quit end
Public Instance Methods
Debugs a script only if syntax checks okay.
# File lib/byebug/runner.rb, line 178 def debug_program error = Byebug.debug_load(program, stop) puts "#{error}\n#{error.backtrace}" if error end
There is an error with the specified script
# File lib/byebug/runner.rb, line 141 def error_in_script? no_script? || non_existing_script? || invalid_script? end
# File lib/byebug/runner.rb, line 52 def help=(text) @help ||= text interface.puts("#{text}\n") end
# File lib/byebug/runner.rb, line 70 def init_script defined?(@init_script) ? @init_script : true end
# File lib/byebug/runner.rb, line 109 def interface @interface ||= LocalInterface.new end
Checks the debugged script has correct syntax
# File lib/byebug/runner.rb, line 168 def invalid_script? return false if syntax_valid?(File.read(program)) print_error('The script has incorrect syntax') true end
No script to debug specified
# File lib/byebug/runner.rb, line 148 def no_script? return false unless $ARGV.empty? print_error('You must specify a program to debug') true end
Extracts debugged program from command line args.
# File lib/byebug/runner.rb, line 158 def non_existing_script? return false if program print_error("The script doesn't exist") true end
An option that doesn't need a script specified was given
# File lib/byebug/runner.rb, line 134 def non_script_option? version || help || remote end
Processes options passed from the command line.
# File lib/byebug/runner.rb, line 116 def option_parser @option_parser ||= OptionParser.new(banner, 25) do |opts| opts.banner = banner OptionSetter.new(self, opts).setup end end
Prints an error message and a help string
# File lib/byebug/runner.rb, line 186 def print_error(msg) interface.errmsg(msg) interface.puts(option_parser.help) end
# File lib/byebug/runner.rb, line 124 def program @program ||= begin candidate = which($ARGV.shift) candidate == which('ruby') ? which($ARGV.shift) : candidate end end
# File lib/byebug/runner.rb, line 64 def remote=(host_and_port) @remote ||= Byebug.parse_host_and_port(host_and_port) Byebug.start_client(*@remote) end
Starts byebug to debug a program.
# File lib/byebug/runner.rb, line 88 def run Byebug.mode = :standalone option_parser.order!($ARGV) return if non_script_option? || error_in_script? $PROGRAM_NAME = program Byebug.run_init_script if init_script loop do debug_program break if quit ControlProcessor.new.process_commands end end
# File lib/byebug/runner.rb, line 58 def version=(number) @version ||= number interface.puts("\n Running byebug #{number}\n") end