Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/215 host port environment config #216

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 . .
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions bin/rdebug-ide
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby-debug-ide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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|
Expand Down
53 changes: 37 additions & 16 deletions lib/ruby-debug-ide/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
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
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
Expand All @@ -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__)
Expand All @@ -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
Expand All @@ -67,7 +79,7 @@ def method_missing(meth, *args, &block)
end
end
end

def options
@options ||= {}
end
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -155,7 +176,7 @@ def debug_silent_eval(str)
nil
end
end

def get_binding
@state.context.frame_binding(@state.frame_pos)
end
Expand All @@ -182,6 +203,6 @@ def realpath(filename)
end
end
end

Command.load_commands
end
30 changes: 30 additions & 0 deletions test/ruby-debug-ide/command_test.rb
Original file line number Diff line number Diff line change
@@ -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