Class: Byebug::Runner
- Inherits:
-
Object
- Object
- Byebug::Runner
- Defined in:
- lib/byebug/runner.rb
Overview
Responsible for starting the debugger when started from the command line.
Instance Attribute Summary collapse
-
#help ⇒ Object
Special working modes that don’t actually start the debugger.
- #init_script ⇒ Object
-
#quit ⇒ Object
Signals that we should exit after the debugged program is finished.
-
#remote ⇒ Object
Special working modes that don’t actually start the debugger.
-
#stop ⇒ Object
Signals that we should stop before program starts.
-
#version ⇒ Object
Special working modes that don’t actually start the debugger.
Instance Method Summary collapse
-
#banner ⇒ Object
Usage banner.
-
#debug_program ⇒ Object
Debugs a script only if syntax checks okay.
-
#error_in_script? ⇒ Boolean
There is an error with the specified script.
-
#initialize(stop = true, quit = true) ⇒ Runner
constructor
starting the program.
- #interface ⇒ Object
-
#invalid_script? ⇒ Boolean
Checks the debugged script has correct syntax.
-
#no_script? ⇒ Boolean
No script to debug specified.
-
#non_existing_script? ⇒ Boolean
Extracts debugged program from command line args.
-
#non_script_option? ⇒ Boolean
An option that doesn’t need a script specified was given.
-
#option_parser ⇒ Object
Processes options passed from the command line.
-
#print_error(msg) ⇒ Object
Prints an error message and a help string.
- #program ⇒ Object
-
#run ⇒ Object
Starts byebug to debug a program.
Methods included from Helpers::StringHelper
#camelize, #deindent, #prettify
Methods included from Helpers::ParseHelper
#get_int, #parse_steps, #syntax_valid?
Methods included from Helpers::BinHelper
#executable_file_extensions, #find_executable, #real_executable?, #search_paths, #which
Constructor Details
#initialize(stop = true, quit = true) ⇒ Runner
starting the program.
finishing the program.
49 50 51 52 |
# File 'lib/byebug/runner.rb', line 49 def initialize(stop = true, quit = true) @stop = stop @quit = quit end |
Instance Attribute Details
#help ⇒ Object
Special working modes that don’t actually start the debugger.
25 26 27 |
# File 'lib/byebug/runner.rb', line 25 def help @help end |
#init_script ⇒ Object
74 75 76 |
# File 'lib/byebug/runner.rb', line 74 def init_script defined?(@init_script) ? @init_script : true end |
#quit ⇒ Object
Signals that we should exit after the debugged program is finished.
30 31 32 |
# File 'lib/byebug/runner.rb', line 30 def quit @quit end |
#remote ⇒ Object
Special working modes that don’t actually start the debugger.
25 26 27 |
# File 'lib/byebug/runner.rb', line 25 def remote @remote end |
#stop ⇒ Object
Signals that we should stop before program starts
35 36 37 |
# File 'lib/byebug/runner.rb', line 35 def stop @stop end |
#version ⇒ Object
Special working modes that don’t actually start the debugger.
25 26 27 |
# File 'lib/byebug/runner.rb', line 25 def version @version end |
Instance Method Details
#banner ⇒ Object
Usage banner.
81 82 83 84 85 86 87 |
# File 'lib/byebug/runner.rb', line 81 def prettify <<-BANNER byebug #{Byebug::VERSION} Usage: byebug [options] <script.rb> -- <script.rb parameters> BANNER end |
#debug_program ⇒ Object
Debugs a script only if syntax checks okay.
185 186 187 188 |
# File 'lib/byebug/runner.rb', line 185 def debug_program error = Byebug.debug_load(program, stop) puts "#{error}\n#{error.backtrace}" if error end |
#error_in_script? ⇒ Boolean
There is an error with the specified script
148 149 150 |
# File 'lib/byebug/runner.rb', line 148 def error_in_script? no_script? || non_existing_script? || invalid_script? end |
#interface ⇒ Object
111 112 113 |
# File 'lib/byebug/runner.rb', line 111 def interface @interface ||= Context.interface end |
#invalid_script? ⇒ Boolean
Checks the debugged script has correct syntax
175 176 177 178 179 180 |
# File 'lib/byebug/runner.rb', line 175 def invalid_script? return false if syntax_valid?(File.read(program)) print_error("The script has incorrect syntax") true end |
#no_script? ⇒ Boolean
No script to debug specified
155 156 157 158 159 160 |
# File 'lib/byebug/runner.rb', line 155 def no_script? return false unless $ARGV.empty? print_error("You must specify a program to debug") true end |
#non_existing_script? ⇒ Boolean
Extracts debugged program from command line args.
165 166 167 168 169 170 |
# File 'lib/byebug/runner.rb', line 165 def non_existing_script? return false if program print_error("The script doesn't exist") true end |
#non_script_option? ⇒ Boolean
An option that doesn’t need a script specified was given
141 142 143 |
# File 'lib/byebug/runner.rb', line 141 def non_script_option? version || help || remote end |
#option_parser ⇒ Object
Processes options passed from the command line.
118 119 120 121 122 123 124 |
# File 'lib/byebug/runner.rb', line 118 def option_parser @option_parser ||= OptionParser.new(, 25) do |opts| opts. = OptionSetter.new(self, opts).setup end end |
#print_error(msg) ⇒ Object
Prints an error message and a help string
193 194 195 196 |
# File 'lib/byebug/runner.rb', line 193 def print_error(msg) interface.errmsg(msg) interface.puts(option_parser.help) end |
#program ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/byebug/runner.rb', line 126 def program @program ||= begin candidate = which($ARGV.shift) if [which("ruby"), RbConfig.ruby].include?(candidate) which($ARGV.shift) else candidate end end end |
#run ⇒ Object
Starts byebug to debug a program.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/byebug/runner.rb', line 92 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(nil, interface).process_commands end end |