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(src: 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(src: 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 | if (!m_opaque_up) |
61 | return nullptr; |
62 | |
63 | return ConstString(m_opaque_up->GetName()).GetCString(); |
64 | } |
65 | |
66 | SBFileSpec SBProcessInfo::GetExecutableFile() { |
67 | LLDB_INSTRUMENT_VA(this); |
68 | |
69 | SBFileSpec file_spec; |
70 | if (m_opaque_up) { |
71 | file_spec.SetFileSpec(m_opaque_up->GetExecutableFile()); |
72 | } |
73 | return file_spec; |
74 | } |
75 | |
76 | lldb::pid_t SBProcessInfo::GetProcessID() { |
77 | LLDB_INSTRUMENT_VA(this); |
78 | |
79 | lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID; |
80 | if (m_opaque_up) { |
81 | proc_id = m_opaque_up->GetProcessID(); |
82 | } |
83 | return proc_id; |
84 | } |
85 | |
86 | uint32_t SBProcessInfo::GetUserID() { |
87 | LLDB_INSTRUMENT_VA(this); |
88 | |
89 | uint32_t user_id = UINT32_MAX; |
90 | if (m_opaque_up) { |
91 | user_id = m_opaque_up->GetUserID(); |
92 | } |
93 | return user_id; |
94 | } |
95 | |
96 | uint32_t SBProcessInfo::GetGroupID() { |
97 | LLDB_INSTRUMENT_VA(this); |
98 | |
99 | uint32_t group_id = UINT32_MAX; |
100 | if (m_opaque_up) { |
101 | group_id = m_opaque_up->GetGroupID(); |
102 | } |
103 | return group_id; |
104 | } |
105 | |
106 | bool SBProcessInfo::UserIDIsValid() { |
107 | LLDB_INSTRUMENT_VA(this); |
108 | |
109 | bool is_valid = false; |
110 | if (m_opaque_up) { |
111 | is_valid = m_opaque_up->UserIDIsValid(); |
112 | } |
113 | return is_valid; |
114 | } |
115 | |
116 | bool SBProcessInfo::GroupIDIsValid() { |
117 | LLDB_INSTRUMENT_VA(this); |
118 | |
119 | bool is_valid = false; |
120 | if (m_opaque_up) { |
121 | is_valid = m_opaque_up->GroupIDIsValid(); |
122 | } |
123 | return is_valid; |
124 | } |
125 | |
126 | uint32_t SBProcessInfo::GetEffectiveUserID() { |
127 | LLDB_INSTRUMENT_VA(this); |
128 | |
129 | uint32_t user_id = UINT32_MAX; |
130 | if (m_opaque_up) { |
131 | user_id = m_opaque_up->GetEffectiveUserID(); |
132 | } |
133 | return user_id; |
134 | } |
135 | |
136 | uint32_t SBProcessInfo::GetEffectiveGroupID() { |
137 | LLDB_INSTRUMENT_VA(this); |
138 | |
139 | uint32_t group_id = UINT32_MAX; |
140 | if (m_opaque_up) { |
141 | group_id = m_opaque_up->GetEffectiveGroupID(); |
142 | } |
143 | return group_id; |
144 | } |
145 | |
146 | bool SBProcessInfo::EffectiveUserIDIsValid() { |
147 | LLDB_INSTRUMENT_VA(this); |
148 | |
149 | bool is_valid = false; |
150 | if (m_opaque_up) { |
151 | is_valid = m_opaque_up->EffectiveUserIDIsValid(); |
152 | } |
153 | return is_valid; |
154 | } |
155 | |
156 | bool SBProcessInfo::EffectiveGroupIDIsValid() { |
157 | LLDB_INSTRUMENT_VA(this); |
158 | |
159 | bool is_valid = false; |
160 | if (m_opaque_up) { |
161 | is_valid = m_opaque_up->EffectiveGroupIDIsValid(); |
162 | } |
163 | return is_valid; |
164 | } |
165 | |
166 | lldb::pid_t SBProcessInfo::GetParentProcessID() { |
167 | LLDB_INSTRUMENT_VA(this); |
168 | |
169 | lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID; |
170 | if (m_opaque_up) { |
171 | proc_id = m_opaque_up->GetParentProcessID(); |
172 | } |
173 | return proc_id; |
174 | } |
175 | |
176 | const char *SBProcessInfo::GetTriple() { |
177 | LLDB_INSTRUMENT_VA(this); |
178 | |
179 | if (!m_opaque_up) |
180 | return nullptr; |
181 | |
182 | const auto &arch = m_opaque_up->GetArchitecture(); |
183 | if (!arch.IsValid()) |
184 | return nullptr; |
185 | |
186 | return ConstString(arch.GetTriple().getTriple().c_str()).GetCString(); |
187 | } |
188 |