Skip to content

Commit 66b2fbe

Browse files
authored
Merge pull request #88 from equivalence1/monkey_fix
exec monkey patch fix
2 parents 4512d5e + 279e28e commit 66b2fbe

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

bin/rdebug-ide

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ if options.dispatcher_port != -1
117117
else
118118
require_relative '../lib/ruby-debug-ide/multiprocess'
119119
end
120+
Debugger::MultiProcess.do_monkey
120121

121122
ENV['DEBUGGER_STORED_RUBYLIB'] = ENV['RUBYLIB']
122123
old_opts = ENV['RUBYOPT'] || ''
@@ -140,8 +141,6 @@ Debugger.evaluation_timeout = options.evaluation_timeout
140141
Debugger.catchpoint_deleted_event = options.catchpoint_deleted_event || options.rm_protocol_extensions
141142
Debugger.value_as_nested_element = options.value_as_nested_element || options.rm_protocol_extensions
142143

143-
Debugger.attached = true
144-
145144
if options.attach_mode
146145
if Debugger::FRONT_END == "debase"
147146
Debugger.init_variables

lib/ruby-debug-ide/commands/control.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ def regexp
136136
end
137137

138138
def execute
139-
Debugger.attached = false
140139
Debugger.stop
141140
Debugger.interface.close
141+
Debugger::MultiProcess.undo_monkey
142142
Debugger.control_thread = nil
143143
Thread.current.exit #@control_thread is a current thread
144144
end

lib/ruby-debug-ide/multiprocess.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
if RUBY_VERSION < "1.9"
1+
if RUBY_VERSION < '1.9'
22
require 'ruby-debug-ide/multiprocess/pre_child'
3-
require 'ruby-debug-ide/multiprocess/monkey'
43
else
54
require_relative 'multiprocess/pre_child'
6-
require_relative 'multiprocess/monkey'
5+
end
6+
7+
module Debugger
8+
module MultiProcess
9+
class << self
10+
def do_monkey
11+
load File.expand_path(File.dirname(__FILE__) + '/multiprocess/monkey.rb')
12+
end
13+
14+
def undo_monkey
15+
if ENV['IDE_PROCESS_DISPATCHER']
16+
load File.expand_path(File.dirname(__FILE__) + '/multiprocess/unmonkey.rb')
17+
ruby_opts = ENV['RUBYOPT'].split(' ')
18+
ENV['RUBYOPT'] = ruby_opts.keep_if {|opt| !opt.end_with?('ruby-debug-ide/multiprocess/starter')}.join(' ')
19+
end
20+
end
21+
end
22+
end
723
end

lib/ruby-debug-ide/multiprocess/pre_child.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ module Debugger
22
module MultiProcess
33
class << self
44
def pre_child(options = nil)
5-
return unless Debugger.attached
6-
75
require 'socket'
86
require 'ostruct'
97

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Debugger
2+
module MultiProcess
3+
def self.restore_fork
4+
%Q{
5+
alias fork pre_debugger_fork
6+
}
7+
end
8+
9+
def self.restore_exec
10+
%Q{
11+
alias exec pre_debugger_exec
12+
}
13+
end
14+
end
15+
end
16+
17+
module Kernel
18+
class << self
19+
module_eval Debugger::MultiProcess.restore_fork
20+
module_eval Debugger::MultiProcess.restore_exec
21+
end
22+
module_eval Debugger::MultiProcess.restore_fork
23+
module_eval Debugger::MultiProcess.restore_exec
24+
end
25+
26+
module Process
27+
class << self
28+
module_eval Debugger::MultiProcess.restore_fork
29+
module_eval Debugger::MultiProcess.restore_exec
30+
end
31+
end

0 commit comments

Comments
 (0)