File indexing completed on 2026-05-10 08:42:53
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_SYMBOL_TYPESYSTEM_H
0010 #define LLDB_SYMBOL_TYPESYSTEM_H
0011
0012 #include <functional>
0013 #include <mutex>
0014 #include <optional>
0015 #include <string>
0016
0017 #include "llvm/ADT/APFloat.h"
0018 #include "llvm/ADT/APSInt.h"
0019 #include "llvm/ADT/DenseMap.h"
0020 #include "llvm/ADT/SmallBitVector.h"
0021 #include "llvm/Support/Casting.h"
0022 #include "llvm/Support/Error.h"
0023 #include "llvm/Support/JSON.h"
0024
0025 #include "lldb/Core/PluginInterface.h"
0026 #include "lldb/Expression/Expression.h"
0027 #include "lldb/Symbol/CompilerDecl.h"
0028 #include "lldb/Symbol/CompilerDeclContext.h"
0029 #include "lldb/Symbol/Type.h"
0030 #include "lldb/Utility/Scalar.h"
0031 #include "lldb/lldb-forward.h"
0032 #include "lldb/lldb-private.h"
0033 #include "lldb/lldb-types.h"
0034
0035 class PDBASTParser;
0036
0037 namespace lldb_private {
0038
0039 namespace plugin {
0040 namespace dwarf {
0041 class DWARFDIE;
0042 class DWARFASTParser;
0043 }
0044 }
0045
0046 namespace npdb {
0047 class PdbAstBuilder;
0048 }
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 class TypeSystem : public PluginInterface,
0070 public std::enable_shared_from_this<TypeSystem> {
0071 public:
0072
0073 TypeSystem();
0074 ~TypeSystem() override;
0075
0076
0077 virtual bool isA(const void *ClassID) const = 0;
0078
0079 static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language,
0080 Module *module);
0081
0082 static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language,
0083 Target *target);
0084
0085
0086
0087 virtual void Finalize() {}
0088
0089 virtual plugin::dwarf::DWARFASTParser *GetDWARFParser() { return nullptr; }
0090
0091 virtual PDBASTParser *GetPDBParser() { return nullptr; }
0092 virtual npdb::PdbAstBuilder *GetNativePDBParser() { return nullptr; }
0093
0094 virtual SymbolFile *GetSymbolFile() const { return m_sym_file; }
0095
0096 virtual void SetSymbolFile(SymbolFile *sym_file) { m_sym_file = sym_file; }
0097
0098
0099 virtual ConstString DeclGetName(void *opaque_decl) = 0;
0100
0101 virtual ConstString DeclGetMangledName(void *opaque_decl);
0102
0103 virtual CompilerDeclContext DeclGetDeclContext(void *opaque_decl);
0104
0105 virtual CompilerType DeclGetFunctionReturnType(void *opaque_decl);
0106
0107 virtual size_t DeclGetFunctionNumArguments(void *opaque_decl);
0108
0109 virtual CompilerType DeclGetFunctionArgumentType(void *opaque_decl,
0110 size_t arg_idx);
0111
0112 virtual std::vector<lldb_private::CompilerContext>
0113 DeclGetCompilerContext(void *opaque_decl);
0114
0115 virtual Scalar DeclGetConstantValue(void *opaque_decl) { return Scalar(); }
0116
0117 virtual CompilerType GetTypeForDecl(void *opaque_decl) = 0;
0118
0119
0120
0121 virtual std::vector<CompilerDecl>
0122 DeclContextFindDeclByName(void *opaque_decl_ctx, ConstString name,
0123 const bool ignore_imported_decls);
0124
0125 virtual ConstString DeclContextGetName(void *opaque_decl_ctx) = 0;
0126
0127 virtual ConstString
0128 DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) = 0;
0129
0130 virtual bool DeclContextIsClassMethod(void *opaque_decl_ctx) = 0;
0131
0132 virtual bool DeclContextIsContainedInLookup(void *opaque_decl_ctx,
0133 void *other_opaque_decl_ctx) = 0;
0134
0135 virtual lldb::LanguageType DeclContextGetLanguage(void *opaque_decl_ctx) = 0;
0136
0137
0138 virtual CompilerDeclContext
0139 GetCompilerDeclContextForType(const CompilerType &type);
0140
0141 virtual std::vector<lldb_private::CompilerContext>
0142 DeclContextGetCompilerContext(void *opaque_decl_ctx);
0143
0144
0145 #ifndef NDEBUG
0146
0147
0148 virtual bool Verify(lldb::opaque_compiler_type_t type) = 0;
0149 #endif
0150
0151 virtual bool IsArrayType(lldb::opaque_compiler_type_t type,
0152 CompilerType *element_type, uint64_t *size,
0153 bool *is_incomplete) = 0;
0154
0155 virtual bool IsAggregateType(lldb::opaque_compiler_type_t type) = 0;
0156
0157 virtual bool IsAnonymousType(lldb::opaque_compiler_type_t type);
0158
0159 virtual bool IsCharType(lldb::opaque_compiler_type_t type) = 0;
0160
0161 virtual bool IsCompleteType(lldb::opaque_compiler_type_t type) = 0;
0162
0163 virtual bool IsDefined(lldb::opaque_compiler_type_t type) = 0;
0164
0165 virtual bool IsFloatingPointType(lldb::opaque_compiler_type_t type,
0166 uint32_t &count, bool &is_complex) = 0;
0167
0168 virtual bool IsFunctionType(lldb::opaque_compiler_type_t type) = 0;
0169
0170 virtual size_t
0171 GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) = 0;
0172
0173 virtual CompilerType
0174 GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type,
0175 const size_t index) = 0;
0176
0177 virtual bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) = 0;
0178
0179 virtual bool
0180 IsMemberFunctionPointerType(lldb::opaque_compiler_type_t type) = 0;
0181
0182 virtual bool IsBlockPointerType(lldb::opaque_compiler_type_t type,
0183 CompilerType *function_pointer_type_ptr) = 0;
0184
0185 virtual bool IsIntegerType(lldb::opaque_compiler_type_t type,
0186 bool &is_signed) = 0;
0187
0188 virtual bool IsEnumerationType(lldb::opaque_compiler_type_t type,
0189 bool &is_signed) {
0190 is_signed = false;
0191 return false;
0192 }
0193
0194 virtual bool IsScopedEnumerationType(lldb::opaque_compiler_type_t type) = 0;
0195
0196 virtual bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
0197 CompilerType *target_type,
0198 bool check_cplusplus, bool check_objc) = 0;
0199
0200 virtual bool IsPointerType(lldb::opaque_compiler_type_t type,
0201 CompilerType *pointee_type) = 0;
0202
0203 virtual bool IsScalarType(lldb::opaque_compiler_type_t type) = 0;
0204
0205 virtual bool IsVoidType(lldb::opaque_compiler_type_t type) = 0;
0206
0207 virtual bool CanPassInRegisters(const CompilerType &type) = 0;
0208
0209
0210 virtual bool SupportsLanguage(lldb::LanguageType language) = 0;
0211
0212 static bool SupportsLanguageStatic(lldb::LanguageType language);
0213
0214
0215 virtual bool GetCompleteType(lldb::opaque_compiler_type_t type) = 0;
0216
0217 virtual bool IsForcefullyCompleted(lldb::opaque_compiler_type_t type) {
0218 return false;
0219 }
0220
0221
0222
0223 virtual uint32_t GetPointerByteSize() = 0;
0224
0225 virtual unsigned GetPtrAuthKey(lldb::opaque_compiler_type_t type) = 0;
0226
0227 virtual unsigned
0228 GetPtrAuthDiscriminator(lldb::opaque_compiler_type_t type) = 0;
0229
0230 virtual bool
0231 GetPtrAuthAddressDiversity(lldb::opaque_compiler_type_t type) = 0;
0232
0233
0234
0235 virtual ConstString GetTypeName(lldb::opaque_compiler_type_t type,
0236 bool BaseOnly) = 0;
0237
0238 virtual ConstString GetDisplayTypeName(lldb::opaque_compiler_type_t type) = 0;
0239
0240
0241
0242 virtual ConstString GetMangledTypeName(lldb::opaque_compiler_type_t type);
0243
0244 virtual uint32_t
0245 GetTypeInfo(lldb::opaque_compiler_type_t type,
0246 CompilerType *pointee_or_element_compiler_type) = 0;
0247
0248 virtual lldb::LanguageType
0249 GetMinimumLanguage(lldb::opaque_compiler_type_t type) = 0;
0250
0251 virtual lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) = 0;
0252
0253
0254
0255 virtual CompilerType
0256 GetArrayElementType(lldb::opaque_compiler_type_t type,
0257 ExecutionContextScope *exe_scope) = 0;
0258
0259 virtual CompilerType GetArrayType(lldb::opaque_compiler_type_t type,
0260 uint64_t size);
0261
0262 virtual CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) = 0;
0263
0264 virtual CompilerType
0265 GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) = 0;
0266
0267
0268
0269 virtual int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) = 0;
0270
0271 virtual CompilerType
0272 GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type,
0273 size_t idx) = 0;
0274
0275 virtual CompilerType
0276 GetFunctionReturnType(lldb::opaque_compiler_type_t type) = 0;
0277
0278 virtual size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) = 0;
0279
0280 virtual TypeMemberFunctionImpl
0281 GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type, size_t idx) = 0;
0282
0283 virtual CompilerType GetPointeeType(lldb::opaque_compiler_type_t type) = 0;
0284
0285 virtual CompilerType GetPointerType(lldb::opaque_compiler_type_t type) = 0;
0286
0287 virtual CompilerType
0288 GetLValueReferenceType(lldb::opaque_compiler_type_t type);
0289
0290 virtual CompilerType
0291 GetRValueReferenceType(lldb::opaque_compiler_type_t type);
0292
0293 virtual CompilerType GetAtomicType(lldb::opaque_compiler_type_t type);
0294
0295 virtual CompilerType AddConstModifier(lldb::opaque_compiler_type_t type);
0296
0297 virtual CompilerType AddVolatileModifier(lldb::opaque_compiler_type_t type);
0298
0299 virtual CompilerType AddRestrictModifier(lldb::opaque_compiler_type_t type);
0300
0301 virtual CompilerType AddPtrAuthModifier(lldb::opaque_compiler_type_t type,
0302 uint32_t payload);
0303
0304
0305
0306 virtual CompilerType CreateTypedef(lldb::opaque_compiler_type_t type,
0307 const char *name,
0308 const CompilerDeclContext &decl_ctx,
0309 uint32_t opaque_payload);
0310
0311
0312
0313 virtual const llvm::fltSemantics &GetFloatTypeSemantics(size_t byte_size) = 0;
0314
0315 virtual std::optional<uint64_t>
0316 GetBitSize(lldb::opaque_compiler_type_t type,
0317 ExecutionContextScope *exe_scope) = 0;
0318
0319 virtual lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
0320 uint64_t &count) = 0;
0321
0322 virtual lldb::Format GetFormat(lldb::opaque_compiler_type_t type) = 0;
0323
0324 virtual llvm::Expected<uint32_t>
0325 GetNumChildren(lldb::opaque_compiler_type_t type,
0326 bool omit_empty_base_classes,
0327 const ExecutionContext *exe_ctx) = 0;
0328
0329 virtual CompilerType GetBuiltinTypeByName(ConstString name);
0330
0331 virtual lldb::BasicType
0332 GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) = 0;
0333
0334 virtual void ForEachEnumerator(
0335 lldb::opaque_compiler_type_t type,
0336 std::function<bool(const CompilerType &integer_type,
0337 ConstString name,
0338 const llvm::APSInt &value)> const &callback) {}
0339
0340 virtual uint32_t GetNumFields(lldb::opaque_compiler_type_t type) = 0;
0341
0342 virtual CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type,
0343 size_t idx, std::string &name,
0344 uint64_t *bit_offset_ptr,
0345 uint32_t *bitfield_bit_size_ptr,
0346 bool *is_bitfield_ptr) = 0;
0347
0348 virtual uint32_t
0349 GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) = 0;
0350
0351 virtual uint32_t
0352 GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) = 0;
0353
0354 virtual CompilerType
0355 GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx,
0356 uint32_t *bit_offset_ptr) = 0;
0357
0358 virtual CompilerType
0359 GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t type, size_t idx,
0360 uint32_t *bit_offset_ptr) = 0;
0361
0362 virtual CompilerDecl GetStaticFieldWithName(lldb::opaque_compiler_type_t type,
0363 llvm::StringRef name) {
0364 return CompilerDecl();
0365 }
0366
0367 virtual llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
0368 lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
0369 bool transparent_pointers, bool omit_empty_base_classes,
0370 bool ignore_array_bounds, std::string &child_name,
0371 uint32_t &child_byte_size, int32_t &child_byte_offset,
0372 uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
0373 bool &child_is_base_class, bool &child_is_deref_of_parent,
0374 ValueObject *valobj, uint64_t &language_flags) = 0;
0375
0376
0377
0378 virtual uint32_t GetIndexOfChildWithName(lldb::opaque_compiler_type_t type,
0379 llvm::StringRef name,
0380 bool omit_empty_base_classes) = 0;
0381
0382
0383
0384
0385
0386
0387
0388 virtual size_t GetIndexOfChildMemberWithName(
0389 lldb::opaque_compiler_type_t type, llvm::StringRef name,
0390 bool omit_empty_base_classes, std::vector<uint32_t> &child_indexes) = 0;
0391
0392 virtual CompilerType
0393 GetDirectNestedTypeWithName(lldb::opaque_compiler_type_t type,
0394 llvm::StringRef name) {
0395 return CompilerType();
0396 }
0397
0398 virtual bool IsTemplateType(lldb::opaque_compiler_type_t type);
0399
0400 virtual size_t GetNumTemplateArguments(lldb::opaque_compiler_type_t type,
0401 bool expand_pack);
0402
0403 virtual lldb::TemplateArgumentKind
0404 GetTemplateArgumentKind(lldb::opaque_compiler_type_t type, size_t idx,
0405 bool expand_pack);
0406 virtual CompilerType
0407 GetTypeTemplateArgument(lldb::opaque_compiler_type_t type, size_t idx,
0408 bool expand_pack);
0409 virtual std::optional<CompilerType::IntegralTemplateArgument>
0410 GetIntegralTemplateArgument(lldb::opaque_compiler_type_t type, size_t idx,
0411 bool expand_pack);
0412
0413
0414
0415 #ifndef NDEBUG
0416
0417 LLVM_DUMP_METHOD virtual void
0418 dump(lldb::opaque_compiler_type_t type) const = 0;
0419 #endif
0420
0421 virtual bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream &s,
0422 lldb::Format format, const DataExtractor &data,
0423 lldb::offset_t data_offset, size_t data_byte_size,
0424 uint32_t bitfield_bit_size,
0425 uint32_t bitfield_bit_offset,
0426 ExecutionContextScope *exe_scope) = 0;
0427
0428
0429 virtual void DumpTypeDescription(
0430 lldb::opaque_compiler_type_t type,
0431 lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) = 0;
0432
0433
0434
0435
0436
0437 virtual void DumpTypeDescription(
0438 lldb::opaque_compiler_type_t type, Stream &s,
0439 lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) = 0;
0440
0441
0442
0443
0444
0445 virtual void Dump(llvm::raw_ostream &output) = 0;
0446
0447
0448 virtual bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) = 0;
0449
0450
0451
0452 virtual bool IsPointerOrReferenceType(lldb::opaque_compiler_type_t type,
0453 CompilerType *pointee_type) = 0;
0454
0455 virtual unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) = 0;
0456
0457 virtual std::optional<size_t>
0458 GetTypeBitAlign(lldb::opaque_compiler_type_t type,
0459 ExecutionContextScope *exe_scope) = 0;
0460
0461 virtual CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) = 0;
0462
0463 virtual CompilerType CreateGenericFunctionPrototype() {
0464 return CompilerType();
0465 }
0466
0467 virtual CompilerType
0468 GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding,
0469 size_t bit_size) = 0;
0470
0471 virtual bool IsBeingDefined(lldb::opaque_compiler_type_t type) = 0;
0472
0473 virtual bool IsConst(lldb::opaque_compiler_type_t type) = 0;
0474
0475 virtual uint32_t IsHomogeneousAggregate(lldb::opaque_compiler_type_t type,
0476 CompilerType *base_type_ptr) = 0;
0477
0478 virtual bool IsPolymorphicClass(lldb::opaque_compiler_type_t type) = 0;
0479
0480 virtual bool IsTypedefType(lldb::opaque_compiler_type_t type) = 0;
0481
0482
0483 virtual CompilerType GetTypedefedType(lldb::opaque_compiler_type_t type) = 0;
0484
0485 virtual bool IsVectorType(lldb::opaque_compiler_type_t type,
0486 CompilerType *element_type, uint64_t *size) = 0;
0487
0488 virtual CompilerType
0489 GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) = 0;
0490
0491 virtual CompilerType
0492 GetNonReferenceType(lldb::opaque_compiler_type_t type) = 0;
0493
0494 virtual bool IsReferenceType(lldb::opaque_compiler_type_t type,
0495 CompilerType *pointee_type, bool *is_rvalue) = 0;
0496
0497 virtual bool
0498 ShouldTreatScalarValueAsAddress(lldb::opaque_compiler_type_t type) {
0499 return IsPointerOrReferenceType(type, nullptr);
0500 }
0501
0502 virtual UserExpression *GetUserExpression(
0503 llvm::StringRef expr, llvm::StringRef prefix, SourceLanguage language,
0504 Expression::ResultType desired_type,
0505 const EvaluateExpressionOptions &options, ValueObject *ctx_obj) {
0506 return nullptr;
0507 }
0508
0509 virtual FunctionCaller *GetFunctionCaller(const CompilerType &return_type,
0510 const Address &function_address,
0511 const ValueList &arg_value_list,
0512 const char *name) {
0513 return nullptr;
0514 }
0515
0516 virtual std::unique_ptr<UtilityFunction>
0517 CreateUtilityFunction(std::string text, std::string name);
0518
0519 virtual PersistentExpressionState *GetPersistentExpressionState() {
0520 return nullptr;
0521 }
0522
0523 virtual CompilerType GetTypeForFormatters(void *type);
0524
0525 virtual LazyBool ShouldPrintAsOneLiner(void *type, ValueObject *valobj);
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539 virtual bool IsMeaninglessWithoutDynamicResolution(void *type);
0540
0541 virtual std::optional<llvm::json::Value> ReportStatistics();
0542
0543 bool GetHasForcefullyCompletedTypes() const {
0544 return m_has_forcefully_completed_types;
0545 }
0546 protected:
0547 SymbolFile *m_sym_file = nullptr;
0548
0549 bool m_has_forcefully_completed_types = false;
0550 };
0551
0552 class TypeSystemMap {
0553 public:
0554 TypeSystemMap();
0555 ~TypeSystemMap();
0556
0557
0558
0559 void Clear();
0560
0561
0562
0563 void ForEach(std::function<bool(lldb::TypeSystemSP)> const &callback);
0564
0565 llvm::Expected<lldb::TypeSystemSP>
0566 GetTypeSystemForLanguage(lldb::LanguageType language, Module *module,
0567 bool can_create);
0568
0569 llvm::Expected<lldb::TypeSystemSP>
0570 GetTypeSystemForLanguage(lldb::LanguageType language, Target *target,
0571 bool can_create);
0572
0573
0574
0575 bool GetHasForcefullyCompletedTypes() const;
0576 protected:
0577 typedef llvm::DenseMap<uint16_t, lldb::TypeSystemSP> collection;
0578 mutable std::mutex m_mutex;
0579
0580 collection m_map;
0581 bool m_clear_in_progress = false;
0582
0583 private:
0584 typedef llvm::function_ref<lldb::TypeSystemSP()> CreateCallback;
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597 llvm::Expected<lldb::TypeSystemSP> GetTypeSystemForLanguage(
0598 lldb::LanguageType language,
0599 std::optional<CreateCallback> create_callback = std::nullopt);
0600 };
0601
0602 }
0603
0604 #endif