1 //===-- SBProcessInfo.cpp -------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/API/SBProcessInfo.h" 10 #include "Utils.h" 11 #include "lldb/API/SBFileSpec.h" 12 #include "lldb/Utility/Instrumentation.h" 13 #include "lldb/Utility/ProcessInfo.h" 14 15 using namespace lldb; 16 using namespace lldb_private; 17 18 SBProcessInfo::SBProcessInfo() { LLDB_INSTRUMENT_VA(this); } 19 20 SBProcessInfo::SBProcessInfo(const SBProcessInfo &rhs) { 21 LLDB_INSTRUMENT_VA(this, rhs); 22 23 m_opaque_up = clone(rhs.m_opaque_up); 24 } 25 26 SBProcessInfo::~SBProcessInfo() = default; 27 28 SBProcessInfo &SBProcessInfo::operator=(const SBProcessInfo &rhs) { 29 LLDB_INSTRUMENT_VA(this, rhs); 30 31 if (this != &rhs) 32 m_opaque_up = clone(rhs.m_opaque_up); 33 return *this; 34 } 35 36 ProcessInstanceInfo &SBProcessInfo::ref() { 37 if (m_opaque_up == nullptr) { 38 m_opaque_up = std::make_unique<ProcessInstanceInfo>(); 39 } 40 return *m_opaque_up; 41 } 42 43 void SBProcessInfo::SetProcessInfo(const ProcessInstanceInfo &proc_info_ref) { 44 ref() = proc_info_ref; 45 } 46 47 bool SBProcessInfo::IsValid() const { 48 LLDB_INSTRUMENT_VA(this); 49 return this->operator bool(); 50 } 51 SBProcessInfo::operator bool() const { 52 LLDB_INSTRUMENT_VA(this); 53 54 return m_opaque_up != nullptr; 55 } 56 57 const char *SBProcessInfo::GetName() { 58 LLDB_INSTRUMENT_VA(this); 59 60 const char *name = nullptr; 61 if (m_opaque_up) { 62 name = m_opaque_up->GetName(); 63 } 64 return name; 65 } 66 67 SBFileSpec SBProcessInfo::GetExecutableFile() { 68 LLDB_INSTRUMENT_VA(this); 69 70 SBFileSpec file_spec; 71 if (m_opaque_up) { 72 file_spec.SetFileSpec(m_opaque_up->GetExecutableFile()); 73 } 74 return file_spec; 75 } 76 77 lldb::pid_t SBProcessInfo::GetProcessID() { 78 LLDB_INSTRUMENT_VA(this); 79 80 lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID; 81 if (m_opaque_up) { 82 proc_id = m_opaque_up->GetProcessID(); 83 } 84 return proc_id; 85 } 86 87 uint32_t SBProcessInfo::GetUserID() { 88 LLDB_INSTRUMENT_VA(this); 89 90 uint32_t user_id = UINT32_MAX; 91 if (m_opaque_up) { 92 user_id = m_opaque_up->GetUserID(); 93 } 94 return user_id; 95 } 96 97 uint32_t SBProcessInfo::GetGroupID() { 98 LLDB_INSTRUMENT_VA(this); 99 100 uint32_t group_id = UINT32_MAX; 101 if (m_opaque_up) { 102 group_id = m_opaque_up->GetGroupID(); 103 } 104 return group_id; 105 } 106 107 bool SBProcessInfo::UserIDIsValid() { 108 LLDB_INSTRUMENT_VA(this); 109 110 bool is_valid = false; 111 if (m_opaque_up) { 112 is_valid = m_opaque_up->UserIDIsValid(); 113 } 114 return is_valid; 115 } 116 117 bool SBProcessInfo::GroupIDIsValid() { 118 LLDB_INSTRUMENT_VA(this); 119 120 bool is_valid = false; 121 if (m_opaque_up) { 122 is_valid = m_opaque_up->GroupIDIsValid(); 123 } 124 return is_valid; 125 } 126 127 uint32_t SBProcessInfo::GetEffectiveUserID() { 128 LLDB_INSTRUMENT_VA(this); 129 130 uint32_t user_id = UINT32_MAX; 131 if (m_opaque_up) { 132 user_id = m_opaque_up->GetEffectiveUserID(); 133 } 134 return user_id; 135 } 136 137 uint32_t SBProcessInfo::GetEffectiveGroupID() { 138 LLDB_INSTRUMENT_VA(this); 139 140 uint32_t group_id = UINT32_MAX; 141 if (m_opaque_up) { 142 group_id = m_opaque_up->GetEffectiveGroupID(); 143 } 144 return group_id; 145 } 146 147 bool SBProcessInfo::EffectiveUserIDIsValid() { 148 LLDB_INSTRUMENT_VA(this); 149 150 bool is_valid = false; 151 if (m_opaque_up) { 152 is_valid = m_opaque_up->EffectiveUserIDIsValid(); 153 } 154 return is_valid; 155 } 156 157 bool SBProcessInfo::EffectiveGroupIDIsValid() { 158 LLDB_INSTRUMENT_VA(this); 159 160 bool is_valid = false; 161 if (m_opaque_up) { 162 is_valid = m_opaque_up->EffectiveGroupIDIsValid(); 163 } 164 return is_valid; 165 } 166 167 lldb::pid_t SBProcessInfo::GetParentProcessID() { 168 LLDB_INSTRUMENT_VA(this); 169 170 lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID; 171 if (m_opaque_up) { 172 proc_id = m_opaque_up->GetParentProcessID(); 173 } 174 return proc_id; 175 } 176 177 const char *SBProcessInfo::GetTriple() { 178 LLDB_INSTRUMENT_VA(this); 179 180 const char *triple = nullptr; 181 if (m_opaque_up) { 182 const auto &arch = m_opaque_up->GetArchitecture(); 183 if (arch.IsValid()) { 184 // Const-ify the string so we don't need to worry about the lifetime of 185 // the string 186 triple = ConstString(arch.GetTriple().getTriple().c_str()).GetCString(); 187 } 188 } 189 return triple; 190 } 191