1 //===-- SBModuleSpec.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/SBModuleSpec.h"
10 #include "SBReproducerPrivate.h"
11 #include "Utils.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Core/ModuleSpec.h"
15 #include "lldb/Host/Host.h"
16 #include "lldb/Symbol/ObjectFile.h"
17 #include "lldb/Utility/Stream.h"
18
19 using namespace lldb;
20 using namespace lldb_private;
21
SBModuleSpec()22 SBModuleSpec::SBModuleSpec() : m_opaque_up(new lldb_private::ModuleSpec()) {
23 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBModuleSpec);
24 }
25
SBModuleSpec(const SBModuleSpec & rhs)26 SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) : m_opaque_up() {
27 LLDB_RECORD_CONSTRUCTOR(SBModuleSpec, (const lldb::SBModuleSpec &), rhs);
28
29 m_opaque_up = clone(rhs.m_opaque_up);
30 }
31
operator =(const SBModuleSpec & rhs)32 const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) {
33 LLDB_RECORD_METHOD(const lldb::SBModuleSpec &,
34 SBModuleSpec, operator=,(const lldb::SBModuleSpec &), rhs);
35
36 if (this != &rhs)
37 m_opaque_up = clone(rhs.m_opaque_up);
38 return LLDB_RECORD_RESULT(*this);
39 }
40
41 SBModuleSpec::~SBModuleSpec() = default;
42
IsValid() const43 bool SBModuleSpec::IsValid() const {
44 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBModuleSpec, IsValid);
45 return this->operator bool();
46 }
operator bool() const47 SBModuleSpec::operator bool() const {
48 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBModuleSpec, operator bool);
49
50 return m_opaque_up->operator bool();
51 }
52
Clear()53 void SBModuleSpec::Clear() {
54 LLDB_RECORD_METHOD_NO_ARGS(void, SBModuleSpec, Clear);
55
56 m_opaque_up->Clear();
57 }
58
GetFileSpec()59 SBFileSpec SBModuleSpec::GetFileSpec() {
60 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBModuleSpec, GetFileSpec);
61
62 SBFileSpec sb_spec(m_opaque_up->GetFileSpec());
63 return LLDB_RECORD_RESULT(sb_spec);
64 }
65
SetFileSpec(const lldb::SBFileSpec & sb_spec)66 void SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) {
67 LLDB_RECORD_METHOD(void, SBModuleSpec, SetFileSpec,
68 (const lldb::SBFileSpec &), sb_spec);
69
70 m_opaque_up->GetFileSpec() = *sb_spec;
71 }
72
GetPlatformFileSpec()73 lldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() {
74 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBModuleSpec,
75 GetPlatformFileSpec);
76
77 return LLDB_RECORD_RESULT(SBFileSpec(m_opaque_up->GetPlatformFileSpec()));
78 }
79
SetPlatformFileSpec(const lldb::SBFileSpec & sb_spec)80 void SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) {
81 LLDB_RECORD_METHOD(void, SBModuleSpec, SetPlatformFileSpec,
82 (const lldb::SBFileSpec &), sb_spec);
83
84 m_opaque_up->GetPlatformFileSpec() = *sb_spec;
85 }
86
GetSymbolFileSpec()87 lldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() {
88 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBModuleSpec, GetSymbolFileSpec);
89
90 return LLDB_RECORD_RESULT(SBFileSpec(m_opaque_up->GetSymbolFileSpec()));
91 }
92
SetSymbolFileSpec(const lldb::SBFileSpec & sb_spec)93 void SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) {
94 LLDB_RECORD_METHOD(void, SBModuleSpec, SetSymbolFileSpec,
95 (const lldb::SBFileSpec &), sb_spec);
96
97 m_opaque_up->GetSymbolFileSpec() = *sb_spec;
98 }
99
GetObjectName()100 const char *SBModuleSpec::GetObjectName() {
101 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBModuleSpec, GetObjectName);
102
103 return m_opaque_up->GetObjectName().GetCString();
104 }
105
SetObjectName(const char * name)106 void SBModuleSpec::SetObjectName(const char *name) {
107 LLDB_RECORD_METHOD(void, SBModuleSpec, SetObjectName, (const char *), name);
108
109 m_opaque_up->GetObjectName().SetCString(name);
110 }
111
GetTriple()112 const char *SBModuleSpec::GetTriple() {
113 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBModuleSpec, GetTriple);
114
115 std::string triple(m_opaque_up->GetArchitecture().GetTriple().str());
116 // Unique the string so we don't run into ownership issues since the const
117 // strings put the string into the string pool once and the strings never
118 // comes out
119 ConstString const_triple(triple.c_str());
120 return const_triple.GetCString();
121 }
122
SetTriple(const char * triple)123 void SBModuleSpec::SetTriple(const char *triple) {
124 LLDB_RECORD_METHOD(void, SBModuleSpec, SetTriple, (const char *), triple);
125
126 m_opaque_up->GetArchitecture().SetTriple(triple);
127 }
128
GetUUIDBytes()129 const uint8_t *SBModuleSpec::GetUUIDBytes() {
130 return m_opaque_up->GetUUID().GetBytes().data();
131 }
132
GetUUIDLength()133 size_t SBModuleSpec::GetUUIDLength() {
134 LLDB_RECORD_METHOD_NO_ARGS(size_t, SBModuleSpec, GetUUIDLength);
135
136 return m_opaque_up->GetUUID().GetBytes().size();
137 }
138
SetUUIDBytes(const uint8_t * uuid,size_t uuid_len)139 bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) {
140 m_opaque_up->GetUUID() = UUID::fromOptionalData(uuid, uuid_len);
141 return m_opaque_up->GetUUID().IsValid();
142 }
143
GetDescription(lldb::SBStream & description)144 bool SBModuleSpec::GetDescription(lldb::SBStream &description) {
145 LLDB_RECORD_METHOD(bool, SBModuleSpec, GetDescription, (lldb::SBStream &),
146 description);
147
148 m_opaque_up->Dump(description.ref());
149 return true;
150 }
151
SBModuleSpecList()152 SBModuleSpecList::SBModuleSpecList() : m_opaque_up(new ModuleSpecList()) {
153 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBModuleSpecList);
154 }
155
SBModuleSpecList(const SBModuleSpecList & rhs)156 SBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs)
157 : m_opaque_up(new ModuleSpecList(*rhs.m_opaque_up)) {
158 LLDB_RECORD_CONSTRUCTOR(SBModuleSpecList, (const lldb::SBModuleSpecList &),
159 rhs);
160 }
161
operator =(const SBModuleSpecList & rhs)162 SBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) {
163 LLDB_RECORD_METHOD(
164 lldb::SBModuleSpecList &,
165 SBModuleSpecList, operator=,(const lldb::SBModuleSpecList &), rhs);
166
167 if (this != &rhs)
168 *m_opaque_up = *rhs.m_opaque_up;
169 return LLDB_RECORD_RESULT(*this);
170 }
171
172 SBModuleSpecList::~SBModuleSpecList() = default;
173
GetModuleSpecifications(const char * path)174 SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) {
175 LLDB_RECORD_STATIC_METHOD(lldb::SBModuleSpecList, SBModuleSpecList,
176 GetModuleSpecifications, (const char *), path);
177
178 SBModuleSpecList specs;
179 FileSpec file_spec(path);
180 FileSystem::Instance().Resolve(file_spec);
181 Host::ResolveExecutableInBundle(file_spec);
182 ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_up);
183 return LLDB_RECORD_RESULT(specs);
184 }
185
Append(const SBModuleSpec & spec)186 void SBModuleSpecList::Append(const SBModuleSpec &spec) {
187 LLDB_RECORD_METHOD(void, SBModuleSpecList, Append,
188 (const lldb::SBModuleSpec &), spec);
189
190 m_opaque_up->Append(*spec.m_opaque_up);
191 }
192
Append(const SBModuleSpecList & spec_list)193 void SBModuleSpecList::Append(const SBModuleSpecList &spec_list) {
194 LLDB_RECORD_METHOD(void, SBModuleSpecList, Append,
195 (const lldb::SBModuleSpecList &), spec_list);
196
197 m_opaque_up->Append(*spec_list.m_opaque_up);
198 }
199
GetSize()200 size_t SBModuleSpecList::GetSize() {
201 LLDB_RECORD_METHOD_NO_ARGS(size_t, SBModuleSpecList, GetSize);
202
203 return m_opaque_up->GetSize();
204 }
205
GetSpecAtIndex(size_t i)206 SBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) {
207 LLDB_RECORD_METHOD(lldb::SBModuleSpec, SBModuleSpecList, GetSpecAtIndex,
208 (size_t), i);
209
210 SBModuleSpec sb_module_spec;
211 m_opaque_up->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_up);
212 return LLDB_RECORD_RESULT(sb_module_spec);
213 }
214
215 SBModuleSpec
FindFirstMatchingSpec(const SBModuleSpec & match_spec)216 SBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) {
217 LLDB_RECORD_METHOD(lldb::SBModuleSpec, SBModuleSpecList,
218 FindFirstMatchingSpec, (const lldb::SBModuleSpec &),
219 match_spec);
220
221 SBModuleSpec sb_module_spec;
222 m_opaque_up->FindMatchingModuleSpec(*match_spec.m_opaque_up,
223 *sb_module_spec.m_opaque_up);
224 return LLDB_RECORD_RESULT(sb_module_spec);
225 }
226
227 SBModuleSpecList
FindMatchingSpecs(const SBModuleSpec & match_spec)228 SBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) {
229 LLDB_RECORD_METHOD(lldb::SBModuleSpecList, SBModuleSpecList,
230 FindMatchingSpecs, (const lldb::SBModuleSpec &),
231 match_spec);
232
233 SBModuleSpecList specs;
234 m_opaque_up->FindMatchingModuleSpecs(*match_spec.m_opaque_up,
235 *specs.m_opaque_up);
236 return LLDB_RECORD_RESULT(specs);
237 }
238
GetDescription(lldb::SBStream & description)239 bool SBModuleSpecList::GetDescription(lldb::SBStream &description) {
240 LLDB_RECORD_METHOD(bool, SBModuleSpecList, GetDescription, (lldb::SBStream &),
241 description);
242
243 m_opaque_up->Dump(description.ref());
244 return true;
245 }
246
247 namespace lldb_private {
248 namespace repro {
249
250 template <>
RegisterMethods(Registry & R)251 void RegisterMethods<SBModuleSpec>(Registry &R) {
252 LLDB_REGISTER_CONSTRUCTOR(SBModuleSpec, ());
253 LLDB_REGISTER_CONSTRUCTOR(SBModuleSpec, (const lldb::SBModuleSpec &));
254 LLDB_REGISTER_METHOD(const lldb::SBModuleSpec &,
255 SBModuleSpec, operator=,(const lldb::SBModuleSpec &));
256 LLDB_REGISTER_METHOD_CONST(bool, SBModuleSpec, IsValid, ());
257 LLDB_REGISTER_METHOD_CONST(bool, SBModuleSpec, operator bool, ());
258 LLDB_REGISTER_METHOD(void, SBModuleSpec, Clear, ());
259 LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBModuleSpec, GetFileSpec, ());
260 LLDB_REGISTER_METHOD(void, SBModuleSpec, SetFileSpec,
261 (const lldb::SBFileSpec &));
262 LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBModuleSpec, GetPlatformFileSpec,
263 ());
264 LLDB_REGISTER_METHOD(void, SBModuleSpec, SetPlatformFileSpec,
265 (const lldb::SBFileSpec &));
266 LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBModuleSpec, GetSymbolFileSpec, ());
267 LLDB_REGISTER_METHOD(void, SBModuleSpec, SetSymbolFileSpec,
268 (const lldb::SBFileSpec &));
269 LLDB_REGISTER_METHOD(const char *, SBModuleSpec, GetObjectName, ());
270 LLDB_REGISTER_METHOD(void, SBModuleSpec, SetObjectName, (const char *));
271 LLDB_REGISTER_METHOD(const char *, SBModuleSpec, GetTriple, ());
272 LLDB_REGISTER_METHOD(void, SBModuleSpec, SetTriple, (const char *));
273 LLDB_REGISTER_METHOD(size_t, SBModuleSpec, GetUUIDLength, ());
274 LLDB_REGISTER_METHOD(bool, SBModuleSpec, GetDescription,
275 (lldb::SBStream &));
276 LLDB_REGISTER_CONSTRUCTOR(SBModuleSpecList, ());
277 LLDB_REGISTER_CONSTRUCTOR(SBModuleSpecList,
278 (const lldb::SBModuleSpecList &));
279 LLDB_REGISTER_METHOD(
280 lldb::SBModuleSpecList &,
281 SBModuleSpecList, operator=,(const lldb::SBModuleSpecList &));
282 LLDB_REGISTER_STATIC_METHOD(lldb::SBModuleSpecList, SBModuleSpecList,
283 GetModuleSpecifications, (const char *));
284 LLDB_REGISTER_METHOD(void, SBModuleSpecList, Append,
285 (const lldb::SBModuleSpec &));
286 LLDB_REGISTER_METHOD(void, SBModuleSpecList, Append,
287 (const lldb::SBModuleSpecList &));
288 LLDB_REGISTER_METHOD(size_t, SBModuleSpecList, GetSize, ());
289 LLDB_REGISTER_METHOD(lldb::SBModuleSpec, SBModuleSpecList, GetSpecAtIndex,
290 (size_t));
291 LLDB_REGISTER_METHOD(lldb::SBModuleSpec, SBModuleSpecList,
292 FindFirstMatchingSpec, (const lldb::SBModuleSpec &));
293 LLDB_REGISTER_METHOD(lldb::SBModuleSpecList, SBModuleSpecList,
294 FindMatchingSpecs, (const lldb::SBModuleSpec &));
295 LLDB_REGISTER_METHOD(bool, SBModuleSpecList, GetDescription,
296 (lldb::SBStream &));
297 }
298
299 }
300 }
301