11#!/usr/bin/env ruby
22
33require 'optparse'
4+ require 'thread'
45require 'ostruct'
56
67$stdout. sync = true
@@ -65,6 +66,7 @@ unless options.ruby_path
6566end
6667
6768argv = '["' + ARGV * '", "' + '"]'
69+ child_argv = '["' + ARGV * '", "' + "', '--ignore-port" + '"]'
6870debugger_loader_path = File . expand_path ( File . dirname ( __FILE__ ) ) + '/../lib/ruby-debug-ide/attach/debugger_loader'
6971
7072options . gems_to_include . each do |gem_path |
@@ -78,51 +80,17 @@ require 'ruby-debug-ide/attach/util'
7880require 'ruby-debug-ide/attach/native_debugger'
7981require 'ruby-debug-ide/attach/process_thread'
8082
81- debugger = choose_debugger ( options . ruby_path , options . pid , options . gems_to_include , debugger_loader_path , argv )
8283
83- trap ( 'INT' ) do
84- unless debugger . exited?
85- $stderr. puts "backtraces for threads:\n \n "
86- process_threads = debugger . process_threads
87- if process_threads
88- process_threads . each do |thread |
89- $stderr. puts "#{ thread . thread_info } \n #{ thread . last_bt } \n \n "
90- end
91- end
92- debugger . exit
93- end
94- exit!
95- end
84+ child_pids = get_child_pids ( options . pid . to_s )
85+ attach_threads = Array . new
86+ attach_threads << attach_and_return_thread ( options , options . pid , debugger_loader_path , argv )
9687
97- debugger . attach_to_process
98- debugger . set_flags
88+ attach_threads << child_pids . map { |pid | attach_and_return_thread ( options , pid , debugger_loader_path , child_argv ) }
9989
90+
91+ attach_threads . each { |thread | thread . join }
10092if options . uid
10193 DebugPrinter . print_debug ( "changing current uid from #{ Process . uid } to #{ options . uid } " )
10294 Process ::Sys . setuid ( options . uid . to_i )
10395end
104-
105- if debugger . check_already_under_debug
106- $stderr. puts "Process #{ debugger . pid } is already under debug"
107- debugger . exit
108- exit!
109- end
110-
111- should_check_threads_state = true
112-
113- while should_check_threads_state
114- should_check_threads_state = false
115- debugger . update_threads . each do |thread |
116- thread . switch
117- while thread . need_finish_frame
118- should_check_threads_state = true
119- thread . finish
120- end
121- end
122- end
123-
124- debugger . wait_line_event
125- debugger . load_debugger
126- debugger . exit
127-
12896sleep
0 commit comments