11#include <sys/signal.h>
14#include <sys/ptrace.h>
15#include <sys/sysctl.h>
31#include "llvm/TargetParser/Host.h"
44 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ARGS,
48 size_t arg_data_size =
sizeof(arg_data);
49 if (::sysctl(mib, 4, arg_data, &arg_data_size, NULL, 0) == 0) {
59 if (!(match_info_ptr == NULL ||
68 const uint8_t *p = data.
PeekData(offset, 1);
69 while ((p != NULL) && (*p ==
'\0') && offset < arg_data_size) {
73 if (p == NULL || offset >= arg_data_size)
91 HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
99 struct kinfo_proc proc_kinfo;
100 size_t proc_kinfo_size;
103 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID,
105 proc_kinfo_size =
sizeof(
struct kinfo_proc);
107 if (::sysctl(mib, 4, &proc_kinfo, &proc_kinfo_size, NULL, 0) == 0) {
108 if (proc_kinfo_size > 0) {
110 process_info.
SetUserID(proc_kinfo.p_ruid);
128 std::vector<struct kinfo_proc> kinfos;
130 int mib[3] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
132 size_t pid_data_size = 0;
133 if (::sysctl(mib, 3, NULL, &pid_data_size, NULL, 0) != 0)
137 const size_t estimated_pid_count =
138 (pid_data_size /
sizeof(
struct kinfo_proc)) + 10;
140 kinfos.resize(estimated_pid_count);
141 pid_data_size = kinfos.size() *
sizeof(
struct kinfo_proc);
143 if (::sysctl(mib, 3, &kinfos[0], &pid_data_size, NULL, 0) != 0)
146 const size_t actual_pid_count = (pid_data_size /
sizeof(
struct kinfo_proc));
149 const ::pid_t our_pid = getpid();
150 const uid_t our_uid = getuid();
151 for (
size_t i = 0; i < actual_pid_count; i++) {
152 const struct kinfo_proc &kinfo = kinfos[i];
153 const bool kinfo_user_matches = (all_users || (kinfo.p_ruid == our_uid) ||
158 if (kinfo_user_matches ==
false ||
159 kinfo.p_pid == our_pid ||
161 kinfo.p_stat == SZOMB ||
162 kinfo.p_psflags & PS_TRACED ||
163 kinfo.p_flag & P_WEXIT)
175 if (match_info.
Matches(process_info) &&
178 if (match_info.
Matches(process_info))
179 process_infos.push_back(process_info);
183 return process_infos.size();
196 process_info.
Clear();
void Clear()
Clears the object state.
A command line argument class.
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
const char * GetCString() const
Get the string value as a C string.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
const ConstString & GetFilename() const
Filename string const get accessor.
static Status ShellExpandArguments(ProcessLaunchInfo &launch_info)
Perform expansion of the command-line for this launch info This can potentially involve wildcard expa...
static uint32_t FindProcessesImpl(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
static bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
void SetGroupID(uint32_t gid)
bool ProcessIDIsValid() const
const char * GetName() const
lldb::pid_t GetProcessID() const
void SetProcessID(lldb::pid_t pid)
FileSpec & GetExecutableFile()
void SetUserID(uint32_t uid)
ArchSpec & GetArchitecture()
NameMatch GetNameMatchType() const
bool Matches(const ProcessInstanceInfo &proc_info) const
bool GetMatchAllUsers() const
ProcessInstanceInfo & GetProcessInfo()
void SetEffectiveGroupID(uint32_t gid)
void SetParentProcessID(lldb::pid_t pid)
void SetEffectiveUserID(uint32_t uid)
static Status FromErrorString(const char *str)
#define LLDB_INVALID_PROCESS_ID
lldb::ByteOrder InlHostByteOrder()
A class that represents a running process on the host machine.
bool NameMatches(llvm::StringRef name, NameMatch match_type, llvm::StringRef match)
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
static bool GetOpenBSDProcessUserAndGroup(ProcessInstanceInfo &process_info)
static bool GetOpenBSDProcessCPUType(ProcessInstanceInfo &process_info)
static bool GetOpenBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr, ProcessInstanceInfo &process_info)