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 "Utils.h"
11#include "lldb/API/SBStream.h"
12#include "lldb/Core/Module.h"
13#include "lldb/Core/ModuleSpec.h"
14#include "lldb/Host/Host.h"
15#include "lldb/Symbol/ObjectFile.h"
16#include "lldb/Utility/Instrumentation.h"
17#include "lldb/Utility/Stream.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
22SBModuleSpec::SBModuleSpec() : m_opaque_up(new lldb_private::ModuleSpec()) {
23 LLDB_INSTRUMENT_VA(this);
24}
25
26SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) {
27 LLDB_INSTRUMENT_VA(this, rhs);
28
29 m_opaque_up = clone(src: rhs.m_opaque_up);
30}
31
32SBModuleSpec::SBModuleSpec(const lldb_private::ModuleSpec &module_spec)
33 : m_opaque_up(new lldb_private::ModuleSpec(module_spec)) {
34 LLDB_INSTRUMENT_VA(this, module_spec);
35}
36
37const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) {
38 LLDB_INSTRUMENT_VA(this, rhs);
39
40 if (this != &rhs)
41 m_opaque_up = clone(src: rhs.m_opaque_up);
42 return *this;
43}
44
45SBModuleSpec::~SBModuleSpec() = default;
46
47bool SBModuleSpec::IsValid() const {
48 LLDB_INSTRUMENT_VA(this);
49 return this->operator bool();
50}
51SBModuleSpec::operator bool() const {
52 LLDB_INSTRUMENT_VA(this);
53
54 return m_opaque_up->operator bool();
55}
56
57void SBModuleSpec::Clear() {
58 LLDB_INSTRUMENT_VA(this);
59
60 m_opaque_up->Clear();
61}
62
63SBFileSpec SBModuleSpec::GetFileSpec() {
64 LLDB_INSTRUMENT_VA(this);
65
66 SBFileSpec sb_spec(m_opaque_up->GetFileSpec());
67 return sb_spec;
68}
69
70void SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) {
71 LLDB_INSTRUMENT_VA(this, sb_spec);
72
73 m_opaque_up->GetFileSpec() = *sb_spec;
74}
75
76lldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() {
77 LLDB_INSTRUMENT_VA(this);
78
79 return SBFileSpec(m_opaque_up->GetPlatformFileSpec());
80}
81
82void SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) {
83 LLDB_INSTRUMENT_VA(this, sb_spec);
84
85 m_opaque_up->GetPlatformFileSpec() = *sb_spec;
86}
87
88lldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() {
89 LLDB_INSTRUMENT_VA(this);
90
91 return SBFileSpec(m_opaque_up->GetSymbolFileSpec());
92}
93
94void SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) {
95 LLDB_INSTRUMENT_VA(this, sb_spec);
96
97 m_opaque_up->GetSymbolFileSpec() = *sb_spec;
98}
99
100const char *SBModuleSpec::GetObjectName() {
101 LLDB_INSTRUMENT_VA(this);
102
103 return m_opaque_up->GetObjectName().GetCString();
104}
105
106void SBModuleSpec::SetObjectName(const char *name) {
107 LLDB_INSTRUMENT_VA(this, name);
108
109 m_opaque_up->GetObjectName().SetCString(name);
110}
111
112const char *SBModuleSpec::GetTriple() {
113 LLDB_INSTRUMENT_VA(this);
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
123void SBModuleSpec::SetTriple(const char *triple) {
124 LLDB_INSTRUMENT_VA(this, triple);
125
126 m_opaque_up->GetArchitecture().SetTriple(triple);
127}
128
129const uint8_t *SBModuleSpec::GetUUIDBytes() {
130 LLDB_INSTRUMENT_VA(this)
131 return m_opaque_up->GetUUID().GetBytes().data();
132}
133
134size_t SBModuleSpec::GetUUIDLength() {
135 LLDB_INSTRUMENT_VA(this);
136
137 return m_opaque_up->GetUUID().GetBytes().size();
138}
139
140bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) {
141 LLDB_INSTRUMENT_VA(this, uuid, uuid_len)
142 m_opaque_up->GetUUID() = UUID(uuid, uuid_len);
143 return m_opaque_up->GetUUID().IsValid();
144}
145
146bool SBModuleSpec::GetDescription(lldb::SBStream &description) {
147 LLDB_INSTRUMENT_VA(this, description);
148
149 m_opaque_up->Dump(strm&: description.ref());
150 return true;
151}
152
153uint64_t SBModuleSpec::GetObjectOffset() {
154 LLDB_INSTRUMENT_VA(this);
155
156 return m_opaque_up->GetObjectOffset();
157}
158
159void SBModuleSpec::SetObjectOffset(uint64_t object_offset) {
160 LLDB_INSTRUMENT_VA(this, object_offset);
161
162 m_opaque_up->SetObjectOffset(object_offset);
163}
164
165uint64_t SBModuleSpec::GetObjectSize() {
166 LLDB_INSTRUMENT_VA(this);
167
168 return m_opaque_up->GetObjectSize();
169}
170
171void SBModuleSpec::SetObjectSize(uint64_t object_size) {
172 LLDB_INSTRUMENT_VA(this, object_size);
173
174 m_opaque_up->SetObjectSize(object_size);
175}
176
177SBModuleSpecList::SBModuleSpecList() : m_opaque_up(new ModuleSpecList()) {
178 LLDB_INSTRUMENT_VA(this);
179}
180
181SBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs)
182 : m_opaque_up(new ModuleSpecList(*rhs.m_opaque_up)) {
183 LLDB_INSTRUMENT_VA(this, rhs);
184}
185
186SBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) {
187 LLDB_INSTRUMENT_VA(this, rhs);
188
189 if (this != &rhs)
190 *m_opaque_up = *rhs.m_opaque_up;
191 return *this;
192}
193
194SBModuleSpecList::~SBModuleSpecList() = default;
195
196SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) {
197 LLDB_INSTRUMENT_VA(path);
198
199 SBModuleSpecList specs;
200 FileSpec file_spec(path);
201 FileSystem::Instance().Resolve(file_spec);
202 Host::ResolveExecutableInBundle(file&: file_spec);
203 ObjectFile::GetModuleSpecifications(file: file_spec, file_offset: 0, file_size: 0, specs&: *specs.m_opaque_up);
204 return specs;
205}
206
207void SBModuleSpecList::Append(const SBModuleSpec &spec) {
208 LLDB_INSTRUMENT_VA(this, spec);
209
210 m_opaque_up->Append(spec: *spec.m_opaque_up);
211}
212
213void SBModuleSpecList::Append(const SBModuleSpecList &spec_list) {
214 LLDB_INSTRUMENT_VA(this, spec_list);
215
216 m_opaque_up->Append(rhs: *spec_list.m_opaque_up);
217}
218
219size_t SBModuleSpecList::GetSize() {
220 LLDB_INSTRUMENT_VA(this);
221
222 return m_opaque_up->GetSize();
223}
224
225SBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) {
226 LLDB_INSTRUMENT_VA(this, i);
227
228 SBModuleSpec sb_module_spec;
229 m_opaque_up->GetModuleSpecAtIndex(i, module_spec&: *sb_module_spec.m_opaque_up);
230 return sb_module_spec;
231}
232
233SBModuleSpec
234SBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) {
235 LLDB_INSTRUMENT_VA(this, match_spec);
236
237 SBModuleSpec sb_module_spec;
238 m_opaque_up->FindMatchingModuleSpec(module_spec: *match_spec.m_opaque_up,
239 match_module_spec&: *sb_module_spec.m_opaque_up);
240 return sb_module_spec;
241}
242
243SBModuleSpecList
244SBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) {
245 LLDB_INSTRUMENT_VA(this, match_spec);
246
247 SBModuleSpecList specs;
248 m_opaque_up->FindMatchingModuleSpecs(module_spec: *match_spec.m_opaque_up,
249 matching_list&: *specs.m_opaque_up);
250 return specs;
251}
252
253bool SBModuleSpecList::GetDescription(lldb::SBStream &description) {
254 LLDB_INSTRUMENT_VA(this, description);
255
256 m_opaque_up->Dump(strm&: description.ref());
257 return true;
258}
259

source code of lldb/source/API/SBModuleSpec.cpp