Skip to content

Commit 8fd8ad5

Browse files
committed
Implementation with a separate thread and ML changed to 1mb
1 parent 8328947 commit 8fd8ad5

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

bin/rdebug-ide

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ EOB
3737
opts.separator ""
3838
opts.separator "Options:"
3939

40-
ENV['DEBUGGER_MEMORY_LIMIT'] = '10'
41-
opts.on("-m", "--memory-limit LIMIT", Integer, "evaluation memory limit in mb (default: 10)") do |limit|
40+
ENV['DEBUGGER_MEMORY_LIMIT'] = '1'
41+
opts.on("-m", "--memory-limit LIMIT", Integer, "evaluation memory limit in mb (default: 1)") do |limit|
4242
ENV['DEBUGGER_MEMORY_LIMIT'] = limit
4343
end
4444

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -385,28 +385,33 @@ def max_compact_name_size
385385
end
386386

387387
def inspect_with_allocation_control(slice, memory_limit)
388-
curr_thread = Thread.current
389-
390-
start_alloc_size = ObjectSpace.memsize_of_all
391-
392-
trace = TracePoint.new(:c_call, :call) do |tp|
393-
curr_alloc_size = ObjectSpace.memsize_of_all
394-
395-
if(curr_alloc_size - start_alloc_size > 1e6 * memory_limit)
396-
397-
trace.disable
398-
curr_thread.raise MemoryLimitError, "Out of memory: evaluation of inspect took more than #{memory_limit}mb." if curr_thread.alive?
399-
end
388+
if Thread.respond_to?(:critical) and Thread.critical
389+
raise ThreadError, "memory_limit within critical session"
400390
end
391+
392+
curr_thread = Thread.current
401393

402-
trace.enable
403-
result = slice.inspect
404-
trace.disable
405-
result
394+
result = nil
395+
inspect_thread = DebugThread.start {
396+
start_alloc_size = ObjectSpace.memsize_of_all
397+
trace = TracePoint.new(:c_call, :call) do |tp|
398+
curr_alloc_size = ObjectSpace.memsize_of_all
399+
start_alloc_size = curr_alloc_size if (curr_alloc_size < start_alloc_size)
400+
401+
if(curr_alloc_size - start_alloc_size > 1e6 * memory_limit)
402+
curr_thread.raise MemoryLimitError, "Out of memory: evaluation of inspect took more than #{memory_limit}mb. \n#{caller.map{|l| "\t#{l}"}.join("\n")}"
403+
inspect_thread.kill
404+
end
405+
end.enable {
406+
result = slice.inspect
407+
}
408+
}
409+
inspect_thread.join
410+
return result
406411
rescue MemoryLimitError => e
407412
print_debug(e.message)
408413
return nil
409-
end
414+
end
410415

411416
def compact_array_str(value)
412417
slice = value[0..10]

0 commit comments

Comments
 (0)