#!/usr/bin/env ruby # -*- coding: utf-8 -*- require 'rubygems' require 'ruby-debug-base' require 'optparse' require 'require_relative' require_relative '../app/run' require_relative '../app/options' require_relative '../interface/user' require_relative '../lib/trepanning' begin eval(File.read(Trepan::CMD_INITFILE)) if File.exist?(Trepan::CMD_INITFILE) rescue end options = Trepan.copy_default_options opts = Trepan.setup_options(options) begin if not defined? Trepan::ARGV Trepan::ARGV = ARGV.clone end trepan8_path = File.expand_path($0) if RUBY_PLATFORM =~ /mswin/ trepan8_path += '.cmd' unless trepan8_path =~ /\.cmd$/i end Trepan::PROG_UNRESOLVED_SCRIPT = trepan8_path Trepan::TREPAN8_FILE = __FILE__ Trepan::INITIAL_DIR = Dir.pwd opts.parse! ARGV rescue StandardError => e puts opts puts puts e.message exit(-1) end if options[:client] Debugger.start_client(options[:host], options[:port]) else if ARGV.empty? exit if $VERBOSE and not options[:verbose_long] puts opts puts puts 'Must specify a script to run' exit(-1) end # save script name prog_script = ARGV.shift prog_script = Trepan::whence_file(prog_script) unless File.exist?(prog_script) Trepan::PROG_SCRIPT = File.expand_path prog_script # install interruption handler trap('INT') { Debugger.interrupt_last } # set options Trepan.wait_connection = options[:wait] Debugger.keep_frame_binding = options[:frame_bind] if options[:server] # start remote mode Debugger.start_remote(options[:host], [options[:port], options[:cport]], options[:post_mortem]) do # load initrc script Trepan.add_startup_files unless options[:nx] end debug_program(RbConfig.ruby, options) else # Set up trace hook for debugger Trepan.start # start control thread Trepan.start_control(options[:host], options[:cport]) if options[:control] # load initrc script (e.g. .trepan8rc) Trepan.add_startup_files unless options[:nx] # run startup script if specified Trepan.add_command_file(options[:script]) if options[:script] # activate post-mortem Trepan.post_mortem if options[:post_mortem] options[:stop] = false if options[:tracing] Debugger.tracing = options[:tracing] if !options[:quit] if Debugger.started? until Debugger.stop do end end begin debug_program(RbConfig.ruby, options) rescue SyntaxError puts $!.backtrace.map{|l| "\t#{l}"}.join("\n") puts "Uncaught Syntax Error\n" rescue print $!.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n" print "Uncaught exception: #{$!}\n" end print "The program finished.\n" unless Debugger.annotate.to_i > 1 # annotate has its own way ## interface = Debugger::LocalInterface.new interface = Trepan::UserInterface.new # Not sure if ControlCommandProcessor is really the right # thing to use. CommandProcessor requires a state. processor = Debugger::ControlCommandProcessor.new(interface) processor.process_commands else Trepan::debug_program(RbConfig.ruby, options) end end end