Skip to content

Commit 7fda807

Browse files
viuginick1valich
authored andcommitted
jruby and error class fix (#116)
* jruby and error class fix * Tabs for backtrace output
1 parent 2f7b3e0 commit 7fda807

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
require 'stringio'
22
require 'cgi'
33
require 'monitor'
4-
require 'objspace'
4+
if (!defined?(JRUBY_VERSION))
5+
require 'objspace'
6+
end
57

68
module Debugger
79

@@ -15,7 +17,7 @@ class MemoryLimitError < StandardError
1517
attr_reader :message
1618
attr_reader :backtrace
1719

18-
def initialize(message, backtrace = '')
20+
def initialize(message, backtrace = [])
1921
@message = message
2022
@backtrace = backtrace
2123
end
@@ -25,7 +27,7 @@ class TimeLimitError < StandardError
2527
attr_reader :message
2628
attr_reader :backtrace
2729

28-
def initialize(message, backtrace = '')
30+
def initialize(message, backtrace = [])
2931
@message = message
3032
@backtrace = backtrace
3133
end
@@ -183,7 +185,7 @@ def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, o
183185
curr_time = Time.now.to_f
184186

185187
if ((curr_time - start_time) * 1e3 > time_limit)
186-
curr_thread.raise TimeLimitError.new("Timeout: evaluation of #{exec_method} took longer than #{time_limit}ms.", "#{caller.map {|l| "\t#{l}"}.join("\n")}")
188+
curr_thread.raise TimeLimitError.new("Timeout: evaluation of #{exec_method} took longer than #{time_limit}ms.", caller.to_a)
187189
inspect_thread.kill
188190
end
189191

@@ -192,7 +194,7 @@ def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, o
192194
start_alloc_size = curr_alloc_size if (curr_alloc_size < start_alloc_size)
193195

194196
if (curr_alloc_size - start_alloc_size > 1e6 * memory_limit)
195-
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")}")
197+
curr_thread.raise MemoryLimitError.new("Out of memory: evaluation of #{exec_method} took more than #{memory_limit}mb.", caller.to_a)
196198
inspect_thread.kill
197199
end
198200
end
@@ -205,8 +207,7 @@ def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, o
205207
inspect_thread.kill
206208
return result
207209
rescue MemoryLimitError, TimeLimitError => e
208-
print_debug(e.message + "\n" + e.backtrace)
209-
210+
print_debug(e.message + "\n" + e.backtrace.map{|l| "\t#{l}"}.join("\n"))
210211
return overflow_message_type.call(e)
211212
end
212213

@@ -231,7 +232,6 @@ def print_variable(name, value, kind)
231232
has_children = !value.instance_variables.empty? || !value.class.class_variables.empty?
232233

233234
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: #{$!}>"
234-
235235
unless value_str.is_a?(String)
236236
value_str = "ERROR: #{value.class}.to_s method returns #{value_str.class}. Should return String."
237237
end

0 commit comments

Comments
 (0)