180814287SRaphael Isemann //===-- SBModuleSpec.cpp --------------------------------------------------===//
2226cce25SGreg Clayton //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6226cce25SGreg Clayton //
7226cce25SGreg Clayton //===----------------------------------------------------------------------===//
8226cce25SGreg Clayton
9226cce25SGreg Clayton #include "lldb/API/SBModuleSpec.h"
10bd4bf82aSJonas Devlieghere #include "Utils.h"
11226cce25SGreg Clayton #include "lldb/API/SBStream.h"
12226cce25SGreg Clayton #include "lldb/Core/Module.h"
13226cce25SGreg Clayton #include "lldb/Core/ModuleSpec.h"
14226cce25SGreg Clayton #include "lldb/Host/Host.h"
15226cce25SGreg Clayton #include "lldb/Symbol/ObjectFile.h"
16*1755f5b1SJonas Devlieghere #include "lldb/Utility/Instrumentation.h"
17bf9a7730SZachary Turner #include "lldb/Utility/Stream.h"
18226cce25SGreg Clayton
19226cce25SGreg Clayton using namespace lldb;
20226cce25SGreg Clayton using namespace lldb_private;
21226cce25SGreg Clayton
SBModuleSpec()22baf5664fSJonas Devlieghere SBModuleSpec::SBModuleSpec() : m_opaque_up(new lldb_private::ModuleSpec()) {
23*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
24baf5664fSJonas Devlieghere }
25226cce25SGreg Clayton
SBModuleSpec(const SBModuleSpec & rhs)26a3436f73SKazu Hirata SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) {
27*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, rhs);
28baf5664fSJonas Devlieghere
29bd4bf82aSJonas Devlieghere m_opaque_up = clone(rhs.m_opaque_up);
30bd4bf82aSJonas Devlieghere }
31226cce25SGreg Clayton
operator =(const SBModuleSpec & rhs)32b9c1b51eSKate Stone const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) {
33*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, rhs);
34baf5664fSJonas Devlieghere
35226cce25SGreg Clayton if (this != &rhs)
36bd4bf82aSJonas Devlieghere m_opaque_up = clone(rhs.m_opaque_up);
37d232abc3SJonas Devlieghere return *this;
38226cce25SGreg Clayton }
39226cce25SGreg Clayton
40866b7a65SJonas Devlieghere SBModuleSpec::~SBModuleSpec() = default;
41226cce25SGreg Clayton
IsValid() const42baf5664fSJonas Devlieghere bool SBModuleSpec::IsValid() const {
43*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
447f5237bcSPavel Labath return this->operator bool();
457f5237bcSPavel Labath }
operator bool() const467f5237bcSPavel Labath SBModuleSpec::operator bool() const {
47*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
48226cce25SGreg Clayton
49baf5664fSJonas Devlieghere return m_opaque_up->operator bool();
50baf5664fSJonas Devlieghere }
51baf5664fSJonas Devlieghere
Clear()52baf5664fSJonas Devlieghere void SBModuleSpec::Clear() {
53*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
54baf5664fSJonas Devlieghere
55baf5664fSJonas Devlieghere m_opaque_up->Clear();
56baf5664fSJonas Devlieghere }
57226cce25SGreg Clayton
GetFileSpec()58b9c1b51eSKate Stone SBFileSpec SBModuleSpec::GetFileSpec() {
59*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
60baf5664fSJonas Devlieghere
61d5b44036SJonas Devlieghere SBFileSpec sb_spec(m_opaque_up->GetFileSpec());
62d232abc3SJonas Devlieghere return sb_spec;
63226cce25SGreg Clayton }
64226cce25SGreg Clayton
SetFileSpec(const lldb::SBFileSpec & sb_spec)65b9c1b51eSKate Stone void SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) {
66*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, sb_spec);
67baf5664fSJonas Devlieghere
68d5b44036SJonas Devlieghere m_opaque_up->GetFileSpec() = *sb_spec;
69226cce25SGreg Clayton }
70226cce25SGreg Clayton
GetPlatformFileSpec()71b9c1b51eSKate Stone lldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() {
72*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
73baf5664fSJonas Devlieghere
74d232abc3SJonas Devlieghere return SBFileSpec(m_opaque_up->GetPlatformFileSpec());
75226cce25SGreg Clayton }
76226cce25SGreg Clayton
SetPlatformFileSpec(const lldb::SBFileSpec & sb_spec)77b9c1b51eSKate Stone void SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) {
78*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, sb_spec);
79baf5664fSJonas Devlieghere
80d5b44036SJonas Devlieghere m_opaque_up->GetPlatformFileSpec() = *sb_spec;
81226cce25SGreg Clayton }
82226cce25SGreg Clayton
GetSymbolFileSpec()83b9c1b51eSKate Stone lldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() {
84*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
85baf5664fSJonas Devlieghere
86d232abc3SJonas Devlieghere return SBFileSpec(m_opaque_up->GetSymbolFileSpec());
87226cce25SGreg Clayton }
88226cce25SGreg Clayton
SetSymbolFileSpec(const lldb::SBFileSpec & sb_spec)89b9c1b51eSKate Stone void SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) {
90*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, sb_spec);
91baf5664fSJonas Devlieghere
92d5b44036SJonas Devlieghere m_opaque_up->GetSymbolFileSpec() = *sb_spec;
93226cce25SGreg Clayton }
94226cce25SGreg Clayton
GetObjectName()95b9c1b51eSKate Stone const char *SBModuleSpec::GetObjectName() {
96*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
97baf5664fSJonas Devlieghere
98d5b44036SJonas Devlieghere return m_opaque_up->GetObjectName().GetCString();
99226cce25SGreg Clayton }
100226cce25SGreg Clayton
SetObjectName(const char * name)101b9c1b51eSKate Stone void SBModuleSpec::SetObjectName(const char *name) {
102*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, name);
103baf5664fSJonas Devlieghere
104d5b44036SJonas Devlieghere m_opaque_up->GetObjectName().SetCString(name);
105226cce25SGreg Clayton }
106226cce25SGreg Clayton
GetTriple()107b9c1b51eSKate Stone const char *SBModuleSpec::GetTriple() {
108*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
109baf5664fSJonas Devlieghere
110d5b44036SJonas Devlieghere std::string triple(m_opaque_up->GetArchitecture().GetTriple().str());
11105097246SAdrian Prantl // Unique the string so we don't run into ownership issues since the const
11205097246SAdrian Prantl // strings put the string into the string pool once and the strings never
11305097246SAdrian Prantl // comes out
114226cce25SGreg Clayton ConstString const_triple(triple.c_str());
115226cce25SGreg Clayton return const_triple.GetCString();
116226cce25SGreg Clayton }
117226cce25SGreg Clayton
SetTriple(const char * triple)118b9c1b51eSKate Stone void SBModuleSpec::SetTriple(const char *triple) {
119*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, triple);
120baf5664fSJonas Devlieghere
121d5b44036SJonas Devlieghere m_opaque_up->GetArchitecture().SetTriple(triple);
122226cce25SGreg Clayton }
123226cce25SGreg Clayton
GetUUIDBytes()124b9c1b51eSKate Stone const uint8_t *SBModuleSpec::GetUUIDBytes() {
125*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this)
126d5b44036SJonas Devlieghere return m_opaque_up->GetUUID().GetBytes().data();
127226cce25SGreg Clayton }
128226cce25SGreg Clayton
GetUUIDLength()129b9c1b51eSKate Stone size_t SBModuleSpec::GetUUIDLength() {
130*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
131baf5664fSJonas Devlieghere
132d5b44036SJonas Devlieghere return m_opaque_up->GetUUID().GetBytes().size();
133226cce25SGreg Clayton }
134226cce25SGreg Clayton
SetUUIDBytes(const uint8_t * uuid,size_t uuid_len)135b9c1b51eSKate Stone bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) {
136*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, uuid, uuid_len)
137d5b44036SJonas Devlieghere m_opaque_up->GetUUID() = UUID::fromOptionalData(uuid, uuid_len);
138d5b44036SJonas Devlieghere return m_opaque_up->GetUUID().IsValid();
139226cce25SGreg Clayton }
140226cce25SGreg Clayton
GetDescription(lldb::SBStream & description)141b9c1b51eSKate Stone bool SBModuleSpec::GetDescription(lldb::SBStream &description) {
142*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, description);
143baf5664fSJonas Devlieghere
144d5b44036SJonas Devlieghere m_opaque_up->Dump(description.ref());
145226cce25SGreg Clayton return true;
146226cce25SGreg Clayton }
147226cce25SGreg Clayton
SBModuleSpecList()148baf5664fSJonas Devlieghere SBModuleSpecList::SBModuleSpecList() : m_opaque_up(new ModuleSpecList()) {
149*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
150baf5664fSJonas Devlieghere }
151226cce25SGreg Clayton
SBModuleSpecList(const SBModuleSpecList & rhs)152b9c1b51eSKate Stone SBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs)
153baf5664fSJonas Devlieghere : m_opaque_up(new ModuleSpecList(*rhs.m_opaque_up)) {
154*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, rhs);
155baf5664fSJonas Devlieghere }
156226cce25SGreg Clayton
operator =(const SBModuleSpecList & rhs)157b9c1b51eSKate Stone SBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) {
158*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, rhs);
159baf5664fSJonas Devlieghere
160226cce25SGreg Clayton if (this != &rhs)
161d5b44036SJonas Devlieghere *m_opaque_up = *rhs.m_opaque_up;
162d232abc3SJonas Devlieghere return *this;
163226cce25SGreg Clayton }
164226cce25SGreg Clayton
165866b7a65SJonas Devlieghere SBModuleSpecList::~SBModuleSpecList() = default;
166226cce25SGreg Clayton
GetModuleSpecifications(const char * path)167b9c1b51eSKate Stone SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) {
168*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(path);
169baf5664fSJonas Devlieghere
170226cce25SGreg Clayton SBModuleSpecList specs;
1718f3be7a3SJonas Devlieghere FileSpec file_spec(path);
1728f3be7a3SJonas Devlieghere FileSystem::Instance().Resolve(file_spec);
173226cce25SGreg Clayton Host::ResolveExecutableInBundle(file_spec);
174d5b44036SJonas Devlieghere ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_up);
175d232abc3SJonas Devlieghere return specs;
176226cce25SGreg Clayton }
177226cce25SGreg Clayton
Append(const SBModuleSpec & spec)178b9c1b51eSKate Stone void SBModuleSpecList::Append(const SBModuleSpec &spec) {
179*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, spec);
180baf5664fSJonas Devlieghere
181d5b44036SJonas Devlieghere m_opaque_up->Append(*spec.m_opaque_up);
182226cce25SGreg Clayton }
183226cce25SGreg Clayton
Append(const SBModuleSpecList & spec_list)184b9c1b51eSKate Stone void SBModuleSpecList::Append(const SBModuleSpecList &spec_list) {
185*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, spec_list);
186baf5664fSJonas Devlieghere
187d5b44036SJonas Devlieghere m_opaque_up->Append(*spec_list.m_opaque_up);
188226cce25SGreg Clayton }
189226cce25SGreg Clayton
GetSize()190baf5664fSJonas Devlieghere size_t SBModuleSpecList::GetSize() {
191*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this);
192baf5664fSJonas Devlieghere
193baf5664fSJonas Devlieghere return m_opaque_up->GetSize();
194baf5664fSJonas Devlieghere }
195226cce25SGreg Clayton
GetSpecAtIndex(size_t i)196b9c1b51eSKate Stone SBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) {
197*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, i);
198baf5664fSJonas Devlieghere
199226cce25SGreg Clayton SBModuleSpec sb_module_spec;
200d5b44036SJonas Devlieghere m_opaque_up->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_up);
201d232abc3SJonas Devlieghere return sb_module_spec;
202226cce25SGreg Clayton }
203226cce25SGreg Clayton
204226cce25SGreg Clayton SBModuleSpec
FindFirstMatchingSpec(const SBModuleSpec & match_spec)205b9c1b51eSKate Stone SBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) {
206*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, match_spec);
207baf5664fSJonas Devlieghere
208226cce25SGreg Clayton SBModuleSpec sb_module_spec;
209d5b44036SJonas Devlieghere m_opaque_up->FindMatchingModuleSpec(*match_spec.m_opaque_up,
210d5b44036SJonas Devlieghere *sb_module_spec.m_opaque_up);
211d232abc3SJonas Devlieghere return sb_module_spec;
212226cce25SGreg Clayton }
213226cce25SGreg Clayton
214226cce25SGreg Clayton SBModuleSpecList
FindMatchingSpecs(const SBModuleSpec & match_spec)215b9c1b51eSKate Stone SBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) {
216*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, match_spec);
217baf5664fSJonas Devlieghere
218226cce25SGreg Clayton SBModuleSpecList specs;
219d5b44036SJonas Devlieghere m_opaque_up->FindMatchingModuleSpecs(*match_spec.m_opaque_up,
220d5b44036SJonas Devlieghere *specs.m_opaque_up);
221d232abc3SJonas Devlieghere return specs;
222226cce25SGreg Clayton }
223226cce25SGreg Clayton
GetDescription(lldb::SBStream & description)224b9c1b51eSKate Stone bool SBModuleSpecList::GetDescription(lldb::SBStream &description) {
225*1755f5b1SJonas Devlieghere LLDB_INSTRUMENT_VA(this, description);
226baf5664fSJonas Devlieghere
227d5b44036SJonas Devlieghere m_opaque_up->Dump(description.ref());
228226cce25SGreg Clayton return true;
229226cce25SGreg Clayton }
230