Skip to content

Commit c3890c6

Browse files
viuginick1valich
authored andcommitted
attach only to ruby child processes
1 parent b8783c0 commit c3890c6

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

lib/ruby-debug-ide/attach/util.rb

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'ruby-debug-ide/attach/lldb'
22
require 'ruby-debug-ide/attach/gdb'
33
require 'socket'
4+
require 'set'
45

56
def attach_and_return_thread(options, pid, debugger_loader_path, argv)
67
Thread.new(argv) do |argv|
@@ -57,7 +58,7 @@ def get_child_pids(pid)
5758
q = Queue.new
5859
q.push(pid)
5960

60-
while (!q.empty?) do
61+
until q.empty? do
6162
pid = q.pop
6263

6364
pipe = IO.popen("pgrep -P #{pid}")
@@ -69,7 +70,25 @@ def get_child_pids(pid)
6970
end
7071
end
7172

72-
pids
73+
filter_ruby_processes(pids)
74+
end
75+
76+
def filter_ruby_processes(pids)
77+
pipe = IO.popen(%Q(lsof -c ruby | awk '{print $2 ":" $9}' | grep -E 'bin/ruby([[:digit:]]+\.?)*$'))
78+
79+
ruby_processes = Set.new
80+
81+
pipe.readlines.each do |process|
82+
pid = process.split(/:/).first
83+
ruby_processes.add(pid.to_i)
84+
end
85+
86+
ruby_processes_pids, non_ruby_processes_pids = pids.partition {|pid| ruby_processes.include? pid}
87+
88+
DebugPrinter.print_debug("The following child processes was added to attach: #{ruby_processes_pids.join(', ')}") unless ruby_processes_pids.empty?
89+
DebugPrinter.print_debug("The following child are not ruby processes: #{non_ruby_processes_pids.join(', ')}") unless non_ruby_processes_pids.empty?
90+
91+
ruby_processes_pids
7392
end
7493

7594
def command_exists(command)
@@ -93,4 +112,4 @@ def choose_debugger(ruby_path, pid, gems_to_include, debugger_loader_path, argv)
93112
end
94113

95114
debugger
96-
end
115+
end

0 commit comments

Comments
 (0)