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