From 0fa26c9223c7f51319b91216bcdc5303517ad851 Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Mon, 7 Aug 2017 20:57:06 +0300 Subject: [PATCH 1/2] jruby and error class fix --- lib/ruby-debug-ide/xml_printer.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/ruby-debug-ide/xml_printer.rb b/lib/ruby-debug-ide/xml_printer.rb index 5e449d1..83e4101 100644 --- a/lib/ruby-debug-ide/xml_printer.rb +++ b/lib/ruby-debug-ide/xml_printer.rb @@ -1,7 +1,9 @@ require 'stringio' require 'cgi' require 'monitor' -require 'objspace' +if (!defined?(JRUBY_VERSION)) + require 'objspace' +end module Debugger @@ -15,7 +17,7 @@ class MemoryLimitError < StandardError attr_reader :message attr_reader :backtrace - def initialize(message, backtrace = '') + def initialize(message, backtrace = []) @message = message @backtrace = backtrace end @@ -25,7 +27,7 @@ class TimeLimitError < StandardError attr_reader :message attr_reader :backtrace - def initialize(message, backtrace = '') + def initialize(message, backtrace = []) @message = message @backtrace = backtrace end @@ -183,7 +185,7 @@ def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, o curr_time = Time.now.to_f if ((curr_time - start_time) * 1e3 > time_limit) - curr_thread.raise TimeLimitError.new("Timeout: evaluation of #{exec_method} took longer than #{time_limit}ms.", "#{caller.map {|l| "\t#{l}"}.join("\n")}") + curr_thread.raise TimeLimitError.new("Timeout: evaluation of #{exec_method} took longer than #{time_limit}ms.", caller.to_a) inspect_thread.kill end @@ -192,7 +194,7 @@ def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, o start_alloc_size = curr_alloc_size if (curr_alloc_size < start_alloc_size) if (curr_alloc_size - start_alloc_size > 1e6 * memory_limit) - curr_thread.raise MemoryLimitError.new("Out of memory: evaluation of #{exec_method} took more than #{memory_limit}mb.", "#{caller.map {|l| "\t#{l}"}.join("\n")}") + curr_thread.raise MemoryLimitError.new("Out of memory: evaluation of #{exec_method} took more than #{memory_limit}mb.", caller.to_a) inspect_thread.kill end end @@ -205,7 +207,7 @@ def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, o inspect_thread.kill return result rescue MemoryLimitError, TimeLimitError => e - print_debug(e.message + "\n" + e.backtrace) + print_debug(e.message + "\n" + e.backtrace.join("\n")) return overflow_message_type.call(e) end @@ -231,7 +233,6 @@ def print_variable(name, value, kind) has_children = !value.instance_variables.empty? || !value.class.class_variables.empty? value_str = exec_with_allocation_control(value, ENV['DEBUGGER_MEMORY_LIMIT'].to_i, ENV['INSPECT_TIME_LIMIT'].to_i, :to_s, OverflowMessageType::EXCEPTION_MESSAGE) || 'nil' rescue "<#to_s method raised exception: #{$!}>" - unless value_str.is_a?(String) value_str = "ERROR: #{value.class}.to_s method returns #{value_str.class}. Should return String." end From 4702e96d2e41ac56de9a83ab76feff825bdbcda7 Mon Sep 17 00:00:00 2001 From: Viuginov Nickolay Date: Tue, 8 Aug 2017 11:36:55 +0300 Subject: [PATCH 2/2] Tabs for backtrace output --- 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 83e4101..aad80f6 100644 --- a/lib/ruby-debug-ide/xml_printer.rb +++ b/lib/ruby-debug-ide/xml_printer.rb @@ -207,8 +207,7 @@ def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, o inspect_thread.kill return result rescue MemoryLimitError, TimeLimitError => e - print_debug(e.message + "\n" + e.backtrace.join("\n")) - + print_debug(e.message + "\n" + e.backtrace.map{|l| "\t#{l}"}.join("\n")) return overflow_message_type.call(e) end