1047 lines · cpp
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-exception6//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/Symbol/CompilerDecl.h"17#include "lldb/Symbol/CompilerType.h"18#include "lldb/Symbol/Type.h"19#include "lldb/Symbol/TypeSystem.h"20#include "lldb/Utility/ConstString.h"21#include "lldb/Utility/DataExtractor.h"22#include "lldb/Utility/Instrumentation.h"23#include "lldb/Utility/Scalar.h"24#include "lldb/Utility/Stream.h"25#include "lldb/ValueObject/ValueObjectConstResult.h"26 27#include "llvm/ADT/APSInt.h"28#include "llvm/Support/MathExtras.h"29 30#include <memory>31#include <optional>32 33using namespace lldb;34using namespace lldb_private;35 36SBType::SBType() { LLDB_INSTRUMENT_VA(this); }37 38SBType::SBType(const CompilerType &type) : m_opaque_sp(new TypeImpl(type)) {}39 40SBType::SBType(const lldb::TypeSP &type_sp)41 : m_opaque_sp(new TypeImpl(type_sp)) {}42 43SBType::SBType(const lldb::TypeImplSP &type_impl_sp)44 : m_opaque_sp(type_impl_sp) {}45 46SBType::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//58bool 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 70bool 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 82lldb::TypeImplSP SBType::GetSP() { return m_opaque_sp; }83 84void SBType::SetSP(const lldb::TypeImplSP &type_impl_sp) {85 m_opaque_sp = type_impl_sp;86}87 88SBType &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 97SBType::~SBType() = default;98 99TypeImpl &SBType::ref() {100 if (m_opaque_sp.get() == nullptr)101 m_opaque_sp = std::make_shared<TypeImpl>();102 return *m_opaque_sp;103}104 105const TypeImpl &SBType::ref() const {106 // "const SBAddress &addr" should already have checked "addr.IsValid()" prior107 // to calling this function. In case you didn't we will assert and die to let108 // you know.109 assert(m_opaque_sp.get());110 return *m_opaque_sp;111}112 113bool SBType::IsValid() const {114 LLDB_INSTRUMENT_VA(this);115 return this->operator bool();116}117SBType::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 126uint64_t SBType::GetByteSize() {127 LLDB_INSTRUMENT_VA(this);128 129 if (IsValid())130 if (std::optional<uint64_t> size = llvm::expectedToOptional(131 m_opaque_sp->GetCompilerType(false).GetByteSize(nullptr)))132 return *size;133 return 0;134}135 136uint64_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 148bool SBType::IsPointerType() {149 LLDB_INSTRUMENT_VA(this);150 151 if (!IsValid())152 return false;153 return m_opaque_sp->GetCompilerType(true).IsPointerType();154}155 156bool 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 165bool 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 173bool SBType::IsReferenceType() {174 LLDB_INSTRUMENT_VA(this);175 176 if (!IsValid())177 return false;178 return m_opaque_sp->GetCompilerType(true).IsReferenceType();179}180 181SBType SBType::GetPointerType() {182 LLDB_INSTRUMENT_VA(this);183 184 if (!IsValid())185 return SBType();186 187 return SBType(std::make_shared<TypeImpl>(m_opaque_sp->GetPointerType()));188}189 190SBType SBType::GetPointeeType() {191 LLDB_INSTRUMENT_VA(this);192 193 if (!IsValid())194 return SBType();195 return SBType(std::make_shared<TypeImpl>(m_opaque_sp->GetPointeeType()));196}197 198SBType SBType::GetReferenceType() {199 LLDB_INSTRUMENT_VA(this);200 201 if (!IsValid())202 return SBType();203 return SBType(std::make_shared<TypeImpl>(m_opaque_sp->GetReferenceType()));204}205 206SBType SBType::GetTypedefedType() {207 LLDB_INSTRUMENT_VA(this);208 209 if (!IsValid())210 return SBType();211 return SBType(std::make_shared<TypeImpl>(m_opaque_sp->GetTypedefedType()));212}213 214SBType SBType::GetDereferencedType() {215 LLDB_INSTRUMENT_VA(this);216 217 if (!IsValid())218 return SBType();219 return SBType(std::make_shared<TypeImpl>(m_opaque_sp->GetDereferencedType()));220}221 222SBType SBType::GetArrayElementType() {223 LLDB_INSTRUMENT_VA(this);224 225 if (!IsValid())226 return SBType();227 return SBType(std::make_shared<TypeImpl>(228 m_opaque_sp->GetCompilerType(true).GetArrayElementType(nullptr)));229}230 231SBType SBType::GetArrayType(uint64_t size) {232 LLDB_INSTRUMENT_VA(this, size);233 234 if (!IsValid())235 return SBType();236 return SBType(std::make_shared<TypeImpl>(237 m_opaque_sp->GetCompilerType(true).GetArrayType(size)));238}239 240SBType 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(std::make_shared<TypeImpl>(vector_element_type));249 }250 return type_sb;251}252 253bool SBType::IsFunctionType() {254 LLDB_INSTRUMENT_VA(this);255 256 if (!IsValid())257 return false;258 return m_opaque_sp->GetCompilerType(true).IsFunctionType();259}260 261bool SBType::IsPolymorphicClass() {262 LLDB_INSTRUMENT_VA(this);263 264 if (!IsValid())265 return false;266 return m_opaque_sp->GetCompilerType(true).IsPolymorphicClass();267}268 269bool SBType::IsTypedefType() {270 LLDB_INSTRUMENT_VA(this);271 272 if (!IsValid())273 return false;274 return m_opaque_sp->GetCompilerType(true).IsTypedefType();275}276 277bool SBType::IsAnonymousType() {278 LLDB_INSTRUMENT_VA(this);279 280 if (!IsValid())281 return false;282 return m_opaque_sp->GetCompilerType(true).IsAnonymousType();283}284 285bool SBType::IsScopedEnumerationType() {286 LLDB_INSTRUMENT_VA(this);287 288 if (!IsValid())289 return false;290 return m_opaque_sp->GetCompilerType(true).IsScopedEnumerationType();291}292 293bool SBType::IsAggregateType() {294 LLDB_INSTRUMENT_VA(this);295 296 if (!IsValid())297 return false;298 return m_opaque_sp->GetCompilerType(true).IsAggregateType();299}300 301lldb::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 313lldb::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 327uint32_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 336lldb::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 346SBTypeStaticField::SBTypeStaticField() { LLDB_INSTRUMENT_VA(this); }347 348SBTypeStaticField::SBTypeStaticField(lldb_private::CompilerDecl decl)349 : m_opaque_up(decl ? std::make_unique<CompilerDecl>(decl) : nullptr) {}350 351SBTypeStaticField::SBTypeStaticField(const SBTypeStaticField &rhs) {352 LLDB_INSTRUMENT_VA(this, rhs);353 354 m_opaque_up = clone(rhs.m_opaque_up);355}356 357SBTypeStaticField &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 364SBTypeStaticField::~SBTypeStaticField() { LLDB_INSTRUMENT_VA(this); }365 366SBTypeStaticField::operator bool() const {367 LLDB_INSTRUMENT_VA(this);368 369 return IsValid();370}371 372bool SBTypeStaticField::IsValid() const {373 LLDB_INSTRUMENT_VA(this);374 375 return m_opaque_up != nullptr;376}377 378const char *SBTypeStaticField::GetName() {379 LLDB_INSTRUMENT_VA(this);380 381 if (!IsValid())382 return "";383 return m_opaque_up->GetName().GetCString();384}385 386const char *SBTypeStaticField::GetMangledName() {387 LLDB_INSTRUMENT_VA(this);388 389 if (!IsValid())390 return "";391 return m_opaque_up->GetMangledName().GetCString();392}393 394SBType SBTypeStaticField::GetType() {395 LLDB_INSTRUMENT_VA(this);396 397 if (!IsValid())398 return SBType();399 return SBType(m_opaque_up->GetType());400}401 402SBValue 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 419lldb::SBType SBType::GetUnqualifiedType() {420 LLDB_INSTRUMENT_VA(this);421 422 if (!IsValid())423 return SBType();424 return SBType(std::make_shared<TypeImpl>(m_opaque_sp->GetUnqualifiedType()));425}426 427lldb::SBType SBType::GetCanonicalType() {428 LLDB_INSTRUMENT_VA(this);429 430 if (IsValid())431 return SBType(std::make_shared<TypeImpl>(m_opaque_sp->GetCanonicalType()));432 return SBType();433}434 435SBType 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 445lldb::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 453SBType 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 462uint32_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 470uint32_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 478uint32_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 486bool 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 } else495 strm.PutCString("No value");496 497 return true;498}499 500SBTypeMember 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 std::make_shared<TypeImpl>(base_class_type), bit_offset));512 }513 return sb_type_member;514}515 516SBTypeMember 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 std::make_shared<TypeImpl>(base_class_type), bit_offset));528 }529 return sb_type_member;530}531 532SBTypeStaticField 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 542SBTypeEnumMemberList 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(550 [&sb_enum_member_list](const CompilerType &integer_type,551 ConstString name,552 const llvm::APSInt &value) -> bool {553 SBTypeEnumMember enum_member(std::make_shared<TypeEnumMemberImpl>(554 std::make_shared<TypeImpl>(integer_type), name, value));555 sb_enum_member_list.Append(enum_member);556 return true; // Keep iterating557 });558 }559 }560 return sb_enum_member_list;561}562 563SBTypeMember SBType::GetFieldAtIndex(uint32_t idx) {564 LLDB_INSTRUMENT_VA(this, idx);565 566 SBTypeMember sb_type_member;567 if (IsValid()) {568 CompilerType this_type(m_opaque_sp->GetCompilerType(false));569 if (this_type.IsValid()) {570 uint64_t bit_offset = 0;571 uint32_t bitfield_bit_size = 0;572 bool is_bitfield = false;573 std::string name_sstr;574 CompilerType field_type(this_type.GetFieldAtIndex(575 idx, name_sstr, &bit_offset, &bitfield_bit_size, &is_bitfield));576 if (field_type.IsValid()) {577 ConstString name;578 if (!name_sstr.empty())579 name.SetCString(name_sstr.c_str());580 sb_type_member.reset(new TypeMemberImpl(581 std::make_shared<TypeImpl>(field_type), bit_offset, name,582 bitfield_bit_size, is_bitfield));583 }584 }585 }586 return sb_type_member;587}588 589bool SBType::IsTypeComplete() {590 LLDB_INSTRUMENT_VA(this);591 592 if (!IsValid())593 return false;594 CompilerType compiler_type = m_opaque_sp->GetCompilerType(false);595 // Only return true if we have a complete type and it wasn't forcefully596 // completed.597 if (compiler_type.IsCompleteType())598 return !compiler_type.IsForcefullyCompleted();599 return false;600}601 602uint32_t SBType::GetTypeFlags() {603 LLDB_INSTRUMENT_VA(this);604 605 if (!IsValid())606 return 0;607 return m_opaque_sp->GetCompilerType(true).GetTypeInfo();608}609 610lldb::SBModule SBType::GetModule() {611 LLDB_INSTRUMENT_VA(this);612 613 lldb::SBModule sb_module;614 if (!IsValid())615 return sb_module;616 617 sb_module.SetSP(m_opaque_sp->GetModule());618 return sb_module;619}620 621const char *SBType::GetName() {622 LLDB_INSTRUMENT_VA(this);623 624 if (!IsValid())625 return "";626 return m_opaque_sp->GetName().GetCString();627}628 629const char *SBType::GetDisplayTypeName() {630 LLDB_INSTRUMENT_VA(this);631 632 if (!IsValid())633 return "";634 return m_opaque_sp->GetDisplayTypeName().GetCString();635}636 637lldb::TypeClass SBType::GetTypeClass() {638 LLDB_INSTRUMENT_VA(this);639 640 if (IsValid())641 return m_opaque_sp->GetCompilerType(true).GetTypeClass();642 return lldb::eTypeClassInvalid;643}644 645uint32_t SBType::GetNumberOfTemplateArguments() {646 LLDB_INSTRUMENT_VA(this);647 648 if (IsValid())649 return m_opaque_sp->GetCompilerType(false).GetNumTemplateArguments(650 /*expand_pack=*/true);651 return 0;652}653 654lldb::SBType SBType::GetTemplateArgumentType(uint32_t idx) {655 LLDB_INSTRUMENT_VA(this, idx);656 657 if (!IsValid())658 return SBType();659 660 CompilerType type;661 const bool expand_pack = true;662 switch(GetTemplateArgumentKind(idx)) {663 case eTemplateArgumentKindType:664 type = m_opaque_sp->GetCompilerType(false).GetTypeTemplateArgument(665 idx, expand_pack);666 break;667 case eTemplateArgumentKindIntegral:668 type = m_opaque_sp->GetCompilerType(false)669 .GetIntegralTemplateArgument(idx, expand_pack)670 ->type;671 break;672 default:673 break;674 }675 if (type.IsValid())676 return SBType(type);677 return SBType();678}679 680lldb::TemplateArgumentKind SBType::GetTemplateArgumentKind(uint32_t idx) {681 LLDB_INSTRUMENT_VA(this, idx);682 683 if (IsValid())684 return m_opaque_sp->GetCompilerType(false).GetTemplateArgumentKind(685 idx, /*expand_pack=*/true);686 return eTemplateArgumentKindNull;687}688 689lldb::SBValue SBType::GetTemplateArgumentValue(lldb::SBTarget target,690 uint32_t idx) {691 LLDB_INSTRUMENT_VA(this, target, idx);692 693 if (!IsValid())694 return {};695 696 std::optional<CompilerType::IntegralTemplateArgument> arg;697 const bool expand_pack = true;698 switch (GetTemplateArgumentKind(idx)) {699 case eTemplateArgumentKindStructuralValue:700 case eTemplateArgumentKindIntegral:701 arg = m_opaque_sp->GetCompilerType(false).GetIntegralTemplateArgument(702 idx, expand_pack);703 break;704 default:705 break;706 }707 708 if (!arg)709 return {};710 711 DataExtractor data;712 arg->value.GetData(data);713 714 ExecutionContext exe_ctx;715 auto target_sp = target.GetSP();716 if (!target_sp)717 return {};718 719 target_sp->CalculateExecutionContext(exe_ctx);720 721 return ValueObject::CreateValueObjectFromData("value", data, exe_ctx,722 arg->type);723}724 725SBType SBType::FindDirectNestedType(const char *name) {726 LLDB_INSTRUMENT_VA(this, name);727 728 if (!IsValid())729 return SBType();730 return SBType(m_opaque_sp->FindDirectNestedType(name));731}732 733SBTypeList::SBTypeList() : m_opaque_up(new TypeListImpl()) {734 LLDB_INSTRUMENT_VA(this);735}736 737SBTypeList::SBTypeList(const SBTypeList &rhs)738 : m_opaque_up(new TypeListImpl()) {739 LLDB_INSTRUMENT_VA(this, rhs);740 741 for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize();742 i < rhs_size; i++)743 Append(const_cast<SBTypeList &>(rhs).GetTypeAtIndex(i));744}745 746bool SBTypeList::IsValid() {747 LLDB_INSTRUMENT_VA(this);748 return this->operator bool();749}750SBTypeList::operator bool() const {751 LLDB_INSTRUMENT_VA(this);752 753 return (m_opaque_up != nullptr);754}755 756SBTypeList &SBTypeList::operator=(const SBTypeList &rhs) {757 LLDB_INSTRUMENT_VA(this, rhs);758 759 if (this != &rhs) {760 m_opaque_up = std::make_unique<TypeListImpl>();761 for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize();762 i < rhs_size; i++)763 Append(const_cast<SBTypeList &>(rhs).GetTypeAtIndex(i));764 }765 return *this;766}767 768void SBTypeList::Append(SBType type) {769 LLDB_INSTRUMENT_VA(this, type);770 771 if (type.IsValid())772 m_opaque_up->Append(type.m_opaque_sp);773}774 775SBType SBTypeList::GetTypeAtIndex(uint32_t index) {776 LLDB_INSTRUMENT_VA(this, index);777 778 if (m_opaque_up)779 return SBType(m_opaque_up->GetTypeAtIndex(index));780 return SBType();781}782 783uint32_t SBTypeList::GetSize() {784 LLDB_INSTRUMENT_VA(this);785 786 return m_opaque_up->GetSize();787}788 789SBTypeList::~SBTypeList() = default;790 791SBTypeMember::SBTypeMember() { LLDB_INSTRUMENT_VA(this); }792 793SBTypeMember::~SBTypeMember() = default;794 795SBTypeMember::SBTypeMember(const SBTypeMember &rhs) {796 LLDB_INSTRUMENT_VA(this, rhs);797 798 if (this != &rhs) {799 if (rhs.IsValid())800 m_opaque_up = std::make_unique<TypeMemberImpl>(rhs.ref());801 }802}803 804lldb::SBTypeMember &SBTypeMember::operator=(const lldb::SBTypeMember &rhs) {805 LLDB_INSTRUMENT_VA(this, rhs);806 807 if (this != &rhs) {808 if (rhs.IsValid())809 m_opaque_up = std::make_unique<TypeMemberImpl>(rhs.ref());810 }811 return *this;812}813 814bool SBTypeMember::IsValid() const {815 LLDB_INSTRUMENT_VA(this);816 return this->operator bool();817}818SBTypeMember::operator bool() const {819 LLDB_INSTRUMENT_VA(this);820 821 return m_opaque_up.get();822}823 824const char *SBTypeMember::GetName() {825 LLDB_INSTRUMENT_VA(this);826 827 if (m_opaque_up)828 return m_opaque_up->GetName().GetCString();829 return nullptr;830}831 832SBType SBTypeMember::GetType() {833 LLDB_INSTRUMENT_VA(this);834 835 SBType sb_type;836 if (m_opaque_up) {837 sb_type.SetSP(m_opaque_up->GetTypeImpl());838 }839 return sb_type;840}841 842uint64_t SBTypeMember::GetOffsetInBytes() {843 LLDB_INSTRUMENT_VA(this);844 845 if (m_opaque_up)846 return m_opaque_up->GetBitOffset() / 8u;847 return 0;848}849 850uint64_t SBTypeMember::GetOffsetInBits() {851 LLDB_INSTRUMENT_VA(this);852 853 if (m_opaque_up)854 return m_opaque_up->GetBitOffset();855 return 0;856}857 858bool SBTypeMember::IsBitfield() {859 LLDB_INSTRUMENT_VA(this);860 861 if (m_opaque_up)862 return m_opaque_up->GetIsBitfield();863 return false;864}865 866uint32_t SBTypeMember::GetBitfieldSizeInBits() {867 LLDB_INSTRUMENT_VA(this);868 869 if (m_opaque_up)870 return m_opaque_up->GetBitfieldBitSize();871 return 0;872}873 874bool SBTypeMember::GetDescription(lldb::SBStream &description,875 lldb::DescriptionLevel description_level) {876 LLDB_INSTRUMENT_VA(this, description, description_level);877 878 Stream &strm = description.ref();879 880 if (m_opaque_up) {881 const uint32_t bit_offset = m_opaque_up->GetBitOffset();882 const uint32_t byte_offset = bit_offset / 8u;883 const uint32_t byte_bit_offset = bit_offset % 8u;884 const char *name = m_opaque_up->GetName().GetCString();885 if (byte_bit_offset)886 strm.Printf("+%u + %u bits: (", byte_offset, byte_bit_offset);887 else888 strm.Printf("+%u: (", byte_offset);889 890 TypeImplSP type_impl_sp(m_opaque_up->GetTypeImpl());891 if (type_impl_sp)892 type_impl_sp->GetDescription(strm, description_level);893 894 strm.Printf(") %s", name);895 if (m_opaque_up->GetIsBitfield()) {896 const uint32_t bitfield_bit_size = m_opaque_up->GetBitfieldBitSize();897 strm.Printf(" : %u", bitfield_bit_size);898 }899 } else {900 strm.PutCString("No value");901 }902 return true;903}904 905void SBTypeMember::reset(TypeMemberImpl *type_member_impl) {906 m_opaque_up.reset(type_member_impl);907}908 909TypeMemberImpl &SBTypeMember::ref() {910 if (m_opaque_up == nullptr)911 m_opaque_up = std::make_unique<TypeMemberImpl>();912 return *m_opaque_up;913}914 915const TypeMemberImpl &SBTypeMember::ref() const { return *m_opaque_up; }916 917SBTypeMemberFunction::SBTypeMemberFunction() { LLDB_INSTRUMENT_VA(this); }918 919SBTypeMemberFunction::~SBTypeMemberFunction() = default;920 921SBTypeMemberFunction::SBTypeMemberFunction(const SBTypeMemberFunction &rhs)922 : m_opaque_sp(rhs.m_opaque_sp) {923 LLDB_INSTRUMENT_VA(this, rhs);924}925 926lldb::SBTypeMemberFunction &SBTypeMemberFunction::927operator=(const lldb::SBTypeMemberFunction &rhs) {928 LLDB_INSTRUMENT_VA(this, rhs);929 930 if (this != &rhs)931 m_opaque_sp = rhs.m_opaque_sp;932 return *this;933}934 935bool SBTypeMemberFunction::IsValid() const {936 LLDB_INSTRUMENT_VA(this);937 return this->operator bool();938}939SBTypeMemberFunction::operator bool() const {940 LLDB_INSTRUMENT_VA(this);941 942 return m_opaque_sp.get();943}944 945const char *SBTypeMemberFunction::GetName() {946 LLDB_INSTRUMENT_VA(this);947 948 if (m_opaque_sp)949 return m_opaque_sp->GetName().GetCString();950 return nullptr;951}952 953const char *SBTypeMemberFunction::GetDemangledName() {954 LLDB_INSTRUMENT_VA(this);955 956 if (!m_opaque_sp)957 return nullptr;958 959 ConstString mangled_str = m_opaque_sp->GetMangledName();960 if (!mangled_str)961 return nullptr;962 963 Mangled mangled(mangled_str);964 return mangled.GetDemangledName().GetCString();965}966 967const char *SBTypeMemberFunction::GetMangledName() {968 LLDB_INSTRUMENT_VA(this);969 970 if (m_opaque_sp)971 return m_opaque_sp->GetMangledName().GetCString();972 return nullptr;973}974 975SBType SBTypeMemberFunction::GetType() {976 LLDB_INSTRUMENT_VA(this);977 978 SBType sb_type;979 if (m_opaque_sp) {980 sb_type.SetSP(std::make_shared<TypeImpl>(m_opaque_sp->GetType()));981 }982 return sb_type;983}984 985lldb::SBType SBTypeMemberFunction::GetReturnType() {986 LLDB_INSTRUMENT_VA(this);987 988 SBType sb_type;989 if (m_opaque_sp) {990 sb_type.SetSP(std::make_shared<TypeImpl>(m_opaque_sp->GetReturnType()));991 }992 return sb_type;993}994 995uint32_t SBTypeMemberFunction::GetNumberOfArguments() {996 LLDB_INSTRUMENT_VA(this);997 998 if (m_opaque_sp)999 return m_opaque_sp->GetNumArguments();1000 return 0;1001}1002 1003lldb::SBType SBTypeMemberFunction::GetArgumentTypeAtIndex(uint32_t i) {1004 LLDB_INSTRUMENT_VA(this, i);1005 1006 SBType sb_type;1007 if (m_opaque_sp) {1008 sb_type.SetSP(1009 std::make_shared<TypeImpl>(m_opaque_sp->GetArgumentAtIndex(i)));1010 }1011 return sb_type;1012}1013 1014lldb::MemberFunctionKind SBTypeMemberFunction::GetKind() {1015 LLDB_INSTRUMENT_VA(this);1016 1017 if (m_opaque_sp)1018 return m_opaque_sp->GetKind();1019 return lldb::eMemberFunctionKindUnknown;1020}1021 1022bool SBTypeMemberFunction::GetDescription(1023 lldb::SBStream &description, lldb::DescriptionLevel description_level) {1024 LLDB_INSTRUMENT_VA(this, description, description_level);1025 1026 Stream &strm = description.ref();1027 1028 if (m_opaque_sp)1029 return m_opaque_sp->GetDescription(strm);1030 1031 return false;1032}1033 1034void SBTypeMemberFunction::reset(TypeMemberFunctionImpl *type_member_impl) {1035 m_opaque_sp.reset(type_member_impl);1036}1037 1038TypeMemberFunctionImpl &SBTypeMemberFunction::ref() {1039 if (!m_opaque_sp)1040 m_opaque_sp = std::make_shared<TypeMemberFunctionImpl>();1041 return *m_opaque_sp.get();1042}1043 1044const TypeMemberFunctionImpl &SBTypeMemberFunction::ref() const {1045 return *m_opaque_sp.get();1046}1047