From e912ed2834d833ae0b2241b19c05251c0376fe28 Mon Sep 17 00:00:00 2001 From: Valentin Fondaratov Date: Thu, 1 Feb 2018 11:38:40 +0300 Subject: [PATCH 01/25] set target version to 0.7.0.beta1 --- lib/ruby-debug-ide/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-debug-ide/version.rb b/lib/ruby-debug-ide/version.rb index 41f8b9f..ff7fbb7 100755 --- a/lib/ruby-debug-ide/version.rb +++ b/lib/ruby-debug-ide/version.rb @@ -1,3 +1,3 @@ module Debugger - IDE_VERSION='0.6.1' + IDE_VERSION='0.7.0.beta1' end From 2849d3f8e49a950a4eed357f4788f00e7caf18f1 Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Tue, 30 Jan 2018 18:36:31 +0300 Subject: [PATCH 02/25] new strategy of notifying the dispatcher (cherry picked from commit f1c9639) --- lib/ruby-debug-ide.rb | 33 ++++++++++++++++---- lib/ruby-debug-ide/greeter.rb | 4 +-- lib/ruby-debug-ide/multiprocess/pre_child.rb | 12 ++----- lib/ruby-debug-ide/version.rb | 2 +- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/lib/ruby-debug-ide.rb b/lib/ruby-debug-ide.rb index 62c0671..7874134 100644 --- a/lib/ruby-debug-ide.rb +++ b/lib/ruby-debug-ide.rb @@ -18,6 +18,13 @@ module Debugger class << self + def find_free_port(host) + server = TCPServer.open(host, 0) + port = server.addr[1] + server.close + port + end + # Prints to the stderr using printf(*args) if debug logging flag (-d) is on. def print_debug(*args) if Debugger.cli_debug @@ -111,9 +118,15 @@ def start_control(host, port, notify_dispatcher) # 127.0.0.1 seemingly works with all systems and with IPv6 as well. # "localhost" and nil have problems on some systems. host ||= '127.0.0.1' - server = TCPServer.new(host, port) - print_greeting_msg($stderr, host, port) if defined? IDE_VERSION - notify_dispatcher(port) if notify_dispatcher + + server = notify_dispatcher_if_needed(host, port, notify_dispatcher) do |real_port, port_changed = false| + s = TCPServer.new(host, real_port) + print_greeting_msg $stderr, host, real_port, port_changed ? "Subprocess" : "Fast" if defined? IDE_VERSION + s + end + + return unless server + while (session = server.accept) $stderr.puts "Connected from #{session.peeraddr[2]}" if Debugger.cli_debug dispatcher = ENV['IDE_PROCESS_DISPATCHER'] @@ -141,8 +154,9 @@ def start_control(host, port, notify_dispatcher) private + def notify_dispatcher_if_needed(host, port, need_notify) + return yield port unless need_notify - def notify_dispatcher(port) 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 @@ -151,11 +165,19 @@ def notify_dispatcher(port) 3.times do |i| begin s = TCPSocket.open(acceptor_host, acceptor_port) + dispatcher_answer = s.gets.chomp + + if dispatcher_answer == "true" + port = Debugger.find_free_port(host) + end + + server = yield port, dispatcher_answer == "true" + s.print(port) s.close connected = true print_debug "Ide process dispatcher notified about sub-debugger which listens on #{port}\n" - return + return server rescue => bt $stderr.puts "#{Process.pid}: connection failed(#{i+1})" $stderr.puts "Exception: #{bt}" @@ -164,7 +186,6 @@ def notify_dispatcher(port) end unless connected end end - end class Exception # :nodoc: diff --git a/lib/ruby-debug-ide/greeter.rb b/lib/ruby-debug-ide/greeter.rb index df9b042..7e3dd93 100644 --- a/lib/ruby-debug-ide/greeter.rb +++ b/lib/ruby-debug-ide/greeter.rb @@ -10,7 +10,7 @@ module Debugger class << self - def print_greeting_msg(stream, host, port) + def print_greeting_msg(stream, host, port, debugger_name = "Fast") base_gem_name = if defined?(JRUBY_VERSION) || RUBY_VERSION < '1.9.0' 'ruby-debug-base' elsif RUBY_VERSION < '2.0.0' @@ -31,7 +31,7 @@ def print_greeting_msg(stream, host, port) listens_on = "\n" end - msg = "Fast Debugger (ruby-debug-ide #{IDE_VERSION}, #{base_gem_name} #{VERSION}, file filtering is #{file_filtering_support})" + listens_on + msg = "#{debugger_name} Debugger (ruby-debug-ide #{IDE_VERSION}, #{base_gem_name} #{VERSION}, file filtering is #{file_filtering_support})" + listens_on stream.printf msg end diff --git a/lib/ruby-debug-ide/multiprocess/pre_child.rb b/lib/ruby-debug-ide/multiprocess/pre_child.rb index 4a349fd..b707fc4 100644 --- a/lib/ruby-debug-ide/multiprocess/pre_child.rb +++ b/lib/ruby-debug-ide/multiprocess/pre_child.rb @@ -11,7 +11,7 @@ def pre_child(options = nil) 'frame_bind' => false, 'host' => host, 'load_mode' => false, - 'port' => find_free_port(host), + 'port' => Debugger.find_free_port(host), 'stop' => false, 'tracing' => false, 'int_handler' => true, @@ -24,7 +24,7 @@ def pre_child(options = nil) ) if(options.ignore_port) - options.port = find_free_port(options.host) + options.port = Debugger.find_free_port(options.host) options.notify_dispatcher = true end @@ -54,14 +54,6 @@ def start_debugger(options) Debugger.cli_debug = options.cli_debug Debugger.prepare_debugger(options) end - - - def find_free_port(host) - server = TCPServer.open(host, 0) - port = server.addr[1] - server.close - port - end end end end \ No newline at end of file diff --git a/lib/ruby-debug-ide/version.rb b/lib/ruby-debug-ide/version.rb index ff7fbb7..d14c8d8 100755 --- a/lib/ruby-debug-ide/version.rb +++ b/lib/ruby-debug-ide/version.rb @@ -1,3 +1,3 @@ module Debugger - IDE_VERSION='0.7.0.beta1' + IDE_VERSION='0.7.0.beta2' end From 0d291b51f4c443133fd481a0e5508eb8017c5ee4 Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Fri, 4 Aug 2017 20:41:34 +0300 Subject: [PATCH 03/25] set alias for Thread during eval execution (cherry picked from commit 56e1a3f) --- bin/rdebug-ide | 8 ++++++++ lib/ruby-debug-ide/command.rb | 11 ++++++++++- lib/ruby-debug-ide/thread-alias/alias_thread.rb | 2 ++ lib/ruby-debug-ide/thread-alias/unalias_thread.rb | 1 + lib/ruby-debug-ide/thread_alias.rb | 13 +++++++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 lib/ruby-debug-ide/thread-alias/alias_thread.rb create mode 100644 lib/ruby-debug-ide/thread-alias/unalias_thread.rb create mode 100644 lib/ruby-debug-ide/thread_alias.rb diff --git a/bin/rdebug-ide b/bin/rdebug-ide index a72dfd1..698564e 100755 --- a/bin/rdebug-ide +++ b/bin/rdebug-ide @@ -131,6 +131,14 @@ else Debugger::PROG_SCRIPT = $0 end +if RUBY_VERSION < "1.9" + lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib/") + $: << lib_path unless $:.include? lib_path + require 'ruby-debug-ide/thread_alias.rb' +else + require_relative '../lib/ruby-debug-ide/thread_alias' +end + if options.dispatcher_port != -1 ENV['IDE_PROCESS_DISPATCHER'] = options.dispatcher_port.to_s if RUBY_VERSION < "1.9" diff --git a/lib/ruby-debug-ide/command.rb b/lib/ruby-debug-ide/command.rb index e6ee3e1..55f96f7 100644 --- a/lib/ruby-debug-ide/command.rb +++ b/lib/ruby-debug-ide/command.rb @@ -128,9 +128,18 @@ def debug_eval(str, b = get_binding) to_inspect = Command.unescape_incoming(str) max_time = Debugger.evaluation_timeout @printer.print_debug("Evaluating %s with timeout after %i sec", str, max_time) + + Debugger::TimeoutHandler.do_thread_alias + + eval_result = nil + timeout(max_time) do - eval(to_inspect, b) + eval_result = eval(to_inspect, b) end + + Debugger::TimeoutHandler.undo_thread_alias + + return eval_result rescue StandardError, ScriptError => e @printer.print_exception(e, @state.binding) throw :debug_error diff --git a/lib/ruby-debug-ide/thread-alias/alias_thread.rb b/lib/ruby-debug-ide/thread-alias/alias_thread.rb new file mode 100644 index 0000000..a37eddb --- /dev/null +++ b/lib/ruby-debug-ide/thread-alias/alias_thread.rb @@ -0,0 +1,2 @@ +OldThread = Thread +Thread = Debugger::DebugThread \ No newline at end of file diff --git a/lib/ruby-debug-ide/thread-alias/unalias_thread.rb b/lib/ruby-debug-ide/thread-alias/unalias_thread.rb new file mode 100644 index 0000000..8ead867 --- /dev/null +++ b/lib/ruby-debug-ide/thread-alias/unalias_thread.rb @@ -0,0 +1 @@ +Thread = OldThread \ No newline at end of file diff --git a/lib/ruby-debug-ide/thread_alias.rb b/lib/ruby-debug-ide/thread_alias.rb new file mode 100644 index 0000000..1cc38d4 --- /dev/null +++ b/lib/ruby-debug-ide/thread_alias.rb @@ -0,0 +1,13 @@ +module Debugger + module TimeoutHandler + class << self + def do_thread_alias + load File.expand_path(File.dirname(__FILE__) + '/thread-alias/alias_thread.rb') + end + + def undo_thread_alias + load File.expand_path(File.dirname(__FILE__) + '/thread-alias/unalias_thread.rb') + end + end + end +end \ No newline at end of file From 01219cea969058c0ab95e59aecb28e56a79a3ee0 Mon Sep 17 00:00:00 2001 From: Valentin Fondaratov Date: Sun, 11 Mar 2018 19:25:41 +0300 Subject: [PATCH 04/25] add tests for thread aliasing Covering commit 0d291b51f4c443133fd481a0e5508eb8017c5ee4. --- test-base/inspect_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test-base/inspect_test.rb b/test-base/inspect_test.rb index ca57de8..c130bc0 100644 --- a/test-base/inspect_test.rb +++ b/test-base/inspect_test.rb @@ -58,6 +58,26 @@ def test_inspect_error_2 send_cont end + def test_inspect_expr_with_timeout + create_socket ["require 'timeout'", "puts 'test'"] + run_to_line(2) + send_ruby("v inspect (Timeout::timeout(10) { nil })") + variables = read_variables + assert_equal(1, variables.length, "There is one variable returned which is nil.") + assert_equal(nil, variables[0].value) + send_cont + end + + def test_inspect_failing_expr_with_timeout + create_socket ["require 'timeout'", "puts 'test'"] + run_to_line(2) + send_ruby("v inspect (Timeout::timeout(0.1) { sleep 0.2 })") + variables = read_variables + assert_equal(1, variables.length, "There is one variable returned which is nil.") + assert_equal("Timeout::Error", variables[0].type) + send_cont + end + def test_inspect_multiline_expression create_socket ["sleep 0.1"] run_to_line(1) From 5bca348f14ca36623e83c53823ef4aa6270b9ee0 Mon Sep 17 00:00:00 2001 From: Valentin Fondaratov Date: Sun, 11 Mar 2018 19:36:27 +0300 Subject: [PATCH 05/25] #137 fix warnings on thread aliasing --- .../thread-alias/alias_thread.rb | 2 -- .../thread-alias/unalias_thread.rb | 1 - lib/ruby-debug-ide/thread_alias.rb | 18 ++++++++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) delete mode 100644 lib/ruby-debug-ide/thread-alias/alias_thread.rb delete mode 100644 lib/ruby-debug-ide/thread-alias/unalias_thread.rb diff --git a/lib/ruby-debug-ide/thread-alias/alias_thread.rb b/lib/ruby-debug-ide/thread-alias/alias_thread.rb deleted file mode 100644 index a37eddb..0000000 --- a/lib/ruby-debug-ide/thread-alias/alias_thread.rb +++ /dev/null @@ -1,2 +0,0 @@ -OldThread = Thread -Thread = Debugger::DebugThread \ No newline at end of file diff --git a/lib/ruby-debug-ide/thread-alias/unalias_thread.rb b/lib/ruby-debug-ide/thread-alias/unalias_thread.rb deleted file mode 100644 index 8ead867..0000000 --- a/lib/ruby-debug-ide/thread-alias/unalias_thread.rb +++ /dev/null @@ -1 +0,0 @@ -Thread = OldThread \ No newline at end of file diff --git a/lib/ruby-debug-ide/thread_alias.rb b/lib/ruby-debug-ide/thread_alias.rb index 1cc38d4..4e10a7b 100644 --- a/lib/ruby-debug-ide/thread_alias.rb +++ b/lib/ruby-debug-ide/thread_alias.rb @@ -2,11 +2,25 @@ module Debugger module TimeoutHandler class << self def do_thread_alias - load File.expand_path(File.dirname(__FILE__) + '/thread-alias/alias_thread.rb') + if defined? ::OldThread + Debugger.print_debug 'Tried to re-alias thread for eval' + return + end + + Object.const_set :OldThread, ::Thread + Object.send :remove_const, :Thread + Object.const_set :Thread, ::Debugger::DebugThread end def undo_thread_alias - load File.expand_path(File.dirname(__FILE__) + '/thread-alias/unalias_thread.rb') + unless defined? ::OldThread + Debugger.print_debug 'Tried to de-alias thread twice' + return + end + + Object.send :remove_const, :Thread + Object.const_set :Thread, ::OldThread + Object.send :remove_const, :OldThread end end end From bd9f77aa93b7d1dd7352576f7ddef43311cc6cb1 Mon Sep 17 00:00:00 2001 From: Valentin Fondaratov Date: Tue, 13 Mar 2018 16:12:20 +0300 Subject: [PATCH 06/25] bump version to beta3 [ci skip] --- lib/ruby-debug-ide/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-debug-ide/version.rb b/lib/ruby-debug-ide/version.rb index d14c8d8..36552ae 100755 --- a/lib/ruby-debug-ide/version.rb +++ b/lib/ruby-debug-ide/version.rb @@ -1,3 +1,3 @@ module Debugger - IDE_VERSION='0.7.0.beta2' + IDE_VERSION='0.7.0.beta3' end From badd1054a7f2f3f82722083f0c06a90d52081a9e Mon Sep 17 00:00:00 2001 From: ViugiNick Date: Mon, 26 Mar 2018 13:39:32 +0300 Subject: [PATCH 07/25] require thread_alias in caller (#141) --- bin/rdebug-ide | 8 -------- lib/ruby-debug-ide/command.rb | 1 + 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/bin/rdebug-ide b/bin/rdebug-ide index 698564e..a72dfd1 100755 --- a/bin/rdebug-ide +++ b/bin/rdebug-ide @@ -131,14 +131,6 @@ else Debugger::PROG_SCRIPT = $0 end -if RUBY_VERSION < "1.9" - lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib/") - $: << lib_path unless $:.include? lib_path - require 'ruby-debug-ide/thread_alias.rb' -else - require_relative '../lib/ruby-debug-ide/thread_alias' -end - if options.dispatcher_port != -1 ENV['IDE_PROCESS_DISPATCHER'] = options.dispatcher_port.to_s if RUBY_VERSION < "1.9" diff --git a/lib/ruby-debug-ide/command.rb b/lib/ruby-debug-ide/command.rb index 55f96f7..ecbd2ba 100644 --- a/lib/ruby-debug-ide/command.rb +++ b/lib/ruby-debug-ide/command.rb @@ -4,6 +4,7 @@ require 'debase' end +require 'ruby-debug-ide/thread_alias' require 'ruby-debug-ide/helper' require 'delegate' From d171ee2d1522a6ce73afb2600b4aa917ce6304ff Mon Sep 17 00:00:00 2001 From: Valentin Fondaratov Date: Tue, 27 Mar 2018 20:11:38 +0300 Subject: [PATCH 08/25] bump version to beta4 [ci skip] --- lib/ruby-debug-ide/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-debug-ide/version.rb b/lib/ruby-debug-ide/version.rb index 36552ae..8524da7 100755 --- a/lib/ruby-debug-ide/version.rb +++ b/lib/ruby-debug-ide/version.rb @@ -1,3 +1,3 @@ module Debugger - IDE_VERSION='0.7.0.beta3' + IDE_VERSION='0.7.0.beta4' end From 91ff6d7d1660ef74c74399d38f39eed82002b45e Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Fri, 23 Mar 2018 19:28:24 +0300 Subject: [PATCH 09/25] check if block given before yield in xml's print_element --- lib/ruby-debug-ide/xml_printer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-debug-ide/xml_printer.rb b/lib/ruby-debug-ide/xml_printer.rb index 49b0b2e..916f33a 100644 --- a/lib/ruby-debug-ide/xml_printer.rb +++ b/lib/ruby-debug-ide/xml_printer.rb @@ -442,7 +442,7 @@ def print_load_result(file, exception = nil) def print_element(name) print("<#{name}>") begin - yield + yield if block_given? ensure print("") end From 421fb009c3eade2b13c372e578adc3989827db6f Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Mon, 4 Jun 2018 20:13:39 +0300 Subject: [PATCH 10/25] new hash item presentation, lets add objectId of a hash key to the xml so we can inspect it later --- bin/rdebug-ide | 7 +++- lib/ruby-debug-ide.rb | 1 + lib/ruby-debug-ide/xml_printer.rb | 32 +++++++++++--- test-base/test_base.rb | 8 ++-- test-base/variables_test.rb | 70 ++++++++++++++++++++++++------- test/rd_test_base.rb | 4 +- 6 files changed, 96 insertions(+), 26 deletions(-) diff --git a/bin/rdebug-ide b/bin/rdebug-ide index a72dfd1..3054353 100755 --- a/bin/rdebug-ide +++ b/bin/rdebug-ide @@ -27,7 +27,8 @@ options = OpenStruct.new( 'catchpoint_deleted_event' => false, 'value_as_nested_element' => false, 'attach_mode' => false, - 'cli_debug' => false + 'cli_debug' => false, + 'key_value_mode' => false ) opts = OptionParser.new do |opts| @@ -80,6 +81,9 @@ EOB opts.on("--attach-mode", "Tells that rdebug-ide is working in attach mode") do options.attach_mode = true end + opts.on("--key-value", "Key/Value presentation of hash items") do + options.key_value_mode = true + end opts.on("--ignore-port", "Generate another port") do options.ignore_port = true end @@ -166,6 +170,7 @@ Debugger.debugger_memory_limit = options.debugger_memory_limit Debugger.inspect_time_limit = options.inspect_time_limit Debugger.catchpoint_deleted_event = options.catchpoint_deleted_event || options.rm_protocol_extensions Debugger.value_as_nested_element = options.value_as_nested_element || options.rm_protocol_extensions +Debugger.key_value_mode = options.key_value_mode if options.attach_mode if Debugger::FRONT_END == "debase" diff --git a/lib/ruby-debug-ide.rb b/lib/ruby-debug-ide.rb index 7874134..e7b57d4 100644 --- a/lib/ruby-debug-ide.rb +++ b/lib/ruby-debug-ide.rb @@ -51,6 +51,7 @@ def cleanup_backtrace(backtrace) end attr_accessor :attached + attr_accessor :key_value_mode attr_accessor :cli_debug, :xml_debug, :evaluation_timeout attr_accessor :trace_to_s, :debugger_memory_limit, :inspect_time_limit attr_accessor :control_thread diff --git a/lib/ruby-debug-ide/xml_printer.rb b/lib/ruby-debug-ide/xml_printer.rb index 916f33a..65b8dbf 100644 --- a/lib/ruby-debug-ide/xml_printer.rb +++ b/lib/ruby-debug-ide/xml_printer.rb @@ -144,19 +144,36 @@ def print_array(array) end end - def print_hash(hash) + def do_print_hash_key_value(hash) + print_element("variables", {:type => 'hashItem'}) do + hash.each {|(k, v)| + print_variable('key', k, 'instance') + print_variable('value', v, 'instance') + } + end + end + + def do_print_hash(hash) print_element("variables") do - hash.keys.each {|k| + hash.each {|(k, v)| if k.class.name == "String" name = '\'' + k + '\'' else name = exec_with_allocation_control(k, :to_s, OverflowMessageType::EXCEPTION_MESSAGE) end - print_variable(name, hash[k], 'instance') + print_variable(name, v, 'instance') } end end + def print_hash(hash) + if Debugger.key_value_mode + do_print_hash_key_value(hash) + else + do_print_hash(hash) + end + end + def print_string(string) print_element("variables") do if string.respond_to?('bytes') @@ -243,6 +260,7 @@ def exec_with_allocation_control(value, exec_method, overflow_message_type) def print_variable(name, value, kind) name = name.to_s + if value.nil? print("", CGI.escapeHTML(name), kind) return @@ -280,6 +298,7 @@ def print_variable(name, value, kind) CGI.escapeHTML(name), build_compact_value_attr(value, value_str), kind, build_value_attr(escaped_value_str), value.class, has_children, value.object_id) + print("", escaped_value_str) if Debugger.value_as_nested_element print('') rescue StandardError => e @@ -439,8 +458,11 @@ def print_load_result(file, exception = nil) end end - def print_element(name) - print("<#{name}>") + def print_element(name, additional_tags = nil) + additional_tags_presentation = additional_tags.nil? ? '' + : additional_tags.map {|tag, value| " #{tag}=\"#{value}\""}.reduce(:+) + + print("<#{name}#{additional_tags_presentation}>") begin yield if block_given? ensure diff --git a/test-base/test_base.rb b/test-base/test_base.rb index 01bd85d..91cf22d 100644 --- a/test-base/test_base.rb +++ b/test-base/test_base.rb @@ -82,9 +82,9 @@ def debug_jruby? config_load('debug_jruby') end - def start_ruby_process(script) + def start_ruby_process(script, additional_opts = '') @port = TestBase.find_free_port - cmd = debug_command(script, @port) + cmd = debug_command(script, @port, additional_opts) debug "Starting: #{cmd}\n" Thread.new do @@ -147,10 +147,10 @@ def create_test2(lines) # Creates test.rb with the given lines, set up @test_name and @test_path # variables and then start the process. - def create_socket(lines) + def create_socket(lines, additional_opts = '') @test_name = "test.rb" @test_path = create_file(@test_name, lines) - start_ruby_process(@test_path) + start_ruby_process(@test_path, additional_opts) end def socket diff --git a/test-base/variables_test.rb b/test-base/variables_test.rb index 67f9b48..50c1b2d 100644 --- a/test-base/variables_test.rb +++ b/test-base/variables_test.rb @@ -199,22 +199,64 @@ def test_to_s_raises_exception send_cont end + def test_new_hash_presentation + create_socket ['class A', + ' def to_s', + ' "A instance"', + ' end', + 'end', + + 'class C', + ' def to_s', + ' "C instance"', + ' end', + 'end', + + 'b = Hash.new', + 'c = C.new', + 'a = A.new', + 'b[1] = a', + 'b[a] = "1"', + 'b[c] = a', + 'puts b #bp here'], '--key-value' + run_to_line(17) + send_ruby('v l') + assert_variables(read_variables, 3, + {:name => "a", :value => "A instance",:type => "A"}, + {:name => "b", :value => "Hash (3 elements)", :type => "Hash"}, + {:name => "c", :value => "C instance", :type => "C"}) + + send_ruby("v i b") + + assert_variables(read_variables, 6, + {:name => "key", :value => "1"}, + {:name => "value", :value => "A instance", :type => "A"}, + + {:name => "key", :value => "A instance", :type => "A"}, + {:name => "value", :value => "1", :type => "String"}, + + {:name => "key", :value => "C instance", :type => "C"}, + {:name => "value", :value => "A instance", :type => "A"}) + send_cont + end + def test_to_s_timelimit create_socket ['class A', - 'def to_s', - 'a = 1', - 'loop do', - 'a = a + 1', - 'sleep 1', - 'break if (a > 2)', - 'end', - 'a.to_s', - 'end', - 'end', - 'b = Hash.new', - 'b[A.new] = A.new', - 'b[1] = A.new', - 'puts b #bp here'] + 'def to_s', + 'a = 1', + 'loop do', + 'a = a + 1', + 'sleep 1', + 'break if (a > 2)', + 'end', + 'a.to_s', + 'end', + 'end', + + 'b = Hash.new', + 'b[A.new] = A.new', + 'b[1] = A.new', + 'puts b #bp here'], '--evaluation-control --time-limit 100 --memory-limit 0' run_to_line(15) send_ruby('v l') assert_variables(read_variables, 1, diff --git a/test/rd_test_base.rb b/test/rd_test_base.rb index 7d29edc..d5b7e4f 100644 --- a/test/rd_test_base.rb +++ b/test/rd_test_base.rb @@ -18,13 +18,13 @@ def setup end end - def debug_command(script, port) + def debug_command(script, port, additional_opts='') cmd = "#{interpreter}" cmd << " --debug" if jruby? cmd << " -J-Xdebug -J-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y" if jruby? and debug_jruby? cmd << " -I 'lib:#{File.dirname(script)}' #{@rdebug_ide}" + (@verbose_server ? " -d" : "") + - " -p #{port} --evaluation-control --time-limit 100 --memory-limit 0 -- '#{script}'" + " -p #{port} #{additional_opts} -- '#{script}'" end def start_debugger From bff361864ff4a99296dd0177209193e3fb85a770 Mon Sep 17 00:00:00 2001 From: ViugiNick Date: Wed, 13 Jun 2018 17:53:14 +0300 Subject: [PATCH 11/25] notify debugger about gdb_wrapper pid to kill it when debugging finished (#149) --- bin/gdb_wrapper | 5 ++++- bin/rdebug-ide | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/gdb_wrapper b/bin/gdb_wrapper index a439204..2442036 100755 --- a/bin/gdb_wrapper +++ b/bin/gdb_wrapper @@ -65,7 +65,10 @@ unless options.ruby_path exit 1 end -argv = '["' + ARGV * '", "' + '"]' +main_process_argv = ARGV +main_process_argv << '--gdb-wrapper-pid' << "#{Process.pid}" +argv = '["' + main_process_argv * '", "' + '"]' + child_argv = '["' + ARGV * '", "' + "', '--ignore-port" + '"]' debugger_loader_path = File.expand_path(File.dirname(__FILE__)) + '/../lib/ruby-debug-ide/attach/debugger_loader' diff --git a/bin/rdebug-ide b/bin/rdebug-ide index 3054353..1a244bd 100755 --- a/bin/rdebug-ide +++ b/bin/rdebug-ide @@ -28,6 +28,7 @@ options = OpenStruct.new( 'value_as_nested_element' => false, 'attach_mode' => false, 'cli_debug' => false, + 'gdb_wrapper_pid' => nil, 'key_value_mode' => false ) @@ -43,6 +44,8 @@ EOB opts.on("-h", "--host HOST", "Host name used for remote debugging") {|host| options.host = host} opts.on("-p", "--port PORT", Integer, "Port used for remote debugging") {|port| options.port = port} + opts.on("-gdbp", "--gdb-wrapper-pid PID", Integer, "Pid of corresponding gdb_wrapper (for attach case)") {|pid| options.gdb_wrapper_pid = pid} + opts.on("--dispatcher-port PORT", Integer, "Port used for multi-process debugging dispatcher") do |dp| options.dispatcher_port = dp end @@ -173,6 +176,7 @@ Debugger.value_as_nested_element = options.value_as_nested_element || options.rm Debugger.key_value_mode = options.key_value_mode if options.attach_mode + at_exit {Process.kill('INT', options.gdb_wrapper_pid)} if options.gdb_wrapper_pid if Debugger::FRONT_END == "debase" Debugger.init_variables end From da167dbda47dd91db058f5e5fb2810dd6a585034 Mon Sep 17 00:00:00 2001 From: Valentin Fondaratov Date: Mon, 18 Jun 2018 19:36:53 +0300 Subject: [PATCH 12/25] bump version to 0.7.0.beta5 [ci skip] --- lib/ruby-debug-ide/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-debug-ide/version.rb b/lib/ruby-debug-ide/version.rb index 8524da7..9b16003 100755 --- a/lib/ruby-debug-ide/version.rb +++ b/lib/ruby-debug-ide/version.rb @@ -1,3 +1,3 @@ module Debugger - IDE_VERSION='0.7.0.beta4' + IDE_VERSION='0.7.0.beta5' end From b4c8f15cb4ad48b636a381757363e9a3d705baf5 Mon Sep 17 00:00:00 2001 From: ViugiNick Date: Thu, 21 Jun 2018 18:09:36 +0300 Subject: [PATCH 13/25] fix debase dependency version to accept 2.3, too (#150) --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 9d8626c..3f1837e 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ end gem "ruby-debug-base", :platforms => [:jruby, *mries('18')] gem "ruby-debug-base19x", ">= 0.11.32", :platforms => mries('19') if RUBY_VERSION && RUBY_VERSION >= "2.0" - gem "debase", "~> 0.2.2", :platforms => mries('20', '21', '22', '23', '24', '25') + gem "debase", "~> 0.2", ">= 0.2.2", :platforms => mries('20', '21', '22', '23', '24', '25') end gemspec From 235f8fa86b23295f23b4f7894b2ec3418da73e3e Mon Sep 17 00:00:00 2001 From: Geunwoo Shin Date: Fri, 6 Jul 2018 11:23:13 +0900 Subject: [PATCH 14/25] Fixed syntax error on ruby 1.8 --- lib/ruby-debug-ide.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-debug-ide.rb b/lib/ruby-debug-ide.rb index e7b57d4..10f70f4 100644 --- a/lib/ruby-debug-ide.rb +++ b/lib/ruby-debug-ide.rb @@ -120,7 +120,7 @@ def start_control(host, port, notify_dispatcher) # "localhost" and nil have problems on some systems. host ||= '127.0.0.1' - server = notify_dispatcher_if_needed(host, port, notify_dispatcher) do |real_port, port_changed = false| + server = notify_dispatcher_if_needed(host, port, notify_dispatcher) do |real_port, port_changed| s = TCPServer.new(host, real_port) print_greeting_msg $stderr, host, real_port, port_changed ? "Subprocess" : "Fast" if defined? IDE_VERSION s From 45b6f400bdad8ba32f6702b89eb4bebb71bf47c3 Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Tue, 10 Jul 2018 15:25:41 +0300 Subject: [PATCH 15/25] Revert "notify debugger about gdb_wrapper pid to kill it when debugging finished (#149)" This reverts commit bff3618 --- bin/gdb_wrapper | 5 +---- bin/rdebug-ide | 4 ---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/bin/gdb_wrapper b/bin/gdb_wrapper index 2442036..a439204 100755 --- a/bin/gdb_wrapper +++ b/bin/gdb_wrapper @@ -65,10 +65,7 @@ unless options.ruby_path exit 1 end -main_process_argv = ARGV -main_process_argv << '--gdb-wrapper-pid' << "#{Process.pid}" -argv = '["' + main_process_argv * '", "' + '"]' - +argv = '["' + ARGV * '", "' + '"]' child_argv = '["' + ARGV * '", "' + "', '--ignore-port" + '"]' debugger_loader_path = File.expand_path(File.dirname(__FILE__)) + '/../lib/ruby-debug-ide/attach/debugger_loader' diff --git a/bin/rdebug-ide b/bin/rdebug-ide index 1a244bd..3054353 100755 --- a/bin/rdebug-ide +++ b/bin/rdebug-ide @@ -28,7 +28,6 @@ options = OpenStruct.new( 'value_as_nested_element' => false, 'attach_mode' => false, 'cli_debug' => false, - 'gdb_wrapper_pid' => nil, 'key_value_mode' => false ) @@ -44,8 +43,6 @@ EOB opts.on("-h", "--host HOST", "Host name used for remote debugging") {|host| options.host = host} opts.on("-p", "--port PORT", Integer, "Port used for remote debugging") {|port| options.port = port} - opts.on("-gdbp", "--gdb-wrapper-pid PID", Integer, "Pid of corresponding gdb_wrapper (for attach case)") {|pid| options.gdb_wrapper_pid = pid} - opts.on("--dispatcher-port PORT", Integer, "Port used for multi-process debugging dispatcher") do |dp| options.dispatcher_port = dp end @@ -176,7 +173,6 @@ Debugger.value_as_nested_element = options.value_as_nested_element || options.rm Debugger.key_value_mode = options.key_value_mode if options.attach_mode - at_exit {Process.kill('INT', options.gdb_wrapper_pid)} if options.gdb_wrapper_pid if Debugger::FRONT_END == "debase" Debugger.init_variables end From 103a1a25e253bae0c686055f8a8ebdfec8378501 Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Tue, 10 Jul 2018 15:56:40 +0300 Subject: [PATCH 16/25] bump ruby-debug-ide version to 0.7.0.beta6 --- lib/ruby-debug-ide/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-debug-ide/version.rb b/lib/ruby-debug-ide/version.rb index 9b16003..c47f24f 100755 --- a/lib/ruby-debug-ide/version.rb +++ b/lib/ruby-debug-ide/version.rb @@ -1,3 +1,3 @@ module Debugger - IDE_VERSION='0.7.0.beta5' + IDE_VERSION='0.7.0.beta6' end From bc1bd1dc46a0a154957e8959e24d49e276bd6c07 Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Tue, 17 Jul 2018 16:17:37 +0300 Subject: [PATCH 17/25] linux 1.8.7 added to travis --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 31827b8..e2f2db4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ os: - osx rvm: + - 1.8.7 - 1.9.3 - 2.0.0 - 2.1.10 @@ -25,6 +26,9 @@ matrix: - os: osx rvm: 2.0.0 + - os: osx + rvm: 1.8.7 + # include: # - os: osx # rvm: 1.9.3 From 4c60264483b49e9495649d60f84d52e6fec29344 Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Tue, 17 Jul 2018 16:18:02 +0300 Subject: [PATCH 18/25] old ruby doesn't support multiline commands --- lib/ruby-debug-ide/xml_printer.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/ruby-debug-ide/xml_printer.rb b/lib/ruby-debug-ide/xml_printer.rb index 65b8dbf..416be25 100644 --- a/lib/ruby-debug-ide/xml_printer.rb +++ b/lib/ruby-debug-ide/xml_printer.rb @@ -459,8 +459,7 @@ def print_load_result(file, exception = nil) end def print_element(name, additional_tags = nil) - additional_tags_presentation = additional_tags.nil? ? '' - : additional_tags.map {|tag, value| " #{tag}=\"#{value}\""}.reduce(:+) + additional_tags_presentation = additional_tags.nil? ? '' : additional_tags.map {|tag, value| " #{tag}=\"#{value}\""}.reduce(:+) print("<#{name}#{additional_tags_presentation}>") begin From ad80334f236f530e9fb44c261c18dbc6f822604b Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Tue, 17 Jul 2018 16:19:31 +0300 Subject: [PATCH 19/25] tests reworked to work on 1.8.7 --- test-base/inspect_test.rb | 4 ++++ test-base/test_base.rb | 9 ++++++--- test-base/variables_test.rb | 20 +++++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/test-base/inspect_test.rb b/test-base/inspect_test.rb index c130bc0..c7ff66b 100644 --- a/test-base/inspect_test.rb +++ b/test-base/inspect_test.rb @@ -69,6 +69,10 @@ def test_inspect_expr_with_timeout end def test_inspect_failing_expr_with_timeout + if RUBY_VERSION < "1.9" + @process_finished = true + return + end create_socket ["require 'timeout'", "puts 'test'"] run_to_line(2) send_ruby("v inspect (Timeout::timeout(0.1) { sleep 0.2 })") diff --git a/test-base/test_base.rb b/test-base/test_base.rb index 91cf22d..c026750 100644 --- a/test-base/test_base.rb +++ b/test-base/test_base.rb @@ -132,8 +132,9 @@ def TestBase.find_free_port(port = 1098) end def create_file(script_name, lines) - script_path = File.realdirpath(File.join(TMP_DIR, script_name)) - + file = File.join(TMP_DIR, script_name) + script_path = RUBY_VERSION >= "1.9" ? File.realdirpath(file) : file.to_s + File.open(script_path, "w") do |script| script.printf(lines.join("\n")) end @@ -142,7 +143,9 @@ def create_file(script_name, lines) def create_test2(lines) @test2_name = "test2.rb" - @test2_path = create_file(@test2_name, lines).force_encoding(Encoding::UTF_8) + @test2_path = create_file(@test2_name, lines) + + @test2_path = @test2_path.force_encoding(Encoding::UTF_8) if RUBY_VERSION >= "1.9" end # Creates test.rb with the given lines, set up @test_name and @test_path diff --git a/test-base/variables_test.rb b/test-base/variables_test.rb index 50c1b2d..85a44b3 100644 --- a/test-base/variables_test.rb +++ b/test-base/variables_test.rb @@ -100,7 +100,9 @@ def test_variable_local end def test_variable_instance - create_socket ["require_relative 'test2.rb'", "custom_object=Test2.new", "puts custom_object"] + require_string = RUBY_VERSION < "1.9" ? "require" : "require_relative" + + create_socket ["#{require_string} 'test2.rb'", "custom_object=Test2.new", "puts custom_object"] create_test2 ["class Test2", "def initialize", "@y=5", "end", "def to_s", "'test'", "end", "end"] run_to("test2.rb", 6) frame_number = 3 @@ -130,8 +132,9 @@ def test_variable_hash_with_string_keys assert_variables(read_variables, 1, {:name => "hash", :hasChildren => true}) send_ruby("v i hash") + expected_name = CGI::escapeHTML("'a'") assert_variables(read_variables, 2, - {:name => CGI.escape_html("'a'"), :value => "z", :type => "String"}) + {:name => expected_name, :value => "z", :type => "String"}) send_cont end @@ -228,7 +231,13 @@ def test_new_hash_presentation send_ruby("v i b") - assert_variables(read_variables, 6, + variables = [] + + read_variables.each_slice(2) do |var| + variables << var + end + + assert_variables(variables.sort_by{|a| a[0].value}.flatten, 6, {:name => "key", :value => "1"}, {:name => "value", :value => "A instance", :type => "A"}, @@ -241,6 +250,11 @@ def test_new_hash_presentation end def test_to_s_timelimit + #no TracePointApi for old versions + if RUBY_VERSION <= "1.9" + @process_finished = true + return + end create_socket ['class A', 'def to_s', 'a = 1', From 694f1a06856d66ca67a3e32fc505fa9fec545a7c Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Tue, 17 Jul 2018 16:20:27 +0300 Subject: [PATCH 20/25] gemfile reworked to work on old ruby versions --- Gemfile | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index 3f1837e..c8e7b16 100644 --- a/Gemfile +++ b/Gemfile @@ -3,15 +3,19 @@ source "http://rubygems.org/" # @param [Array] versions compatible ruby versions # @return [Array] an array with mri platforms of given versions def mries(*versions) - versions.flat_map do |v| - %w(ruby mingw x64_mingw) - .map { |platform| "#{platform}_#{v}".to_sym unless platform == "x64_mingw" && v < "2.0" } - .delete_if &:nil? - end + versions.map do |v| + %w(ruby mingw x64_mingw).map do |platform| + "#{platform}_#{v}".to_sym unless platform == "x64_mingw" && v < "2.0" + end.delete_if &:nil? + end.flatten +end + +gem "ruby-debug-base", :platforms => [:jruby, *mries('18')] + +if RUBY_VERSION && RUBY_VERSION >= "1.9" + gem "ruby-debug-base19x", ">= 0.11.32", :platforms => mries('19') end -gem "ruby-debug-base", :platforms => [:jruby, *mries('18')] -gem "ruby-debug-base19x", ">= 0.11.32", :platforms => mries('19') if RUBY_VERSION && RUBY_VERSION >= "2.0" gem "debase", "~> 0.2", ">= 0.2.2", :platforms => mries('20', '21', '22', '23', '24', '25') end @@ -23,6 +27,10 @@ group :development do end group :test do - gem "test-unit" + if RUBY_VERSION < "1.9" + gem "test-unit", "~> 2.1.2" + else + gem "test-unit" + end end From 7b5d00be148a15d7bb4f59741b199b56449602d5 Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Tue, 17 Jul 2018 16:43:34 +0300 Subject: [PATCH 21/25] bump version to 0.7.0.beta7 --- lib/ruby-debug-ide/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-debug-ide/version.rb b/lib/ruby-debug-ide/version.rb index c47f24f..6bcc59e 100755 --- a/lib/ruby-debug-ide/version.rb +++ b/lib/ruby-debug-ide/version.rb @@ -1,3 +1,3 @@ module Debugger - IDE_VERSION='0.7.0.beta6' + IDE_VERSION='0.7.0.beta7' end From ab971e6097a41267e17418d4879698d33719650f Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Wed, 18 Jul 2018 14:56:35 +0300 Subject: [PATCH 22/25] gemfile ruby-debug-base case --- Gemfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c8e7b16..c36df53 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,9 @@ def mries(*versions) end.flatten end -gem "ruby-debug-base", :platforms => [:jruby, *mries('18')] +if RUBY_VERSION < '1.9' || defined?(JRUBY_VERSION) + gem "ruby-debug-base", :platforms => [:jruby, *mries('18')] +end if RUBY_VERSION && RUBY_VERSION >= "1.9" gem "ruby-debug-base19x", ">= 0.11.32", :platforms => mries('19') From cae6dd65bedd182355281370dcc5d44ab4912cba Mon Sep 17 00:00:00 2001 From: Valentin Fondaratov Date: Fri, 7 Jun 2019 16:12:57 +0300 Subject: [PATCH 23/25] update ruby version matrix in travis config --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e2f2db4..15a86ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,10 @@ rvm: - 2.0.0 - 2.1.10 - 2.2.8 - - 2.3.5 - - 2.4.2 - - 2.5.0 + - 2.3.8 + - 2.4.6 + - 2.5.5 + - 2.6.3 - ruby-head matrix: @@ -35,4 +36,4 @@ matrix: # before_script: rvm install ruby-1.9.3 # not binary # - os: osx # rvm: 2.0.0 -# before_script: rvm install ruby-2.0.0 # not binary \ No newline at end of file +# before_script: rvm install ruby-2.0.0 # not binary From d051a4d9c58c64832849106296c068aa24501ce6 Mon Sep 17 00:00:00 2001 From: Alexandr Evstigneev Date: Fri, 7 Jun 2019 16:16:26 +0300 Subject: [PATCH 24/25] Install dependencies into the same root as debugger itself (#172) * Install dependencies into the same root as debugger itself Helps with --user-install on system ruby --- ext/mkrf_conf.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/mkrf_conf.rb b/ext/mkrf_conf.rb index c8170ac..478dca6 100644 --- a/ext/mkrf_conf.rb +++ b/ext/mkrf_conf.rb @@ -1,3 +1,4 @@ +install_dir = File.expand_path("../../../..", __FILE__) jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && 'jruby' == RUBY_ENGINE) rbx = defined?(RUBY_ENGINE) && 'rbx' == RUBY_ENGINE @@ -27,11 +28,11 @@ def already_installed(dep) begin puts "Installing base gem" - inst = Gem::DependencyInstaller.new :prerelease => dep.prerelease? + inst = Gem::DependencyInstaller.new(:prerelease => dep.prerelease?, :install_dir => install_dir) inst.install dep rescue begin - inst = Gem::DependencyInstaller.new(:prerelease => true) + inst = Gem::DependencyInstaller.new(:prerelease => true, :install_dir => install_dir) inst.install dep rescue Exception => e puts e From b4aff0d9c102309bc9e84787b76a416c80eeb402 Mon Sep 17 00:00:00 2001 From: Valentin Fondaratov Date: Mon, 8 Apr 2019 13:58:45 +0300 Subject: [PATCH 25/25] bump version to 0.7.0 --- lib/ruby-debug-ide/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby-debug-ide/version.rb b/lib/ruby-debug-ide/version.rb index 6bcc59e..43d918b 100755 --- a/lib/ruby-debug-ide/version.rb +++ b/lib/ruby-debug-ide/version.rb @@ -1,3 +1,3 @@ module Debugger - IDE_VERSION='0.7.0.beta7' + IDE_VERSION='0.7.0' end