From 1e091ce77eecebe9ee92ef4490beffb9b708dbc3 Mon Sep 17 00:00:00 2001 From: equivalence1 Date: Wed, 9 Nov 2016 13:44:59 +0300 Subject: [PATCH 1/3] We should use stdout to print greeting message in attach mode because gksudo swallows stderr. --- bin/gdb_wrapper | 2 +- lib/ruby-debug-ide.rb | 2 +- lib/ruby-debug-ide/greeter.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/gdb_wrapper b/bin/gdb_wrapper index 905e741..56eb0d8 100755 --- a/bin/gdb_wrapper +++ b/bin/gdb_wrapper @@ -72,7 +72,7 @@ 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' diff --git a/lib/ruby-debug-ide.rb b/lib/ruby-debug-ide.rb index 30fc079..d100fe5 100644 --- a/lib/ruby-debug-ide.rb +++ b/lib/ruby-debug-ide.rb @@ -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 diff --git a/lib/ruby-debug-ide/greeter.rb b/lib/ruby-debug-ide/greeter.rb index a851913..df9b042 100644 --- a/lib/ruby-debug-ide/greeter.rb +++ b/lib/ruby-debug-ide/greeter.rb @@ -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' @@ -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 From 7e69ab7ad8941b899a6605e31dfc32ccc333477f Mon Sep 17 00:00:00 2001 From: equivalence1 Date: Wed, 9 Nov 2016 15:31:15 +0300 Subject: [PATCH 2/3] refactoring -- moved trap initialization to main --- bin/gdb_wrapper | 11 +++++++++++ lib/ruby-debug-ide/attach/util.rb | 10 ---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bin/gdb_wrapper b/bin/gdb_wrapper index 56eb0d8..0f0709d 100755 --- a/bin/gdb_wrapper +++ b/bin/gdb_wrapper @@ -79,6 +79,17 @@ 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.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.attach_to_process debugger.set_flags diff --git a/lib/ruby-debug-ide/attach/util.rb b/lib/ruby-debug-ide/attach/util.rb index 035933c..faa8478 100644 --- a/lib/ruby-debug-ide/attach/util.rb +++ b/lib/ruby-debug-ide/attach/util.rb @@ -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 From e1d1d363ae4c2338726a1acaa3aafe1abaadbe82 Mon Sep 17 00:00:00 2001 From: equivalence1 Date: Wed, 9 Nov 2016 15:40:01 +0300 Subject: [PATCH 3/3] better handling of int signal. --- bin/gdb_wrapper | 10 +++++++--- lib/ruby-debug-ide/attach/native_debugger.rb | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/gdb_wrapper b/bin/gdb_wrapper index 0f0709d..c89bd8d 100755 --- a/bin/gdb_wrapper +++ b/bin/gdb_wrapper @@ -81,11 +81,15 @@ 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.pipe.closed? + unless debugger.exited? $stderr.puts "backtraces for threads:\n\n" - debugger.process_threads.each do |thread| - $stderr.puts "#{thread.thread_info}\n#{thread.last_bt}\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 diff --git a/lib/ruby-debug-ide/attach/native_debugger.rb b/lib/ruby-debug-ide/attach/native_debugger.rb index e0a8c1c..05ea9d9 100644 --- a/lib/ruby-debug-ide/attach/native_debugger.rb +++ b/lib/ruby-debug-ide/attach/native_debugger.rb @@ -118,8 +118,11 @@ def load_debugger end + def exited? + @pipe.closed? + end + def exit - execute 'q' @pipe.close end