55
66module Debugger
77
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+
814 class MemoryLimitError < StandardError
915 attr_reader :message
1016 attr_reader :backtrace
@@ -159,7 +165,7 @@ def print_string(string)
159165 end
160166 end
161167
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 )
163169 if ( defined? ( JRUBY_VERSION ) || ENV [ 'DEBUGGER_MEMORY_LIMIT' ] . to_i <= 0 )
164170 return value . send exec_method
165171 end
@@ -197,7 +203,7 @@ def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, r
197203 rescue MemoryLimitError , TimeLimitError => e
198204 print_debug ( e . message + "\n " + e . backtrace )
199205
200- return return_message_if_overflow ? e . message : nil
206+ return overflow_message_type . call ( e )
201207 end
202208
203209 def print_variable ( name , value , kind )
@@ -220,7 +226,7 @@ def print_variable(name, value, kind)
220226 else
221227 has_children = !value . instance_variables . empty? || !value . class . class_variables . empty?
222228
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: #{ $!} >"
224230
225231 unless value_str . is_a? ( String )
226232 value_str = "ERROR: #{ value . class } .to_s method returns #{ value_str . class } . Should return String."
@@ -447,7 +453,7 @@ def max_compact_name_size
447453 def compact_array_str ( value )
448454 slice = value [ 0 ..10 ]
449455
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 )
451457
452458 if compact && value . size != slice . size
453459 compact [ 0 ..compact . size -2 ] + ", ...]"
0 commit comments