#!/usr/bin/env ruby # Copyright (C) 2010, 2011 Rocky Bernstein # Invoke debugger from the command line. require 'rbconfig' # For RbConfig.ruby require_relative '../app/run' require_relative '../app/options' require_relative '../app/client' require_relative '../lib/trepanning' # FIXME: the figure out how to run via gem installation. if File.basename(__FILE__) == File.basename($0) include Trepanning # One way to get local variables is to create a block which is run # once. # # Note however that since there are constants below, we can't # wrap all of this in a procedure as that would be defining # constants dynamically. 1.times do | ; trepan_path, program_to_debug | # options = DEFAULT_CMDLINE_SETTINGS.merge({}) seems to change up # DEFAULT_CMDLINE_SETTINGS when options[:key] is changed. The # below is the simplest thing I can come up with so far. options = Trepan.copy_default_options opts = Trepan.setup_options(options) Trepan::ARGV = ARGV.clone rest = opts.parse! ARGV trepan_path = File.expand_path($0) if RUBY_PLATFORM =~ /mswin/ trepan_path += '.cmd' unless trepan_path =~ /\.cmd$/i end # FIXME: do we need to test defined? # FIXME: Should (some of) these be instance variables? Trepan::TREPAN_PATH = trepan_path if ARGV.empty? if options[:version] || options[:help] exit 100 elsif options[:client] start_client(options) exit else STDERR.puts 'Sorry - for now you must specify a Ruby script to debug or use the --client option.' exit(1) end end program_to_debug = (Trepan::PROG_UNRESOLVED_SCRIPT = ARGV.shift).dup program_to_debug = whence_file(Trepan::PROG_UNRESOLVED_SCRIPT) unless File.exist?(Trepan::PROG_UNRESOLVED_SCRIPT) Trepan::PROG_SCRIPT = program_to_debug opts = {} %w(cmdfiles highlight initial_dir host nx port readline server ).each do |opt| opts[opt.to_sym] = options[opt.to_sym] end # Set global so others may use this debugger. $trepan = Trepan.new(opts) debug_program($trepan, RbConfig.ruby, File.expand_path(program_to_debug)) end end