Module: GDB::Util

Defined in:
lib/gdb/util.rb

Overview

Defines utility methods.

Class Method Summary collapse

Class Method Details

.find_gdbString?

The name of gdb could be:

- gdb
- ggdb (macOS)

Examples:

find_gdb
#=> 'gdb'

Returns:

  • (String?)

33
34
35
# File 'lib/gdb/util.rb', line 33

def find_gdb
  %w[gdb ggdb].find { |n| which(n) }
end

.which(cmd) ⇒ String?

Cross-platform way of finding an executable in the $PATH.

Examples:

which('ruby')
#=> "/usr/bin/ruby"

Parameters:

  • cmd (String)

Returns:

  • (String?)

15
16
17
18
19
20
21
22
23
24
# File 'lib/gdb/util.rb', line 15

def which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    end
  end
  nil
end