1cfca06d7SDimitry Andric //===-- SBModuleSpec.cpp --------------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste
9f034231aSEd Maste #include "lldb/API/SBModuleSpec.h"
105f29bb8aSDimitry Andric #include "Utils.h"
11f034231aSEd Maste #include "lldb/API/SBStream.h"
12f034231aSEd Maste #include "lldb/Core/Module.h"
13f034231aSEd Maste #include "lldb/Core/ModuleSpec.h"
14f034231aSEd Maste #include "lldb/Host/Host.h"
15f034231aSEd Maste #include "lldb/Symbol/ObjectFile.h"
166f8fc217SDimitry Andric #include "lldb/Utility/Instrumentation.h"
1774a628f7SDimitry Andric #include "lldb/Utility/Stream.h"
18f034231aSEd Maste
19f034231aSEd Maste using namespace lldb;
20f034231aSEd Maste using namespace lldb_private;
21f034231aSEd Maste
SBModuleSpec()225f29bb8aSDimitry Andric SBModuleSpec::SBModuleSpec() : m_opaque_up(new lldb_private::ModuleSpec()) {
236f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
245f29bb8aSDimitry Andric }
25f034231aSEd Maste
SBModuleSpec(const SBModuleSpec & rhs)266f8fc217SDimitry Andric SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) {
276f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
285f29bb8aSDimitry Andric
295f29bb8aSDimitry Andric m_opaque_up = clone(rhs.m_opaque_up);
305f29bb8aSDimitry Andric }
31f034231aSEd Maste
SBModuleSpec(const lldb_private::ModuleSpec & module_spec)327fa27ce4SDimitry Andric SBModuleSpec::SBModuleSpec(const lldb_private::ModuleSpec &module_spec)
337fa27ce4SDimitry Andric : m_opaque_up(new lldb_private::ModuleSpec(module_spec)) {
347fa27ce4SDimitry Andric LLDB_INSTRUMENT_VA(this, module_spec);
357fa27ce4SDimitry Andric }
367fa27ce4SDimitry Andric
operator =(const SBModuleSpec & rhs)3714f1b3e8SDimitry Andric const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) {
386f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
395f29bb8aSDimitry Andric
40f034231aSEd Maste if (this != &rhs)
415f29bb8aSDimitry Andric m_opaque_up = clone(rhs.m_opaque_up);
426f8fc217SDimitry Andric return *this;
43f034231aSEd Maste }
44f034231aSEd Maste
45cfca06d7SDimitry Andric SBModuleSpec::~SBModuleSpec() = default;
46f034231aSEd Maste
IsValid() const475f29bb8aSDimitry Andric bool SBModuleSpec::IsValid() const {
486f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
495f29bb8aSDimitry Andric return this->operator bool();
505f29bb8aSDimitry Andric }
operator bool() const515f29bb8aSDimitry Andric SBModuleSpec::operator bool() const {
526f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
53f034231aSEd Maste
545f29bb8aSDimitry Andric return m_opaque_up->operator bool();
555f29bb8aSDimitry Andric }
565f29bb8aSDimitry Andric
Clear()575f29bb8aSDimitry Andric void SBModuleSpec::Clear() {
586f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
595f29bb8aSDimitry Andric
605f29bb8aSDimitry Andric m_opaque_up->Clear();
615f29bb8aSDimitry Andric }
62f034231aSEd Maste
GetFileSpec()6314f1b3e8SDimitry Andric SBFileSpec SBModuleSpec::GetFileSpec() {
646f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
655f29bb8aSDimitry Andric
665f29bb8aSDimitry Andric SBFileSpec sb_spec(m_opaque_up->GetFileSpec());
676f8fc217SDimitry Andric return sb_spec;
68f034231aSEd Maste }
69f034231aSEd Maste
SetFileSpec(const lldb::SBFileSpec & sb_spec)7014f1b3e8SDimitry Andric void SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) {
716f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, sb_spec);
725f29bb8aSDimitry Andric
735f29bb8aSDimitry Andric m_opaque_up->GetFileSpec() = *sb_spec;
74f034231aSEd Maste }
75f034231aSEd Maste
GetPlatformFileSpec()7614f1b3e8SDimitry Andric lldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() {
776f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
785f29bb8aSDimitry Andric
796f8fc217SDimitry Andric return SBFileSpec(m_opaque_up->GetPlatformFileSpec());
80f034231aSEd Maste }
81f034231aSEd Maste
SetPlatformFileSpec(const lldb::SBFileSpec & sb_spec)8214f1b3e8SDimitry Andric void SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) {
836f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, sb_spec);
845f29bb8aSDimitry Andric
855f29bb8aSDimitry Andric m_opaque_up->GetPlatformFileSpec() = *sb_spec;
86f034231aSEd Maste }
87f034231aSEd Maste
GetSymbolFileSpec()8814f1b3e8SDimitry Andric lldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() {
896f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
905f29bb8aSDimitry Andric
916f8fc217SDimitry Andric return SBFileSpec(m_opaque_up->GetSymbolFileSpec());
92f034231aSEd Maste }
93f034231aSEd Maste
SetSymbolFileSpec(const lldb::SBFileSpec & sb_spec)9414f1b3e8SDimitry Andric void SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) {
956f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, sb_spec);
965f29bb8aSDimitry Andric
975f29bb8aSDimitry Andric m_opaque_up->GetSymbolFileSpec() = *sb_spec;
98f034231aSEd Maste }
99f034231aSEd Maste
GetObjectName()10014f1b3e8SDimitry Andric const char *SBModuleSpec::GetObjectName() {
1016f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1025f29bb8aSDimitry Andric
1035f29bb8aSDimitry Andric return m_opaque_up->GetObjectName().GetCString();
104f034231aSEd Maste }
105f034231aSEd Maste
SetObjectName(const char * name)10614f1b3e8SDimitry Andric void SBModuleSpec::SetObjectName(const char *name) {
1076f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, name);
1085f29bb8aSDimitry Andric
1095f29bb8aSDimitry Andric m_opaque_up->GetObjectName().SetCString(name);
110f034231aSEd Maste }
111f034231aSEd Maste
GetTriple()11214f1b3e8SDimitry Andric const char *SBModuleSpec::GetTriple() {
1136f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1145f29bb8aSDimitry Andric
1155f29bb8aSDimitry Andric std::string triple(m_opaque_up->GetArchitecture().GetTriple().str());
116f73363f1SDimitry Andric // Unique the string so we don't run into ownership issues since the const
117f73363f1SDimitry Andric // strings put the string into the string pool once and the strings never
118f73363f1SDimitry Andric // comes out
119f034231aSEd Maste ConstString const_triple(triple.c_str());
120f034231aSEd Maste return const_triple.GetCString();
121f034231aSEd Maste }
122f034231aSEd Maste
SetTriple(const char * triple)12314f1b3e8SDimitry Andric void SBModuleSpec::SetTriple(const char *triple) {
1246f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, triple);
1255f29bb8aSDimitry Andric
1265f29bb8aSDimitry Andric m_opaque_up->GetArchitecture().SetTriple(triple);
127f034231aSEd Maste }
128f034231aSEd Maste
GetUUIDBytes()12914f1b3e8SDimitry Andric const uint8_t *SBModuleSpec::GetUUIDBytes() {
1306f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this)
1315f29bb8aSDimitry Andric return m_opaque_up->GetUUID().GetBytes().data();
132f034231aSEd Maste }
133f034231aSEd Maste
GetUUIDLength()13414f1b3e8SDimitry Andric size_t SBModuleSpec::GetUUIDLength() {
1356f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1365f29bb8aSDimitry Andric
1375f29bb8aSDimitry Andric return m_opaque_up->GetUUID().GetBytes().size();
138f034231aSEd Maste }
139f034231aSEd Maste
SetUUIDBytes(const uint8_t * uuid,size_t uuid_len)14014f1b3e8SDimitry Andric bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) {
1416f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, uuid, uuid_len)
142e3b55780SDimitry Andric m_opaque_up->GetUUID() = UUID(uuid, uuid_len);
1435f29bb8aSDimitry Andric return m_opaque_up->GetUUID().IsValid();
144f034231aSEd Maste }
145f034231aSEd Maste
GetDescription(lldb::SBStream & description)14614f1b3e8SDimitry Andric bool SBModuleSpec::GetDescription(lldb::SBStream &description) {
1476f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, description);
1485f29bb8aSDimitry Andric
1495f29bb8aSDimitry Andric m_opaque_up->Dump(description.ref());
150f034231aSEd Maste return true;
151f034231aSEd Maste }
152f034231aSEd Maste
GetObjectOffset()1537fa27ce4SDimitry Andric uint64_t SBModuleSpec::GetObjectOffset() {
1547fa27ce4SDimitry Andric LLDB_INSTRUMENT_VA(this);
1557fa27ce4SDimitry Andric
1567fa27ce4SDimitry Andric return m_opaque_up->GetObjectOffset();
1577fa27ce4SDimitry Andric }
1587fa27ce4SDimitry Andric
SetObjectOffset(uint64_t object_offset)1597fa27ce4SDimitry Andric void SBModuleSpec::SetObjectOffset(uint64_t object_offset) {
1607fa27ce4SDimitry Andric LLDB_INSTRUMENT_VA(this, object_offset);
1617fa27ce4SDimitry Andric
1627fa27ce4SDimitry Andric m_opaque_up->SetObjectOffset(object_offset);
1637fa27ce4SDimitry Andric }
1647fa27ce4SDimitry Andric
GetObjectSize()1657fa27ce4SDimitry Andric uint64_t SBModuleSpec::GetObjectSize() {
1667fa27ce4SDimitry Andric LLDB_INSTRUMENT_VA(this);
1677fa27ce4SDimitry Andric
1687fa27ce4SDimitry Andric return m_opaque_up->GetObjectSize();
1697fa27ce4SDimitry Andric }
1707fa27ce4SDimitry Andric
SetObjectSize(uint64_t object_size)1717fa27ce4SDimitry Andric void SBModuleSpec::SetObjectSize(uint64_t object_size) {
1727fa27ce4SDimitry Andric LLDB_INSTRUMENT_VA(this, object_size);
1737fa27ce4SDimitry Andric
1747fa27ce4SDimitry Andric m_opaque_up->SetObjectSize(object_size);
1757fa27ce4SDimitry Andric }
1767fa27ce4SDimitry Andric
SBModuleSpecList()1775f29bb8aSDimitry Andric SBModuleSpecList::SBModuleSpecList() : m_opaque_up(new ModuleSpecList()) {
1786f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1795f29bb8aSDimitry Andric }
180f034231aSEd Maste
SBModuleSpecList(const SBModuleSpecList & rhs)18114f1b3e8SDimitry Andric SBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs)
1825f29bb8aSDimitry Andric : m_opaque_up(new ModuleSpecList(*rhs.m_opaque_up)) {
1836f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
1845f29bb8aSDimitry Andric }
185f034231aSEd Maste
operator =(const SBModuleSpecList & rhs)18614f1b3e8SDimitry Andric SBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) {
1876f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
1885f29bb8aSDimitry Andric
189f034231aSEd Maste if (this != &rhs)
1905f29bb8aSDimitry Andric *m_opaque_up = *rhs.m_opaque_up;
1916f8fc217SDimitry Andric return *this;
192f034231aSEd Maste }
193f034231aSEd Maste
194cfca06d7SDimitry Andric SBModuleSpecList::~SBModuleSpecList() = default;
195f034231aSEd Maste
GetModuleSpecifications(const char * path)19614f1b3e8SDimitry Andric SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) {
1976f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(path);
1985f29bb8aSDimitry Andric
199f034231aSEd Maste SBModuleSpecList specs;
20094994d37SDimitry Andric FileSpec file_spec(path);
20194994d37SDimitry Andric FileSystem::Instance().Resolve(file_spec);
202f034231aSEd Maste Host::ResolveExecutableInBundle(file_spec);
2035f29bb8aSDimitry Andric ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_up);
2046f8fc217SDimitry Andric return specs;
205f034231aSEd Maste }
206f034231aSEd Maste
Append(const SBModuleSpec & spec)20714f1b3e8SDimitry Andric void SBModuleSpecList::Append(const SBModuleSpec &spec) {
2086f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, spec);
2095f29bb8aSDimitry Andric
2105f29bb8aSDimitry Andric m_opaque_up->Append(*spec.m_opaque_up);
211f034231aSEd Maste }
212f034231aSEd Maste
Append(const SBModuleSpecList & spec_list)21314f1b3e8SDimitry Andric void SBModuleSpecList::Append(const SBModuleSpecList &spec_list) {
2146f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, spec_list);
2155f29bb8aSDimitry Andric
2165f29bb8aSDimitry Andric m_opaque_up->Append(*spec_list.m_opaque_up);
217f034231aSEd Maste }
218f034231aSEd Maste
GetSize()2195f29bb8aSDimitry Andric size_t SBModuleSpecList::GetSize() {
2206f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
2215f29bb8aSDimitry Andric
2225f29bb8aSDimitry Andric return m_opaque_up->GetSize();
2235f29bb8aSDimitry Andric }
224f034231aSEd Maste
GetSpecAtIndex(size_t i)22514f1b3e8SDimitry Andric SBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) {
2266f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, i);
2275f29bb8aSDimitry Andric
228f034231aSEd Maste SBModuleSpec sb_module_spec;
2295f29bb8aSDimitry Andric m_opaque_up->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_up);
2306f8fc217SDimitry Andric return sb_module_spec;
231f034231aSEd Maste }
232f034231aSEd Maste
233f034231aSEd Maste SBModuleSpec
FindFirstMatchingSpec(const SBModuleSpec & match_spec)23414f1b3e8SDimitry Andric SBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) {
2356f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, match_spec);
2365f29bb8aSDimitry Andric
237f034231aSEd Maste SBModuleSpec sb_module_spec;
2385f29bb8aSDimitry Andric m_opaque_up->FindMatchingModuleSpec(*match_spec.m_opaque_up,
2395f29bb8aSDimitry Andric *sb_module_spec.m_opaque_up);
2406f8fc217SDimitry Andric return sb_module_spec;
241f034231aSEd Maste }
242f034231aSEd Maste
243f034231aSEd Maste SBModuleSpecList
FindMatchingSpecs(const SBModuleSpec & match_spec)24414f1b3e8SDimitry Andric SBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) {
2456f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, match_spec);
2465f29bb8aSDimitry Andric
247f034231aSEd Maste SBModuleSpecList specs;
2485f29bb8aSDimitry Andric m_opaque_up->FindMatchingModuleSpecs(*match_spec.m_opaque_up,
2495f29bb8aSDimitry Andric *specs.m_opaque_up);
2506f8fc217SDimitry Andric return specs;
251f034231aSEd Maste }
252f034231aSEd Maste
GetDescription(lldb::SBStream & description)25314f1b3e8SDimitry Andric bool SBModuleSpecList::GetDescription(lldb::SBStream &description) {
2546f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, description);
2555f29bb8aSDimitry Andric
2565f29bb8aSDimitry Andric m_opaque_up->Dump(description.ref());
257f034231aSEd Maste return true;
258f034231aSEd Maste }
259