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 "SBReproducerPrivate.h"
11 #include "Utils.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Core/ModuleSpec.h"
15 #include "lldb/Host/Host.h"
16 #include "lldb/Symbol/ObjectFile.h"
17 #include "lldb/Utility/Stream.h"
18 
19 using namespace lldb;
20 using namespace lldb_private;
21 
24 }
25 
26 SBModuleSpec::SBModuleSpec(const SBModuleSpec &rhs) : m_opaque_up() {
28 
30 }
31 
34  SBModuleSpec, operator=,(const lldb::SBModuleSpec &), rhs);
35 
36  if (this != &rhs)
38  return LLDB_RECORD_RESULT(*this);
39 }
40 
41 SBModuleSpec::~SBModuleSpec() = default;
42 
43 bool SBModuleSpec::IsValid() const {
45  return this->operator bool();
46 }
47 SBModuleSpec::operator bool() const {
48  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBModuleSpec, operator bool);
49 
50  return m_opaque_up->operator bool();
51 }
52 
55 
56  m_opaque_up->Clear();
57 }
58 
61 
62  SBFileSpec sb_spec(m_opaque_up->GetFileSpec());
63  return LLDB_RECORD_RESULT(sb_spec);
64 }
65 
68  (const lldb::SBFileSpec &), sb_spec);
69 
70  m_opaque_up->GetFileSpec() = *sb_spec;
71 }
72 
76 
77  return LLDB_RECORD_RESULT(SBFileSpec(m_opaque_up->GetPlatformFileSpec()));
78 }
79 
82  (const lldb::SBFileSpec &), sb_spec);
83 
84  m_opaque_up->GetPlatformFileSpec() = *sb_spec;
85 }
86 
89 
90  return LLDB_RECORD_RESULT(SBFileSpec(m_opaque_up->GetSymbolFileSpec()));
91 }
92 
95  (const lldb::SBFileSpec &), sb_spec);
96 
97  m_opaque_up->GetSymbolFileSpec() = *sb_spec;
98 }
99 
102 
103  return m_opaque_up->GetObjectName().GetCString();
104 }
105 
106 void SBModuleSpec::SetObjectName(const char *name) {
107  LLDB_RECORD_METHOD(void, SBModuleSpec, SetObjectName, (const char *), name);
108 
109  m_opaque_up->GetObjectName().SetCString(name);
110 }
111 
112 const char *SBModuleSpec::GetTriple() {
114 
115  std::string triple(m_opaque_up->GetArchitecture().GetTriple().str());
116  // Unique the string so we don't run into ownership issues since the const
117  // strings put the string into the string pool once and the strings never
118  // comes out
119  ConstString const_triple(triple.c_str());
120  return const_triple.GetCString();
121 }
122 
123 void SBModuleSpec::SetTriple(const char *triple) {
124  LLDB_RECORD_METHOD(void, SBModuleSpec, SetTriple, (const char *), triple);
125 
126  m_opaque_up->GetArchitecture().SetTriple(triple);
127 }
128 
129 const uint8_t *SBModuleSpec::GetUUIDBytes() {
130  return m_opaque_up->GetUUID().GetBytes().data();
131 }
132 
135 
136  return m_opaque_up->GetUUID().GetBytes().size();
137 }
138 
139 bool SBModuleSpec::SetUUIDBytes(const uint8_t *uuid, size_t uuid_len) {
140  m_opaque_up->GetUUID() = UUID::fromOptionalData(uuid, uuid_len);
141  return m_opaque_up->GetUUID().IsValid();
142 }
143 
146  description);
147 
148  m_opaque_up->Dump(description.ref());
149  return true;
150 }
151 
154 }
155 
157  : m_opaque_up(new ModuleSpecList(*rhs.m_opaque_up)) {
159  rhs);
160 }
161 
165  SBModuleSpecList, operator=,(const lldb::SBModuleSpecList &), rhs);
166 
167  if (this != &rhs)
168  *m_opaque_up = *rhs.m_opaque_up;
169  return LLDB_RECORD_RESULT(*this);
170 }
171 
173 
176  GetModuleSpecifications, (const char *), path);
177 
178  SBModuleSpecList specs;
179  FileSpec file_spec(path);
180  FileSystem::Instance().Resolve(file_spec);
181  Host::ResolveExecutableInBundle(file_spec);
182  ObjectFile::GetModuleSpecifications(file_spec, 0, 0, *specs.m_opaque_up);
183  return LLDB_RECORD_RESULT(specs);
184 }
185 
188  (const lldb::SBModuleSpec &), spec);
189 
190  m_opaque_up->Append(*spec.m_opaque_up);
191 }
192 
195  (const lldb::SBModuleSpecList &), spec_list);
196 
197  m_opaque_up->Append(*spec_list.m_opaque_up);
198 }
199 
202 
203  return m_opaque_up->GetSize();
204 }
205 
208  (size_t), i);
209 
210  SBModuleSpec sb_module_spec;
211  m_opaque_up->GetModuleSpecAtIndex(i, *sb_module_spec.m_opaque_up);
212  return LLDB_RECORD_RESULT(sb_module_spec);
213 }
214 
219  match_spec);
220 
221  SBModuleSpec sb_module_spec;
222  m_opaque_up->FindMatchingModuleSpec(*match_spec.m_opaque_up,
223  *sb_module_spec.m_opaque_up);
224  return LLDB_RECORD_RESULT(sb_module_spec);
225 }
226 
231  match_spec);
232 
233  SBModuleSpecList specs;
234  m_opaque_up->FindMatchingModuleSpecs(*match_spec.m_opaque_up,
235  *specs.m_opaque_up);
236  return LLDB_RECORD_RESULT(specs);
237 }
238 
241  description);
242 
243  m_opaque_up->Dump(description.ref());
244  return true;
245 }
246 
247 namespace lldb_private {
248 namespace repro {
249 
250 template <>
255  SBModuleSpec, operator=,(const lldb::SBModuleSpec &));
256  LLDB_REGISTER_METHOD_CONST(bool, SBModuleSpec, IsValid, ());
257  LLDB_REGISTER_METHOD_CONST(bool, SBModuleSpec, operator bool, ());
258  LLDB_REGISTER_METHOD(void, SBModuleSpec, Clear, ());
260  LLDB_REGISTER_METHOD(void, SBModuleSpec, SetFileSpec,
261  (const lldb::SBFileSpec &));
262  LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBModuleSpec, GetPlatformFileSpec,
263  ());
264  LLDB_REGISTER_METHOD(void, SBModuleSpec, SetPlatformFileSpec,
265  (const lldb::SBFileSpec &));
266  LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBModuleSpec, GetSymbolFileSpec, ());
267  LLDB_REGISTER_METHOD(void, SBModuleSpec, SetSymbolFileSpec,
268  (const lldb::SBFileSpec &));
269  LLDB_REGISTER_METHOD(const char *, SBModuleSpec, GetObjectName, ());
270  LLDB_REGISTER_METHOD(void, SBModuleSpec, SetObjectName, (const char *));
271  LLDB_REGISTER_METHOD(const char *, SBModuleSpec, GetTriple, ());
272  LLDB_REGISTER_METHOD(void, SBModuleSpec, SetTriple, (const char *));
273  LLDB_REGISTER_METHOD(size_t, SBModuleSpec, GetUUIDLength, ());
274  LLDB_REGISTER_METHOD(bool, SBModuleSpec, GetDescription,
275  (lldb::SBStream &));
278  (const lldb::SBModuleSpecList &));
281  SBModuleSpecList, operator=,(const lldb::SBModuleSpecList &));
283  GetModuleSpecifications, (const char *));
285  (const lldb::SBModuleSpec &));
287  (const lldb::SBModuleSpecList &));
288  LLDB_REGISTER_METHOD(size_t, SBModuleSpecList, GetSize, ());
290  (size_t));
292  FindFirstMatchingSpec, (const lldb::SBModuleSpec &));
294  FindMatchingSpecs, (const lldb::SBModuleSpec &));
295  LLDB_REGISTER_METHOD(bool, SBModuleSpecList, GetDescription,
296  (lldb::SBStream &));
297 }
298 
299 }
300 }
lldb::SBModuleSpecList::FindFirstMatchingSpec
SBModuleSpec FindFirstMatchingSpec(const SBModuleSpec &match_spec)
Definition: SBModuleSpec.cpp:216
lldb::SBModuleSpec
Definition: SBModuleSpec.h:17
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:178
lldb::SBModuleSpecList
Definition: SBModuleSpec.h:90
lldb::SBModuleSpecList::GetModuleSpecifications
static SBModuleSpecList GetModuleSpecifications(const char *path)
Definition: SBModuleSpec.cpp:174
lldb::SBModuleSpec::GetTriple
const char * GetTriple()
Definition: SBModuleSpec.cpp:112
ModuleSpec.h
lldb::SBModuleSpec::m_opaque_up
std::unique_ptr< lldb_private::ModuleSpec > m_opaque_up
Definition: SBModuleSpec.h:87
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
Host.h
LLDB_RECORD_METHOD_CONST_NO_ARGS
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:168
SBModuleSpec.h
lldb::SBModuleSpecList::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBModuleSpec.cpp:239
lldb_private::ModuleSpecList
Definition: ModuleSpec.h:280
lldb::SBModuleSpec::GetUUIDBytes
const uint8_t * GetUUIDBytes()
Definition: SBModuleSpec.cpp:129
LLDB_RECORD_METHOD_NO_ARGS
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:165
Module.h
LLDB_RECORD_CONSTRUCTOR_NO_ARGS
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
Definition: ReproducerInstrumentation.h:136
lldb::SBModuleSpecList::SBModuleSpecList
SBModuleSpecList()
Definition: SBModuleSpec.cpp:152
LLDB_REGISTER_METHOD_CONST
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:98
lldb::SBModuleSpec::GetFileSpec
lldb::SBFileSpec GetFileSpec()
Get const accessor for the module file.
Definition: SBModuleSpec.cpp:59
SBReproducerPrivate.h
LLDB_REGISTER_CONSTRUCTOR
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
Definition: ReproducerInstrumentation.h:89
lldb::SBModuleSpec::IsValid
bool IsValid() const
Definition: SBModuleSpec.cpp:43
lldb_private::repro::RegisterMethods< SBModuleSpec >
void RegisterMethods< SBModuleSpec >(Registry &R)
Definition: SBModuleSpec.cpp:251
R
#define R(base)
lldb::SBModuleSpec::Clear
void Clear()
Definition: SBModuleSpec.cpp:53
lldb_private::FileSpec
Definition: FileSpec.h:56
SBStream.h
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
lldb::SBModuleSpecList::operator=
SBModuleSpecList & operator=(const SBModuleSpecList &rhs)
Definition: SBModuleSpec.cpp:162
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:93
lldb::SBModuleSpec::GetUUIDLength
size_t GetUUIDLength()
Definition: SBModuleSpec.cpp:133
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:144
LLDB_REGISTER_STATIC_METHOD
#define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:103
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
ObjectFile.h
LLDB_RECORD_CONSTRUCTOR
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
Definition: ReproducerInstrumentation.h:133
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
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:206
lldb::SBModuleSpec::GetPlatformFileSpec
lldb::SBFileSpec GetPlatformFileSpec()
Get accessor for the module platform file.
Definition: SBModuleSpec.cpp:73
lldb::SBModuleSpec::GetSymbolFileSpec
lldb::SBFileSpec GetSymbolFileSpec()
Definition: SBModuleSpec.cpp:87
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:200
lldb::SBModuleSpec::SetObjectName
void SetObjectName(const char *name)
Definition: SBModuleSpec.cpp:106
LLDB_RECORD_STATIC_METHOD
#define LLDB_RECORD_STATIC_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:171
Stream.h
lldb::SBModuleSpecList::Append
void Append(const SBModuleSpec &spec)
Definition: SBModuleSpec.cpp:186
lldb::SBStream
Definition: SBStream.h:18
lldb::SBModuleSpec::GetObjectName
const char * GetObjectName()
Definition: SBModuleSpec.cpp:100
lldb::SBModuleSpec::SetPlatformFileSpec
void SetPlatformFileSpec(const lldb::SBFileSpec &fspec)
Definition: SBModuleSpec.cpp:80
lldb::SBModuleSpecList::FindMatchingSpecs
SBModuleSpecList FindMatchingSpecs(const SBModuleSpec &match_spec)
Definition: SBModuleSpec.cpp:228
lldb::SBModuleSpec::SetTriple
void SetTriple(const char *triple)
Definition: SBModuleSpec.cpp:123
lldb
Definition: SBAddress.h:15
lldb::SBModuleSpec::SetUUIDBytes
bool SetUUIDBytes(const uint8_t *uuid, size_t uuid_len)
Definition: SBModuleSpec.cpp:139
lldb::SBModuleSpec::SetFileSpec
void SetFileSpec(const lldb::SBFileSpec &fspec)
Definition: SBModuleSpec.cpp:66
lldb::SBFileSpec
class LLDB_API SBFileSpec
Definition: SBDefines.h:46
lldb::SBModuleSpec::SBModuleSpec
SBModuleSpec()
Definition: SBModuleSpec.cpp:22
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93