-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathrdbg
executable file
·53 lines (46 loc) · 1.53 KB
/
rdbg
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
#!/usr/bin/env ruby
require_relative '../lib/debug/config'
config = DEBUGGER__::Config::parse_argv(ARGV)
# mode is not an actual configuration option
# it's only used to carry the result of parse_argv here
case config.delete(:mode)
when :start
require 'rbconfig'
libpath = File.join(File.expand_path(File.dirname(__dir__)), 'lib/debug')
start_mode = config[:open] ? "open" : 'start'
cmd = config[:command] ? ARGV.shift : (ENV['RUBY'] || RbConfig.ruby)
if defined?($:.resolve_feature_path)
begin
_, sopath = $:.resolve_feature_path('debug/debug.so')
rescue LoadError
# raises LoadError before 3.1 (2.7 and 3.0)
else
sopath = File.dirname(File.dirname(sopath)) if sopath
end
else
# `$:.resolve_feature_path` is not defined in 2.6 or earlier.
so = "debug/debug.#{RbConfig::CONFIG['DLEXT']}"
sopath = $:.find {|dir| File.exist?(File.join(dir, so))}
end
added = "-r #{libpath}/#{start_mode}"
added = "-I #{sopath} #{added}" if sopath
rubyopt = ENV['RUBYOPT']
env = ::DEBUGGER__::Config.config_to_env_hash(config)
env['RUBY_DEBUG_ADDED_RUBYOPT'] = added
env['RUBYOPT'] = "#{rubyopt} #{added}"
exec(env, cmd, *ARGV)
when :attach
require_relative "../lib/debug/client"
::DEBUGGER__::CONFIG.set_config(**config)
begin
if ARGV.empty? && config[:port]
DEBUGGER__::Client.new([config[:host], config[:port]].compact).connect
else
DEBUGGER__::Client.new(ARGV).connect
end
rescue DEBUGGER__::CommandLineOptionError
puts opt.help
end
else
raise # assert
end