diff --git a/bin/rdebug-ide b/bin/rdebug-ide index a72dfd1..698564e 100755 --- a/bin/rdebug-ide +++ b/bin/rdebug-ide @@ -131,6 +131,14 @@ else Debugger::PROG_SCRIPT = $0 end +if RUBY_VERSION < "1.9" + lib_path = File.expand_path(File.dirname(__FILE__) + "/../lib/") + $: << lib_path unless $:.include? lib_path + require 'ruby-debug-ide/thread_alias.rb' +else + require_relative '../lib/ruby-debug-ide/thread_alias' +end + if options.dispatcher_port != -1 ENV['IDE_PROCESS_DISPATCHER'] = options.dispatcher_port.to_s if RUBY_VERSION < "1.9" diff --git a/lib/ruby-debug-ide/command.rb b/lib/ruby-debug-ide/command.rb index e6ee3e1..55f96f7 100644 --- a/lib/ruby-debug-ide/command.rb +++ b/lib/ruby-debug-ide/command.rb @@ -128,9 +128,18 @@ def debug_eval(str, b = get_binding) to_inspect = Command.unescape_incoming(str) max_time = Debugger.evaluation_timeout @printer.print_debug("Evaluating %s with timeout after %i sec", str, max_time) + + Debugger::TimeoutHandler.do_thread_alias + + eval_result = nil + timeout(max_time) do - eval(to_inspect, b) + eval_result = eval(to_inspect, b) end + + Debugger::TimeoutHandler.undo_thread_alias + + return eval_result rescue StandardError, ScriptError => e @printer.print_exception(e, @state.binding) throw :debug_error diff --git a/lib/ruby-debug-ide/thread-alias/alias_thread.rb b/lib/ruby-debug-ide/thread-alias/alias_thread.rb new file mode 100644 index 0000000..a37eddb --- /dev/null +++ b/lib/ruby-debug-ide/thread-alias/alias_thread.rb @@ -0,0 +1,2 @@ +OldThread = Thread +Thread = Debugger::DebugThread \ No newline at end of file diff --git a/lib/ruby-debug-ide/thread-alias/unalias_thread.rb b/lib/ruby-debug-ide/thread-alias/unalias_thread.rb new file mode 100644 index 0000000..8ead867 --- /dev/null +++ b/lib/ruby-debug-ide/thread-alias/unalias_thread.rb @@ -0,0 +1 @@ +Thread = OldThread \ No newline at end of file diff --git a/lib/ruby-debug-ide/thread_alias.rb b/lib/ruby-debug-ide/thread_alias.rb new file mode 100644 index 0000000..1cc38d4 --- /dev/null +++ b/lib/ruby-debug-ide/thread_alias.rb @@ -0,0 +1,13 @@ +module Debugger + module TimeoutHandler + class << self + def do_thread_alias + load File.expand_path(File.dirname(__FILE__) + '/thread-alias/alias_thread.rb') + end + + def undo_thread_alias + load File.expand_path(File.dirname(__FILE__) + '/thread-alias/unalias_thread.rb') + end + end + end +end \ No newline at end of file