11require 'stringio'
22require 'cgi'
33require 'monitor'
4- if ( !defined? ( JRUBY_VERSION ) )
5- include ObjectSpace
6- end
74
85module 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