15ffd83dbSDimitry Andric //===-- SBProcessInfo.cpp -------------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "lldb/API/SBProcessInfo.h"
100b57cec5SDimitry Andric #include "SBReproducerPrivate.h"
110b57cec5SDimitry Andric #include "Utils.h"
120b57cec5SDimitry Andric #include "lldb/API/SBFileSpec.h"
130b57cec5SDimitry Andric #include "lldb/Utility/ProcessInfo.h"
140b57cec5SDimitry Andric
150b57cec5SDimitry Andric using namespace lldb;
160b57cec5SDimitry Andric using namespace lldb_private;
170b57cec5SDimitry Andric
SBProcessInfo()180b57cec5SDimitry Andric SBProcessInfo::SBProcessInfo() : m_opaque_up() {
190b57cec5SDimitry Andric LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBProcessInfo);
200b57cec5SDimitry Andric }
210b57cec5SDimitry Andric
SBProcessInfo(const SBProcessInfo & rhs)220b57cec5SDimitry Andric SBProcessInfo::SBProcessInfo(const SBProcessInfo &rhs) : m_opaque_up() {
230b57cec5SDimitry Andric LLDB_RECORD_CONSTRUCTOR(SBProcessInfo, (const lldb::SBProcessInfo &), rhs);
240b57cec5SDimitry Andric
250b57cec5SDimitry Andric m_opaque_up = clone(rhs.m_opaque_up);
260b57cec5SDimitry Andric }
270b57cec5SDimitry Andric
285ffd83dbSDimitry Andric SBProcessInfo::~SBProcessInfo() = default;
290b57cec5SDimitry Andric
operator =(const SBProcessInfo & rhs)300b57cec5SDimitry Andric SBProcessInfo &SBProcessInfo::operator=(const SBProcessInfo &rhs) {
310b57cec5SDimitry Andric LLDB_RECORD_METHOD(lldb::SBProcessInfo &,
320b57cec5SDimitry Andric SBProcessInfo, operator=,(const lldb::SBProcessInfo &),
330b57cec5SDimitry Andric rhs);
340b57cec5SDimitry Andric
350b57cec5SDimitry Andric if (this != &rhs)
360b57cec5SDimitry Andric m_opaque_up = clone(rhs.m_opaque_up);
370b57cec5SDimitry Andric return LLDB_RECORD_RESULT(*this);
380b57cec5SDimitry Andric }
390b57cec5SDimitry Andric
ref()400b57cec5SDimitry Andric ProcessInstanceInfo &SBProcessInfo::ref() {
410b57cec5SDimitry Andric if (m_opaque_up == nullptr) {
425ffd83dbSDimitry Andric m_opaque_up = std::make_unique<ProcessInstanceInfo>();
430b57cec5SDimitry Andric }
440b57cec5SDimitry Andric return *m_opaque_up;
450b57cec5SDimitry Andric }
460b57cec5SDimitry Andric
SetProcessInfo(const ProcessInstanceInfo & proc_info_ref)470b57cec5SDimitry Andric void SBProcessInfo::SetProcessInfo(const ProcessInstanceInfo &proc_info_ref) {
480b57cec5SDimitry Andric ref() = proc_info_ref;
490b57cec5SDimitry Andric }
500b57cec5SDimitry Andric
IsValid() const510b57cec5SDimitry Andric bool SBProcessInfo::IsValid() const {
520b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBProcessInfo, IsValid);
530b57cec5SDimitry Andric return this->operator bool();
540b57cec5SDimitry Andric }
operator bool() const550b57cec5SDimitry Andric SBProcessInfo::operator bool() const {
560b57cec5SDimitry Andric LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBProcessInfo, operator bool);
570b57cec5SDimitry Andric
580b57cec5SDimitry Andric return m_opaque_up != nullptr;
590b57cec5SDimitry Andric }
600b57cec5SDimitry Andric
GetName()610b57cec5SDimitry Andric const char *SBProcessInfo::GetName() {
620b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBProcessInfo, GetName);
630b57cec5SDimitry Andric
640b57cec5SDimitry Andric const char *name = nullptr;
650b57cec5SDimitry Andric if (m_opaque_up) {
660b57cec5SDimitry Andric name = m_opaque_up->GetName();
670b57cec5SDimitry Andric }
680b57cec5SDimitry Andric return name;
690b57cec5SDimitry Andric }
700b57cec5SDimitry Andric
GetExecutableFile()710b57cec5SDimitry Andric SBFileSpec SBProcessInfo::GetExecutableFile() {
720b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBProcessInfo,
730b57cec5SDimitry Andric GetExecutableFile);
740b57cec5SDimitry Andric
750b57cec5SDimitry Andric SBFileSpec file_spec;
760b57cec5SDimitry Andric if (m_opaque_up) {
770b57cec5SDimitry Andric file_spec.SetFileSpec(m_opaque_up->GetExecutableFile());
780b57cec5SDimitry Andric }
790b57cec5SDimitry Andric return LLDB_RECORD_RESULT(file_spec);
800b57cec5SDimitry Andric }
810b57cec5SDimitry Andric
GetProcessID()820b57cec5SDimitry Andric lldb::pid_t SBProcessInfo::GetProcessID() {
830b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::pid_t, SBProcessInfo, GetProcessID);
840b57cec5SDimitry Andric
850b57cec5SDimitry Andric lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID;
860b57cec5SDimitry Andric if (m_opaque_up) {
870b57cec5SDimitry Andric proc_id = m_opaque_up->GetProcessID();
880b57cec5SDimitry Andric }
890b57cec5SDimitry Andric return proc_id;
900b57cec5SDimitry Andric }
910b57cec5SDimitry Andric
GetUserID()920b57cec5SDimitry Andric uint32_t SBProcessInfo::GetUserID() {
930b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetUserID);
940b57cec5SDimitry Andric
950b57cec5SDimitry Andric uint32_t user_id = UINT32_MAX;
960b57cec5SDimitry Andric if (m_opaque_up) {
970b57cec5SDimitry Andric user_id = m_opaque_up->GetUserID();
980b57cec5SDimitry Andric }
990b57cec5SDimitry Andric return user_id;
1000b57cec5SDimitry Andric }
1010b57cec5SDimitry Andric
GetGroupID()1020b57cec5SDimitry Andric uint32_t SBProcessInfo::GetGroupID() {
1030b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetGroupID);
1040b57cec5SDimitry Andric
1050b57cec5SDimitry Andric uint32_t group_id = UINT32_MAX;
1060b57cec5SDimitry Andric if (m_opaque_up) {
1070b57cec5SDimitry Andric group_id = m_opaque_up->GetGroupID();
1080b57cec5SDimitry Andric }
1090b57cec5SDimitry Andric return group_id;
1100b57cec5SDimitry Andric }
1110b57cec5SDimitry Andric
UserIDIsValid()1120b57cec5SDimitry Andric bool SBProcessInfo::UserIDIsValid() {
1130b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(bool, SBProcessInfo, UserIDIsValid);
1140b57cec5SDimitry Andric
1150b57cec5SDimitry Andric bool is_valid = false;
1160b57cec5SDimitry Andric if (m_opaque_up) {
1170b57cec5SDimitry Andric is_valid = m_opaque_up->UserIDIsValid();
1180b57cec5SDimitry Andric }
1190b57cec5SDimitry Andric return is_valid;
1200b57cec5SDimitry Andric }
1210b57cec5SDimitry Andric
GroupIDIsValid()1220b57cec5SDimitry Andric bool SBProcessInfo::GroupIDIsValid() {
1230b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(bool, SBProcessInfo, GroupIDIsValid);
1240b57cec5SDimitry Andric
1250b57cec5SDimitry Andric bool is_valid = false;
1260b57cec5SDimitry Andric if (m_opaque_up) {
1270b57cec5SDimitry Andric is_valid = m_opaque_up->GroupIDIsValid();
1280b57cec5SDimitry Andric }
1290b57cec5SDimitry Andric return is_valid;
1300b57cec5SDimitry Andric }
1310b57cec5SDimitry Andric
GetEffectiveUserID()1320b57cec5SDimitry Andric uint32_t SBProcessInfo::GetEffectiveUserID() {
1330b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetEffectiveUserID);
1340b57cec5SDimitry Andric
1350b57cec5SDimitry Andric uint32_t user_id = UINT32_MAX;
1360b57cec5SDimitry Andric if (m_opaque_up) {
1370b57cec5SDimitry Andric user_id = m_opaque_up->GetEffectiveUserID();
1380b57cec5SDimitry Andric }
1390b57cec5SDimitry Andric return user_id;
1400b57cec5SDimitry Andric }
1410b57cec5SDimitry Andric
GetEffectiveGroupID()1420b57cec5SDimitry Andric uint32_t SBProcessInfo::GetEffectiveGroupID() {
1430b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetEffectiveGroupID);
1440b57cec5SDimitry Andric
1450b57cec5SDimitry Andric uint32_t group_id = UINT32_MAX;
1460b57cec5SDimitry Andric if (m_opaque_up) {
1470b57cec5SDimitry Andric group_id = m_opaque_up->GetEffectiveGroupID();
1480b57cec5SDimitry Andric }
1490b57cec5SDimitry Andric return group_id;
1500b57cec5SDimitry Andric }
1510b57cec5SDimitry Andric
EffectiveUserIDIsValid()1520b57cec5SDimitry Andric bool SBProcessInfo::EffectiveUserIDIsValid() {
1530b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(bool, SBProcessInfo, EffectiveUserIDIsValid);
1540b57cec5SDimitry Andric
1550b57cec5SDimitry Andric bool is_valid = false;
1560b57cec5SDimitry Andric if (m_opaque_up) {
1570b57cec5SDimitry Andric is_valid = m_opaque_up->EffectiveUserIDIsValid();
1580b57cec5SDimitry Andric }
1590b57cec5SDimitry Andric return is_valid;
1600b57cec5SDimitry Andric }
1610b57cec5SDimitry Andric
EffectiveGroupIDIsValid()1620b57cec5SDimitry Andric bool SBProcessInfo::EffectiveGroupIDIsValid() {
1630b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(bool, SBProcessInfo, EffectiveGroupIDIsValid);
1640b57cec5SDimitry Andric
1650b57cec5SDimitry Andric bool is_valid = false;
1660b57cec5SDimitry Andric if (m_opaque_up) {
1670b57cec5SDimitry Andric is_valid = m_opaque_up->EffectiveGroupIDIsValid();
1680b57cec5SDimitry Andric }
1690b57cec5SDimitry Andric return is_valid;
1700b57cec5SDimitry Andric }
1710b57cec5SDimitry Andric
GetParentProcessID()1720b57cec5SDimitry Andric lldb::pid_t SBProcessInfo::GetParentProcessID() {
1730b57cec5SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(lldb::pid_t, SBProcessInfo, GetParentProcessID);
1740b57cec5SDimitry Andric
1750b57cec5SDimitry Andric lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID;
1760b57cec5SDimitry Andric if (m_opaque_up) {
1770b57cec5SDimitry Andric proc_id = m_opaque_up->GetParentProcessID();
1780b57cec5SDimitry Andric }
1790b57cec5SDimitry Andric return proc_id;
1800b57cec5SDimitry Andric }
1810b57cec5SDimitry Andric
GetTriple()182*5f7ddb14SDimitry Andric const char *SBProcessInfo::GetTriple() {
183*5f7ddb14SDimitry Andric LLDB_RECORD_METHOD_NO_ARGS(const char *, SBProcessInfo, GetTriple);
184*5f7ddb14SDimitry Andric
185*5f7ddb14SDimitry Andric const char *triple = nullptr;
186*5f7ddb14SDimitry Andric if (m_opaque_up) {
187*5f7ddb14SDimitry Andric const auto &arch = m_opaque_up->GetArchitecture();
188*5f7ddb14SDimitry Andric if (arch.IsValid()) {
189*5f7ddb14SDimitry Andric // Const-ify the string so we don't need to worry about the lifetime of
190*5f7ddb14SDimitry Andric // the string
191*5f7ddb14SDimitry Andric triple = ConstString(arch.GetTriple().getTriple().c_str()).GetCString();
192*5f7ddb14SDimitry Andric }
193*5f7ddb14SDimitry Andric }
194*5f7ddb14SDimitry Andric return triple;
195*5f7ddb14SDimitry Andric }
196*5f7ddb14SDimitry Andric
1970b57cec5SDimitry Andric namespace lldb_private {
1980b57cec5SDimitry Andric namespace repro {
1990b57cec5SDimitry Andric
2000b57cec5SDimitry Andric template <>
RegisterMethods(Registry & R)2010b57cec5SDimitry Andric void RegisterMethods<SBProcessInfo>(Registry &R) {
2020b57cec5SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBProcessInfo, ());
2030b57cec5SDimitry Andric LLDB_REGISTER_CONSTRUCTOR(SBProcessInfo, (const lldb::SBProcessInfo &));
2040b57cec5SDimitry Andric LLDB_REGISTER_METHOD(
2050b57cec5SDimitry Andric lldb::SBProcessInfo &,
2060b57cec5SDimitry Andric SBProcessInfo, operator=,(const lldb::SBProcessInfo &));
2070b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(bool, SBProcessInfo, IsValid, ());
2080b57cec5SDimitry Andric LLDB_REGISTER_METHOD_CONST(bool, SBProcessInfo, operator bool, ());
2090b57cec5SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBProcessInfo, GetName, ());
2100b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBProcessInfo, GetExecutableFile,
2110b57cec5SDimitry Andric ());
2120b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::pid_t, SBProcessInfo, GetProcessID, ());
2130b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetUserID, ());
2140b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetGroupID, ());
2150b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBProcessInfo, UserIDIsValid, ());
2160b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBProcessInfo, GroupIDIsValid, ());
2170b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetEffectiveUserID, ());
2180b57cec5SDimitry Andric LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetEffectiveGroupID, ());
2190b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBProcessInfo, EffectiveUserIDIsValid, ());
2200b57cec5SDimitry Andric LLDB_REGISTER_METHOD(bool, SBProcessInfo, EffectiveGroupIDIsValid, ());
2210b57cec5SDimitry Andric LLDB_REGISTER_METHOD(lldb::pid_t, SBProcessInfo, GetParentProcessID, ());
222*5f7ddb14SDimitry Andric LLDB_REGISTER_METHOD(const char *, SBProcessInfo, GetTriple, ());
2230b57cec5SDimitry Andric }
2240b57cec5SDimitry Andric
2250b57cec5SDimitry Andric }
2260b57cec5SDimitry Andric }
227