Skip to content

Commit

Permalink
set alias for Thread during eval execution
Browse files Browse the repository at this point in the history
(cherry picked from commit 56e1a3f)
  • Loading branch information
ViugiNick authored and valich committed Feb 20, 2018
1 parent 2849d3f commit 0d291b5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bin/rdebug-ide
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion lib/ruby-debug-ide/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/ruby-debug-ide/thread-alias/alias_thread.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OldThread = Thread
Thread = Debugger::DebugThread
1 change: 1 addition & 0 deletions lib/ruby-debug-ide/thread-alias/unalias_thread.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thread = OldThread
13 changes: 13 additions & 0 deletions lib/ruby-debug-ide/thread_alias.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0d291b5

Please sign in to comment.