Skip to content

Commit ff58069

Browse files
committed
Merge pull request #22 from phekmat/remote-host-fix
Fix debugging for forking process run on a remote machine
2 parents 391e660 + e3aac51 commit ff58069

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

lib/ruby-debug-ide.rb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
require 'ruby-debug-base'
77
else
88
require 'debase'
9-
end
9+
end
1010

1111
require 'ruby-debug-ide/version'
1212
require 'ruby-debug-ide/xml_printer'
1313
require 'ruby-debug-ide/ide_processor'
1414
require 'ruby-debug-ide/event_processor'
1515

1616
module Debugger
17-
17+
1818
class << self
1919
# Prints to the stderr using printf(*args) if debug logging flag (-d) is on.
2020
def print_debug(*args)
@@ -25,7 +25,7 @@ def print_debug(*args)
2525
$stderr.flush
2626
end
2727
end
28-
28+
2929
def cleanup_backtrace(backtrace)
3030
cleared = []
3131
return cleared unless backtrace
@@ -40,12 +40,12 @@ def cleanup_backtrace(backtrace)
4040
end
4141
cleared
4242
end
43-
43+
4444
attr_accessor :cli_debug, :xml_debug
4545
attr_accessor :control_thread
4646
attr_reader :interface
4747

48-
48+
4949
#
5050
# Interrupts the last debugged thread
5151
#
@@ -69,10 +69,10 @@ def prepare_debugger(options)
6969
start_server(options.host, options.port)
7070

7171
raise "Control thread did not start (#{@control_thread}}" unless @control_thread && @control_thread.alive?
72-
72+
7373
@mutex = Mutex.new
7474
@proceed = ConditionVariable.new
75-
75+
7676
# wait for 'start' command
7777
@mutex.synchronize do
7878
@proceed.wait(@mutex)
@@ -89,14 +89,14 @@ def debug_program(options)
8989
$stderr.print Debugger.cleanup_backtrace(bt.backtrace).map{|l| "\t#{l}"}.join("\n"), "\n"
9090
end
9191
end
92-
92+
9393
def run_prog_script
9494
return unless @mutex
9595
@mutex.synchronize do
9696
@proceed.signal
9797
end
9898
end
99-
99+
100100
def start_control(host, port)
101101
raise "Debugger is not started" unless started?
102102
return if @control_thread
@@ -110,11 +110,12 @@ def start_control(host, port)
110110
$stderr.printf "Fast Debugger (ruby-debug-ide #{IDE_VERSION}, #{gem_name} #{VERSION}) listens on #{host}:#{port}\n"
111111
server = TCPServer.new(host, port)
112112
while (session = server.accept)
113-
$stderr.puts "Connected from #{session.addr[2]}" if Debugger.cli_debug
113+
$stderr.puts "Connected from #{session.peeraddr[2]}" if Debugger.cli_debug
114114
dispatcher = ENV['IDE_PROCESS_DISPATCHER']
115115
if (dispatcher)
116-
ENV['IDE_PROCESS_DISPATCHER'] = "#{session.addr[2]}:#{dispatcher}" unless dispatcher.include?(":")
117-
end
116+
ENV['IDE_PROCESS_DISPATCHER'] = "#{session.peeraddr[2]}:#{dispatcher}" unless dispatcher.include?(":")
117+
ENV['DEBUGGER_HOST'] = host
118+
end
118119
begin
119120
@interface = RemoteInterface.new(session)
120121
self.handler = EventProcessor.new(interface)
@@ -132,9 +133,9 @@ def start_control(host, port)
132133
end
133134
end
134135
end
135-
136+
136137
end
137-
138+
138139
class Exception # :nodoc:
139140
attr_reader :__debug_file, :__debug_line, :__debug_binding, :__debug_context
140141
end

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ def pre_child
55

66
require "socket"
77
require "ostruct"
8-
9-
host = '127.0.0.1'
8+
9+
host = ENV['DEBUGGER_HOST']
1010
port = find_free_port(host)
11-
11+
1212
options = OpenStruct.new(
1313
'frame_bind' => false,
1414
'host' => host,
@@ -18,10 +18,10 @@ def pre_child
1818
'tracing' => false,
1919
'int_handler' => true
2020
)
21-
21+
2222
acceptor_host, acceptor_port = ENV['IDE_PROCESS_DISPATCHER'].split(":")
2323
acceptor_host, acceptor_port = '127.0.0.1', acceptor_host unless acceptor_port
24-
24+
2525
connected = false
2626
3.times do |i|
2727
begin
@@ -39,28 +39,28 @@ def pre_child
3939
end unless connected
4040
end
4141
end
42-
42+
4343
def start_debugger(options)
4444
if Debugger.started?
4545
#we're in forked child, only need to restart control thread
46-
Debugger.breakpoints.clear
46+
Debugger.breakpoints.clear
4747
Debugger.control_thread = nil
4848
Debugger.start_control(options.host, options.port)
4949
end
50-
50+
5151
if options.int_handler
5252
# install interruption handler
5353
trap('INT') { Debugger.interrupt_last }
5454
end
55-
55+
5656
# set options
5757
Debugger.keep_frame_binding = options.frame_bind
58-
Debugger.tracing = options.tracing
59-
58+
Debugger.tracing = options.tracing
59+
6060
Debugger.prepare_debugger(options)
6161
end
62-
63-
62+
63+
6464
def find_free_port(host)
6565
server = TCPServer.open(host, 0)
6666
port = server.addr[1]

0 commit comments

Comments
 (0)