Skip to content

Commit 7b3a875

Browse files
committed
Fixes according to the review
1 parent 8328947 commit 7b3a875

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
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: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -386,27 +386,29 @@ def max_compact_name_size
386386

387387
def inspect_with_allocation_control(slice, memory_limit)
388388
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)
389+
result = nil
390+
inspect_thread = DebugThread.start {
391+
start_alloc_size = ObjectSpace.memsize_of_all
392+
trace = TracePoint.new(:c_call, :call) do |tp|
396393

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
400-
end
401-
402-
trace.enable
403-
result = slice.inspect
404-
trace.disable
405-
result
394+
curr_alloc_size = ObjectSpace.memsize_of_all
395+
start_alloc_size = curr_alloc_size if (curr_alloc_size < start_alloc_size)
396+
397+
if(curr_alloc_size - start_alloc_size > 1e6 * memory_limit)
398+
curr_thread.raise MemoryLimitError, "Out of memory: evaluation of inspect took more than #{memory_limit}mb. \n#{caller.map{|l| "\t#{l}"}.join("\n")}"
399+
trace.disable
400+
end
401+
end.enable {
402+
result = slice.inspect
403+
}
404+
}
405+
inspect_thread.join
406+
inspect_thread.kill
407+
return result
406408
rescue MemoryLimitError => e
407409
print_debug(e.message)
408410
return nil
409-
end
411+
end
410412

411413
def compact_array_str(value)
412414
slice = value[0..10]
@@ -420,7 +422,7 @@ def compact_array_str(value)
420422
if compact && value.size != slice.size
421423
compact[0..compact.size-2] + ", ...]"
422424
end
423-
compact
425+
compact
424426
end
425427

426428
def compact_hash_str(value)

0 commit comments

Comments
 (0)