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