1254721Semaste//===-- SBModuleSpec.cpp ----------------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#include "lldb/API/SBModuleSpec.h"
11254721Semaste#include "lldb/API/SBStream.h"
12254721Semaste#include "lldb/Core/Module.h"
13254721Semaste#include "lldb/Core/ModuleSpec.h"
14254721Semaste#include "lldb/Core/Stream.h"
15254721Semaste#include "lldb/Host/Host.h"
16254721Semaste#include "lldb/Symbol/ObjectFile.h"
17254721Semaste
18254721Semasteusing namespace lldb;
19254721Semasteusing namespace lldb_private;
20254721Semaste
21254721Semaste
22254721SemasteSBModuleSpec::SBModuleSpec () :
23254721Semaste    m_opaque_ap (new lldb_private::ModuleSpec())
24254721Semaste{
25254721Semaste}
26254721Semaste
27254721SemasteSBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) :
28254721Semaste    m_opaque_ap (new lldb_private::ModuleSpec(*rhs.m_opaque_ap))
29254721Semaste{
30254721Semaste}
31254721Semaste
32254721Semasteconst SBModuleSpec &
33254721SemasteSBModuleSpec::operator = (const SBModuleSpec &rhs)
34254721Semaste{
35254721Semaste    if (this != &rhs)
36254721Semaste        *m_opaque_ap = *(rhs.m_opaque_ap);
37254721Semaste    return *this;
38254721Semaste}
39254721Semaste
40254721SemasteSBModuleSpec::~SBModuleSpec ()
41254721Semaste{
42254721Semaste}
43254721Semaste
44254721Semastebool
45254721SemasteSBModuleSpec::IsValid () const
46254721Semaste{
47263363Semaste    return m_opaque_ap->operator bool();
48254721Semaste}
49254721Semaste
50254721Semastevoid
51254721SemasteSBModuleSpec::Clear()
52254721Semaste{
53254721Semaste    m_opaque_ap->Clear();
54254721Semaste}
55254721Semaste
56254721SemasteSBFileSpec
57254721SemasteSBModuleSpec::GetFileSpec ()
58254721Semaste{
59254721Semaste    SBFileSpec sb_spec(m_opaque_ap->GetFileSpec());
60254721Semaste    return sb_spec;
61254721Semaste}
62254721Semaste
63254721Semastevoid
64254721SemasteSBModuleSpec::SetFileSpec (const lldb::SBFileSpec &sb_spec)
65254721Semaste{
66254721Semaste    m_opaque_ap->GetFileSpec() = *sb_spec;
67254721Semaste}
68254721Semaste
69254721Semastelldb::SBFileSpec
70254721SemasteSBModuleSpec::GetPlatformFileSpec ()
71254721Semaste{
72254721Semaste    return SBFileSpec(m_opaque_ap->GetPlatformFileSpec());
73254721Semaste}
74254721Semaste
75254721Semastevoid
76254721SemasteSBModuleSpec::SetPlatformFileSpec (const lldb::SBFileSpec &sb_spec)
77254721Semaste{
78254721Semaste    m_opaque_ap->GetPlatformFileSpec() = *sb_spec;
79254721Semaste}
80254721Semaste
81254721Semastelldb::SBFileSpec
82254721SemasteSBModuleSpec::GetSymbolFileSpec ()
83254721Semaste{
84254721Semaste    return SBFileSpec(m_opaque_ap->GetSymbolFileSpec());
85254721Semaste}
86254721Semaste
87254721Semastevoid
88254721SemasteSBModuleSpec::SetSymbolFileSpec (const lldb::SBFileSpec &sb_spec)
89254721Semaste{
90254721Semaste    m_opaque_ap->GetSymbolFileSpec() = *sb_spec;
91254721Semaste}
92254721Semaste
93254721Semasteconst char *
94254721SemasteSBModuleSpec::GetObjectName ()
95254721Semaste{
96254721Semaste    return m_opaque_ap->GetObjectName().GetCString();
97254721Semaste}
98254721Semaste
99254721Semastevoid
100254721SemasteSBModuleSpec::SetObjectName (const char *name)
101254721Semaste{
102254721Semaste    m_opaque_ap->GetObjectName().SetCString(name);
103254721Semaste}
104254721Semaste
105254721Semasteconst char *
106254721SemasteSBModuleSpec::GetTriple ()
107254721Semaste{
108254721Semaste    std::string triple (m_opaque_ap->GetArchitecture().GetTriple().str());
109254721Semaste    // Unique the string so we don't run into ownership issues since
110254721Semaste    // the const strings put the string into the string pool once and
111254721Semaste    // the strings never comes out
112254721Semaste    ConstString const_triple (triple.c_str());
113254721Semaste    return const_triple.GetCString();
114254721Semaste}
115254721Semaste
116254721Semastevoid
117254721SemasteSBModuleSpec::SetTriple (const char *triple)
118254721Semaste{
119254721Semaste    m_opaque_ap->GetArchitecture().SetTriple(triple);
120254721Semaste}
121254721Semaste
122254721Semasteconst uint8_t *
123254721SemasteSBModuleSpec::GetUUIDBytes ()
124254721Semaste{
125254721Semaste    return (const uint8_t *)m_opaque_ap->GetUUID().GetBytes();
126254721Semaste}
127254721Semaste
128254721Semastesize_t
129254721SemasteSBModuleSpec::GetUUIDLength ()
130254721Semaste{
131254721Semaste    return m_opaque_ap->GetUUID().GetByteSize();
132254721Semaste}
133254721Semaste
134254721Semastebool
135254721SemasteSBModuleSpec::SetUUIDBytes (const uint8_t *uuid, size_t uuid_len)
136254721Semaste{
137254721Semaste    return m_opaque_ap->GetUUID().SetBytes(uuid, uuid_len);
138254721Semaste}
139254721Semaste
140254721Semastebool
141254721SemasteSBModuleSpec::GetDescription (lldb::SBStream &description)
142254721Semaste{
143254721Semaste    m_opaque_ap->Dump (description.ref());
144254721Semaste    return true;
145254721Semaste}
146254721Semaste
147254721SemasteSBModuleSpecList::SBModuleSpecList() :
148254721Semaste    m_opaque_ap(new ModuleSpecList())
149254721Semaste{
150254721Semaste
151254721Semaste}
152254721Semaste
153254721SemasteSBModuleSpecList::SBModuleSpecList (const SBModuleSpecList &rhs) :
154254721Semaste    m_opaque_ap(new ModuleSpecList(*rhs.m_opaque_ap))
155254721Semaste{
156254721Semaste
157254721Semaste}
158254721Semaste
159254721SemasteSBModuleSpecList &
160254721SemasteSBModuleSpecList::operator = (const SBModuleSpecList &rhs)
161254721Semaste{
162254721Semaste    if (this != &rhs)
163254721Semaste        *m_opaque_ap = *rhs.m_opaque_ap;
164254721Semaste    return *this;
165254721Semaste}
166254721Semaste
167254721SemasteSBModuleSpecList::~SBModuleSpecList()
168254721Semaste{
169254721Semaste
170254721Semaste}
171254721Semaste
172254721SemasteSBModuleSpecList
173254721SemasteSBModuleSpecList::GetModuleSpecifications (const char *path)
174254721Semaste{
175254721Semaste    SBModuleSpecList specs;
176254721Semaste    FileSpec file_spec(path, true);
177254721Semaste    Host::ResolveExecutableInBundle(file_spec);
178254721Semaste    ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_ap);
179254721Semaste    return specs;
180254721Semaste}
181254721Semaste
182254721Semastevoid
183254721SemasteSBModuleSpecList::Append (const SBModuleSpec &spec)
184254721Semaste{
185254721Semaste    m_opaque_ap->Append (*spec.m_opaque_ap);
186254721Semaste}
187254721Semaste
188254721Semastevoid
189254721SemasteSBModuleSpecList::Append (const SBModuleSpecList &spec_list)
190254721Semaste{
191254721Semaste    m_opaque_ap->Append (*spec_list.m_opaque_ap);
192254721Semaste}
193254721Semaste
194254721Semastesize_t
195254721SemasteSBModuleSpecList::GetSize()
196254721Semaste{
197254721Semaste    return m_opaque_ap->GetSize();
198254721Semaste}
199254721Semaste
200254721SemasteSBModuleSpec
201254721SemasteSBModuleSpecList::GetSpecAtIndex (size_t i)
202254721Semaste{
203254721Semaste    SBModuleSpec sb_module_spec;
204254721Semaste    m_opaque_ap->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_ap);
205254721Semaste    return sb_module_spec;
206254721Semaste}
207254721Semaste
208254721SemasteSBModuleSpec
209254721SemasteSBModuleSpecList::FindFirstMatchingSpec (const SBModuleSpec &match_spec)
210254721Semaste{
211254721Semaste    SBModuleSpec sb_module_spec;
212254721Semaste    m_opaque_ap->FindMatchingModuleSpec(*match_spec.m_opaque_ap, *sb_module_spec.m_opaque_ap);
213254721Semaste    return sb_module_spec;
214254721Semaste}
215254721Semaste
216254721SemasteSBModuleSpecList
217254721SemasteSBModuleSpecList::FindMatchingSpecs (const SBModuleSpec &match_spec)
218254721Semaste{
219254721Semaste    SBModuleSpecList specs;
220254721Semaste    m_opaque_ap->FindMatchingModuleSpecs(*match_spec.m_opaque_ap, *specs.m_opaque_ap);
221254721Semaste    return specs;
222254721Semaste
223254721Semaste}
224254721Semaste
225254721Semastebool
226254721SemasteSBModuleSpecList::GetDescription (lldb::SBStream &description)
227254721Semaste{
228254721Semaste    m_opaque_ap->Dump (description.ref());
229254721Semaste    return true;
230254721Semaste}
231