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