/
trepan
executable file
·67 lines (59 loc) · 2.18 KB
/
trepan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env ruby
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
# 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(basename cmdfiles highlight initial_dir host nx port post_mortem
readline server traceprint
).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, File.expand_path(program_to_debug))
end
end