Sha256: 37c9ceba45453bff5ec59eb4496aecb878fc9eb1fe85331922090abdef49ed9e

Contents?: true

Size: 1.53 KB

Versions: 84

Compression:

Stored size: 1.53 KB

Contents

module RunLoop

  # A class for interacting with the lldb command-line tool
  class LLDB

    # Returns a list of lldb pids.
    # @return [Array<Integer>] An array of integer pids.
    def self.lldb_pids
      ps_output = `#{LLDB_FIND_PIDS_CMD}`.strip
      lines = ps_output.lines("\n").map { |line| line.strip }
      lldb_processes = lines.select { |line| self.is_lldb_process?(line) }
      lldb_processes.map do |ps_description|
        tokens = ps_description.strip.split(' ').map { |token| token.strip }
        pid = tokens.fetch(0, nil)
        if pid.nil?
          nil
        else
          pid.to_i
        end
      end.compact.sort
    end

    # @!visibility private
    # Is the process described an lldb process?
    #
    # @param [String] ps_details Details about a process as returned by `ps`
    # @return [Boolean] True if the details describe an lldb process.
    def self.is_lldb_process?(ps_details)
      return false if ps_details.nil?
      ps_details[/Contents\/Developer\/usr\/bin\/lldb/, 0] != nil
    end

    # Attempts to gracefully kill all running lldb processes.
    def self.kill_lldb_processes
      self.lldb_pids.each do |pid|
        self.kill_with_signal(pid, 'KILL')
      end
    end

    private

    # @!visibility private
    LLDB_FIND_PIDS_CMD = 'ps x -o pid,command | grep -v grep | grep lldb'

    # @!visibility private
    def self.kill_with_signal(pid, signal)
      options = {:timeout => 1.0, :delay => 0.1}
      RunLoop::ProcessTerminator.new(pid, signal, 'lldb', options).kill_process
    end

  end
end

Version data entries

84 entries across 84 versions & 2 rubygems

Version Path
run_loop-4.9.1 lib/run_loop/lldb.rb
run_loop-4.9.0 lib/run_loop/lldb.rb
run_loop-4.8.1 lib/run_loop/lldb.rb
run_loop-4.8.0 lib/run_loop/lldb.rb
run_loop-4.7.0 lib/run_loop/lldb.rb
run_loop-4.6.3 lib/run_loop/lldb.rb
run_loop-4.6.1 lib/run_loop/lldb.rb
run_loop-4.6.0 lib/run_loop/lldb.rb
run_loop-4.5.7 lib/run_loop/lldb.rb
run_loop-4.5.6 lib/run_loop/lldb.rb
run_loop-4.5.5 lib/run_loop/lldb.rb
run_loop-4.5.4 lib/run_loop/lldb.rb
run_loop-4.5.3 lib/run_loop/lldb.rb
run_loop-4.5.2 lib/run_loop/lldb.rb
run_loop-4.5.1 lib/run_loop/lldb.rb
run_loop-4.5.0 lib/run_loop/lldb.rb
run_loop-4.4.2 lib/run_loop/lldb.rb
run_loop-4.4.1 lib/run_loop/lldb.rb
run_loop-2.3.2 lib/run_loop/lldb.rb
run_loop-4.3.0 lib/run_loop/lldb.rb