diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..4633a7ac --- /dev/null +++ b/.editorconfig @@ -0,0 +1,30 @@ +root = true + +[*] +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +tab_width = 8 +trim_trailing_whitespace = true + +[*.bat] +end_of_line = crlf + +[*.gemspec] +indent_size = 2 + +[*.rb] +indent_size = 2 + +[*.yml] +indent_size = 2 + +[{*[Mm]akefile*,*.mak,*.mk,depend}] +indent_style = tab + +[enc/*] +indent_size = 2 + +[reg*.[ch]] +indent_size = 2 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e226d484 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# docker build -t rdebug-ide . +# docker run --rm rdebug-ide rake +# docker run -it --rm -e RUBYLIB=/mounted/lib/ -p 127.0.0.1:1234:1234 -v $PWD:/mounted -w /mounted rdebug-ide bash + +# Maybe you prefer jruby? +# docker build --build-arg IMAGE=jruby --build-arg TAG=latest -t rdebug-ide . +ARG IMAGE=ruby +ARG TAG=3.0 +FROM ${IMAGE}:${TAG} + +WORKDIR /src + +COPY Gemfile . +COPY *.gemspec . +COPY lib/ruby-debug-ide/version.rb ./lib/ruby-debug-ide/version.rb + +RUN bundle + +COPY . . diff --git a/Gemfile b/Gemfile index c36df534..585c6ccf 100644 --- a/Gemfile +++ b/Gemfile @@ -18,10 +18,14 @@ if RUBY_VERSION && RUBY_VERSION >= "1.9" gem "ruby-debug-base19x", ">= 0.11.32", :platforms => mries('19') end -if RUBY_VERSION && RUBY_VERSION >= "2.0" +if RUBY_VERSION && ("2.0".."2.5").include?(RUBY_VERSION) gem "debase", "~> 0.2", ">= 0.2.2", :platforms => mries('20', '21', '22', '23', '24', '25') end +if RUBY_VERSION && RUBY_VERSION > "2.5" + gem "debase", "~> 0.2.4" +end + gemspec group :development do diff --git a/bin/rdebug-ide b/bin/rdebug-ide index fce28c94..123c836d 100755 --- a/bin/rdebug-ide +++ b/bin/rdebug-ide @@ -12,9 +12,9 @@ $stdout.sync=true options = OpenStruct.new( 'frame_bind' => false, - 'host' => nil, + 'host' => Debugger::Command.host, 'load_mode' => false, - 'port' => 1234, + 'port' => Debugger::Command.port, 'stop' => false, 'tracing' => false, 'skip_wait_for_start' => false, @@ -142,7 +142,7 @@ else end if options.dispatcher_port != -1 - ENV['IDE_PROCESS_DISPATCHER'] = options.dispatcher_port.to_s + ENV['IDE_PROCESS_DISPATCHER'] ||= options.dispatcher_port.to_s if RUBY_VERSION < "1.9" lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib/") $: << lib_path unless $:.include? lib_path diff --git a/lib/ruby-debug-ide.rb b/lib/ruby-debug-ide.rb index bc61c90e..061b5146 100644 --- a/lib/ruby-debug-ide.rb +++ b/lib/ruby-debug-ide.rb @@ -73,7 +73,7 @@ def interrupt_last end end - def start_server(host = nil, port = 1234, notify_dispatcher = false) + def start_server(host = nil, port = Debugger::Command::DEFAULT_PORT, notify_dispatcher = false) _start_server_common(host, port, nil, notify_dispatcher) end @@ -193,7 +193,7 @@ def notify_dispatcher_if_needed(host, port, need_notify) return unless ENV['IDE_PROCESS_DISPATCHER'] acceptor_host, acceptor_port = ENV['IDE_PROCESS_DISPATCHER'].split(":") - acceptor_host, acceptor_port = '127.0.0.1', acceptor_host unless acceptor_port + acceptor_host, acceptor_port = Debugger::Command::DEFAULT_HOST, acceptor_host unless acceptor_port connected = false 3.times do |i| diff --git a/lib/ruby-debug-ide/command.rb b/lib/ruby-debug-ide/command.rb index ecbd2ba5..8e6a40fb 100644 --- a/lib/ruby-debug-ide/command.rb +++ b/lib/ruby-debug-ide/command.rb @@ -11,8 +11,7 @@ module Debugger class Command < SimpleDelegator # :nodoc: - SubcmdStruct=Struct.new(:name, :min, :short_help, :long_help) unless - defined?(SubcmdStruct) + SubcmdStruct=Struct.new(:name, :min, :short_help, :long_help) unless defined?(SubcmdStruct) # Find param in subcmds. param id downcased and can be abbreviated # to the minimum length listed in the subcommands @@ -20,7 +19,7 @@ def find(subcmds, param) param.downcase! for try_subcmd in subcmds do if (param.size >= try_subcmd.min) and - (try_subcmd.name[0..param.size-1] == param) + (try_subcmd.name[0..param.size-1] == param) return try_subcmd end end @@ -31,20 +30,25 @@ class << self def commands @commands ||= [] end - + DEF_OPTIONS = { - :event => true, - :control => false, + :event => true, + :control => false, :unknown => false, :need_context => false, } - + + # 127.0.0.1 seemingly works with all systems and with IPv6 as well. + # "localhost" and nil have problems on some systems. + DEFAULT_HOST = '127.0.0.1' + DEFAULT_PORT = 1234 + def inherited(klass) DEF_OPTIONS.each do |o, v| klass.options[o] = v if klass.options[o].nil? end commands << klass - end + end def load_commands dir = File.dirname(__FILE__) @@ -55,7 +59,15 @@ def load_commands include mod end end - + + def host + host_and_port_from_environment.first || DEFAULT_HOST + end + + def port + host_and_port_from_environment.last || DEFAULT_PORT + end + def method_missing(meth, *args, &block) if meth.to_s =~ /^(.+?)=$/ @options[$1.intern] = args.first @@ -67,7 +79,7 @@ def method_missing(meth, *args, &block) end end end - + def options @options ||= {} end @@ -81,13 +93,22 @@ def unescape_incoming(str) def file_filter_supported? defined?(Debugger.file_filter) end + + private + + def host_and_port_from_environment + return [] unless ENV['IDE_PROCESS_DISPATCHER'] + host, port = ENV['IDE_PROCESS_DISPATCHER'].split(':') + return [] unless port + [host, port.to_i] + end end - + def initialize(state, printer) @state, @printer = state, printer super @printer end - + def match(input) @match = regexp.match(input) end @@ -108,7 +129,7 @@ def print(*args) def timeout(sec) return yield if sec == nil or sec.zero? if Thread.respond_to?(:critical) and Thread.critical - raise ThreadError, "timeout within critical session" + raise ThreadError, "timeout within critical session" end begin x = Thread.current @@ -142,7 +163,7 @@ def debug_eval(str, b = get_binding) return eval_result rescue StandardError, ScriptError => e - @printer.print_exception(e, @state.binding) + @printer.print_exception(e, @state.binding) throw :debug_error end end @@ -155,7 +176,7 @@ def debug_silent_eval(str) nil end end - + def get_binding @state.context.frame_binding(@state.frame_pos) end @@ -182,6 +203,6 @@ def realpath(filename) end end end - + Command.load_commands end diff --git a/test/ruby-debug-ide/command_test.rb b/test/ruby-debug-ide/command_test.rb new file mode 100644 index 00000000..5be3001b --- /dev/null +++ b/test/ruby-debug-ide/command_test.rb @@ -0,0 +1,30 @@ +require 'test_base' + +$:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib") + +require 'ruby-debug-ide' + +class CommandTest < TestBase + def with_environment_setting(key, value) + old_value = ENV[key] + ENV[key] = value + begin + yield + ensure + ENV[key] = old_value + end + end + + def test_host_and_port + with_environment_setting('IDE_PROCESS_DISPATCHER', '0.0.0.0:2345') do + assert_equal(Debugger::Command.host, '0.0.0.0') + assert_equal(Debugger::Command.port, 2345) + end + + # Bail if we don't have host:port + with_environment_setting('IDE_PROCESS_DISPATCHER', '0.0.0.0') do + assert_equal(Debugger::Command.host, '127.0.0.1') + assert_equal(Debugger::Command.port, 1234) + end + end +end