@@ -15,6 +15,7 @@ class << self
1515 # Prints to the stderr using printf(*args) if debug logging flag (-d) is on.
1616 def print_debug ( *args )
1717 if Debugger . cli_debug
18+ $stderr. printf ( "#{ Process . pid } : " )
1819 $stderr. printf ( *args )
1920 $stderr. printf ( "\n " )
2021 $stderr. flush
@@ -76,7 +77,8 @@ def at_return(file, line)
7677 class << self
7778
7879 attr_accessor :event_processor , :cli_debug , :xml_debug
79- attr_reader :control_thread
80+ attr_accessor :control_thread
81+ attr_reader :interface
8082
8183 #
8284 # Interrupts the current thread
@@ -104,7 +106,7 @@ def start_server(host = nil, port = 1234)
104106 start_control ( host , port )
105107 end
106108
107- def debug_program ( options )
109+ def prepare_debugger ( options )
108110 start_server ( options . host , options . port )
109111
110112 raise "Control thread did not start (#{ @control_thread } }" unless @control_thread && @control_thread . alive?
@@ -116,7 +118,11 @@ def debug_program(options)
116118 @mutex . synchronize do
117119 @proceed . wait ( @mutex )
118120 end
119-
121+ end
122+
123+ def debug_program ( options )
124+ prepare_debugger ( options )
125+
120126 abs_prog_script = File . expand_path ( Debugger ::PROG_SCRIPT )
121127 bt = debug_load ( abs_prog_script , options . stop , options . load_mode )
122128 if bt && !bt . is_a? ( SystemExit )
@@ -143,13 +149,18 @@ def start_control(host, port)
143149 $stderr. printf "Fast Debugger (ruby-debug-ide #{ IDE_VERSION } , ruby-debug-base #{ VERSION } ) listens on #{ host } :#{ port } \n "
144150 server = TCPServer . new ( host , port )
145151 while ( session = server . accept )
152+ $stderr. puts "Connected from #{ session . addr [ 2 ] } " if Debugger . cli_debug
153+ dispatcher = ENV [ 'IDE_PROCESS_DISPATCHER' ]
154+ if ( dispatcher )
155+ ENV [ 'IDE_PROCESS_DISPATCHER' ] = "#{ session . addr [ 2 ] } :#{ dispatcher } " unless dispatcher . include? ( ":" )
156+ end
146157 begin
147- interface = RemoteInterface . new ( session )
158+ @ interface = RemoteInterface . new ( session )
148159 @event_processor = EventProcessor . new ( interface )
149160 IdeControlCommandProcessor . new ( interface ) . process_commands
150161 rescue StandardError , ScriptError => ex
151162 bt = ex . backtrace
152- $stderr. printf "Exception in DebugThread loop: #{ ex . message } \n Backtrace:\n #{ bt ? bt . join ( "\n from: " ) : "<none>" } \n "
163+ $stderr. printf "#{ Process . pid } : Exception in DebugThread loop: #{ ex . message } \n Backtrace:\n #{ bt ? bt . join ( "\n from: " ) : "<none>" } \n "
153164 exit 1
154165 end
155166 end
0 commit comments