LLDB  mainline
SBProcessInfo.cpp
Go to the documentation of this file.
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 
10 #include "SBReproducerPrivate.h"
11 #include "Utils.h"
12 #include "lldb/API/SBFileSpec.h"
14 
15 using namespace lldb;
16 using namespace lldb_private;
17 
18 SBProcessInfo::SBProcessInfo() : m_opaque_up() {
20 }
21 
22 SBProcessInfo::SBProcessInfo(const SBProcessInfo &rhs) : m_opaque_up() {
24 
26 }
27 
29 
32  SBProcessInfo, operator=,(const lldb::SBProcessInfo &),
33  rhs);
34 
35  if (this != &rhs)
37  return LLDB_RECORD_RESULT(*this);
38 }
39 
41  if (m_opaque_up == nullptr) {
42  m_opaque_up = std::make_unique<ProcessInstanceInfo>();
43  }
44  return *m_opaque_up;
45 }
46 
48  ref() = proc_info_ref;
49 }
50 
51 bool SBProcessInfo::IsValid() const {
53  return this->operator bool();
54 }
55 SBProcessInfo::operator bool() const {
56  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBProcessInfo, operator bool);
57 
58  return m_opaque_up != nullptr;
59 }
60 
61 const char *SBProcessInfo::GetName() {
63 
64  const char *name = nullptr;
65  if (m_opaque_up) {
66  name = m_opaque_up->GetName();
67  }
68  return name;
69 }
70 
74 
75  SBFileSpec file_spec;
76  if (m_opaque_up) {
77  file_spec.SetFileSpec(m_opaque_up->GetExecutableFile());
78  }
79  return LLDB_RECORD_RESULT(file_spec);
80 }
81 
84 
86  if (m_opaque_up) {
87  proc_id = m_opaque_up->GetProcessID();
88  }
89  return proc_id;
90 }
91 
94 
95  uint32_t user_id = UINT32_MAX;
96  if (m_opaque_up) {
97  user_id = m_opaque_up->GetUserID();
98  }
99  return user_id;
100 }
101 
104 
105  uint32_t group_id = UINT32_MAX;
106  if (m_opaque_up) {
107  group_id = m_opaque_up->GetGroupID();
108  }
109  return group_id;
110 }
111 
114 
115  bool is_valid = false;
116  if (m_opaque_up) {
117  is_valid = m_opaque_up->UserIDIsValid();
118  }
119  return is_valid;
120 }
121 
124 
125  bool is_valid = false;
126  if (m_opaque_up) {
127  is_valid = m_opaque_up->GroupIDIsValid();
128  }
129  return is_valid;
130 }
131 
134 
135  uint32_t user_id = UINT32_MAX;
136  if (m_opaque_up) {
137  user_id = m_opaque_up->GetEffectiveUserID();
138  }
139  return user_id;
140 }
141 
144 
145  uint32_t group_id = UINT32_MAX;
146  if (m_opaque_up) {
147  group_id = m_opaque_up->GetEffectiveGroupID();
148  }
149  return group_id;
150 }
151 
154 
155  bool is_valid = false;
156  if (m_opaque_up) {
157  is_valid = m_opaque_up->EffectiveUserIDIsValid();
158  }
159  return is_valid;
160 }
161 
164 
165  bool is_valid = false;
166  if (m_opaque_up) {
167  is_valid = m_opaque_up->EffectiveGroupIDIsValid();
168  }
169  return is_valid;
170 }
171 
174 
176  if (m_opaque_up) {
177  proc_id = m_opaque_up->GetParentProcessID();
178  }
179  return proc_id;
180 }
181 
184 
185  const char *triple = nullptr;
186  if (m_opaque_up) {
187  const auto &arch = m_opaque_up->GetArchitecture();
188  if (arch.IsValid()) {
189  // Const-ify the string so we don't need to worry about the lifetime of
190  // the string
191  triple = ConstString(arch.GetTriple().getTriple().c_str()).GetCString();
192  }
193  }
194  return triple;
195 }
196 
197 namespace lldb_private {
198 namespace repro {
199 
200 template <>
206  SBProcessInfo, operator=,(const lldb::SBProcessInfo &));
207  LLDB_REGISTER_METHOD_CONST(bool, SBProcessInfo, IsValid, ());
208  LLDB_REGISTER_METHOD_CONST(bool, SBProcessInfo, operator bool, ());
209  LLDB_REGISTER_METHOD(const char *, SBProcessInfo, GetName, ());
211  ());
212  LLDB_REGISTER_METHOD(lldb::pid_t, SBProcessInfo, GetProcessID, ());
214  LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetGroupID, ());
215  LLDB_REGISTER_METHOD(bool, SBProcessInfo, UserIDIsValid, ());
216  LLDB_REGISTER_METHOD(bool, SBProcessInfo, GroupIDIsValid, ());
217  LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetEffectiveUserID, ());
218  LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetEffectiveGroupID, ());
219  LLDB_REGISTER_METHOD(bool, SBProcessInfo, EffectiveUserIDIsValid, ());
220  LLDB_REGISTER_METHOD(bool, SBProcessInfo, EffectiveGroupIDIsValid, ());
221  LLDB_REGISTER_METHOD(lldb::pid_t, SBProcessInfo, GetParentProcessID, ());
222  LLDB_REGISTER_METHOD(const char *, SBProcessInfo, GetTriple, ());
223 }
224 
225 }
226 }
lldb::SBProcessInfo::EffectiveUserIDIsValid
bool EffectiveUserIDIsValid()
Definition: SBProcessInfo.cpp:152
lldb_private::ProcessInstanceInfo
Definition: ProcessInfo.h:108
lldb::SBProcessInfo::~SBProcessInfo
~SBProcessInfo()
lldb::SBProcessInfo::IsValid
bool IsValid() const
Definition: SBProcessInfo.cpp:51
lldb::SBProcessInfo::GroupIDIsValid
bool GroupIDIsValid()
Definition: SBProcessInfo.cpp:122
lldb::SBProcessInfo::GetTriple
const char * GetTriple()
Return the target triple (arch-vendor-os) for the described process.
Definition: SBProcessInfo.cpp:182
LLDB_INVALID_PROCESS_ID
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:93
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
LLDB_RECORD_METHOD_CONST_NO_ARGS
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:168
lldb::SBProcessInfo::UserIDIsValid
bool UserIDIsValid()
Definition: SBProcessInfo.cpp:112
LLDB_RECORD_METHOD_NO_ARGS
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:165
LLDB_RECORD_CONSTRUCTOR_NO_ARGS
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
Definition: ReproducerInstrumentation.h:136
lldb::SBProcessInfo
Definition: SBProcessInfo.h:16
LLDB_REGISTER_METHOD_CONST
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:98
SBReproducerPrivate.h
lldb::SBProcessInfo::GetName
const char * GetName()
Definition: SBProcessInfo.cpp:61
LLDB_REGISTER_CONSTRUCTOR
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
Definition: ReproducerInstrumentation.h:89
lldb::SBFileSpec::SetFileSpec
void SetFileSpec(const lldb_private::FileSpec &fspec)
Definition: SBFileSpec.cpp:170
lldb::SBProcessInfo::SetProcessInfo
void SetProcessInfo(const lldb_private::ProcessInstanceInfo &proc_info_ref)
Definition: SBProcessInfo.cpp:47
lldb::SBProcessInfo::EffectiveGroupIDIsValid
bool EffectiveGroupIDIsValid()
Definition: SBProcessInfo.cpp:162
ProcessInfo.h
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
lldb_private::clone
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
Utils.h
SBFileSpec.h
GetName
static llvm::StringRef GetName(XcodeSDK::Type type)
Definition: XcodeSDK.cpp:21
lldb_private::ConstString
Definition: ConstString.h:40
lldb::SBProcessInfo::SBProcessInfo
SBProcessInfo()
Definition: SBProcessInfo.cpp:18
lldb::SBProcessInfo::GetEffectiveUserID
uint32_t GetEffectiveUserID()
Definition: SBProcessInfo.cpp:132
lldb::SBProcessInfo::ref
lldb_private::ProcessInstanceInfo & ref()
Definition: SBProcessInfo.cpp:40
LLDB_RECORD_CONSTRUCTOR
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
Definition: ReproducerInstrumentation.h:133
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
lldb::SBProcessInfo::GetExecutableFile
SBFileSpec GetExecutableFile()
Definition: SBProcessInfo.cpp:71
uint32_t
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb::SBProcessInfo::GetParentProcessID
lldb::pid_t GetParentProcessID()
Definition: SBProcessInfo.cpp:172
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
lldb::SBFileSpec
Definition: SBFileSpec.h:16
SBProcessInfo.h
lldb::SBProcessInfo::GetUserID
uint32_t GetUserID()
Definition: SBProcessInfo.cpp:92
lldb::SBProcessInfo::m_opaque_up
std::unique_ptr< lldb_private::ProcessInstanceInfo > m_opaque_up
Definition: SBProcessInfo.h:63
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::repro::RegisterMethods< SBProcessInfo >
void RegisterMethods< SBProcessInfo >(Registry &R)
Definition: SBProcessInfo.cpp:201
lldb::SBProcessInfo::GetGroupID
uint32_t GetGroupID()
Definition: SBProcessInfo.cpp:102
lldb
Definition: SBAddress.h:15
lldb::SBProcessInfo::GetEffectiveGroupID
uint32_t GetEffectiveGroupID()
Definition: SBProcessInfo.cpp:142
lldb::SBProcessInfo::GetProcessID
lldb::pid_t GetProcessID()
Definition: SBProcessInfo.cpp:82
lldb::SBProcessInfo::operator=
SBProcessInfo & operator=(const SBProcessInfo &rhs)
Definition: SBProcessInfo.cpp:30
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93