Skip to content

Commit cfb1f06

Browse files
committed
unify time/memlimit opts with other ones; fix objspace req
1 parent 1faaa98 commit cfb1f06

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

bin/rdebug-ide

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ options = OpenStruct.new(
2020
'int_handler' => true,
2121
'dispatcher_port' => -1,
2222
'evaluation_timeout' => 10,
23+
'trace_to_s' => false,
24+
'debugger_memory_limit' => 10,
25+
'inspect_time_limit' => 100,
2326
'rm_protocol_extensions' => false,
2427
'catchpoint_deleted_event' => false,
2528
'value_as_nested_element' => false,
@@ -45,19 +48,20 @@ EOB
4548
opts.on('--evaluation-timeout TIMEOUT', Integer,'evaluation timeout in seconds (default: 10)') do |timeout|
4649
options.evaluation_timeout = timeout
4750
end
48-
Debugger.trace_to_s = false
49-
opts.on("--evaluation-control", "trace to_s evaluation") do
50-
Debugger.trace_to_s = true
51-
end
51+
opts.on("--evaluation-control", "trace to_s evaluation") {options.trace_to_s = true}
5252

53-
ENV['DEBUGGER_MEMORY_LIMIT'] = '10'
5453
opts.on("-m", "--memory-limit LIMIT", Integer, "evaluation memory limit in mb (default: 10)") do |limit|
55-
ENV['DEBUGGER_MEMORY_LIMIT'] = limit.to_s
54+
if defined?(JRUBY_VERSION) || RUBY_VERSION < '2.0'
55+
$stderr.puts "Evaluation memory limit is ineffective in JRuby and MRI < 2.0"
56+
limit = 0
57+
end
58+
options.debugger_memory_limit = limit
59+
options.trace_to_s ||= limit > 0
5660
end
5761

58-
ENV['INSPECT_TIME_LIMIT'] = '100'
5962
opts.on("-t", "--time-limit LIMIT", Integer, "evaluation time limit in milliseconds (default: 100)") do |limit|
60-
ENV['INSPECT_TIME_LIMIT'] = limit.to_s
63+
options.inspect_time_limit = limit
64+
options.trace_to_s ||= limit > 0
6165
end
6266

6367
opts.on('--stop', 'stop when the script is loaded') {options.stop = true}
@@ -157,6 +161,9 @@ end
157161
Debugger.keep_frame_binding = options.frame_bind
158162
Debugger.tracing = options.tracing
159163
Debugger.evaluation_timeout = options.evaluation_timeout
164+
Debugger.trace_to_s = options.trace_to_s && (options.debugger_memory_limit > 0 || options.inspect_time_limit > 0)
165+
Debugger.debugger_memory_limit = options.debugger_memory_limit
166+
Debugger.inspect_time_limit = options.inspect_time_limit
160167
Debugger.catchpoint_deleted_event = options.catchpoint_deleted_event || options.rm_protocol_extensions
161168
Debugger.value_as_nested_element = options.value_as_nested_element || options.rm_protocol_extensions
162169

lib/ruby-debug-ide.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def cleanup_backtrace(backtrace)
4444
end
4545

4646
attr_accessor :attached
47-
attr_accessor :cli_debug, :xml_debug, :evaluation_timeout, :trace_to_s
47+
attr_accessor :cli_debug, :xml_debug, :evaluation_timeout
48+
attr_accessor :trace_to_s, :debugger_memory_limit, :inspect_time_limit
4849
attr_accessor :control_thread
4950
attr_reader :interface
5051
# protocol extensions

lib/ruby-debug-ide/multiprocess/pre_child.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ def pre_child(options = nil)
1717
'int_handler' => true,
1818
'cli_debug' => (ENV['DEBUGGER_CLI_DEBUG'] == 'true'),
1919
'notify_dispatcher' => true,
20-
'evaluation_timeout' => 10
20+
'evaluation_timeout' => 10,
21+
'trace_to_s' => false,
22+
'debugger_memory_limit' => 10,
23+
'inspect_time_limit' => 100
2124
)
2225

2326
if(options.ignore_port)
@@ -45,6 +48,9 @@ def start_debugger(options)
4548
Debugger.keep_frame_binding = options.frame_bind
4649
Debugger.tracing = options.tracing
4750
Debugger.evaluation_timeout = options.evaluation_timeout
51+
Debugger.trace_to_s = options.trace_to_s
52+
Debugger.debugger_memory_limit = options.debugger_memory_limit
53+
Debugger.inspect_time_limit = options.inspect_time_limit
4854
Debugger.cli_debug = options.cli_debug
4955
Debugger.prepare_debugger(options)
5056
end

lib/ruby-debug-ide/xml_printer.rb

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

85
module Debugger
96

