Skip to content

Commit 4512d5e

Browse files
authored
Merge pull request #87 from equivalence1/ruby-attach-to-process
fixes for sudo issue + some small changes
2 parents 2dc4480 + e1d1d36 commit 4512d5e

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

bin/gdb_wrapper

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,28 @@ options.gems_to_include.each do |gem_path|
7272
end
7373

7474
require 'ruby-debug-ide/greeter'
75-
Debugger::print_greeting_msg(nil, nil)
75+
Debugger::print_greeting_msg($stdout, nil, nil)
7676

7777
require 'ruby-debug-ide/attach/util'
7878
require 'ruby-debug-ide/attach/native_debugger'
7979
require 'ruby-debug-ide/attach/process_thread'
8080

8181
debugger = choose_debugger(options.ruby_path, options.pid, options.gems_to_include, debugger_loader_path, argv)
82+
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
96+
8297
debugger.attach_to_process
8398
debugger.set_flags
8499

lib/ruby-debug-ide.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def start_control(host, port, notify_dispatcher)
111111
# "localhost" and nil have problems on some systems.
112112
host ||= '127.0.0.1'
113113
server = TCPServer.new(host, port)
114-
print_greeting_msg(host, port)
114+
print_greeting_msg($stderr, host, port)
115115
notify_dispatcher(port) if notify_dispatcher
116116
while (session = server.accept)
117117
$stderr.puts "Connected from #{session.peeraddr[2]}" if Debugger.cli_debug

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ def load_debugger
118118

119119
end
120120

121+
def exited?
122+
@pipe.closed?
123+
end
124+
121125
def exit
122-
execute 'q'
123126
@pipe.close
124127
end
125128

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,5 @@ def choose_debugger(ruby_path, pid, gems_to_include, debugger_loader_path, argv)
2121
raise 'Neither gdb nor lldb was found. Aborting.'
2222
end
2323

24-
trap('INT') do
25-
unless debugger.pipe.closed?
26-
$stderr.puts "backtraces for threads:\n\n"
27-
debugger.process_threads.each do |thread|
28-
$stderr.puts "#{thread.thread_info}\n#{thread.last_bt}\n\n"
29-
end
30-
end
31-
exit!
32-
end
33-
3424
debugger
3525
end

lib/ruby-debug-ide/greeter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
module Debugger
1111

1212
class << self
13-
def print_greeting_msg(host, port)
13+
def print_greeting_msg(stream, host, port)
1414
base_gem_name = if defined?(JRUBY_VERSION) || RUBY_VERSION < '1.9.0'
1515
'ruby-debug-base'
1616
elsif RUBY_VERSION < '2.0.0'
@@ -33,7 +33,7 @@ def print_greeting_msg(host, port)
3333

3434
msg = "Fast Debugger (ruby-debug-ide #{IDE_VERSION}, #{base_gem_name} #{VERSION}, file filtering is #{file_filtering_support})" + listens_on
3535

36-
$stderr.printf msg
36+
stream.printf msg
3737
end
3838
end
3939

0 commit comments

Comments
 (0)