module DEBUGGER__::ForkInterceptor
def __fork_setup_for_debugger fork_mode = nil
def __fork_setup_for_debugger fork_mode = nil ode ||= CONFIG[:fork_mode] k_mode == :both && CONFIG[:parent_on_fork] _mode = :parent _pid = Process.pid re fork ork_mode parent nt_hook = -> child_pid { Do nothing d_hook = -> { BUGGER__.info "Detaching after fork from child process #{Process.pid}" SSION.deactivate child ION.before_fork false nt_hook = -> child_pid { BUGGER__.info "Detaching after fork from parent process #{Process.pid}" SSION.after_fork_parent SSION.deactivate d_hook = -> { BUGGER__.info "Attaching after process #{parent_pid} fork to child process #{Process.pid}" SSION.activate on_fork: true both ION.before_fork nt_hook = -> child_pid { SSION.process_group.after_fork SSION.after_fork_parent d_hook = -> { BUGGER__.info "Attaching after process #{parent_pid} fork to child process #{Process.pid}" SSION.process_group.after_fork child: true SSION.activate on_fork: true parent_hook, child_hook
def _fork
def _fork return super unless defined?(SESSION) && SESSION.active? parent_hook, child_hook = __fork_setup_for_debugger super.tap do |pid| if pid != 0 # after fork: parent parent_hook.call pid else # after fork: child child_hook.call end end end
def fork(&given_block)
def fork(&given_block) return super unless defined?(SESSION) && SESSION.active? parent_hook, child_hook = __fork_setup_for_debugger if given_block new_block = proc { # after fork: child child_hook.call given_block.call } super(&new_block).tap{|pid| parent_hook.call(pid)} else super.tap do |pid| if pid # after fork: parent parent_hook.call pid else # after fork: child child_hook.call end end end end