Skip to content

Commit

Permalink
Merge pull request #87 from equivalence1/ruby-attach-to-process
Browse files Browse the repository at this point in the history
fixes for sudo issue + some small changes
  • Loading branch information
denofevil authored Nov 9, 2016
2 parents 2dc4480 + e1d1d36 commit 4512d5e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
17 changes: 16 additions & 1 deletion bin/gdb_wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,28 @@ options.gems_to_include.each do |gem_path|
end

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

require 'ruby-debug-ide/attach/util'
require 'ruby-debug-ide/attach/native_debugger'
require 'ruby-debug-ide/attach/process_thread'

debugger = choose_debugger(options.ruby_path, options.pid, options.gems_to_include, debugger_loader_path, argv)

trap('INT') do
unless debugger.exited?
$stderr.puts "backtraces for threads:\n\n"
process_threads = debugger.process_threads
if process_threads
process_threads.each do |thread|
$stderr.puts "#{thread.thread_info}\n#{thread.last_bt}\n\n"
end
end
debugger.exit
end
exit!
end

debugger.attach_to_process
debugger.set_flags

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-debug-ide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def start_control(host, port, notify_dispatcher)
# "localhost" and nil have problems on some systems.
host ||= '127.0.0.1'
server = TCPServer.new(host, port)
print_greeting_msg(host, port)
print_greeting_msg($stderr, host, port)
notify_dispatcher(port) if notify_dispatcher
while (session = server.accept)
$stderr.puts "Connected from #{session.peeraddr[2]}" if Debugger.cli_debug
Expand Down
5 changes: 4 additions & 1 deletion lib/ruby-debug-ide/attach/native_debugger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ def load_debugger

end

def exited?
@pipe.closed?
end

def exit
execute 'q'
@pipe.close
end

Expand Down
10 changes: 0 additions & 10 deletions lib/ruby-debug-ide/attach/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,5 @@ def choose_debugger(ruby_path, pid, gems_to_include, debugger_loader_path, argv)
raise 'Neither gdb nor lldb was found. Aborting.'
end

trap('INT') do
unless debugger.pipe.closed?
$stderr.puts "backtraces for threads:\n\n"
debugger.process_threads.each do |thread|
$stderr.puts "#{thread.thread_info}\n#{thread.last_bt}\n\n"
end
end
exit!
end

debugger
end
4 changes: 2 additions & 2 deletions lib/ruby-debug-ide/greeter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
module Debugger

class << self
def print_greeting_msg(host, port)
def print_greeting_msg(stream, host, port)
base_gem_name = if defined?(JRUBY_VERSION) || RUBY_VERSION < '1.9.0'
'ruby-debug-base'
elsif RUBY_VERSION < '2.0.0'
Expand All @@ -33,7 +33,7 @@ def print_greeting_msg(host, port)

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

$stderr.printf msg
stream.printf msg
end
end

Expand Down

0 comments on commit 4512d5e

Please sign in to comment.