xref: /llvm-project/lldb/source/API/SBModuleSpec.cpp (revision bd4bf82a48c2b5b632766593916f8d7ea98c9e0a)
1 //===-- SBModuleSpec.cpp ----------------------------------------*- C++ -*-===//
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/Stream.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
21 SBModuleSpec::SBModuleSpec() : m_opaque_up(new lldb_private::ModuleSpec()) {}
22 
23 SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) : m_opaque_up() {
24   m_opaque_up = clone(rhs.m_opaque_up);
25 }
26 
27 const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) {
28   if (this != &rhs)
29     m_opaque_up = clone(rhs.m_opaque_up);
30   return *this;
31 }
32 
33 SBModuleSpec::~SBModuleSpec() {}
34 
35 bool SBModuleSpec::IsValid() const { return m_opaque_up->operator bool(); }
36 
37 void SBModuleSpec::Clear() { m_opaque_up->Clear(); }
38 
39 SBFileSpec SBModuleSpec::GetFileSpec() {
40   SBFileSpec sb_spec(m_opaque_up->GetFileSpec());
41   return sb_spec;
42 }
43 
44 void SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) {
45   m_opaque_up->GetFileSpec() = *sb_spec;
46 }
47 
48 lldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() {
49   return SBFileSpec(m_opaque_up->GetPlatformFileSpec());
50 }
51 
52 void SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) {
53   m_opaque_up->GetPlatformFileSpec() = *sb_spec;
54 }
55 
56 lldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() {
57   return SBFileSpec(m_opaque_up->GetSymbolFileSpec());
58 }
59 
60 void SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) {
61   m_opaque_up->GetSymbolFileSpec() = *sb_spec;
62 }
63 
64 const char *SBModuleSpec::GetObjectName() {
65   return m_opaque_up->GetObjectName().GetCString();
66 }
67 
68 void SBModuleSpec::SetObjectName(const char *name) {
69   m_opaque_up->GetObjectName().SetCString(name);
70 }
71 
72 const char *SBModuleSpec::GetTriple() {
73   std::string triple(m_opaque_up->GetArchitecture().GetTriple().str());
74   // Unique the string so we don't run into ownership issues since the const
75   // strings put the string into the string pool once and the strings never
76   // comes out
77   ConstString const_triple(triple.c_str());
78   return const_triple.GetCString();
79 }
80 
81 void SBModuleSpec::SetTriple(const char *triple) {
82   m_opaque_up->GetArchitecture().SetTriple(triple);
83 }
84 
85 const uint8_t *SBModuleSpec::GetUUIDBytes() {
86   return m_opaque_up->GetUUID().GetBytes().data();
87 }
88 
89 size_t SBModuleSpec::GetUUIDLength() {
90   return m_opaque_up->GetUUID().GetBytes().size();
91 }
92 
93 bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) {
94   m_opaque_up->GetUUID() = UUID::fromOptionalData(uuid, uuid_len);
95   return m_opaque_up->GetUUID().IsValid();
96 }
97 
98 bool SBModuleSpec::GetDescription(lldb::SBStream &description) {
99   m_opaque_up->Dump(description.ref());
100   return true;
101 }
102 
103 SBModuleSpecList::SBModuleSpecList() : m_opaque_up(new ModuleSpecList()) {}
104 
105 SBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs)
106     : m_opaque_up(new ModuleSpecList(*rhs.m_opaque_up)) {}
107 
108 SBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) {
109   if (this != &rhs)
110     *m_opaque_up = *rhs.m_opaque_up;
111   return *this;
112 }
113 
114 SBModuleSpecList::~SBModuleSpecList() {}
115 
116 SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) {
117   SBModuleSpecList specs;
118   FileSpec file_spec(path);
119   FileSystem::Instance().Resolve(file_spec);
120   Host::ResolveExecutableInBundle(file_spec);
121   ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_up);
122   return specs;
123 }
124 
125 void SBModuleSpecList::Append(const SBModuleSpec &spec) {
126   m_opaque_up->Append(*spec.m_opaque_up);
127 }
128 
129 void SBModuleSpecList::Append(const SBModuleSpecList &spec_list) {
130   m_opaque_up->Append(*spec_list.m_opaque_up);
131 }
132 
133 size_t SBModuleSpecList::GetSize() { return m_opaque_up->GetSize(); }
134 
135 SBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) {
136   SBModuleSpec sb_module_spec;
137   m_opaque_up->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_up);
138   return sb_module_spec;
139 }
140 
141 SBModuleSpec
142 SBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) {
143   SBModuleSpec sb_module_spec;
144   m_opaque_up->FindMatchingModuleSpec(*match_spec.m_opaque_up,
145                                       *sb_module_spec.m_opaque_up);
146   return sb_module_spec;
147 }
148 
149 SBModuleSpecList
150 SBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) {
151   SBModuleSpecList specs;
152   m_opaque_up->FindMatchingModuleSpecs(*match_spec.m_opaque_up,
153                                        *specs.m_opaque_up);
154   return specs;
155 }
156 
157 bool SBModuleSpecList::GetDescription(lldb::SBStream &description) {
158   m_opaque_up->Dump(description.ref());
159   return true;
160 }
161