diff --git a/bin/gdb_wrapper b/bin/gdb_wrapper index 08c37d2..4fdf002 100755 --- a/bin/gdb_wrapper +++ b/bin/gdb_wrapper @@ -13,6 +13,22 @@ options = OpenStruct.new( 'gems_to_include' => [] ) +module DebugPrinter + + class << self + attr_accessor :cli_debug + + def print_debug(msg) + if DebugPrinter.cli_debug + $stderr.puts msg + end + end + end + +end + +DebugPrinter.cli_debug = ARGV.include? '--debug' + opts = OptionParser.new do |opts| # TODO need some banner opts.banner = </dev/null 2>&1 || { exit 1; }` + if $?.exitstatus != 0 + DebugPrinter.print_debug("#{checking_command}command does not exist.") + else + DebugPrinter.print_debug("#{checking_command}command does exist.") + end $?.exitstatus == 0 end def choose_debugger(ruby_path, pid, gems_to_include, debugger_loader_path, argv) - if command_exists('gdb') - debugger = GDB.new(ruby_path, pid, '-nh -nx', gems_to_include, debugger_loader_path, argv) - elsif command_exists('lldb') + if command_exists('lldb') debugger = LLDB.new(ruby_path, pid, '--no-lldbinit', gems_to_include, debugger_loader_path, argv) + elsif command_exists('gdb') + debugger = GDB.new(ruby_path, pid, '-nh -nx', gems_to_include, debugger_loader_path, argv) else raise 'Neither gdb nor lldb was found. Aborting.' end @@ -348,6 +417,7 @@ debugger.attach_to_process debugger.set_flags if options.uid + DebugPrinter.print_debug("changing current uid from #{Process.uid} to #{options.uid}") Process::Sys.setuid(options.uid.to_i) end