Skip to content

Commit

Permalink
exec monkey patch fix
Browse files Browse the repository at this point in the history
  • Loading branch information
equivalence1 committed Dec 15, 2016
1 parent 4512d5e commit 279e28e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
3 changes: 1 addition & 2 deletions bin/rdebug-ide
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ if options.dispatcher_port != -1
else
require_relative '../lib/ruby-debug-ide/multiprocess'
end
Debugger::MultiProcess.do_monkey

ENV['DEBUGGER_STORED_RUBYLIB'] = ENV['RUBYLIB']
old_opts = ENV['RUBYOPT'] || ''
Expand All @@ -140,8 +141,6 @@ Debugger.evaluation_timeout = options.evaluation_timeout
Debugger.catchpoint_deleted_event = options.catchpoint_deleted_event || options.rm_protocol_extensions
Debugger.value_as_nested_element = options.value_as_nested_element || options.rm_protocol_extensions

Debugger.attached = true

if options.attach_mode
if Debugger::FRONT_END == "debase"
Debugger.init_variables
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-debug-ide/commands/control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ def regexp
end

def execute
Debugger.attached = false
Debugger.stop
Debugger.interface.close
Debugger::MultiProcess.undo_monkey
Debugger.control_thread = nil
Thread.current.exit #@control_thread is a current thread
end
Expand Down
22 changes: 19 additions & 3 deletions lib/ruby-debug-ide/multiprocess.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
if RUBY_VERSION < "1.9"
if RUBY_VERSION < '1.9'
require 'ruby-debug-ide/multiprocess/pre_child'
require 'ruby-debug-ide/multiprocess/monkey'
else
require_relative 'multiprocess/pre_child'
require_relative 'multiprocess/monkey'
end

module Debugger
module MultiProcess
class << self
def do_monkey
load File.expand_path(File.dirname(__FILE__) + '/multiprocess/monkey.rb')
end

def undo_monkey
if ENV['IDE_PROCESS_DISPATCHER']
load File.expand_path(File.dirname(__FILE__) + '/multiprocess/unmonkey.rb')
ruby_opts = ENV['RUBYOPT'].split(' ')
ENV['RUBYOPT'] = ruby_opts.keep_if {|opt| !opt.end_with?('ruby-debug-ide/multiprocess/starter')}.join(' ')
end
end
end
end
end
2 changes: 0 additions & 2 deletions lib/ruby-debug-ide/multiprocess/pre_child.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module Debugger
module MultiProcess
class << self
def pre_child(options = nil)
return unless Debugger.attached

require 'socket'
require 'ostruct'

Expand Down
31 changes: 31 additions & 0 deletions lib/ruby-debug-ide/multiprocess/unmonkey.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Debugger
module MultiProcess
def self.restore_fork
%Q{
alias fork pre_debugger_fork
}
end

def self.restore_exec
%Q{
alias exec pre_debugger_exec
}
end
end
end

module Kernel
class << self
module_eval Debugger::MultiProcess.restore_fork
module_eval Debugger::MultiProcess.restore_exec
end
module_eval Debugger::MultiProcess.restore_fork
module_eval Debugger::MultiProcess.restore_exec
end

module Process
class << self
module_eval Debugger::MultiProcess.restore_fork
module_eval Debugger::MultiProcess.restore_exec
end
end

0 comments on commit 279e28e

Please sign in to comment.