13#include <sys/sysctl.h>
20#include <sys/ptrace.h>
35#include "llvm/Object/ELF.h"
36#include "llvm/TargetParser/Host.h"
58 int mib[4] = {CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_ARGV};
61 size_t arg_data_size =
sizeof(arg_data);
62 if (::sysctl(mib, 4, arg_data, &arg_data_size, NULL, 0) != 0)
75 FileSpec::Style::native);
77 if (!(match_info_ptr == NULL ||
86 const uint8_t *p = data.
PeekData(offset, 1);
87 while ((p != NULL) && (*p ==
'\0') && offset < arg_data_size) {
91 if (p == NULL || offset >= arg_data_size)
112 llvm::object::getElfArchType(
113 {
reinterpret_cast<const char *
>(buffer_sp->GetBytes()),
114 size_t(buffer_sp->GetByteSize())})
118 case llvm::ELF::ELFCLASS32:
120 HostInfo::GetArchitecture(HostInfo::eArchKind32);
122 case llvm::ELF::ELFCLASS64:
124 HostInfo::GetArchitecture(HostInfo::eArchKind64);
127 LLDB_LOG(log,
"Unknown elf class ({0}) in file {1}", exe_class,
138 char errbuf[_POSIX2_LINE_MAX];
140 struct ::kinfo_proc2 *proc_kinfo;
147 if ((kdp = ::kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL)
150 if ((proc_kinfo = ::kvm_getproc2(kdp, KERN_PROC_PID, pid,
151 sizeof(struct ::kinfo_proc2), &nproc)) ==
163 process_info.
SetUserID(proc_kinfo->p_ruid);
183 const ::pid_t our_pid = ::getpid();
184 const ::uid_t our_uid = ::getuid();
186 const bool all_users =
192 char errbuf[_POSIX2_LINE_MAX];
193 if ((kdp = ::kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL)
196 struct ::kinfo_proc2 *proc_kinfo;
198 if ((proc_kinfo = ::kvm_getproc2(kdp, KERN_PROC_ALL, 0,
199 sizeof(struct ::kinfo_proc2), &nproc)) ==
208 for (
int i = 0; i < nproc; i++) {
209 if (proc_kinfo[i].p_pid < 1)
212 if (!all_users && proc_kinfo[i].p_ruid != our_uid)
215 if (proc_kinfo[i].p_pid == our_pid ||
216 proc_kinfo[i].p_pid == 0 ||
217 proc_kinfo[i].p_stat == LSZOMB ||
218 proc_kinfo[i].p_flag & P_TRACED ||
219 proc_kinfo[i].p_flag & P_WEXIT)
225 if (proc_kinfo[i].p_nlwps > 1) {
226 bool already_registered =
false;
227 for (
size_t pi = 0; pi < process_infos.size(); pi++) {
228 if ((
::pid_t)process_infos[pi].GetProcessID() == proc_kinfo[i].p_pid) {
229 already_registered =
true;
234 if (already_registered)
240 process_info.
SetUserID(proc_kinfo[i].p_ruid);
241 process_info.
SetGroupID(proc_kinfo[i].p_rgid);
245 if (match_info_noname.Matches(process_info) &&
248 if (match_info.
Matches(process_info))
249 process_infos.push_back(process_info);
255 return process_infos.size();
267 process_info.
Clear();
static llvm::raw_ostream & error(Stream &strm)
static bool GetNetBSDProcessArgs(const ProcessInstanceInfoMatch *match_info_ptr, ProcessInstanceInfo &process_info)
static bool GetNetBSDProcessUserAndGroup(ProcessInstanceInfo &process_info)
static bool GetNetBSDProcessCPUType(ProcessInstanceInfo &process_info)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
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 FileSystem & Instance()
std::shared_ptr< DataBuffer > CreateDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
Create memory buffer from path.
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 Status FromErrorString(const char *str)
#define LLDB_INVALID_PROCESS_ID
lldb::ByteOrder InlHostByteOrder()
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
bool NameMatches(llvm::StringRef name, NameMatch match_type, llvm::StringRef match)
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList