2017-08-01 15:34:26 +08:00
|
|
|
//===-- SBProcessInfo.cpp ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-08-01 15:34:26 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBProcessInfo.h"
|
2019-03-06 08:06:00 +08:00
|
|
|
#include "SBReproducerPrivate.h"
|
2019-03-06 08:05:55 +08:00
|
|
|
#include "Utils.h"
|
2017-08-01 15:34:26 +08:00
|
|
|
#include "lldb/API/SBFileSpec.h"
|
Move ProcessInfo from Host to Utility.
There are set of classes in Target that describe the parameters of a
process - e.g. it's PID, name, user id, and similar. However, since it
is a bare description of a process and contains no actual functionality,
there's nothing specifically that makes this appropriate for being in
Target -- it could just as well be describing a process on the host, or
some hypothetical virtual process that doesn't even exist.
To cement this, I'm moving these classes to Utility. It's possible that
we can find a better place for it in the future, but as it is neither
Host specific nor Target specific, Utility seems like the most appropriate
place for the time being.
After this there is only 2 remaining references to Target from Host,
which I'll address in a followup.
Differential Revision: https://reviews.llvm.org/D58842
llvm-svn: 355342
2019-03-05 05:51:03 +08:00
|
|
|
#include "lldb/Utility/ProcessInfo.h"
|
2017-08-01 15:34:26 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
SBProcessInfo::SBProcessInfo() : m_opaque_up() {
|
|
|
|
LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBProcessInfo);
|
|
|
|
}
|
2017-08-01 15:34:26 +08:00
|
|
|
|
2019-02-13 14:25:41 +08:00
|
|
|
SBProcessInfo::SBProcessInfo(const SBProcessInfo &rhs) : m_opaque_up() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_CONSTRUCTOR(SBProcessInfo, (const lldb::SBProcessInfo &), rhs);
|
|
|
|
|
2019-03-06 08:05:55 +08:00
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBProcessInfo::~SBProcessInfo() {}
|
|
|
|
|
|
|
|
SBProcessInfo &SBProcessInfo::operator=(const SBProcessInfo &rhs) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD(lldb::SBProcessInfo &,
|
|
|
|
SBProcessInfo, operator=,(const lldb::SBProcessInfo &),
|
|
|
|
rhs);
|
|
|
|
|
2019-03-06 08:05:55 +08:00
|
|
|
if (this != &rhs)
|
|
|
|
m_opaque_up = clone(rhs.m_opaque_up);
|
2019-04-04 05:31:22 +08:00
|
|
|
return LLDB_RECORD_RESULT(*this);
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ProcessInstanceInfo &SBProcessInfo::ref() {
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up == nullptr) {
|
|
|
|
m_opaque_up.reset(new ProcessInstanceInfo());
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
2019-02-13 14:25:41 +08:00
|
|
|
return *m_opaque_up;
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SBProcessInfo::SetProcessInfo(const ProcessInstanceInfo &proc_info_ref) {
|
|
|
|
ref() = proc_info_ref;
|
|
|
|
}
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
bool SBProcessInfo::IsValid() const {
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBProcessInfo, IsValid);
|
Add "operator bool" to SB APIs
Summary:
Our python version of the SB API has (the python equivalent of)
operator bool, but the C++ version doesn't.
This is because our python operators are added by modify-python-lldb.py,
which performs postprocessing on the swig-generated interface files.
In this patch, I add the "operator bool" to all SB classes which have an
IsValid method (which is the same logic used by modify-python-lldb.py).
This way, we make the two interfaces more constent, and it allows us to
rely on swig's automatic syntesis of python __nonzero__ methods instead
of doing manual fixups.
Reviewers: zturner, jingham, clayborg, jfb, serge-sans-paille
Subscribers: jdoerfert, lldb-commits
Differential Revision: https://reviews.llvm.org/D58792
llvm-svn: 355824
2019-03-11 21:58:46 +08:00
|
|
|
return this->operator bool();
|
|
|
|
}
|
|
|
|
SBProcessInfo::operator bool() const {
|
|
|
|
LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBProcessInfo, operator bool);
|
2019-03-06 08:06:00 +08:00
|
|
|
|
|
|
|
return m_opaque_up != nullptr;
|
|
|
|
}
|
2017-08-01 15:34:26 +08:00
|
|
|
|
|
|
|
const char *SBProcessInfo::GetName() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(const char *, SBProcessInfo, GetName);
|
|
|
|
|
2017-08-01 15:34:26 +08:00
|
|
|
const char *name = nullptr;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
name = m_opaque_up->GetName();
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBFileSpec SBProcessInfo::GetExecutableFile() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBProcessInfo,
|
|
|
|
GetExecutableFile);
|
|
|
|
|
2017-08-01 15:34:26 +08:00
|
|
|
SBFileSpec file_spec;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
file_spec.SetFileSpec(m_opaque_up->GetExecutableFile());
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(file_spec);
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::pid_t SBProcessInfo::GetProcessID() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::pid_t, SBProcessInfo, GetProcessID);
|
|
|
|
|
2017-08-01 15:34:26 +08:00
|
|
|
lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
proc_id = m_opaque_up->GetProcessID();
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
return proc_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBProcessInfo::GetUserID() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetUserID);
|
|
|
|
|
2017-08-01 15:34:26 +08:00
|
|
|
uint32_t user_id = UINT32_MAX;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
user_id = m_opaque_up->GetUserID();
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
return user_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBProcessInfo::GetGroupID() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetGroupID);
|
|
|
|
|
2017-08-01 15:34:26 +08:00
|
|
|
uint32_t group_id = UINT32_MAX;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
group_id = m_opaque_up->GetGroupID();
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
return group_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBProcessInfo::UserIDIsValid() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(bool, SBProcessInfo, UserIDIsValid);
|
|
|
|
|
2017-08-01 15:34:26 +08:00
|
|
|
bool is_valid = false;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
is_valid = m_opaque_up->UserIDIsValid();
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
return is_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBProcessInfo::GroupIDIsValid() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(bool, SBProcessInfo, GroupIDIsValid);
|
|
|
|
|
2017-08-01 15:34:26 +08:00
|
|
|
bool is_valid = false;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
is_valid = m_opaque_up->GroupIDIsValid();
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
return is_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBProcessInfo::GetEffectiveUserID() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetEffectiveUserID);
|
|
|
|
|
2017-08-01 15:34:26 +08:00
|
|
|
uint32_t user_id = UINT32_MAX;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
user_id = m_opaque_up->GetEffectiveUserID();
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
return user_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SBProcessInfo::GetEffectiveGroupID() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetEffectiveGroupID);
|
|
|
|
|
2017-08-01 15:34:26 +08:00
|
|
|
uint32_t group_id = UINT32_MAX;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
group_id = m_opaque_up->GetEffectiveGroupID();
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
return group_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBProcessInfo::EffectiveUserIDIsValid() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(bool, SBProcessInfo, EffectiveUserIDIsValid);
|
|
|
|
|
2017-08-01 15:34:26 +08:00
|
|
|
bool is_valid = false;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
is_valid = m_opaque_up->EffectiveUserIDIsValid();
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
return is_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SBProcessInfo::EffectiveGroupIDIsValid() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(bool, SBProcessInfo, EffectiveGroupIDIsValid);
|
|
|
|
|
2017-08-01 15:34:26 +08:00
|
|
|
bool is_valid = false;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
is_valid = m_opaque_up->EffectiveGroupIDIsValid();
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
return is_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::pid_t SBProcessInfo::GetParentProcessID() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_METHOD_NO_ARGS(lldb::pid_t, SBProcessInfo, GetParentProcessID);
|
|
|
|
|
2017-08-01 15:34:26 +08:00
|
|
|
lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID;
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_opaque_up) {
|
|
|
|
proc_id = m_opaque_up->GetParentProcessID();
|
2017-08-01 15:34:26 +08:00
|
|
|
}
|
|
|
|
return proc_id;
|
|
|
|
}
|
2019-03-20 01:13:13 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
namespace repro {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void RegisterMethods<SBProcessInfo>(Registry &R) {
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBProcessInfo, ());
|
|
|
|
LLDB_REGISTER_CONSTRUCTOR(SBProcessInfo, (const lldb::SBProcessInfo &));
|
|
|
|
LLDB_REGISTER_METHOD(
|
|
|
|
lldb::SBProcessInfo &,
|
|
|
|
SBProcessInfo, operator=,(const lldb::SBProcessInfo &));
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBProcessInfo, IsValid, ());
|
|
|
|
LLDB_REGISTER_METHOD_CONST(bool, SBProcessInfo, operator bool, ());
|
|
|
|
LLDB_REGISTER_METHOD(const char *, SBProcessInfo, GetName, ());
|
|
|
|
LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBProcessInfo, GetExecutableFile,
|
|
|
|
());
|
|
|
|
LLDB_REGISTER_METHOD(lldb::pid_t, SBProcessInfo, GetProcessID, ());
|
|
|
|
LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetUserID, ());
|
|
|
|
LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetGroupID, ());
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBProcessInfo, UserIDIsValid, ());
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBProcessInfo, GroupIDIsValid, ());
|
|
|
|
LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetEffectiveUserID, ());
|
|
|
|
LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetEffectiveGroupID, ());
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBProcessInfo, EffectiveUserIDIsValid, ());
|
|
|
|
LLDB_REGISTER_METHOD(bool, SBProcessInfo, EffectiveGroupIDIsValid, ());
|
|
|
|
LLDB_REGISTER_METHOD(lldb::pid_t, SBProcessInfo, GetParentProcessID, ());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|