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