#!/usr/bin/env ruby # Copyright (C) 2010 Rocky Bernstein # Invoke debugger from the command line. require 'rubygems'; require 'require_relative' 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 = nil # 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::RUBY_PATH = ruby_path 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 = ARGV.shift program_to_debug = whence_file(program_to_debug) unless File.exist?(program_to_debug) Trepan::PROG_SCRIPT = program_to_debug # Set global so others may use this debugger. opts = {} %w(cmdfiles initial_dir host nx port terminal server).each do |opt| opts[opt.to_sym] = options[opt.to_sym] end $trepan = Trepan.new(opts) debug_program($trepan, Trepan::RUBY_PATH, File.expand_path(program_to_debug)) end end