13#include <sys/sysctl.h>
20#include <sys/ptrace.h>
35#include "llvm/Object/ELF.h"
36#include "llvm/TargetParser/Host.h"
52 int mib[4] = {CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_ARGV};
55 size_t arg_data_size =
sizeof(arg_data);
56 if (::sysctl(mib, 4, arg_data, &arg_data_size, NULL, 0) != 0)
69 FileSpec::Style::native);
71 if (!(match_info_ptr == NULL ||
80 const uint8_t *p = data.
PeekData(offset, 1);
81 while ((p != NULL) && (*p ==
'\0') && offset < arg_data_size) {
85 if (p == NULL || offset >= arg_data_size)
106 llvm::object::getElfArchType(
107 {
reinterpret_cast<const char *
>(buffer_sp->GetBytes()),
108 size_t(buffer_sp->GetByteSize())})
112 case llvm::ELF::ELFCLASS32:
114 HostInfo::GetArchitecture(HostInfo::eArchKind32);
116 case llvm::ELF::ELFCLASS64:
118 HostInfo::GetArchitecture(HostInfo::eArchKind64);
121 LLDB_LOG(log,
"Unknown elf class ({0}) in file {1}", exe_class,
132 char errbuf[_POSIX2_LINE_MAX];
134 struct ::kinfo_proc2 *proc_kinfo;
141 if ((kdp = ::kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL)
144 if ((proc_kinfo = ::kvm_getproc2(kdp, KERN_PROC_PID, pid,
145 sizeof(struct ::kinfo_proc2), &nproc)) ==
157 process_info.
SetUserID(proc_kinfo->p_ruid);
177 const ::pid_t our_pid = ::getpid();
178 const ::uid_t our_uid = ::getuid();
180 const bool all_users =
186 char errbuf[_POSIX2_LINE_MAX];
187 if ((kdp = ::kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL)
190 struct ::kinfo_proc2 *proc_kinfo;
192 if ((proc_kinfo = ::kvm_getproc2(kdp, KERN_PROC_ALL, 0,
193 sizeof(struct ::kinfo_proc2), &nproc)) ==
202 for (
int i = 0; i < nproc; i++) {
203 if (proc_kinfo[i].p_pid < 1)
206 if (!all_users && proc_kinfo[i].p_ruid != our_uid)
209 if (proc_kinfo[i].p_pid == our_pid ||
210 proc_kinfo[i].p_pid == 0 ||
211 proc_kinfo[i].p_stat == LSZOMB ||
212 proc_kinfo[i].p_flag & P_TRACED ||
213 proc_kinfo[i].p_flag & P_WEXIT)
219 if (proc_kinfo[i].p_nlwps > 1) {
220 bool already_registered =
false;
221 for (
size_t pi = 0; pi < process_infos.size(); pi++) {
222 if ((
::pid_t)process_infos[pi].GetProcessID() == proc_kinfo[i].p_pid) {
223 already_registered =
true;
228 if (already_registered)
234 process_info.
SetUserID(proc_kinfo[i].p_ruid);
235 process_info.
SetGroupID(proc_kinfo[i].p_rgid);
239 if (match_info_noname.Matches(process_info) &&
242 if (match_info.
Matches(process_info))
243 process_infos.push_back(process_info);
249 return process_infos.size();
261 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 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