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()22 SBModuleSpec::SBModuleSpec () :
23     m_opaque_ap (new lldb_private::ModuleSpec())
24 {
25 }
26 
SBModuleSpec(const SBModuleSpec & rhs)27 SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) :
28     m_opaque_ap (new lldb_private::ModuleSpec(*rhs.m_opaque_ap))
29 {
30 }
31 
32 const SBModuleSpec &
operator =(const SBModuleSpec & rhs)33 SBModuleSpec::operator = (const SBModuleSpec &rhs)
34 {
35     if (this != &rhs)
36         *m_opaque_ap = *(rhs.m_opaque_ap);
37     return *this;
38 }
39 
~SBModuleSpec()40 SBModuleSpec::~SBModuleSpec ()
41 {
42 }
43 
44 bool
IsValid() const45 SBModuleSpec::IsValid () const
46 {
47     return *m_opaque_ap;
48 }
49 
50 void
Clear()51 SBModuleSpec::Clear()
52 {
53     m_opaque_ap->Clear();
54 }
55 
56 SBFileSpec
GetFileSpec()57 SBModuleSpec::GetFileSpec ()
58 {
59     SBFileSpec sb_spec(m_opaque_ap->GetFileSpec());
60     return sb_spec;
61 }
62 
63 void
SetFileSpec(const lldb::SBFileSpec & sb_spec)64 SBModuleSpec::SetFileSpec (const lldb::SBFileSpec &sb_spec)
65 {
66     m_opaque_ap->GetFileSpec() = *sb_spec;
67 }
68 
69 lldb::SBFileSpec
GetPlatformFileSpec()70 SBModuleSpec::GetPlatformFileSpec ()
71 {
72     return SBFileSpec(m_opaque_ap->GetPlatformFileSpec());
73 }
74 
75 void
SetPlatformFileSpec(const lldb::SBFileSpec & sb_spec)76 SBModuleSpec::SetPlatformFileSpec (const lldb::SBFileSpec &sb_spec)
77 {
78     m_opaque_ap->GetPlatformFileSpec() = *sb_spec;
79 }
80 
81 lldb::SBFileSpec
GetSymbolFileSpec()82 SBModuleSpec::GetSymbolFileSpec ()
83 {
84     return SBFileSpec(m_opaque_ap->GetSymbolFileSpec());
85 }
86 
87 void
SetSymbolFileSpec(const lldb::SBFileSpec & sb_spec)88 SBModuleSpec::SetSymbolFileSpec (const lldb::SBFileSpec &sb_spec)
89 {
90     m_opaque_ap->GetSymbolFileSpec() = *sb_spec;
91 }
92 
93 const char *
GetObjectName()94 SBModuleSpec::GetObjectName ()
95 {
96     return m_opaque_ap->GetObjectName().GetCString();
97 }
98 
99 void
SetObjectName(const char * name)100 SBModuleSpec::SetObjectName (const char *name)
101 {
102     m_opaque_ap->GetObjectName().SetCString(name);
103 }
104 
105 const char *
GetTriple()106 SBModuleSpec::GetTriple ()
107 {
108     std::string triple (m_opaque_ap->GetArchitecture().GetTriple().str());
109     // Unique the string so we don't run into ownership issues since
110     // the const strings put the string into the string pool once and
111     // the strings never comes out
112     ConstString const_triple (triple.c_str());
113     return const_triple.GetCString();
114 }
115 
116 void
SetTriple(const char * triple)117 SBModuleSpec::SetTriple (const char *triple)
118 {
119     m_opaque_ap->GetArchitecture().SetTriple(triple);
120 }
121 
122 const uint8_t *
GetUUIDBytes()123 SBModuleSpec::GetUUIDBytes ()
124 {
125     return (const uint8_t *)m_opaque_ap->GetUUID().GetBytes();
126 }
127 
128 size_t
GetUUIDLength()129 SBModuleSpec::GetUUIDLength ()
130 {
131     return m_opaque_ap->GetUUID().GetByteSize();
132 }
133 
134 bool
SetUUIDBytes(const uint8_t * uuid,size_t uuid_len)135 SBModuleSpec::SetUUIDBytes (const uint8_t *uuid, size_t uuid_len)
136 {
137     return m_opaque_ap->GetUUID().SetBytes(uuid, uuid_len);
138 }
139 
140 bool
GetDescription(lldb::SBStream & description)141 SBModuleSpec::GetDescription (lldb::SBStream &description)
142 {
143     m_opaque_ap->Dump (description.ref());
144     return true;
145 }
146 
SBModuleSpecList()147 SBModuleSpecList::SBModuleSpecList() :
148     m_opaque_ap(new ModuleSpecList())
149 {
150 
151 }
152 
SBModuleSpecList(const SBModuleSpecList & rhs)153 SBModuleSpecList::SBModuleSpecList (const SBModuleSpecList &rhs) :
154     m_opaque_ap(new ModuleSpecList(*rhs.m_opaque_ap))
155 {
156 
157 }
158 
159 SBModuleSpecList &
operator =(const SBModuleSpecList & rhs)160 SBModuleSpecList::operator = (const SBModuleSpecList &rhs)
161 {
162     if (this != &rhs)
163         *m_opaque_ap = *rhs.m_opaque_ap;
164     return *this;
165 }
166 
~SBModuleSpecList()167 SBModuleSpecList::~SBModuleSpecList()
168 {
169 
170 }
171 
172 SBModuleSpecList
GetModuleSpecifications(const char * path)173 SBModuleSpecList::GetModuleSpecifications (const char *path)
174 {
175     SBModuleSpecList specs;
176     FileSpec file_spec(path, true);
177     Host::ResolveExecutableInBundle(file_spec);
178     ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_ap);
179     return specs;
180 }
181 
182 void
Append(const SBModuleSpec & spec)183 SBModuleSpecList::Append (const SBModuleSpec &spec)
184 {
185     m_opaque_ap->Append (*spec.m_opaque_ap);
186 }
187 
188 void
Append(const SBModuleSpecList & spec_list)189 SBModuleSpecList::Append (const SBModuleSpecList &spec_list)
190 {
191     m_opaque_ap->Append (*spec_list.m_opaque_ap);
192 }
193 
194 size_t
GetSize()195 SBModuleSpecList::GetSize()
196 {
197     return m_opaque_ap->GetSize();
198 }
199 
200 SBModuleSpec
GetSpecAtIndex(size_t i)201 SBModuleSpecList::GetSpecAtIndex (size_t i)
202 {
203     SBModuleSpec sb_module_spec;
204     m_opaque_ap->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_ap);
205     return sb_module_spec;
206 }
207 
208 SBModuleSpec
FindFirstMatchingSpec(const SBModuleSpec & match_spec)209 SBModuleSpecList::FindFirstMatchingSpec (const SBModuleSpec &match_spec)
210 {
211     SBModuleSpec sb_module_spec;
212     m_opaque_ap->FindMatchingModuleSpec(*match_spec.m_opaque_ap, *sb_module_spec.m_opaque_ap);
213     return sb_module_spec;
214 }
215 
216 SBModuleSpecList
FindMatchingSpecs(const SBModuleSpec & match_spec)217 SBModuleSpecList::FindMatchingSpecs (const SBModuleSpec &match_spec)
218 {
219     SBModuleSpecList specs;
220     m_opaque_ap->FindMatchingModuleSpecs(*match_spec.m_opaque_ap, *specs.m_opaque_ap);
221     return specs;
222 
223 }
224 
225 bool
GetDescription(lldb::SBStream & description)226 SBModuleSpecList::GetDescription (lldb::SBStream &description)
227 {
228     m_opaque_ap->Dump (description.ref());
229     return true;
230 }
231