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.
Constant Summary collapse
- BYEBUG_SCRIPT =
File.('../../../../bin/byebug')
Instance Method Summary collapse
-
#debug_program(options) ⇒ Object
Debug a script only if syntax checks okay.
-
#run ⇒ Object
Starts byebug to debug a program.
-
#save_debugged_program ⇒ Object
Save path to program to be debugged.
-
#whence_file(prog_script) ⇒ Object
Do a shell-like path lookup for prog_script and return the results.
Instance Method Details
#debug_program(options) ⇒ Object
Debug a script only if syntax checks okay.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/byebug/runner.rb', line 18 def debug_program() unless File.executable?(Byebug.debugged_program) output = `ruby -c "#{Byebug.debugged_program}" 2>&1` if $CHILD_STATUS.exitstatus != 0 Byebug.puts output exit $CHILD_STATUS.exitstatus end end status = Byebug.debug_load(Byebug.debugged_program, [:stop]) Byebug.puts "#{status}\n#{status.backtrace}" if status end |
#run ⇒ Object
Starts byebug to debug a program
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/byebug/runner.rb', line 70 def run opts = Byebug::Options.parse return Byebug.puts("\n Running byebug #{VERSION}\n") if opts[:version] return Byebug.puts("#{opts.help}\n") if opts[:help] if opts[:remote] port, host = opts[:remote].pop.to_i, opts[:remote].pop || 'localhost' Byebug.puts "Connecting to byebug server #{host}:#{port}..." Byebug.start_client(host, port) return end save_debugged_program # Set up trace hook for byebug Byebug.start # load initrc script (e.g. .byebugrc) Byebug.run_init_script(StringIO.new) if opts[:rc] # Post Mortem mode status Byebug::Setting[:post_mortem] = opts[:'post-mortem'] # Line Tracing Status Byebug::Setting[:linetrace] = opts[:trace] loop do debug_program(opts) break if opts[:quit] processor = Byebug::ControlCommandProcessor.new processor.process_commands end end |
#save_debugged_program ⇒ Object
Save path to program to be debugged
Used for restarts.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/byebug/runner.rb', line 55 def save_debugged_program if ARGV.empty? Byebug.puts 'You must specify a program to debug...' abort end prog_script = ARGV.first prog_script = whence_file(prog_script) unless File.exist?(prog_script) Byebug.debugged_program = File.(prog_script) end |
#whence_file(prog_script) ⇒ Object
Do a shell-like path lookup for prog_script and return the results. If we can’t find anything return prog_script.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/byebug/runner.rb', line 35 def whence_file(prog_script) if prog_script.index(File::SEPARATOR) # Don't search since this name has path separator components return prog_script end ENV['PATH'].split(File::PATH_SEPARATOR).each do |dirname| prog_script_try = File.join(dirname, prog_script) return prog_script_try if File.exist?(prog_script_try) end # Failure prog_script end |