13#include <sys/ptrace.h>
14#include <sys/sysctl.h>
17#include <machine/elf.h>
34#include "llvm/TargetParser/Host.h"
55 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ARGS, pid};
58 size_t arg_data_size =
sizeof(arg_data);
59 if (::sysctl(mib, 4, arg_data, &arg_data_size, NULL, 0) != 0)
72 char pathname[MAXPATHLEN];
73 size_t pathname_len =
sizeof(pathname);
74 mib[2] = KERN_PROC_PATHNAME;
75 if (::sysctl(mib, 4, pathname, &pathname_len, NULL, 0) == 0)
80 if (!(match_info_ptr == NULL ||
89 const uint8_t *p = data.
PeekData(offset, 1);
90 while ((p != NULL) && (*p ==
'\0') && offset < arg_data_size) {
94 if (p == NULL || offset >= arg_data_size)
110 HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
118 struct kinfo_proc proc_kinfo;
119 size_t proc_kinfo_size;
121 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
126 proc_kinfo_size =
sizeof(
struct kinfo_proc);
128 if (::sysctl(mib, 4, &proc_kinfo, &proc_kinfo_size, NULL, 0) != 0)
131 if (proc_kinfo_size == 0)
135 process_info.
SetUserID(proc_kinfo.ki_ruid);
138 if (proc_kinfo.ki_ngroups > 0)
155 const ::pid_t our_pid = ::getpid();
156 const ::uid_t our_uid = ::getuid();
157 std::vector<struct kinfo_proc> kinfos;
161 int mib[3] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
163 size_t pid_data_size = 0;
164 if (::sysctl(mib, 3, NULL, &pid_data_size, NULL, 0) != 0)
168 const size_t estimated_pid_count =
169 (pid_data_size /
sizeof(
struct kinfo_proc)) + 10;
171 kinfos.resize(estimated_pid_count);
172 pid_data_size = kinfos.size() *
sizeof(
struct kinfo_proc);
174 if (::sysctl(mib, 3, &kinfos[0], &pid_data_size, NULL, 0) != 0)
177 const size_t actual_pid_count = (pid_data_size /
sizeof(
struct kinfo_proc));
182 for (
size_t i = 0; i < actual_pid_count; i++) {
183 const struct kinfo_proc &kinfo = kinfos[i];
186 if (!all_users && kinfo.ki_ruid != our_uid)
189 if (kinfo.ki_pid == our_pid ||
191 kinfo.ki_stat == SZOMB ||
192 kinfo.ki_flag & P_TRACED ||
193 kinfo.ki_flag & P_WEXIT)
199 bool already_registered =
false;
200 for (uint32_t pi = 0;
201 !already_registered && (
const int)kinfo.ki_numthreads > 1 &&
202 pi < (
const uint32_t)process_infos.size();
205 (process_infos[pi].GetProcessID() == (uint32_t)kinfo.ki_pid);
207 if (already_registered)
219 if (match_info_noname.Matches(process_info) &&
222 if (match_info.
Matches(process_info))
223 process_infos.push_back(process_info);
227 return process_infos.size();
240 process_info.
Clear();
247 return Status(
"unimplemented");
static llvm::raw_ostream & error(Stream &strm)
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 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
void SetArg0(llvm::StringRef arg)
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
void SetNameMatchType(NameMatch name_match_type)
ProcessInstanceInfo & GetProcessInfo()
void SetEffectiveGroupID(uint32_t gid)
void SetParentProcessID(lldb::pid_t pid)
void SetEffectiveUserID(uint32_t uid)
static bool GetFreeBSDProcessCPUType(ProcessInstanceInfo &process_info)
static bool GetFreeBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr, ProcessInstanceInfo &process_info)
static bool GetFreeBSDProcessUserAndGroup(ProcessInstanceInfo &process_info)
#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