11#include <sys/signal.h>
14#include <sys/ptrace.h>
15#include <sys/sysctl.h>
31#include "llvm/TargetParser/Host.h"
48 for (; var != NULL && *var != NULL; ++var) {
49 v = strchr(*var, (
int)
'-');
61 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ARGS,
65 size_t arg_data_size =
sizeof(arg_data);
66 if (::sysctl(mib, 4, arg_data, &arg_data_size, NULL, 0) == 0) {
76 if (!(match_info_ptr == NULL ||
85 const uint8_t *p = data.
PeekData(offset, 1);
86 while ((p != NULL) && (*p ==
'\0') && offset < arg_data_size) {
90 if (p == NULL || offset >= arg_data_size)
108 HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
116 struct kinfo_proc proc_kinfo;
117 size_t proc_kinfo_size;
120 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID,
122 proc_kinfo_size =
sizeof(
struct kinfo_proc);
124 if (::sysctl(mib, 4, &proc_kinfo, &proc_kinfo_size, NULL, 0) == 0) {
125 if (proc_kinfo_size > 0) {
127 process_info.
SetUserID(proc_kinfo.p_ruid);
145 std::vector<struct kinfo_proc> kinfos;
147 int mib[3] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
149 size_t pid_data_size = 0;
150 if (::sysctl(mib, 3, NULL, &pid_data_size, NULL, 0) != 0)
154 const size_t estimated_pid_count =
155 (pid_data_size /
sizeof(
struct kinfo_proc)) + 10;
157 kinfos.resize(estimated_pid_count);
158 pid_data_size = kinfos.size() *
sizeof(
struct kinfo_proc);
160 if (::sysctl(mib, 3, &kinfos[0], &pid_data_size, NULL, 0) != 0)
163 const size_t actual_pid_count = (pid_data_size /
sizeof(
struct kinfo_proc));
166 const ::pid_t our_pid = getpid();
167 const uid_t our_uid = getuid();
168 for (
size_t i = 0; i < actual_pid_count; i++) {
169 const struct kinfo_proc &kinfo = kinfos[i];
170 const bool kinfo_user_matches = (all_users || (kinfo.p_ruid == our_uid) ||
175 if (kinfo_user_matches ==
false ||
176 kinfo.p_pid == our_pid ||
178 kinfo.p_stat == SZOMB ||
179 kinfo.p_psflags & PS_TRACED ||
180 kinfo.p_flag & P_WEXIT)
192 if (match_info.
Matches(process_info) &&
195 if (match_info.
Matches(process_info))
196 process_infos.push_back(process_info);
200 return process_infos.size();
213 process_info.
Clear();
218 return Status(
"unimplemented");
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.
std::pair< iterator, bool > insert(llvm::StringRef KeyEqValue)
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 Environment GetEnvironment()
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)
#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)