LLDB  mainline
SBModuleSpec.cpp
Go to the documentation of this file.
1 //===-- SBModuleSpec.cpp --------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "Utils.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Core/Module.h"
13 #include "lldb/Core/ModuleSpec.h"
14 #include "lldb/Host/Host.h"
15 #include "lldb/Symbol/ObjectFile.h"
17 #include "lldb/Utility/Stream.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
23  LLDB_INSTRUMENT_VA(this);
24 }
25 
27  LLDB_INSTRUMENT_VA(this, rhs);
28 
30 }
31 
33  LLDB_INSTRUMENT_VA(this, rhs);
34 
35  if (this != &rhs)
37  return *this;
38 }
39 
40 SBModuleSpec::~SBModuleSpec() = default;
41 
42 bool SBModuleSpec::IsValid() const {
43  LLDB_INSTRUMENT_VA(this);
44  return this->operator bool();
45 }
46 SBModuleSpec::operator bool() const {
47  LLDB_INSTRUMENT_VA(this);
48 
49  return m_opaque_up->operator bool();
50 }
51 
53  LLDB_INSTRUMENT_VA(this);
54 
55  m_opaque_up->Clear();
56 }
57 
59  LLDB_INSTRUMENT_VA(this);
60 
61  SBFileSpec sb_spec(m_opaque_up->GetFileSpec());
62  return sb_spec;
63 }
64 
66  LLDB_INSTRUMENT_VA(this, sb_spec);
67 
68  m_opaque_up->GetFileSpec() = *sb_spec;
69 }
70 
72  LLDB_INSTRUMENT_VA(this);
73 
74  return SBFileSpec(m_opaque_up->GetPlatformFileSpec());
75 }
76 
78  LLDB_INSTRUMENT_VA(this, sb_spec);
79 
80  m_opaque_up->GetPlatformFileSpec() = *sb_spec;
81 }
82 
84  LLDB_INSTRUMENT_VA(this);
85 
86  return SBFileSpec(m_opaque_up->GetSymbolFileSpec());
87 }
88 
90  LLDB_INSTRUMENT_VA(this, sb_spec);
91 
92  m_opaque_up->GetSymbolFileSpec() = *sb_spec;
93 }
94 
96  LLDB_INSTRUMENT_VA(this);
97 
98  return m_opaque_up->GetObjectName().GetCString();
99 }
100 
101 void SBModuleSpec::SetObjectName(const char *name) {
102  LLDB_INSTRUMENT_VA(this, name);
103 
104  m_opaque_up->GetObjectName().SetCString(name);
105 }
106 
107 const char *SBModuleSpec::GetTriple() {
108  LLDB_INSTRUMENT_VA(this);
109 
110  std::string triple(m_opaque_up->GetArchitecture().GetTriple().str());
111  // Unique the string so we don't run into ownership issues since the const
112  // strings put the string into the string pool once and the strings never
113  // comes out
114  ConstString const_triple(triple.c_str());
115  return const_triple.GetCString();
116 }
117 
118 void SBModuleSpec::SetTriple(const char *triple) {
119  LLDB_INSTRUMENT_VA(this, triple);
120 
121  m_opaque_up->GetArchitecture().SetTriple(triple);
122 }
123 
124 const uint8_t *SBModuleSpec::GetUUIDBytes() {
125  LLDB_INSTRUMENT_VA(this)
126  return m_opaque_up->GetUUID().GetBytes().data();
127 }
128 
130  LLDB_INSTRUMENT_VA(this);
131 
132  return m_opaque_up->GetUUID().GetBytes().size();
133 }
134 
135 bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) {
136  LLDB_INSTRUMENT_VA(this, uuid, uuid_len)
137  m_opaque_up->GetUUID() = UUID::fromOptionalData(uuid, uuid_len);
138  return m_opaque_up->GetUUID().IsValid();
139 }
140 
142  LLDB_INSTRUMENT_VA(this, description);
143 
144  m_opaque_up->Dump(description.ref());
145  return true;
146 }
147 
149  LLDB_INSTRUMENT_VA(this);
150 }
151 
153  : m_opaque_up(new ModuleSpecList(*rhs.m_opaque_up)) {
154  LLDB_INSTRUMENT_VA(this, rhs);
155 }
156 
158  LLDB_INSTRUMENT_VA(this, rhs);
159 
160  if (this != &rhs)
161  *m_opaque_up = *rhs.m_opaque_up;
162  return *this;
163 }
164 
166 
168  LLDB_INSTRUMENT_VA(path);
169 
170  SBModuleSpecList specs;
171  FileSpec file_spec(path);
172  FileSystem::Instance().Resolve(file_spec);
173  Host::ResolveExecutableInBundle(file_spec);
174  ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_up);
175  return specs;
176 }
177 
179  LLDB_INSTRUMENT_VA(this, spec);
180 
181  m_opaque_up->Append(*spec.m_opaque_up);
182 }
183 
185  LLDB_INSTRUMENT_VA(this, spec_list);
186 
187  m_opaque_up->Append(*spec_list.m_opaque_up);
188 }
189 
191  LLDB_INSTRUMENT_VA(this);
192 
193  return m_opaque_up->GetSize();
194 }
195 
197  LLDB_INSTRUMENT_VA(this, i);
198 
199  SBModuleSpec sb_module_spec;
200  m_opaque_up->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_up);
201  return sb_module_spec;
202 }
203 
206  LLDB_INSTRUMENT_VA(this, match_spec);
207 
208  SBModuleSpec sb_module_spec;
209  m_opaque_up->FindMatchingModuleSpec(*match_spec.m_opaque_up,
210  *sb_module_spec.m_opaque_up);
211  return sb_module_spec;
212 }
213 
216  LLDB_INSTRUMENT_VA(this, match_spec);
217 
218  SBModuleSpecList specs;
219  m_opaque_up->FindMatchingModuleSpecs(*match_spec.m_opaque_up,
220  *specs.m_opaque_up);
221  return specs;
222 }
223 
225  LLDB_INSTRUMENT_VA(this, description);
226 
227  m_opaque_up->Dump(description.ref());
228  return true;
229 }
Instrumentation.h
lldb::SBModuleSpecList::FindFirstMatchingSpec
SBModuleSpec FindFirstMatchingSpec(const SBModuleSpec &match_spec)
Definition: SBModuleSpec.cpp:205
lldb::SBModuleSpec
Definition: SBModuleSpec.h:17
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:175
lldb::SBModuleSpecList
Definition: SBModuleSpec.h:90
lldb::SBModuleSpecList::GetModuleSpecifications
static SBModuleSpecList GetModuleSpecifications(const char *path)
Definition: SBModuleSpec.cpp:167
lldb::SBModuleSpec::GetTriple
const char * GetTriple()
Definition: SBModuleSpec.cpp:107
ModuleSpec.h
lldb::SBModuleSpec::m_opaque_up
std::unique_ptr< lldb_private::ModuleSpec > m_opaque_up
Definition: SBModuleSpec.h:87
Host.h
SBModuleSpec.h
lldb::SBModuleSpecList::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBModuleSpec.cpp:224
lldb_private::ModuleSpecList
Definition: ModuleSpec.h:274
lldb::SBModuleSpec::GetUUIDBytes
const uint8_t * GetUUIDBytes()
Definition: SBModuleSpec.cpp:124
Module.h
lldb::SBModuleSpecList::SBModuleSpecList
SBModuleSpecList()
Definition: SBModuleSpec.cpp:148
lldb::SBModuleSpec::GetFileSpec
lldb::SBFileSpec GetFileSpec()
Get const accessor for the module file.
Definition: SBModuleSpec.cpp:58
lldb::SBModuleSpec::IsValid
bool IsValid() const
Definition: SBModuleSpec.cpp:42
lldb::SBModuleSpec::Clear
void Clear()
Definition: SBModuleSpec.cpp:52
lldb_private::FileSpec
Definition: FileSpec.h:56
SBStream.h
lldb::SBModuleSpecList::operator=
SBModuleSpecList & operator=(const SBModuleSpecList &rhs)
Definition: SBModuleSpec.cpp:157
lldb_private::clone
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
Utils.h
lldb_private::ConstString
Definition: ConstString.h:40
lldb::SBModuleSpec::~SBModuleSpec
~SBModuleSpec()
lldb::SBModuleSpec::SetSymbolFileSpec
void SetSymbolFileSpec(const lldb::SBFileSpec &fspec)
Definition: SBModuleSpec.cpp:89
lldb::SBModuleSpec::GetUUIDLength
size_t GetUUIDLength()
Definition: SBModuleSpec.cpp:129
lldb::SBModuleSpecList::m_opaque_up
std::unique_ptr< lldb_private::ModuleSpecList > m_opaque_up
Definition: SBModuleSpec.h:117
lldb::SBModuleSpecList::~SBModuleSpecList
~SBModuleSpecList()
lldb::SBModuleSpec::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBModuleSpec.cpp:141
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
ObjectFile.h
lldb::SBModuleSpec::operator=
const SBModuleSpec & operator=(const SBModuleSpec &rhs)
Definition: SBModuleSpec.cpp:32
lldb_private::ModuleSpec
Definition: ModuleSpec.h:26
lldb::SBModuleSpecList::GetSpecAtIndex
SBModuleSpec GetSpecAtIndex(size_t i)
Definition: SBModuleSpec.cpp:196
lldb::SBModuleSpec::GetPlatformFileSpec
lldb::SBFileSpec GetPlatformFileSpec()
Get accessor for the module platform file.
Definition: SBModuleSpec.cpp:71
lldb::SBModuleSpec::GetSymbolFileSpec
lldb::SBFileSpec GetSymbolFileSpec()
Definition: SBModuleSpec.cpp:83
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
lldb::SBFileSpec
Definition: SBFileSpec.h:16
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBModuleSpecList::GetSize
size_t GetSize()
Definition: SBModuleSpec.cpp:190
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:100
lldb::SBModuleSpec::SetObjectName
void SetObjectName(const char *name)
Definition: SBModuleSpec.cpp:101
Stream.h
lldb::SBModuleSpecList::Append
void Append(const SBModuleSpec &spec)
Definition: SBModuleSpec.cpp:178
lldb::SBStream
Definition: SBStream.h:18
lldb::SBModuleSpec::GetObjectName
const char * GetObjectName()
Definition: SBModuleSpec.cpp:95
lldb::SBModuleSpec::SetPlatformFileSpec
void SetPlatformFileSpec(const lldb::SBFileSpec &fspec)
Definition: SBModuleSpec.cpp:77
lldb::SBModuleSpecList::FindMatchingSpecs
SBModuleSpecList FindMatchingSpecs(const SBModuleSpec &match_spec)
Definition: SBModuleSpec.cpp:215
lldb::SBModuleSpec::SetTriple
void SetTriple(const char *triple)
Definition: SBModuleSpec.cpp:118
lldb
Definition: SBAddress.h:15
lldb::SBModuleSpec::SetUUIDBytes
bool SetUUIDBytes(const uint8_t *uuid, size_t uuid_len)
Definition: SBModuleSpec.cpp:135
lldb::SBModuleSpec::SetFileSpec
void SetFileSpec(const lldb::SBFileSpec &fspec)
Definition: SBModuleSpec.cpp:65
lldb::SBFileSpec
class LLDB_API SBFileSpec
Definition: SBDefines.h:58
lldb::SBModuleSpec::SBModuleSpec
SBModuleSpec()
Definition: SBModuleSpec.cpp:22