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