File indexing completed on 2026-05-10 08:42:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_SYMBOL_TYPE_H
0010 #define LLDB_SYMBOL_TYPE_H
0011
0012 #include "lldb/Core/Declaration.h"
0013 #include "lldb/Symbol/CompilerDecl.h"
0014 #include "lldb/Symbol/CompilerType.h"
0015 #include "lldb/Symbol/TypeList.h"
0016 #include "lldb/Symbol/TypeMap.h"
0017 #include "lldb/Symbol/TypeSystem.h"
0018 #include "lldb/Utility/ConstString.h"
0019 #include "lldb/Utility/UserID.h"
0020 #include "lldb/lldb-private.h"
0021
0022 #include "llvm/ADT/APSInt.h"
0023 #include "llvm/ADT/DenseSet.h"
0024 #include "llvm/ADT/STLForwardCompat.h"
0025 #include "llvm/Support/raw_ostream.h"
0026
0027 #include <optional>
0028 #include <set>
0029
0030 namespace lldb_private {
0031 class SymbolFileCommon;
0032
0033
0034
0035
0036
0037
0038 struct LanguageSet {
0039 llvm::SmallBitVector bitvector;
0040 LanguageSet();
0041
0042
0043 std::optional<lldb::LanguageType> GetSingularLanguage();
0044 void Insert(lldb::LanguageType language);
0045 bool Empty() const;
0046 size_t Size() const;
0047 bool operator[](unsigned i) const;
0048 };
0049
0050
0051
0052 struct CompilerContext {
0053 CompilerContext(CompilerContextKind t, ConstString n) : kind(t), name(n) {}
0054
0055 bool operator==(const CompilerContext &rhs) const {
0056 return kind == rhs.kind && name == rhs.name;
0057 }
0058 bool operator!=(const CompilerContext &rhs) const { return !(*this == rhs); }
0059
0060 void Dump(Stream &s) const;
0061
0062 CompilerContextKind kind;
0063 ConstString name;
0064 };
0065 llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
0066 const CompilerContext &rhs);
0067
0068 FLAGS_ENUM(TypeQueryOptions){
0069 e_none = 0u,
0070
0071
0072
0073 e_exact_match = (1u << 0),
0074
0075
0076 e_module_search = (1u << 1),
0077
0078
0079 e_ignore_modules = (1u << 2),
0080
0081
0082 e_strict_namespaces = (1u << 3),
0083
0084
0085
0086 e_find_one = (1u << 4),
0087
0088
0089 e_search_by_mangled_name = (1u << 5),
0090 };
0091 LLDB_MARK_AS_BITMASK_ENUM(TypeQueryOptions)
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 class TypeQuery {
0105 public:
0106 TypeQuery() = delete;
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148 TypeQuery(llvm::StringRef name, TypeQueryOptions options = e_none);
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 TypeQuery(const CompilerDeclContext &decl_ctx, ConstString type_basename,
0170 TypeQueryOptions options = e_none);
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190 TypeQuery(const CompilerDecl &decl, TypeQueryOptions options = e_none);
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208 TypeQuery(const llvm::ArrayRef<lldb_private::CompilerContext> &context,
0209 TypeQueryOptions options = e_none);
0210
0211
0212
0213
0214 TypeQuery(const TypeQuery &rhs) = default;
0215
0216
0217
0218 TypeQuery &operator=(const TypeQuery &rhs) = default;
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236 bool
0237 ContextMatches(llvm::ArrayRef<lldb_private::CompilerContext> context) const;
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248 ConstString GetTypeBasename() const;
0249
0250
0251
0252 bool HasLanguage() const { return m_languages.has_value(); }
0253
0254
0255
0256 void AddLanguage(lldb::LanguageType language);
0257
0258
0259
0260 void SetLanguages(LanguageSet languages);
0261
0262
0263
0264
0265
0266
0267
0268 bool LanguageMatches(lldb::LanguageType language) const;
0269
0270 bool GetExactMatch() const { return (m_options & e_exact_match) != 0; }
0271
0272 bool GetIgnoreModules() const { return (m_options & e_ignore_modules) != 0; }
0273 void SetIgnoreModules(bool b) {
0274 if (b)
0275 m_options |= e_ignore_modules;
0276 else
0277 m_options &= ~e_ignore_modules;
0278 }
0279
0280 bool GetStrictNamespaces() const {
0281 return (m_options & e_strict_namespaces) != 0;
0282 }
0283 void SetStrictNamespaces(bool b) {
0284 if (b)
0285 m_options |= e_strict_namespaces;
0286 else
0287 m_options &= ~e_strict_namespaces;
0288 }
0289
0290
0291
0292
0293
0294 bool GetModuleSearch() const { return (m_options & e_module_search) != 0; }
0295
0296
0297
0298 bool GetFindOne() const { return (m_options & e_find_one) != 0; }
0299 void SetFindOne(bool b) {
0300 if (b)
0301 m_options |= e_find_one;
0302 else
0303 m_options &= ~e_find_one;
0304 }
0305
0306
0307
0308 bool GetSearchByMangledName() const {
0309 return (m_options & e_search_by_mangled_name) != 0;
0310 }
0311
0312 void SetSearchByMangledName(bool b) {
0313 if (b)
0314 m_options |= e_search_by_mangled_name;
0315 else
0316 m_options &= ~e_search_by_mangled_name;
0317 }
0318
0319
0320
0321
0322 std::vector<lldb_private::CompilerContext> &GetContextRef() {
0323 return m_context;
0324 }
0325
0326 protected:
0327
0328
0329
0330 std::vector<lldb_private::CompilerContext> m_context;
0331
0332
0333 TypeQueryOptions m_options;
0334
0335
0336
0337 std::optional<LanguageSet> m_languages;
0338 };
0339
0340
0341
0342
0343
0344 class TypeResults {
0345 public:
0346
0347 TypeResults() = default;
0348
0349
0350
0351
0352
0353
0354
0355 bool InsertUnique(const lldb::TypeSP &type_sp);
0356
0357
0358 bool Done(const TypeQuery &query) const;
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378 bool AlreadySearched(lldb_private::SymbolFile *sym_file);
0379
0380
0381 llvm::DenseSet<lldb_private::SymbolFile *> &GetSearchedSymbolFiles() {
0382 return m_searched_symbol_files;
0383 }
0384
0385 lldb::TypeSP GetFirstType() const { return m_type_map.FirstType(); }
0386 TypeMap &GetTypeMap() { return m_type_map; }
0387 const TypeMap &GetTypeMap() const { return m_type_map; }
0388
0389 private:
0390
0391 TypeMap m_type_map;
0392
0393
0394 llvm::DenseSet<lldb_private::SymbolFile *> m_searched_symbol_files;
0395 };
0396
0397 class SymbolFileType : public std::enable_shared_from_this<SymbolFileType>,
0398 public UserID {
0399 public:
0400 SymbolFileType(SymbolFile &symbol_file, lldb::user_id_t uid)
0401 : UserID(uid), m_symbol_file(symbol_file) {}
0402
0403 SymbolFileType(SymbolFile &symbol_file, const lldb::TypeSP &type_sp);
0404
0405 ~SymbolFileType() = default;
0406
0407 Type *operator->() { return GetType(); }
0408
0409 Type *GetType();
0410 SymbolFile &GetSymbolFile() const { return m_symbol_file; }
0411
0412 protected:
0413 SymbolFile &m_symbol_file;
0414 lldb::TypeSP m_type_sp;
0415 };
0416
0417 class Type : public std::enable_shared_from_this<Type>, public UserID {
0418 public:
0419 enum EncodingDataType {
0420
0421 eEncodingInvalid,
0422
0423 eEncodingIsUID,
0424
0425
0426 eEncodingIsConstUID,
0427
0428
0429 eEncodingIsRestrictUID,
0430
0431
0432 eEncodingIsVolatileUID,
0433
0434 eEncodingIsTypedefUID,
0435
0436 eEncodingIsPointerUID,
0437
0438 eEncodingIsLValueReferenceUID,
0439
0440 eEncodingIsRValueReferenceUID,
0441
0442 eEncodingIsAtomicUID,
0443
0444 eEncodingIsSyntheticUID,
0445
0446 eEncodingIsLLVMPtrAuthUID
0447 };
0448
0449 enum class ResolveState : unsigned char {
0450 Unresolved = 0,
0451 Forward = 1,
0452 Layout = 2,
0453 Full = 3
0454 };
0455
0456 void Dump(Stream *s, bool show_context,
0457 lldb::DescriptionLevel level = lldb::eDescriptionLevelFull);
0458
0459 void DumpTypeName(Stream *s);
0460
0461
0462
0463
0464
0465 lldb::ModuleSP GetModule();
0466
0467
0468
0469
0470
0471 lldb::ModuleSP GetExeModule();
0472
0473 void GetDescription(Stream *s, lldb::DescriptionLevel level, bool show_name,
0474 ExecutionContextScope *exe_scope);
0475
0476 SymbolFile *GetSymbolFile() { return m_symbol_file; }
0477 const SymbolFile *GetSymbolFile() const { return m_symbol_file; }
0478
0479 ConstString GetName();
0480
0481 ConstString GetBaseName();
0482
0483 std::optional<uint64_t> GetByteSize(ExecutionContextScope *exe_scope);
0484
0485 llvm::Expected<uint32_t> GetNumChildren(bool omit_empty_base_classes);
0486
0487 bool IsAggregateType();
0488
0489
0490 bool IsTemplateType();
0491
0492 bool IsValidType() { return m_encoding_uid_type != eEncodingInvalid; }
0493
0494 bool IsTypedef() { return m_encoding_uid_type == eEncodingIsTypedefUID; }
0495
0496 lldb::TypeSP GetTypedefType();
0497
0498 ConstString GetName() const { return m_name; }
0499
0500 ConstString GetQualifiedName();
0501
0502 bool ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t address,
0503 AddressType address_type, DataExtractor &data);
0504
0505 bool WriteToMemory(ExecutionContext *exe_ctx, lldb::addr_t address,
0506 AddressType address_type, DataExtractor &data);
0507
0508 lldb::Format GetFormat();
0509
0510 lldb::Encoding GetEncoding(uint64_t &count);
0511
0512 SymbolContextScope *GetSymbolContextScope() { return m_context; }
0513 const SymbolContextScope *GetSymbolContextScope() const { return m_context; }
0514 void SetSymbolContextScope(SymbolContextScope *context) {
0515 m_context = context;
0516 }
0517
0518 const lldb_private::Declaration &GetDeclaration() const;
0519
0520
0521
0522 CompilerType GetFullCompilerType();
0523
0524
0525
0526
0527 CompilerType GetLayoutCompilerType();
0528
0529
0530
0531 CompilerType GetForwardCompilerType();
0532
0533 static int Compare(const Type &a, const Type &b);
0534
0535
0536
0537
0538 struct ParsedName {
0539 lldb::TypeClass type_class = lldb::eTypeClassAny;
0540
0541
0542
0543 llvm::SmallVector<llvm::StringRef> scope;
0544
0545 llvm::StringRef basename;
0546
0547 friend bool operator==(const ParsedName &lhs, const ParsedName &rhs) {
0548 return lhs.type_class == rhs.type_class && lhs.scope == rhs.scope &&
0549 lhs.basename == rhs.basename;
0550 }
0551
0552 friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
0553 const ParsedName &name) {
0554 return os << llvm::formatv(
0555 "Type::ParsedName({0:x}, [{1}], {2})",
0556 llvm::to_underlying(name.type_class),
0557 llvm::make_range(name.scope.begin(), name.scope.end()),
0558 name.basename);
0559 }
0560 };
0561
0562
0563 static std::optional<ParsedName>
0564 GetTypeScopeAndBasename(llvm::StringRef name);
0565
0566 void SetEncodingType(Type *encoding_type) { m_encoding_type = encoding_type; }
0567
0568 uint32_t GetEncodingMask();
0569
0570 typedef uint32_t Payload;
0571
0572 Payload GetPayload() { return m_payload; }
0573
0574 void SetPayload(Payload opaque_payload) { m_payload = opaque_payload; }
0575
0576 protected:
0577 ConstString m_name;
0578 SymbolFile *m_symbol_file = nullptr;
0579
0580 SymbolContextScope *m_context = nullptr;
0581 Type *m_encoding_type = nullptr;
0582 lldb::user_id_t m_encoding_uid = LLDB_INVALID_UID;
0583 EncodingDataType m_encoding_uid_type = eEncodingInvalid;
0584 uint64_t m_byte_size : 63;
0585 uint64_t m_byte_size_has_value : 1;
0586 Declaration m_decl;
0587 CompilerType m_compiler_type;
0588 ResolveState m_compiler_type_resolve_state = ResolveState::Unresolved;
0589
0590 Payload m_payload;
0591
0592 Type *GetEncodingType();
0593
0594 bool ResolveCompilerType(ResolveState compiler_type_resolve_state);
0595 private:
0596
0597
0598
0599
0600 friend class lldb_private::SymbolFileCommon;
0601
0602 Type(lldb::user_id_t uid, SymbolFile *symbol_file, ConstString name,
0603 std::optional<uint64_t> byte_size, SymbolContextScope *context,
0604 lldb::user_id_t encoding_uid, EncodingDataType encoding_uid_type,
0605 const Declaration &decl, const CompilerType &compiler_qual_type,
0606 ResolveState compiler_type_resolve_state, uint32_t opaque_payload = 0);
0607
0608
0609
0610 Type();
0611
0612 Type(Type &t) = default;
0613
0614 Type(Type &&t) = default;
0615
0616 Type &operator=(const Type &t) = default;
0617
0618 Type &operator=(Type &&t) = default;
0619 };
0620
0621
0622
0623
0624 class TypeImpl {
0625 public:
0626 TypeImpl() = default;
0627
0628 ~TypeImpl() = default;
0629
0630 TypeImpl(const lldb::TypeSP &type_sp);
0631
0632 TypeImpl(const CompilerType &compiler_type);
0633
0634 TypeImpl(const lldb::TypeSP &type_sp, const CompilerType &dynamic);
0635
0636 TypeImpl(const CompilerType &compiler_type, const CompilerType &dynamic);
0637
0638 void SetType(const lldb::TypeSP &type_sp);
0639
0640 void SetType(const CompilerType &compiler_type);
0641
0642 void SetType(const lldb::TypeSP &type_sp, const CompilerType &dynamic);
0643
0644 void SetType(const CompilerType &compiler_type, const CompilerType &dynamic);
0645
0646 bool operator==(const TypeImpl &rhs) const;
0647
0648 bool operator!=(const TypeImpl &rhs) const;
0649
0650 bool IsValid() const;
0651
0652 explicit operator bool() const;
0653
0654 void Clear();
0655
0656 lldb::ModuleSP GetModule() const;
0657
0658 ConstString GetName() const;
0659
0660 ConstString GetDisplayTypeName() const;
0661
0662 TypeImpl GetPointerType() const;
0663
0664 TypeImpl GetPointeeType() const;
0665
0666 TypeImpl GetReferenceType() const;
0667
0668 TypeImpl GetTypedefedType() const;
0669
0670 TypeImpl GetDereferencedType() const;
0671
0672 TypeImpl GetUnqualifiedType() const;
0673
0674 TypeImpl GetCanonicalType() const;
0675
0676 CompilerType GetCompilerType(bool prefer_dynamic);
0677
0678 CompilerType::TypeSystemSPWrapper GetTypeSystem(bool prefer_dynamic);
0679
0680 bool GetDescription(lldb_private::Stream &strm,
0681 lldb::DescriptionLevel description_level);
0682
0683 CompilerType FindDirectNestedType(llvm::StringRef name);
0684
0685 private:
0686 bool CheckModule(lldb::ModuleSP &module_sp) const;
0687 bool CheckExeModule(lldb::ModuleSP &module_sp) const;
0688 bool CheckModuleCommon(const lldb::ModuleWP &input_module_wp,
0689 lldb::ModuleSP &module_sp) const;
0690
0691 lldb::ModuleWP m_module_wp;
0692 lldb::ModuleWP m_exe_module_wp;
0693 CompilerType m_static_type;
0694 CompilerType m_dynamic_type;
0695 };
0696
0697 class TypeListImpl {
0698 public:
0699 TypeListImpl() = default;
0700
0701 void Append(const lldb::TypeImplSP &type) { m_content.push_back(type); }
0702
0703 class AppendVisitor {
0704 public:
0705 AppendVisitor(TypeListImpl &type_list) : m_type_list(type_list) {}
0706
0707 void operator()(const lldb::TypeImplSP &type) { m_type_list.Append(type); }
0708
0709 private:
0710 TypeListImpl &m_type_list;
0711 };
0712
0713 void Append(const lldb_private::TypeList &type_list);
0714
0715 lldb::TypeImplSP GetTypeAtIndex(size_t idx) {
0716 lldb::TypeImplSP type_sp;
0717 if (idx < GetSize())
0718 type_sp = m_content[idx];
0719 return type_sp;
0720 }
0721
0722 size_t GetSize() { return m_content.size(); }
0723
0724 private:
0725 std::vector<lldb::TypeImplSP> m_content;
0726 };
0727
0728 class TypeMemberImpl {
0729 public:
0730 TypeMemberImpl() = default;
0731
0732 TypeMemberImpl(const lldb::TypeImplSP &type_impl_sp, uint64_t bit_offset,
0733 ConstString name, uint32_t bitfield_bit_size = 0,
0734 bool is_bitfield = false)
0735 : m_type_impl_sp(type_impl_sp), m_bit_offset(bit_offset), m_name(name),
0736 m_bitfield_bit_size(bitfield_bit_size), m_is_bitfield(is_bitfield) {}
0737
0738 TypeMemberImpl(const lldb::TypeImplSP &type_impl_sp, uint64_t bit_offset)
0739 : m_type_impl_sp(type_impl_sp), m_bit_offset(bit_offset),
0740 m_bitfield_bit_size(0), m_is_bitfield(false) {
0741 if (m_type_impl_sp)
0742 m_name = m_type_impl_sp->GetName();
0743 }
0744
0745 const lldb::TypeImplSP &GetTypeImpl() { return m_type_impl_sp; }
0746
0747 ConstString GetName() const { return m_name; }
0748
0749 uint64_t GetBitOffset() const { return m_bit_offset; }
0750
0751 uint32_t GetBitfieldBitSize() const { return m_bitfield_bit_size; }
0752
0753 void SetBitfieldBitSize(uint32_t bitfield_bit_size) {
0754 m_bitfield_bit_size = bitfield_bit_size;
0755 }
0756
0757 bool GetIsBitfield() const { return m_is_bitfield; }
0758
0759 void SetIsBitfield(bool is_bitfield) { m_is_bitfield = is_bitfield; }
0760
0761 protected:
0762 lldb::TypeImplSP m_type_impl_sp;
0763 uint64_t m_bit_offset = 0;
0764 ConstString m_name;
0765 uint32_t m_bitfield_bit_size = 0;
0766 bool m_is_bitfield = false;
0767 };
0768
0769
0770
0771
0772
0773
0774
0775
0776
0777
0778
0779 class TypeAndOrName {
0780 public:
0781 TypeAndOrName() = default;
0782 TypeAndOrName(lldb::TypeSP &type_sp);
0783 TypeAndOrName(const CompilerType &compiler_type);
0784 TypeAndOrName(const char *type_str);
0785 TypeAndOrName(ConstString &type_const_string);
0786
0787 bool operator==(const TypeAndOrName &other) const;
0788
0789 bool operator!=(const TypeAndOrName &other) const;
0790
0791 ConstString GetName() const;
0792
0793 CompilerType GetCompilerType() const { return m_compiler_type; }
0794
0795 void SetName(ConstString type_name);
0796
0797 void SetName(const char *type_name_cstr);
0798
0799 void SetName(llvm::StringRef name);
0800
0801 void SetTypeSP(lldb::TypeSP type_sp);
0802
0803 void SetCompilerType(CompilerType compiler_type);
0804
0805 bool IsEmpty() const;
0806
0807 bool HasName() const;
0808
0809 bool HasCompilerType() const;
0810
0811 bool HasType() const { return HasCompilerType(); }
0812
0813 void Clear();
0814
0815 explicit operator bool() { return !IsEmpty(); }
0816
0817 private:
0818 CompilerType m_compiler_type;
0819 ConstString m_type_name;
0820 };
0821
0822 class TypeMemberFunctionImpl {
0823 public:
0824 TypeMemberFunctionImpl() = default;
0825
0826 TypeMemberFunctionImpl(const CompilerType &type, const CompilerDecl &decl,
0827 const std::string &name,
0828 const lldb::MemberFunctionKind &kind)
0829 : m_type(type), m_decl(decl), m_name(name), m_kind(kind) {}
0830
0831 bool IsValid();
0832
0833 ConstString GetName() const;
0834
0835 ConstString GetMangledName() const;
0836
0837 CompilerType GetType() const;
0838
0839 CompilerType GetReturnType() const;
0840
0841 size_t GetNumArguments() const;
0842
0843 CompilerType GetArgumentAtIndex(size_t idx) const;
0844
0845 lldb::MemberFunctionKind GetKind() const;
0846
0847 bool GetDescription(Stream &stream);
0848
0849 protected:
0850 std::string GetPrintableTypeName();
0851
0852 private:
0853 CompilerType m_type;
0854 CompilerDecl m_decl;
0855 ConstString m_name;
0856 lldb::MemberFunctionKind m_kind = lldb::eMemberFunctionKindUnknown;
0857 };
0858
0859 class TypeEnumMemberImpl {
0860 public:
0861 TypeEnumMemberImpl() : m_name("<invalid>") {}
0862
0863 TypeEnumMemberImpl(const lldb::TypeImplSP &integer_type_sp, ConstString name,
0864 const llvm::APSInt &value);
0865
0866 TypeEnumMemberImpl(const TypeEnumMemberImpl &rhs) = default;
0867
0868 TypeEnumMemberImpl &operator=(const TypeEnumMemberImpl &rhs);
0869
0870 bool IsValid() { return m_valid; }
0871
0872 ConstString GetName() const { return m_name; }
0873
0874 const lldb::TypeImplSP &GetIntegerType() const { return m_integer_type_sp; }
0875
0876 uint64_t GetValueAsUnsigned() const { return m_value.getZExtValue(); }
0877
0878 int64_t GetValueAsSigned() const { return m_value.getSExtValue(); }
0879
0880 protected:
0881 lldb::TypeImplSP m_integer_type_sp;
0882 ConstString m_name;
0883 llvm::APSInt m_value;
0884 bool m_valid = false;
0885 };
0886
0887 class TypeEnumMemberListImpl {
0888 public:
0889 TypeEnumMemberListImpl() = default;
0890
0891 void Append(const lldb::TypeEnumMemberImplSP &type) {
0892 m_content.push_back(type);
0893 }
0894
0895 void Append(const lldb_private::TypeEnumMemberListImpl &type_list);
0896
0897 lldb::TypeEnumMemberImplSP GetTypeEnumMemberAtIndex(size_t idx) {
0898 lldb::TypeEnumMemberImplSP enum_member;
0899 if (idx < GetSize())
0900 enum_member = m_content[idx];
0901 return enum_member;
0902 }
0903
0904 size_t GetSize() { return m_content.size(); }
0905
0906 private:
0907 std::vector<lldb::TypeEnumMemberImplSP> m_content;
0908 };
0909
0910 }
0911
0912 #endif