@@ -153,7 +150,7 @@ def print_hash(hash)
153150
if k.class.name == "String"
154151
name = '\'' + k + '\''
155152
else
156-
name = exec_with_allocation_control(k, ENV['DEBUGGER_MEMORY_LIMIT'].to_i, ENV['INSPECT_TIME_LIMIT'].to_i, :to_s, OverflowMessageType::EXCEPTION_MESSAGE)
153+
name = exec_with_allocation_control(k, Debugger.debugger_memory_limit, Debugger.inspect_time_limit, :to_s, OverflowMessageType::EXCEPTION_MESSAGE)
157154
end
158155
print_variable(name, hash[k], 'instance')
159156
}
@@ -189,18 +186,16 @@ def exec_with_timeout(sec, error_message)
189186
end
190187

191188
def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, overflow_message_type)
192-
return value.send exec_method if !Debugger.trace_to_s
193-
return exec_with_timeout(time_limit * 1e-3, "Timeout: evaluation of #{exec_method} took longer than #{time_limit}ms.") {value.send exec_method} if defined?(JRUBY_VERSION) || memory_limit <= 0 || (RUBY_VERSION < '2.0' && time_limit > 0)
189+
return value.send exec_method unless Debugger.trace_to_s
194190

191+
if defined?(JRUBY_VERSION) || RUBY_VERSION < '2.0' || memory_limit <= 0
192+
return exec_with_timeout(time_limit * 1e-3, "Timeout: evaluation of #{exec_method} took longer than #{time_limit}ms.") { value.send exec_method }
193+
end
195194

196-
curr_thread = Thread.current
197-
control_thread = Debugger.control_thread
198-
199-
result = nil
200-
195+
require 'objspace'
201196
trace_queue = Queue.new
202197

203-
inspect_thread = DebugThread.start do
198+
DebugThread.start do
204199
start_alloc_size = ObjectSpace.memsize_of_all
205200
start_time = Time.now.to_f
206201

@@ -263,7 +258,7 @@ def print_variable(name, value, kind)
263258
else
264259
has_children = !value.instance_variables.empty? || !value.class.class_variables.empty?
265260

266-
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: #{$!}>"
261+
value_str = exec_with_allocation_control(value, Debugger.debugger_memory_limit, Debugger.inspect_time_limit, :to_s, OverflowMessageType::EXCEPTION_MESSAGE) || 'nil' rescue "<#to_s method raised exception: #{$!}>"
267262
unless value_str.is_a?(String)
268263
value_str = "ERROR: #{value.class}.to_s method returns #{value_str.class}. Should return String."
269264
end
@@ -489,7 +484,7 @@ def max_compact_name_size
489484
def compact_array_str(value)
490485
slice = value[0..10]
491486

492-
compact = exec_with_allocation_control(slice, ENV['DEBUGGER_MEMORY_LIMIT'].to_i, ENV['INSPECT_TIME_LIMIT'].to_i, :inspect, OverflowMessageType::NIL_MESSAGE)
487+
compact = exec_with_allocation_control(slice, Debugger.debugger_memory_limit, Debugger.inspect_time_limit, :inspect, OverflowMessageType::NIL_MESSAGE)
493488

494489
if compact && value.size != slice.size
495490
compact[0..compact.size - 2] + ", ...]"
@@ -501,14 +496,14 @@ def compact_hash_str(value)
501496
keys_strings = Hash.new
502497

503498
slice = value.sort_by do |k, _|
504-
keys_string = exec_with_allocation_control(k, ENV['DEBUGGER_MEMORY_LIMIT'].to_i, ENV['INSPECT_TIME_LIMIT'].to_i, :to_s, OverflowMessageType::SPECIAL_SYMBOL_MESSAGE)
499+
keys_string = exec_with_allocation_control(k, Debugger.debugger_memory_limit, Debugger.inspect_time_limit, :to_s, OverflowMessageType::SPECIAL_SYMBOL_MESSAGE)
505500
keys_strings[k] = keys_string
506501
keys_string
507502
end[0..5]
508503

509504
compact = slice.map do |kv|
510505
key_string = keys_strings[kv[0]]
511-
value_string = exec_with_allocation_control(kv[1], ENV['DEBUGGER_MEMORY_LIMIT'].to_i, ENV['INSPECT_TIME_LIMIT'].to_i, :to_s, OverflowMessageType::SPECIAL_SYMBOL_MESSAGE)
506+
value_string = exec_with_allocation_control(kv[1], Debugger.debugger_memory_limit, Debugger.inspect_time_limit, :to_s, OverflowMessageType::SPECIAL_SYMBOL_MESSAGE)
512507
"#{key_string}: #{handle_binary_data(value_string)}"
513508
end.join(", ")
514509
"{" + compact + (slice.size != value.size ? ", ..." : "") + "}"

0 commit comments

Comments
 (0)