5
5
6
6
module Debugger
7
7
8
+ module OverflowMessageType
9
+ NIL_MESSAGE = lambda { |e | nil }
10
+ EXCEPTION_MESSAGE = lambda { |e | e . message }
11
+ SPECIAL_SYMBOL_MESSAGE = lambda { |e | '<?>' }
12
+ end
13
+
8
14
class MemoryLimitError < StandardError
9
15
attr_reader :message
10
16
attr_reader :backtrace
@@ -159,7 +165,7 @@ def print_string(string)
159
165
end
160
166
end
161
167
162
- def exec_with_allocation_control ( value , memory_limit , time_limit , exec_method , return_message_if_overflow )
168
+ def exec_with_allocation_control ( value , memory_limit , time_limit , exec_method , overflow_message_type )
163
169
if ( defined? ( JRUBY_VERSION ) || ENV [ 'DEBUGGER_MEMORY_LIMIT' ] . to_i <= 0 )
164
170
return value . send exec_method
165
171
end
@@ -197,7 +203,7 @@ def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, r
197
203
rescue MemoryLimitError , TimeLimitError => e
198
204
print_debug ( e . message + "\n " + e . backtrace )
199
205
200
- return return_message_if_overflow ? e . message : nil
206
+ return overflow_message_type . call ( e )
201
207
end
202
208
203
209
def print_variable ( name , value , kind )
@@ -220,7 +226,7 @@ def print_variable(name, value, kind)
220
226
else
221
227
has_children = !value . instance_variables . empty? || !value . class . class_variables . empty?
222
228
223
- value_str = exec_with_allocation_control ( value , ENV [ 'DEBUGGER_MEMORY_LIMIT' ] . to_i , ENV [ 'INSPECT_TIME_LIMIT' ] . to_i , :to_s , true ) || 'nil' rescue "<#to_s method raised exception: #{ $!} >"
229
+ 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: #{ $!} >"
224
230
225
231
unless value_str . is_a? ( String )
226
232
value_str = "ERROR: #{ value . class } .to_s method returns #{ value_str . class } . Should return String."
@@ -447,7 +453,7 @@ def max_compact_name_size
447
453
def compact_array_str ( value )
448
454
slice = value [ 0 ..10 ]
449
455
450
- compact = exec_with_allocation_control ( slice , ENV [ 'DEBUGGER_MEMORY_LIMIT' ] . to_i , ENV [ 'INSPECT_TIME_LIMIT' ] . to_i , :inspect , true )
456
+ compact = exec_with_allocation_control ( slice , ENV [ 'DEBUGGER_MEMORY_LIMIT' ] . to_i , ENV [ 'INSPECT_TIME_LIMIT' ] . to_i , :inspect , OverflowMessageType :: NIL_MESSAGE )
451
457
452
458
if compact && value . size != slice . size
453
459
compact [ 0 ..compact . size -2 ] + ", ...]"
0 commit comments