1ac7ddfbfSEd Maste //===-- SBModuleSpec.cpp ----------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10ac7ddfbfSEd Maste #include "lldb/API/SBModuleSpec.h"
11ac7ddfbfSEd Maste #include "lldb/API/SBStream.h"
12ac7ddfbfSEd Maste #include "lldb/Core/Module.h"
13ac7ddfbfSEd Maste #include "lldb/Core/ModuleSpec.h"
14ac7ddfbfSEd Maste #include "lldb/Host/Host.h"
15ac7ddfbfSEd Maste #include "lldb/Symbol/ObjectFile.h"
16f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
17ac7ddfbfSEd Maste 
18ac7ddfbfSEd Maste using namespace lldb;
19ac7ddfbfSEd Maste using namespace lldb_private;
20ac7ddfbfSEd Maste 
21435933ddSDimitry Andric SBModuleSpec::SBModuleSpec() : m_opaque_ap(new lldb_private::ModuleSpec()) {}
22ac7ddfbfSEd Maste 
23435933ddSDimitry Andric SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs)
24435933ddSDimitry Andric     : m_opaque_ap(new lldb_private::ModuleSpec(*rhs.m_opaque_ap)) {}
25ac7ddfbfSEd Maste 
26435933ddSDimitry Andric const SBModuleSpec &SBModuleSpec::operator=(const SBModuleSpec &rhs) {
27ac7ddfbfSEd Maste   if (this != &rhs)
28ac7ddfbfSEd Maste     *m_opaque_ap = *(rhs.m_opaque_ap);
29ac7ddfbfSEd Maste   return *this;
30ac7ddfbfSEd Maste }
31ac7ddfbfSEd Maste 
32435933ddSDimitry Andric SBModuleSpec::~SBModuleSpec() {}
33ac7ddfbfSEd Maste 
34435933ddSDimitry Andric bool SBModuleSpec::IsValid() const { return m_opaque_ap->operator bool(); }
35ac7ddfbfSEd Maste 
36435933ddSDimitry Andric void SBModuleSpec::Clear() { m_opaque_ap->Clear(); }
37ac7ddfbfSEd Maste 
38435933ddSDimitry Andric SBFileSpec SBModuleSpec::GetFileSpec() {
39ac7ddfbfSEd Maste   SBFileSpec sb_spec(m_opaque_ap->GetFileSpec());
40ac7ddfbfSEd Maste   return sb_spec;
41ac7ddfbfSEd Maste }
42ac7ddfbfSEd Maste 
43435933ddSDimitry Andric void SBModuleSpec::SetFileSpec(const lldb::SBFileSpec &sb_spec) {
44ac7ddfbfSEd Maste   m_opaque_ap->GetFileSpec() = *sb_spec;
45ac7ddfbfSEd Maste }
46ac7ddfbfSEd Maste 
47435933ddSDimitry Andric lldb::SBFileSpec SBModuleSpec::GetPlatformFileSpec() {
48ac7ddfbfSEd Maste   return SBFileSpec(m_opaque_ap->GetPlatformFileSpec());
49ac7ddfbfSEd Maste }
50ac7ddfbfSEd Maste 
51435933ddSDimitry Andric void SBModuleSpec::SetPlatformFileSpec(const lldb::SBFileSpec &sb_spec) {
52ac7ddfbfSEd Maste   m_opaque_ap->GetPlatformFileSpec() = *sb_spec;
53ac7ddfbfSEd Maste }
54ac7ddfbfSEd Maste 
55435933ddSDimitry Andric lldb::SBFileSpec SBModuleSpec::GetSymbolFileSpec() {
56ac7ddfbfSEd Maste   return SBFileSpec(m_opaque_ap->GetSymbolFileSpec());
57ac7ddfbfSEd Maste }
58ac7ddfbfSEd Maste 
59435933ddSDimitry Andric void SBModuleSpec::SetSymbolFileSpec(const lldb::SBFileSpec &sb_spec) {
60ac7ddfbfSEd Maste   m_opaque_ap->GetSymbolFileSpec() = *sb_spec;
61ac7ddfbfSEd Maste }
62ac7ddfbfSEd Maste 
63435933ddSDimitry Andric const char *SBModuleSpec::GetObjectName() {
64ac7ddfbfSEd Maste   return m_opaque_ap->GetObjectName().GetCString();
65ac7ddfbfSEd Maste }
66ac7ddfbfSEd Maste 
67435933ddSDimitry Andric void SBModuleSpec::SetObjectName(const char *name) {
68ac7ddfbfSEd Maste   m_opaque_ap->GetObjectName().SetCString(name);
69ac7ddfbfSEd Maste }
70ac7ddfbfSEd Maste 
71435933ddSDimitry Andric const char *SBModuleSpec::GetTriple() {
72ac7ddfbfSEd Maste   std::string triple(m_opaque_ap->GetArchitecture().GetTriple().str());
73ac7ddfbfSEd Maste   // Unique the string so we don't run into ownership issues since
74ac7ddfbfSEd Maste   // the const strings put the string into the string pool once and
75ac7ddfbfSEd Maste   // the strings never comes out
76ac7ddfbfSEd Maste   ConstString const_triple(triple.c_str());
77ac7ddfbfSEd Maste   return const_triple.GetCString();
78ac7ddfbfSEd Maste }
79ac7ddfbfSEd Maste 
80435933ddSDimitry Andric void SBModuleSpec::SetTriple(const char *triple) {
81ac7ddfbfSEd Maste   m_opaque_ap->GetArchitecture().SetTriple(triple);
82ac7ddfbfSEd Maste }
83ac7ddfbfSEd Maste 
84435933ddSDimitry Andric const uint8_t *SBModuleSpec::GetUUIDBytes() {
85ac7ddfbfSEd Maste   return (const uint8_t *)m_opaque_ap->GetUUID().GetBytes();
86ac7ddfbfSEd Maste }
87ac7ddfbfSEd Maste 
88435933ddSDimitry Andric size_t SBModuleSpec::GetUUIDLength() {
89ac7ddfbfSEd Maste   return m_opaque_ap->GetUUID().GetByteSize();
90ac7ddfbfSEd Maste }
91ac7ddfbfSEd Maste 
92435933ddSDimitry Andric bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) {
93ac7ddfbfSEd Maste   return m_opaque_ap->GetUUID().SetBytes(uuid, uuid_len);
94ac7ddfbfSEd Maste }
95ac7ddfbfSEd Maste 
96435933ddSDimitry Andric bool SBModuleSpec::GetDescription(lldb::SBStream &description) {
97ac7ddfbfSEd Maste   m_opaque_ap->Dump(description.ref());
98ac7ddfbfSEd Maste   return true;
99ac7ddfbfSEd Maste }
100ac7ddfbfSEd Maste 
101435933ddSDimitry Andric SBModuleSpecList::SBModuleSpecList() : m_opaque_ap(new ModuleSpecList()) {}
102ac7ddfbfSEd Maste 
103435933ddSDimitry Andric SBModuleSpecList::SBModuleSpecList(const SBModuleSpecList &rhs)
104435933ddSDimitry Andric     : m_opaque_ap(new ModuleSpecList(*rhs.m_opaque_ap)) {}
105ac7ddfbfSEd Maste 
106435933ddSDimitry Andric SBModuleSpecList &SBModuleSpecList::operator=(const SBModuleSpecList &rhs) {
107ac7ddfbfSEd Maste   if (this != &rhs)
108ac7ddfbfSEd Maste     *m_opaque_ap = *rhs.m_opaque_ap;
109ac7ddfbfSEd Maste   return *this;
110ac7ddfbfSEd Maste }
111ac7ddfbfSEd Maste 
112435933ddSDimitry Andric SBModuleSpecList::~SBModuleSpecList() {}
113ac7ddfbfSEd Maste 
114435933ddSDimitry Andric SBModuleSpecList SBModuleSpecList::GetModuleSpecifications(const char *path) {
115ac7ddfbfSEd Maste   SBModuleSpecList specs;
116ac7ddfbfSEd Maste   FileSpec file_spec(path, true);
117ac7ddfbfSEd Maste   Host::ResolveExecutableInBundle(file_spec);
118ac7ddfbfSEd Maste   ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_ap);
119ac7ddfbfSEd Maste   return specs;
120ac7ddfbfSEd Maste }
121ac7ddfbfSEd Maste 
122435933ddSDimitry Andric void SBModuleSpecList::Append(const SBModuleSpec &spec) {
123ac7ddfbfSEd Maste   m_opaque_ap->Append(*spec.m_opaque_ap);
124ac7ddfbfSEd Maste }
125ac7ddfbfSEd Maste 
126435933ddSDimitry Andric void SBModuleSpecList::Append(const SBModuleSpecList &spec_list) {
127ac7ddfbfSEd Maste   m_opaque_ap->Append(*spec_list.m_opaque_ap);
128ac7ddfbfSEd Maste }
129ac7ddfbfSEd Maste 
130435933ddSDimitry Andric size_t SBModuleSpecList::GetSize() { return m_opaque_ap->GetSize(); }
131ac7ddfbfSEd Maste 
132435933ddSDimitry Andric SBModuleSpec SBModuleSpecList::GetSpecAtIndex(size_t i) {
133ac7ddfbfSEd Maste   SBModuleSpec sb_module_spec;
134ac7ddfbfSEd Maste   m_opaque_ap->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_ap);
135ac7ddfbfSEd Maste   return sb_module_spec;
136ac7ddfbfSEd Maste }
137ac7ddfbfSEd Maste 
138ac7ddfbfSEd Maste SBModuleSpec
139435933ddSDimitry Andric SBModuleSpecList::FindFirstMatchingSpec(const SBModuleSpec &match_spec) {
140ac7ddfbfSEd Maste   SBModuleSpec sb_module_spec;
141435933ddSDimitry Andric   m_opaque_ap->FindMatchingModuleSpec(*match_spec.m_opaque_ap,
142435933ddSDimitry Andric                                       *sb_module_spec.m_opaque_ap);
143ac7ddfbfSEd Maste   return sb_module_spec;
144ac7ddfbfSEd Maste }
145ac7ddfbfSEd Maste 
146ac7ddfbfSEd Maste SBModuleSpecList
147435933ddSDimitry Andric SBModuleSpecList::FindMatchingSpecs(const SBModuleSpec &match_spec) {
148ac7ddfbfSEd Maste   SBModuleSpecList specs;
149435933ddSDimitry Andric   m_opaque_ap->FindMatchingModuleSpecs(*match_spec.m_opaque_ap,
150435933ddSDimitry Andric                                        *specs.m_opaque_ap);
151ac7ddfbfSEd Maste   return specs;
152ac7ddfbfSEd Maste }
153ac7ddfbfSEd Maste 
154435933ddSDimitry Andric bool SBModuleSpecList::GetDescription(lldb::SBStream &description) {
155ac7ddfbfSEd Maste   m_opaque_ap->Dump(description.ref());
156ac7ddfbfSEd Maste   return true;
157ac7ddfbfSEd Maste }
158