1 //===-- SBType.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
9 #include "lldb/API/SBType.h"
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBDefines.h"
12 #include "lldb/API/SBModule.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/API/SBTypeEnumMember.h"
15 #include "lldb/Core/Mangled.h"
16 #include "lldb/Symbol/CompilerType.h"
17 #include "lldb/Symbol/Type.h"
18 #include "lldb/Symbol/TypeSystem.h"
19 #include "lldb/Utility/ConstString.h"
20 #include "lldb/Utility/Stream.h"
21
22 #include "llvm/ADT/APSInt.h"
23
24 #include <memory>
25
26 using namespace lldb;
27 using namespace lldb_private;
28
SBType()29 SBType::SBType() : m_opaque_sp() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBType); }
30
SBType(const CompilerType & type)31 SBType::SBType(const CompilerType &type)
32 : m_opaque_sp(new TypeImpl(
33 CompilerType(type.GetTypeSystem(), type.GetOpaqueQualType()))) {}
34
SBType(const lldb::TypeSP & type_sp)35 SBType::SBType(const lldb::TypeSP &type_sp)
36 : m_opaque_sp(new TypeImpl(type_sp)) {}
37
SBType(const lldb::TypeImplSP & type_impl_sp)38 SBType::SBType(const lldb::TypeImplSP &type_impl_sp)
39 : m_opaque_sp(type_impl_sp) {}
40
SBType(const SBType & rhs)41 SBType::SBType(const SBType &rhs) : m_opaque_sp() {
42 LLDB_RECORD_CONSTRUCTOR(SBType, (const lldb::SBType &), rhs);
43
44 if (this != &rhs) {
45 m_opaque_sp = rhs.m_opaque_sp;
46 }
47 }
48
49 // SBType::SBType (TypeImpl* impl) :
50 // m_opaque_up(impl)
51 //{}
52 //
operator ==(SBType & rhs)53 bool SBType::operator==(SBType &rhs) {
54 LLDB_RECORD_METHOD(bool, SBType, operator==,(lldb::SBType &), rhs);
55
56 if (!IsValid())
57 return !rhs.IsValid();
58
59 if (!rhs.IsValid())
60 return false;
61
62 return *m_opaque_sp.get() == *rhs.m_opaque_sp.get();
63 }
64
operator !=(SBType & rhs)65 bool SBType::operator!=(SBType &rhs) {
66 LLDB_RECORD_METHOD(bool, SBType, operator!=,(lldb::SBType &), rhs);
67
68 if (!IsValid())
69 return rhs.IsValid();
70
71 if (!rhs.IsValid())
72 return true;
73
74 return *m_opaque_sp.get() != *rhs.m_opaque_sp.get();
75 }
76
GetSP()77 lldb::TypeImplSP SBType::GetSP() { return m_opaque_sp; }
78
SetSP(const lldb::TypeImplSP & type_impl_sp)79 void SBType::SetSP(const lldb::TypeImplSP &type_impl_sp) {
80 m_opaque_sp = type_impl_sp;
81 }
82
operator =(const SBType & rhs)83 SBType &SBType::operator=(const SBType &rhs) {
84 LLDB_RECORD_METHOD(lldb::SBType &, SBType, operator=,(const lldb::SBType &),
85 rhs);
86
87 if (this != &rhs) {
88 m_opaque_sp = rhs.m_opaque_sp;
89 }
90 return LLDB_RECORD_RESULT(*this);
91 }
92
93 SBType::~SBType() = default;
94
ref()95 TypeImpl &SBType::ref() {
96 if (m_opaque_sp.get() == nullptr)
97 m_opaque_sp = std::make_shared<TypeImpl>();
98 return *m_opaque_sp;
99 }
100
ref() const101 const TypeImpl &SBType::ref() const {
102 // "const SBAddress &addr" should already have checked "addr.IsValid()" prior
103 // to calling this function. In case you didn't we will assert and die to let
104 // you know.
105 assert(m_opaque_sp.get());
106 return *m_opaque_sp;
107 }
108
IsValid() const109 bool SBType::IsValid() const {
110 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBType, IsValid);
111 return this->operator bool();
112 }
operator bool() const113 SBType::operator bool() const {
114 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBType, operator bool);
115
116 if (m_opaque_sp.get() == nullptr)
117 return false;
118
119 return m_opaque_sp->IsValid();
120 }
121
GetByteSize()122 uint64_t SBType::GetByteSize() {
123 LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBType, GetByteSize);
124
125 if (IsValid())
126 if (llvm::Optional<uint64_t> size =
127 m_opaque_sp->GetCompilerType(false).GetByteSize(nullptr))
128 return *size;
129 return 0;
130 }
131
IsPointerType()132 bool SBType::IsPointerType() {
133 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsPointerType);
134
135 if (!IsValid())
136 return false;
137 return m_opaque_sp->GetCompilerType(true).IsPointerType();
138 }
139
IsArrayType()140 bool SBType::IsArrayType() {
141 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsArrayType);
142
143 if (!IsValid())
144 return false;
145 return m_opaque_sp->GetCompilerType(true).IsArrayType(nullptr, nullptr,
146 nullptr);
147 }
148
IsVectorType()149 bool SBType::IsVectorType() {
150 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsVectorType);
151
152 if (!IsValid())
153 return false;
154 return m_opaque_sp->GetCompilerType(true).IsVectorType(nullptr, nullptr);
155 }
156
IsReferenceType()157 bool SBType::IsReferenceType() {
158 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsReferenceType);
159
160 if (!IsValid())
161 return false;
162 return m_opaque_sp->GetCompilerType(true).IsReferenceType();
163 }
164
GetPointerType()165 SBType SBType::GetPointerType() {
166 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetPointerType);
167
168 if (!IsValid())
169 return LLDB_RECORD_RESULT(SBType());
170
171 return LLDB_RECORD_RESULT(
172 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetPointerType()))));
173 }
174
GetPointeeType()175 SBType SBType::GetPointeeType() {
176 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetPointeeType);
177
178 if (!IsValid())
179 return LLDB_RECORD_RESULT(SBType());
180 return LLDB_RECORD_RESULT(
181 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetPointeeType()))));
182 }
183
GetReferenceType()184 SBType SBType::GetReferenceType() {
185 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetReferenceType);
186
187 if (!IsValid())
188 return LLDB_RECORD_RESULT(SBType());
189 return LLDB_RECORD_RESULT(
190 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetReferenceType()))));
191 }
192
GetTypedefedType()193 SBType SBType::GetTypedefedType() {
194 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetTypedefedType);
195
196 if (!IsValid())
197 return LLDB_RECORD_RESULT(SBType());
198 return LLDB_RECORD_RESULT(
199 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetTypedefedType()))));
200 }
201
GetDereferencedType()202 SBType SBType::GetDereferencedType() {
203 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetDereferencedType);
204
205 if (!IsValid())
206 return LLDB_RECORD_RESULT(SBType());
207 return LLDB_RECORD_RESULT(
208 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetDereferencedType()))));
209 }
210
GetArrayElementType()211 SBType SBType::GetArrayElementType() {
212 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetArrayElementType);
213
214 if (!IsValid())
215 return LLDB_RECORD_RESULT(SBType());
216 return LLDB_RECORD_RESULT(SBType(TypeImplSP(new TypeImpl(
217 m_opaque_sp->GetCompilerType(true).GetArrayElementType(nullptr)))));
218 }
219
GetArrayType(uint64_t size)220 SBType SBType::GetArrayType(uint64_t size) {
221 LLDB_RECORD_METHOD(lldb::SBType, SBType, GetArrayType, (uint64_t), size);
222
223 if (!IsValid())
224 return LLDB_RECORD_RESULT(SBType());
225 return LLDB_RECORD_RESULT(SBType(TypeImplSP(
226 new TypeImpl(m_opaque_sp->GetCompilerType(true).GetArrayType(size)))));
227 }
228
GetVectorElementType()229 SBType SBType::GetVectorElementType() {
230 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetVectorElementType);
231
232 SBType type_sb;
233 if (IsValid()) {
234 CompilerType vector_element_type;
235 if (m_opaque_sp->GetCompilerType(true).IsVectorType(&vector_element_type,
236 nullptr))
237 type_sb.SetSP(TypeImplSP(new TypeImpl(vector_element_type)));
238 }
239 return LLDB_RECORD_RESULT(type_sb);
240 }
241
IsFunctionType()242 bool SBType::IsFunctionType() {
243 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsFunctionType);
244
245 if (!IsValid())
246 return false;
247 return m_opaque_sp->GetCompilerType(true).IsFunctionType();
248 }
249
IsPolymorphicClass()250 bool SBType::IsPolymorphicClass() {
251 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsPolymorphicClass);
252
253 if (!IsValid())
254 return false;
255 return m_opaque_sp->GetCompilerType(true).IsPolymorphicClass();
256 }
257
IsTypedefType()258 bool SBType::IsTypedefType() {
259 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsTypedefType);
260
261 if (!IsValid())
262 return false;
263 return m_opaque_sp->GetCompilerType(true).IsTypedefType();
264 }
265
IsAnonymousType()266 bool SBType::IsAnonymousType() {
267 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsAnonymousType);
268
269 if (!IsValid())
270 return false;
271 return m_opaque_sp->GetCompilerType(true).IsAnonymousType();
272 }
273
GetFunctionReturnType()274 lldb::SBType SBType::GetFunctionReturnType() {
275 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetFunctionReturnType);
276
277 if (IsValid()) {
278 CompilerType return_type(
279 m_opaque_sp->GetCompilerType(true).GetFunctionReturnType());
280 if (return_type.IsValid())
281 return LLDB_RECORD_RESULT(SBType(return_type));
282 }
283 return LLDB_RECORD_RESULT(lldb::SBType());
284 }
285
GetFunctionArgumentTypes()286 lldb::SBTypeList SBType::GetFunctionArgumentTypes() {
287 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeList, SBType,
288 GetFunctionArgumentTypes);
289
290 SBTypeList sb_type_list;
291 if (IsValid()) {
292 CompilerType func_type(m_opaque_sp->GetCompilerType(true));
293 size_t count = func_type.GetNumberOfFunctionArguments();
294 for (size_t i = 0; i < count; i++) {
295 sb_type_list.Append(SBType(func_type.GetFunctionArgumentAtIndex(i)));
296 }
297 }
298 return LLDB_RECORD_RESULT(sb_type_list);
299 }
300
GetNumberOfMemberFunctions()301 uint32_t SBType::GetNumberOfMemberFunctions() {
302 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfMemberFunctions);
303
304 if (IsValid()) {
305 return m_opaque_sp->GetCompilerType(true).GetNumMemberFunctions();
306 }
307 return 0;
308 }
309
GetMemberFunctionAtIndex(uint32_t idx)310 lldb::SBTypeMemberFunction SBType::GetMemberFunctionAtIndex(uint32_t idx) {
311 LLDB_RECORD_METHOD(lldb::SBTypeMemberFunction, SBType,
312 GetMemberFunctionAtIndex, (uint32_t), idx);
313
314 SBTypeMemberFunction sb_func_type;
315 if (IsValid())
316 sb_func_type.reset(new TypeMemberFunctionImpl(
317 m_opaque_sp->GetCompilerType(true).GetMemberFunctionAtIndex(idx)));
318 return LLDB_RECORD_RESULT(sb_func_type);
319 }
320
GetUnqualifiedType()321 lldb::SBType SBType::GetUnqualifiedType() {
322 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetUnqualifiedType);
323
324 if (!IsValid())
325 return LLDB_RECORD_RESULT(SBType());
326 return LLDB_RECORD_RESULT(
327 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetUnqualifiedType()))));
328 }
329
GetCanonicalType()330 lldb::SBType SBType::GetCanonicalType() {
331 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetCanonicalType);
332
333 if (IsValid())
334 return LLDB_RECORD_RESULT(
335 SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetCanonicalType()))));
336 return LLDB_RECORD_RESULT(SBType());
337 }
338
GetBasicType()339 lldb::BasicType SBType::GetBasicType() {
340 LLDB_RECORD_METHOD_NO_ARGS(lldb::BasicType, SBType, GetBasicType);
341
342 if (IsValid())
343 return m_opaque_sp->GetCompilerType(false).GetBasicTypeEnumeration();
344 return eBasicTypeInvalid;
345 }
346
GetBasicType(lldb::BasicType basic_type)347 SBType SBType::GetBasicType(lldb::BasicType basic_type) {
348 LLDB_RECORD_METHOD(lldb::SBType, SBType, GetBasicType, (lldb::BasicType),
349 basic_type);
350
351 if (IsValid() && m_opaque_sp->IsValid())
352 return LLDB_RECORD_RESULT(SBType(
353 m_opaque_sp->GetTypeSystem(false)->GetBasicTypeFromAST(basic_type)));
354 return LLDB_RECORD_RESULT(SBType());
355 }
356
GetNumberOfDirectBaseClasses()357 uint32_t SBType::GetNumberOfDirectBaseClasses() {
358 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfDirectBaseClasses);
359
360 if (IsValid())
361 return m_opaque_sp->GetCompilerType(true).GetNumDirectBaseClasses();
362 return 0;
363 }
364
GetNumberOfVirtualBaseClasses()365 uint32_t SBType::GetNumberOfVirtualBaseClasses() {
366 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfVirtualBaseClasses);
367
368 if (IsValid())
369 return m_opaque_sp->GetCompilerType(true).GetNumVirtualBaseClasses();
370 return 0;
371 }
372
GetNumberOfFields()373 uint32_t SBType::GetNumberOfFields() {
374 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfFields);
375
376 if (IsValid())
377 return m_opaque_sp->GetCompilerType(true).GetNumFields();
378 return 0;
379 }
380
GetDescription(SBStream & description,lldb::DescriptionLevel description_level)381 bool SBType::GetDescription(SBStream &description,
382 lldb::DescriptionLevel description_level) {
383 LLDB_RECORD_METHOD(bool, SBType, GetDescription,
384 (lldb::SBStream &, lldb::DescriptionLevel), description,
385 description_level);
386
387 Stream &strm = description.ref();
388
389 if (m_opaque_sp) {
390 m_opaque_sp->GetDescription(strm, description_level);
391 } else
392 strm.PutCString("No value");
393
394 return true;
395 }
396
GetDirectBaseClassAtIndex(uint32_t idx)397 SBTypeMember SBType::GetDirectBaseClassAtIndex(uint32_t idx) {
398 LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetDirectBaseClassAtIndex,
399 (uint32_t), idx);
400
401 SBTypeMember sb_type_member;
402 if (IsValid()) {
403 uint32_t bit_offset = 0;
404 CompilerType base_class_type =
405 m_opaque_sp->GetCompilerType(true).GetDirectBaseClassAtIndex(
406 idx, &bit_offset);
407 if (base_class_type.IsValid())
408 sb_type_member.reset(new TypeMemberImpl(
409 TypeImplSP(new TypeImpl(base_class_type)), bit_offset));
410 }
411 return LLDB_RECORD_RESULT(sb_type_member);
412 }
413
GetVirtualBaseClassAtIndex(uint32_t idx)414 SBTypeMember SBType::GetVirtualBaseClassAtIndex(uint32_t idx) {
415 LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetVirtualBaseClassAtIndex,
416 (uint32_t), idx);
417
418 SBTypeMember sb_type_member;
419 if (IsValid()) {
420 uint32_t bit_offset = 0;
421 CompilerType base_class_type =
422 m_opaque_sp->GetCompilerType(true).GetVirtualBaseClassAtIndex(
423 idx, &bit_offset);
424 if (base_class_type.IsValid())
425 sb_type_member.reset(new TypeMemberImpl(
426 TypeImplSP(new TypeImpl(base_class_type)), bit_offset));
427 }
428 return LLDB_RECORD_RESULT(sb_type_member);
429 }
430
GetEnumMembers()431 SBTypeEnumMemberList SBType::GetEnumMembers() {
432 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeEnumMemberList, SBType,
433 GetEnumMembers);
434
435 SBTypeEnumMemberList sb_enum_member_list;
436 if (IsValid()) {
437 CompilerType this_type(m_opaque_sp->GetCompilerType(true));
438 if (this_type.IsValid()) {
439 this_type.ForEachEnumerator([&sb_enum_member_list](
440 const CompilerType &integer_type,
441 ConstString name,
442 const llvm::APSInt &value) -> bool {
443 SBTypeEnumMember enum_member(
444 lldb::TypeEnumMemberImplSP(new TypeEnumMemberImpl(
445 lldb::TypeImplSP(new TypeImpl(integer_type)), name, value)));
446 sb_enum_member_list.Append(enum_member);
447 return true; // Keep iterating
448 });
449 }
450 }
451 return LLDB_RECORD_RESULT(sb_enum_member_list);
452 }
453
GetFieldAtIndex(uint32_t idx)454 SBTypeMember SBType::GetFieldAtIndex(uint32_t idx) {
455 LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetFieldAtIndex, (uint32_t),
456 idx);
457
458 SBTypeMember sb_type_member;
459 if (IsValid()) {
460 CompilerType this_type(m_opaque_sp->GetCompilerType(false));
461 if (this_type.IsValid()) {
462 uint64_t bit_offset = 0;
463 uint32_t bitfield_bit_size = 0;
464 bool is_bitfield = false;
465 std::string name_sstr;
466 CompilerType field_type(this_type.GetFieldAtIndex(
467 idx, name_sstr, &bit_offset, &bitfield_bit_size, &is_bitfield));
468 if (field_type.IsValid()) {
469 ConstString name;
470 if (!name_sstr.empty())
471 name.SetCString(name_sstr.c_str());
472 sb_type_member.reset(
473 new TypeMemberImpl(TypeImplSP(new TypeImpl(field_type)), bit_offset,
474 name, bitfield_bit_size, is_bitfield));
475 }
476 }
477 }
478 return LLDB_RECORD_RESULT(sb_type_member);
479 }
480
IsTypeComplete()481 bool SBType::IsTypeComplete() {
482 LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsTypeComplete);
483
484 if (!IsValid())
485 return false;
486 return m_opaque_sp->GetCompilerType(false).IsCompleteType();
487 }
488
GetTypeFlags()489 uint32_t SBType::GetTypeFlags() {
490 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetTypeFlags);
491
492 if (!IsValid())
493 return 0;
494 return m_opaque_sp->GetCompilerType(true).GetTypeInfo();
495 }
496
GetModule()497 lldb::SBModule SBType::GetModule() {
498 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBModule, SBType, GetModule);
499
500 lldb::SBModule sb_module;
501 if (!IsValid())
502 return LLDB_RECORD_RESULT(sb_module);
503
504 sb_module.SetSP(m_opaque_sp->GetModule());
505 return LLDB_RECORD_RESULT(sb_module);
506 }
507
GetName()508 const char *SBType::GetName() {
509 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBType, GetName);
510
511 if (!IsValid())
512 return "";
513 return m_opaque_sp->GetName().GetCString();
514 }
515
GetDisplayTypeName()516 const char *SBType::GetDisplayTypeName() {
517 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBType, GetDisplayTypeName);
518
519 if (!IsValid())
520 return "";
521 return m_opaque_sp->GetDisplayTypeName().GetCString();
522 }
523
GetTypeClass()524 lldb::TypeClass SBType::GetTypeClass() {
525 LLDB_RECORD_METHOD_NO_ARGS(lldb::TypeClass, SBType, GetTypeClass);
526
527 if (IsValid())
528 return m_opaque_sp->GetCompilerType(true).GetTypeClass();
529 return lldb::eTypeClassInvalid;
530 }
531
GetNumberOfTemplateArguments()532 uint32_t SBType::GetNumberOfTemplateArguments() {
533 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfTemplateArguments);
534
535 if (IsValid())
536 return m_opaque_sp->GetCompilerType(false).GetNumTemplateArguments();
537 return 0;
538 }
539
GetTemplateArgumentType(uint32_t idx)540 lldb::SBType SBType::GetTemplateArgumentType(uint32_t idx) {
541 LLDB_RECORD_METHOD(lldb::SBType, SBType, GetTemplateArgumentType, (uint32_t),
542 idx);
543
544 if (!IsValid())
545 return LLDB_RECORD_RESULT(SBType());
546
547 CompilerType type;
548 switch(GetTemplateArgumentKind(idx)) {
549 case eTemplateArgumentKindType:
550 type = m_opaque_sp->GetCompilerType(false).GetTypeTemplateArgument(idx);
551 break;
552 case eTemplateArgumentKindIntegral:
553 type = m_opaque_sp->GetCompilerType(false)
554 .GetIntegralTemplateArgument(idx)
555 ->type;
556 break;
557 default:
558 break;
559 }
560 if (type.IsValid())
561 return LLDB_RECORD_RESULT(SBType(type));
562 return LLDB_RECORD_RESULT(SBType());
563 }
564
GetTemplateArgumentKind(uint32_t idx)565 lldb::TemplateArgumentKind SBType::GetTemplateArgumentKind(uint32_t idx) {
566 LLDB_RECORD_METHOD(lldb::TemplateArgumentKind, SBType,
567 GetTemplateArgumentKind, (uint32_t), idx);
568
569 if (IsValid())
570 return m_opaque_sp->GetCompilerType(false).GetTemplateArgumentKind(idx);
571 return eTemplateArgumentKindNull;
572 }
573
SBTypeList()574 SBTypeList::SBTypeList() : m_opaque_up(new TypeListImpl()) {
575 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeList);
576 }
577
SBTypeList(const SBTypeList & rhs)578 SBTypeList::SBTypeList(const SBTypeList &rhs)
579 : m_opaque_up(new TypeListImpl()) {
580 LLDB_RECORD_CONSTRUCTOR(SBTypeList, (const lldb::SBTypeList &), rhs);
581
582 for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize();
583 i < rhs_size; i++)
584 Append(const_cast<SBTypeList &>(rhs).GetTypeAtIndex(i));
585 }
586
IsValid()587 bool SBTypeList::IsValid() {
588 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeList, IsValid);
589 return this->operator bool();
590 }
operator bool() const591 SBTypeList::operator bool() const {
592 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeList, operator bool);
593
594 return (m_opaque_up != nullptr);
595 }
596
operator =(const SBTypeList & rhs)597 SBTypeList &SBTypeList::operator=(const SBTypeList &rhs) {
598 LLDB_RECORD_METHOD(lldb::SBTypeList &,
599 SBTypeList, operator=,(const lldb::SBTypeList &), rhs);
600
601 if (this != &rhs) {
602 m_opaque_up = std::make_unique<TypeListImpl>();
603 for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize();
604 i < rhs_size; i++)
605 Append(const_cast<SBTypeList &>(rhs).GetTypeAtIndex(i));
606 }
607 return LLDB_RECORD_RESULT(*this);
608 }
609
Append(SBType type)610 void SBTypeList::Append(SBType type) {
611 LLDB_RECORD_METHOD(void, SBTypeList, Append, (lldb::SBType), type);
612
613 if (type.IsValid())
614 m_opaque_up->Append(type.m_opaque_sp);
615 }
616
GetTypeAtIndex(uint32_t index)617 SBType SBTypeList::GetTypeAtIndex(uint32_t index) {
618 LLDB_RECORD_METHOD(lldb::SBType, SBTypeList, GetTypeAtIndex, (uint32_t),
619 index);
620
621 if (m_opaque_up)
622 return LLDB_RECORD_RESULT(SBType(m_opaque_up->GetTypeAtIndex(index)));
623 return LLDB_RECORD_RESULT(SBType());
624 }
625
GetSize()626 uint32_t SBTypeList::GetSize() {
627 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeList, GetSize);
628
629 return m_opaque_up->GetSize();
630 }
631
632 SBTypeList::~SBTypeList() = default;
633
SBTypeMember()634 SBTypeMember::SBTypeMember() : m_opaque_up() {
635 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeMember);
636 }
637
638 SBTypeMember::~SBTypeMember() = default;
639
SBTypeMember(const SBTypeMember & rhs)640 SBTypeMember::SBTypeMember(const SBTypeMember &rhs) : m_opaque_up() {
641 LLDB_RECORD_CONSTRUCTOR(SBTypeMember, (const lldb::SBTypeMember &), rhs);
642
643 if (this != &rhs) {
644 if (rhs.IsValid())
645 m_opaque_up = std::make_unique<TypeMemberImpl>(rhs.ref());
646 }
647 }
648
operator =(const lldb::SBTypeMember & rhs)649 lldb::SBTypeMember &SBTypeMember::operator=(const lldb::SBTypeMember &rhs) {
650 LLDB_RECORD_METHOD(lldb::SBTypeMember &,
651 SBTypeMember, operator=,(const lldb::SBTypeMember &), rhs);
652
653 if (this != &rhs) {
654 if (rhs.IsValid())
655 m_opaque_up = std::make_unique<TypeMemberImpl>(rhs.ref());
656 }
657 return LLDB_RECORD_RESULT(*this);
658 }
659
IsValid() const660 bool SBTypeMember::IsValid() const {
661 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMember, IsValid);
662 return this->operator bool();
663 }
operator bool() const664 SBTypeMember::operator bool() const {
665 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMember, operator bool);
666
667 return m_opaque_up.get();
668 }
669
GetName()670 const char *SBTypeMember::GetName() {
671 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMember, GetName);
672
673 if (m_opaque_up)
674 return m_opaque_up->GetName().GetCString();
675 return nullptr;
676 }
677
GetType()678 SBType SBTypeMember::GetType() {
679 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMember, GetType);
680
681 SBType sb_type;
682 if (m_opaque_up) {
683 sb_type.SetSP(m_opaque_up->GetTypeImpl());
684 }
685 return LLDB_RECORD_RESULT(sb_type);
686 }
687
GetOffsetInBytes()688 uint64_t SBTypeMember::GetOffsetInBytes() {
689 LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBTypeMember, GetOffsetInBytes);
690
691 if (m_opaque_up)
692 return m_opaque_up->GetBitOffset() / 8u;
693 return 0;
694 }
695
GetOffsetInBits()696 uint64_t SBTypeMember::GetOffsetInBits() {
697 LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBTypeMember, GetOffsetInBits);
698
699 if (m_opaque_up)
700 return m_opaque_up->GetBitOffset();
701 return 0;
702 }
703
IsBitfield()704 bool SBTypeMember::IsBitfield() {
705 LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeMember, IsBitfield);
706
707 if (m_opaque_up)
708 return m_opaque_up->GetIsBitfield();
709 return false;
710 }
711
GetBitfieldSizeInBits()712 uint32_t SBTypeMember::GetBitfieldSizeInBits() {
713 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeMember, GetBitfieldSizeInBits);
714
715 if (m_opaque_up)
716 return m_opaque_up->GetBitfieldBitSize();
717 return 0;
718 }
719
GetDescription(lldb::SBStream & description,lldb::DescriptionLevel description_level)720 bool SBTypeMember::GetDescription(lldb::SBStream &description,
721 lldb::DescriptionLevel description_level) {
722 LLDB_RECORD_METHOD(bool, SBTypeMember, GetDescription,
723 (lldb::SBStream &, lldb::DescriptionLevel), description,
724 description_level);
725
726 Stream &strm = description.ref();
727
728 if (m_opaque_up) {
729 const uint32_t bit_offset = m_opaque_up->GetBitOffset();
730 const uint32_t byte_offset = bit_offset / 8u;
731 const uint32_t byte_bit_offset = bit_offset % 8u;
732 const char *name = m_opaque_up->GetName().GetCString();
733 if (byte_bit_offset)
734 strm.Printf("+%u + %u bits: (", byte_offset, byte_bit_offset);
735 else
736 strm.Printf("+%u: (", byte_offset);
737
738 TypeImplSP type_impl_sp(m_opaque_up->GetTypeImpl());
739 if (type_impl_sp)
740 type_impl_sp->GetDescription(strm, description_level);
741
742 strm.Printf(") %s", name);
743 if (m_opaque_up->GetIsBitfield()) {
744 const uint32_t bitfield_bit_size = m_opaque_up->GetBitfieldBitSize();
745 strm.Printf(" : %u", bitfield_bit_size);
746 }
747 } else {
748 strm.PutCString("No value");
749 }
750 return true;
751 }
752
reset(TypeMemberImpl * type_member_impl)753 void SBTypeMember::reset(TypeMemberImpl *type_member_impl) {
754 m_opaque_up.reset(type_member_impl);
755 }
756
ref()757 TypeMemberImpl &SBTypeMember::ref() {
758 if (m_opaque_up == nullptr)
759 m_opaque_up = std::make_unique<TypeMemberImpl>();
760 return *m_opaque_up;
761 }
762
ref() const763 const TypeMemberImpl &SBTypeMember::ref() const { return *m_opaque_up; }
764
SBTypeMemberFunction()765 SBTypeMemberFunction::SBTypeMemberFunction() : m_opaque_sp() {
766 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeMemberFunction);
767 }
768
769 SBTypeMemberFunction::~SBTypeMemberFunction() = default;
770
SBTypeMemberFunction(const SBTypeMemberFunction & rhs)771 SBTypeMemberFunction::SBTypeMemberFunction(const SBTypeMemberFunction &rhs)
772 : m_opaque_sp(rhs.m_opaque_sp) {
773 LLDB_RECORD_CONSTRUCTOR(SBTypeMemberFunction,
774 (const lldb::SBTypeMemberFunction &), rhs);
775 }
776
777 lldb::SBTypeMemberFunction &SBTypeMemberFunction::
operator =(const lldb::SBTypeMemberFunction & rhs)778 operator=(const lldb::SBTypeMemberFunction &rhs) {
779 LLDB_RECORD_METHOD(
780 lldb::SBTypeMemberFunction &,
781 SBTypeMemberFunction, operator=,(const lldb::SBTypeMemberFunction &),
782 rhs);
783
784 if (this != &rhs)
785 m_opaque_sp = rhs.m_opaque_sp;
786 return LLDB_RECORD_RESULT(*this);
787 }
788
IsValid() const789 bool SBTypeMemberFunction::IsValid() const {
790 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMemberFunction, IsValid);
791 return this->operator bool();
792 }
operator bool() const793 SBTypeMemberFunction::operator bool() const {
794 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMemberFunction, operator bool);
795
796 return m_opaque_sp.get();
797 }
798
GetName()799 const char *SBTypeMemberFunction::GetName() {
800 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction, GetName);
801
802 if (m_opaque_sp)
803 return m_opaque_sp->GetName().GetCString();
804 return nullptr;
805 }
806
GetDemangledName()807 const char *SBTypeMemberFunction::GetDemangledName() {
808 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction,
809 GetDemangledName);
810
811 if (m_opaque_sp) {
812 ConstString mangled_str = m_opaque_sp->GetMangledName();
813 if (mangled_str) {
814 Mangled mangled(mangled_str);
815 return mangled.GetDemangledName().GetCString();
816 }
817 }
818 return nullptr;
819 }
820
GetMangledName()821 const char *SBTypeMemberFunction::GetMangledName() {
822 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction,
823 GetMangledName);
824
825 if (m_opaque_sp)
826 return m_opaque_sp->GetMangledName().GetCString();
827 return nullptr;
828 }
829
GetType()830 SBType SBTypeMemberFunction::GetType() {
831 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMemberFunction, GetType);
832
833 SBType sb_type;
834 if (m_opaque_sp) {
835 sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetType())));
836 }
837 return LLDB_RECORD_RESULT(sb_type);
838 }
839
GetReturnType()840 lldb::SBType SBTypeMemberFunction::GetReturnType() {
841 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMemberFunction, GetReturnType);
842
843 SBType sb_type;
844 if (m_opaque_sp) {
845 sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetReturnType())));
846 }
847 return LLDB_RECORD_RESULT(sb_type);
848 }
849
GetNumberOfArguments()850 uint32_t SBTypeMemberFunction::GetNumberOfArguments() {
851 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeMemberFunction,
852 GetNumberOfArguments);
853
854 if (m_opaque_sp)
855 return m_opaque_sp->GetNumArguments();
856 return 0;
857 }
858
GetArgumentTypeAtIndex(uint32_t i)859 lldb::SBType SBTypeMemberFunction::GetArgumentTypeAtIndex(uint32_t i) {
860 LLDB_RECORD_METHOD(lldb::SBType, SBTypeMemberFunction, GetArgumentTypeAtIndex,
861 (uint32_t), i);
862
863 SBType sb_type;
864 if (m_opaque_sp) {
865 sb_type.SetSP(
866 lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetArgumentAtIndex(i))));
867 }
868 return LLDB_RECORD_RESULT(sb_type);
869 }
870
GetKind()871 lldb::MemberFunctionKind SBTypeMemberFunction::GetKind() {
872 LLDB_RECORD_METHOD_NO_ARGS(lldb::MemberFunctionKind, SBTypeMemberFunction,
873 GetKind);
874
875 if (m_opaque_sp)
876 return m_opaque_sp->GetKind();
877 return lldb::eMemberFunctionKindUnknown;
878 }
879
GetDescription(lldb::SBStream & description,lldb::DescriptionLevel description_level)880 bool SBTypeMemberFunction::GetDescription(
881 lldb::SBStream &description, lldb::DescriptionLevel description_level) {
882 LLDB_RECORD_METHOD(bool, SBTypeMemberFunction, GetDescription,
883 (lldb::SBStream &, lldb::DescriptionLevel), description,
884 description_level);
885
886 Stream &strm = description.ref();
887
888 if (m_opaque_sp)
889 return m_opaque_sp->GetDescription(strm);
890
891 return false;
892 }
893
reset(TypeMemberFunctionImpl * type_member_impl)894 void SBTypeMemberFunction::reset(TypeMemberFunctionImpl *type_member_impl) {
895 m_opaque_sp.reset(type_member_impl);
896 }
897
ref()898 TypeMemberFunctionImpl &SBTypeMemberFunction::ref() {
899 if (!m_opaque_sp)
900 m_opaque_sp = std::make_shared<TypeMemberFunctionImpl>();
901 return *m_opaque_sp.get();
902 }
903
ref() const904 const TypeMemberFunctionImpl &SBTypeMemberFunction::ref() const {
905 return *m_opaque_sp.get();
906 }
907
908 namespace lldb_private {
909 namespace repro {
910
911 template <>
RegisterMethods(Registry & R)912 void RegisterMethods<SBType>(Registry &R) {
913 LLDB_REGISTER_CONSTRUCTOR(SBType, ());
914 LLDB_REGISTER_CONSTRUCTOR(SBType, (const lldb::SBType &));
915 LLDB_REGISTER_METHOD(bool, SBType, operator==,(lldb::SBType &));
916 LLDB_REGISTER_METHOD(bool, SBType, operator!=,(lldb::SBType &));
917 LLDB_REGISTER_METHOD(lldb::SBType &,
918 SBType, operator=,(const lldb::SBType &));
919 LLDB_REGISTER_METHOD_CONST(bool, SBType, IsValid, ());
920 LLDB_REGISTER_METHOD_CONST(bool, SBType, operator bool, ());
921 LLDB_REGISTER_METHOD(uint64_t, SBType, GetByteSize, ());
922 LLDB_REGISTER_METHOD(bool, SBType, IsPointerType, ());
923 LLDB_REGISTER_METHOD(bool, SBType, IsArrayType, ());
924 LLDB_REGISTER_METHOD(bool, SBType, IsVectorType, ());
925 LLDB_REGISTER_METHOD(bool, SBType, IsReferenceType, ());
926 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetPointerType, ());
927 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetPointeeType, ());
928 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetReferenceType, ());
929 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetTypedefedType, ());
930 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetDereferencedType, ());
931 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetArrayElementType, ());
932 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetArrayType, (uint64_t));
933 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetVectorElementType, ());
934 LLDB_REGISTER_METHOD(bool, SBType, IsFunctionType, ());
935 LLDB_REGISTER_METHOD(bool, SBType, IsPolymorphicClass, ());
936 LLDB_REGISTER_METHOD(bool, SBType, IsTypedefType, ());
937 LLDB_REGISTER_METHOD(bool, SBType, IsAnonymousType, ());
938 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetFunctionReturnType, ());
939 LLDB_REGISTER_METHOD(lldb::SBTypeList, SBType, GetFunctionArgumentTypes,
940 ());
941 LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfMemberFunctions, ());
942 LLDB_REGISTER_METHOD(lldb::SBTypeMemberFunction, SBType,
943 GetMemberFunctionAtIndex, (uint32_t));
944 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetUnqualifiedType, ());
945 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetCanonicalType, ());
946 LLDB_REGISTER_METHOD(lldb::BasicType, SBType, GetBasicType, ());
947 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetBasicType, (lldb::BasicType));
948 LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfDirectBaseClasses, ());
949 LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfVirtualBaseClasses, ());
950 LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfFields, ());
951 LLDB_REGISTER_METHOD(bool, SBType, GetDescription,
952 (lldb::SBStream &, lldb::DescriptionLevel));
953 LLDB_REGISTER_METHOD(lldb::SBTypeMember, SBType, GetDirectBaseClassAtIndex,
954 (uint32_t));
955 LLDB_REGISTER_METHOD(lldb::SBTypeMember, SBType, GetVirtualBaseClassAtIndex,
956 (uint32_t));
957 LLDB_REGISTER_METHOD(lldb::SBTypeEnumMemberList, SBType, GetEnumMembers,
958 ());
959 LLDB_REGISTER_METHOD(lldb::SBTypeMember, SBType, GetFieldAtIndex,
960 (uint32_t));
961 LLDB_REGISTER_METHOD(bool, SBType, IsTypeComplete, ());
962 LLDB_REGISTER_METHOD(uint32_t, SBType, GetTypeFlags, ());
963 LLDB_REGISTER_METHOD(lldb::SBModule, SBType, GetModule, ());
964 LLDB_REGISTER_METHOD(const char *, SBType, GetName, ());
965 LLDB_REGISTER_METHOD(const char *, SBType, GetDisplayTypeName, ());
966 LLDB_REGISTER_METHOD(lldb::TypeClass, SBType, GetTypeClass, ());
967 LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfTemplateArguments, ());
968 LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetTemplateArgumentType,
969 (uint32_t));
970 LLDB_REGISTER_METHOD(lldb::TemplateArgumentKind, SBType,
971 GetTemplateArgumentKind, (uint32_t));
972 LLDB_REGISTER_CONSTRUCTOR(SBTypeList, ());
973 LLDB_REGISTER_CONSTRUCTOR(SBTypeList, (const lldb::SBTypeList &));
974 LLDB_REGISTER_METHOD(bool, SBTypeList, IsValid, ());
975 LLDB_REGISTER_METHOD_CONST(bool, SBTypeList, operator bool, ());
976 LLDB_REGISTER_METHOD(lldb::SBTypeList &,
977 SBTypeList, operator=,(const lldb::SBTypeList &));
978 LLDB_REGISTER_METHOD(void, SBTypeList, Append, (lldb::SBType));
979 LLDB_REGISTER_METHOD(lldb::SBType, SBTypeList, GetTypeAtIndex, (uint32_t));
980 LLDB_REGISTER_METHOD(uint32_t, SBTypeList, GetSize, ());
981 LLDB_REGISTER_CONSTRUCTOR(SBTypeMember, ());
982 LLDB_REGISTER_CONSTRUCTOR(SBTypeMember, (const lldb::SBTypeMember &));
983 LLDB_REGISTER_METHOD(lldb::SBTypeMember &,
984 SBTypeMember, operator=,(const lldb::SBTypeMember &));
985 LLDB_REGISTER_METHOD_CONST(bool, SBTypeMember, IsValid, ());
986 LLDB_REGISTER_METHOD_CONST(bool, SBTypeMember, operator bool, ());
987 LLDB_REGISTER_METHOD(const char *, SBTypeMember, GetName, ());
988 LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMember, GetType, ());
989 LLDB_REGISTER_METHOD(uint64_t, SBTypeMember, GetOffsetInBytes, ());
990 LLDB_REGISTER_METHOD(uint64_t, SBTypeMember, GetOffsetInBits, ());
991 LLDB_REGISTER_METHOD(bool, SBTypeMember, IsBitfield, ());
992 LLDB_REGISTER_METHOD(uint32_t, SBTypeMember, GetBitfieldSizeInBits, ());
993 LLDB_REGISTER_METHOD(bool, SBTypeMember, GetDescription,
994 (lldb::SBStream &, lldb::DescriptionLevel));
995 LLDB_REGISTER_CONSTRUCTOR(SBTypeMemberFunction, ());
996 LLDB_REGISTER_CONSTRUCTOR(SBTypeMemberFunction,
997 (const lldb::SBTypeMemberFunction &));
998 LLDB_REGISTER_METHOD(
999 lldb::SBTypeMemberFunction &,
1000 SBTypeMemberFunction, operator=,(const lldb::SBTypeMemberFunction &));
1001 LLDB_REGISTER_METHOD_CONST(bool, SBTypeMemberFunction, IsValid, ());
1002 LLDB_REGISTER_METHOD_CONST(bool, SBTypeMemberFunction, operator bool, ());
1003 LLDB_REGISTER_METHOD(const char *, SBTypeMemberFunction, GetName, ());
1004 LLDB_REGISTER_METHOD(const char *, SBTypeMemberFunction, GetDemangledName,
1005 ());
1006 LLDB_REGISTER_METHOD(const char *, SBTypeMemberFunction, GetMangledName,
1007 ());
1008 LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMemberFunction, GetType, ());
1009 LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMemberFunction, GetReturnType, ());
1010 LLDB_REGISTER_METHOD(uint32_t, SBTypeMemberFunction, GetNumberOfArguments,
1011 ());
1012 LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMemberFunction,
1013 GetArgumentTypeAtIndex, (uint32_t));
1014 LLDB_REGISTER_METHOD(lldb::MemberFunctionKind, SBTypeMemberFunction,
1015 GetKind, ());
1016 LLDB_REGISTER_METHOD(bool, SBTypeMemberFunction, GetDescription,
1017 (lldb::SBStream &, lldb::DescriptionLevel));
1018 }
1019
1020 }
1021 }
1022