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
18using namespace lldb;
19using namespace lldb_private;
20
21
22SBModuleSpec::SBModuleSpec () :
23    m_opaque_ap (new lldb_private::ModuleSpec())
24{
25}
26
27SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) :
28    m_opaque_ap (new lldb_private::ModuleSpec(*rhs.m_opaque_ap))
29{
30}
31
32const SBModuleSpec &
33SBModuleSpec::operator = (const SBModuleSpec &rhs)
34{
35    if (this != &rhs)
36        *m_opaque_ap = *(rhs.m_opaque_ap);
37    return *this;
38}
39
40SBModuleSpec::~SBModuleSpec ()
41{
42}
43
44bool
45SBModuleSpec::IsValid () const
46{
47    return *m_opaque_ap;
48}
49
50void
51SBModuleSpec::Clear()
52{
53    m_opaque_ap->Clear();
54}
55
56SBFileSpec
57SBModuleSpec::GetFileSpec ()
58{
59    SBFileSpec sb_spec(m_opaque_ap->GetFileSpec());
60    return sb_spec;
61}
62
63void
64SBModuleSpec::SetFileSpec (const lldb::SBFileSpec &sb_spec)
65{
66    m_opaque_ap->GetFileSpec() = *sb_spec;
67}
68
69lldb::SBFileSpec
70SBModuleSpec::GetPlatformFileSpec ()
71{
72    return SBFileSpec(m_opaque_ap->GetPlatformFileSpec());
73}
74
75void
76SBModuleSpec::SetPlatformFileSpec (const lldb::SBFileSpec &sb_spec)
77{
78    m_opaque_ap->GetPlatformFileSpec() = *sb_spec;
79}
80
81lldb::SBFileSpec
82SBModuleSpec::GetSymbolFileSpec ()
83{
84    return SBFileSpec(m_opaque_ap->GetSymbolFileSpec());
85}
86
87void
88SBModuleSpec::SetSymbolFileSpec (const lldb::SBFileSpec &sb_spec)
89{
90    m_opaque_ap->GetSymbolFileSpec() = *sb_spec;
91}
92
93const char *
94SBModuleSpec::GetObjectName ()
95{
96    return m_opaque_ap->GetObjectName().GetCString();
97}
98
99void
100SBModuleSpec::SetObjectName (const char *name)
101{
102    m_opaque_ap->GetObjectName().SetCString(name);
103}
104
105const char *
106SBModuleSpec::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
116void
117SBModuleSpec::SetTriple (const char *triple)
118{
119    m_opaque_ap->GetArchitecture().SetTriple(triple);
120}
121
122const uint8_t *
123SBModuleSpec::GetUUIDBytes ()
124{
125    return (const uint8_t *)m_opaque_ap->GetUUID().GetBytes();
126}
127
128size_t
129SBModuleSpec::GetUUIDLength ()
130{
131    return m_opaque_ap->GetUUID().GetByteSize();
132}
133
134bool
135SBModuleSpec::SetUUIDBytes (const uint8_t *uuid, size_t uuid_len)
136{
137    return m_opaque_ap->GetUUID().SetBytes(uuid, uuid_len);
138}
139
140bool
141SBModuleSpec::GetDescription (lldb::SBStream &description)
142{
143    m_opaque_ap->Dump (description.ref());
144    return true;
145}
146
147SBModuleSpecList::SBModuleSpecList() :
148    m_opaque_ap(new ModuleSpecList())
149{
150
151}
152
153SBModuleSpecList::SBModuleSpecList (const SBModuleSpecList &rhs) :
154    m_opaque_ap(new ModuleSpecList(*rhs.m_opaque_ap))
155{
156
157}
158
159SBModuleSpecList &
160SBModuleSpecList::operator = (const SBModuleSpecList &rhs)
161{
162    if (this != &rhs)
163        *m_opaque_ap = *rhs.m_opaque_ap;
164    return *this;
165}
166
167SBModuleSpecList::~SBModuleSpecList()
168{
169
170}
171
172SBModuleSpecList
173SBModuleSpecList::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
182void
183SBModuleSpecList::Append (const SBModuleSpec &spec)
184{
185    m_opaque_ap->Append (*spec.m_opaque_ap);
186}
187
188void
189SBModuleSpecList::Append (const SBModuleSpecList &spec_list)
190{
191    m_opaque_ap->Append (*spec_list.m_opaque_ap);
192}
193
194size_t
195SBModuleSpecList::GetSize()
196{
197    return m_opaque_ap->GetSize();
198}
199
200SBModuleSpec
201SBModuleSpecList::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
208SBModuleSpec
209SBModuleSpecList::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
216SBModuleSpecList
217SBModuleSpecList::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
225bool
226SBModuleSpecList::GetDescription (lldb::SBStream &description)
227{
228    m_opaque_ap->Dump (description.ref());
229    return true;
230}
231