-
Notifications
You must be signed in to change notification settings - Fork 24
/
sublime_debug_require.rb
54 lines (45 loc) · 1.83 KB
/
sublime_debug_require.rb
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
class RubyVersion
attr_accessor :version, :gem_name, :init_block, :debug_block, :gem_version
def initialize(version, gem_name, debug_block, init_block, gem_version = nil)
self.version =version
self.gem_name = gem_name
self.init_block = init_block
self.debug_block = debug_block
self.gem_version = gem_version
end
end
require 'byebug/core'
r193 = RubyVersion.new("1.9.3", "debugger", lambda { debugger }, lambda { Debugger.wait_connection = true; Debugger.start_remote "127.0.0.1" })
r200 = RubyVersion.new("2.0.0", "byebug", lambda { byebug }, lambda { Byebug.wait_connection = true; Byebug.start_server "127.0.0.1" }, ">=2.5.0")
if current_version = RUBY_VERSION > "1.9.3" ? r200 : r193
begin
require current_version.gem_name
if current_version.gem_version and not Gem::Specification.find_all_by_name(current_version.gem_name, Gem::Requirement.create(current_version.gem_version)).any?
puts "#{current_version.gem_name} version is not supported,"
puts "please run: gem install byebug --version'#{current_version.gem_version}'"
exit
end
current_version.init_block.call
pid = Process.pid
at_exit {
if $! and pid == Process.pid
puts "Last exception: #{$!.inspect}"
puts "Backtrace: "
puts "#{$@}"
end
}
current_version.debug_block.call
rescue LoadError
puts "#{current_version.gem_name.capitalize} gem is not installed for ruby version: #{RUBY_VERSION}"
puts "please look for installation instructions here:"
puts "https://github.com/shuky19/sublime_debugger"
puts "Last exception: #{$!.inspect}"
puts "Backtrace: "
puts "#{$@}"
exit
rescue Errno::EADDRINUSE
puts "Another process is using the debugging ports (8989,8990)"
puts "please make sure this ports are free and than run the debugger"
exit
end
end