File indexing completed on 2026-05-10 08:42:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_SYMBOL_SYMBOLFILE_H
0010 #define LLDB_SYMBOL_SYMBOLFILE_H
0011
0012 #include "lldb/Core/Module.h"
0013 #include "lldb/Core/ModuleList.h"
0014 #include "lldb/Core/PluginInterface.h"
0015 #include "lldb/Core/SourceLocationSpec.h"
0016 #include "lldb/Symbol/CompilerDecl.h"
0017 #include "lldb/Symbol/CompilerDeclContext.h"
0018 #include "lldb/Symbol/CompilerType.h"
0019 #include "lldb/Symbol/Function.h"
0020 #include "lldb/Symbol/SourceModule.h"
0021 #include "lldb/Symbol/Type.h"
0022 #include "lldb/Symbol/TypeList.h"
0023 #include "lldb/Symbol/TypeSystem.h"
0024 #include "lldb/Target/Statistics.h"
0025 #include "lldb/Utility/StructuredData.h"
0026 #include "lldb/Utility/XcodeSDK.h"
0027 #include "lldb/lldb-private.h"
0028 #include "llvm/ADT/DenseSet.h"
0029 #include "llvm/ADT/SmallSet.h"
0030 #include "llvm/Support/Errc.h"
0031
0032 #include <mutex>
0033 #include <optional>
0034 #include <unordered_map>
0035
0036 #if defined(LLDB_CONFIGURATION_DEBUG)
0037 #define ASSERT_MODULE_LOCK(expr) (expr->AssertModuleLock())
0038 #else
0039 #define ASSERT_MODULE_LOCK(expr) ((void)0)
0040 #endif
0041
0042 namespace lldb_private {
0043
0044
0045
0046
0047
0048
0049
0050 class SymbolFile : public PluginInterface {
0051
0052 static char ID;
0053
0054 public:
0055
0056
0057 virtual bool isA(const void *ClassID) const { return ClassID == &ID; }
0058 static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
0059
0060
0061
0062
0063
0064
0065
0066
0067 enum Abilities {
0068 CompileUnits = (1u << 0),
0069 LineTables = (1u << 1),
0070 Functions = (1u << 2),
0071 Blocks = (1u << 3),
0072 GlobalVariables = (1u << 4),
0073 LocalVariables = (1u << 5),
0074 VariableTypes = (1u << 6),
0075 kAllAbilities = ((1u << 7) - 1u)
0076 };
0077
0078 static SymbolFile *FindPlugin(lldb::ObjectFileSP objfile_sp);
0079
0080
0081 SymbolFile() = default;
0082
0083 ~SymbolFile() override = default;
0084
0085
0086
0087 virtual SymbolFile *GetBackingSymbolFile() { return this; }
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116 virtual uint32_t GetAbilities() = 0;
0117 virtual uint32_t CalculateAbilities() = 0;
0118
0119
0120
0121 virtual std::recursive_mutex &GetModuleMutex() const;
0122
0123
0124
0125
0126
0127
0128
0129
0130 virtual void InitializeObject() {}
0131
0132
0133
0134
0135 virtual bool GetLoadDebugInfoEnabled() { return true; }
0136
0137
0138
0139
0140 virtual void SetLoadDebugInfoEnabled() {}
0141
0142
0143
0144 virtual uint32_t GetNumCompileUnits() = 0;
0145 virtual lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) = 0;
0146
0147 virtual Symtab *GetSymtab() = 0;
0148
0149 virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0;
0150
0151 virtual XcodeSDK ParseXcodeSDK(CompileUnit &comp_unit) { return {}; }
0152
0153
0154
0155
0156 virtual llvm::SmallSet<lldb::LanguageType, 4>
0157 ParseAllLanguages(CompileUnit &comp_unit) {
0158 llvm::SmallSet<lldb::LanguageType, 4> langs;
0159 langs.insert(ParseLanguage(comp_unit));
0160 return langs;
0161 }
0162
0163 virtual size_t ParseFunctions(CompileUnit &comp_unit) = 0;
0164 virtual bool ParseLineTable(CompileUnit &comp_unit) = 0;
0165 virtual bool ParseDebugMacros(CompileUnit &comp_unit) = 0;
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193 virtual bool ForEachExternalModule(
0194 lldb_private::CompileUnit &comp_unit,
0195 llvm::DenseSet<lldb_private::SymbolFile *> &visited_symbol_files,
0196 llvm::function_ref<bool(Module &)> lambda) {
0197 return false;
0198 }
0199 virtual bool ParseSupportFiles(CompileUnit &comp_unit,
0200 SupportFileList &support_files) = 0;
0201 virtual size_t ParseTypes(CompileUnit &comp_unit) = 0;
0202 virtual bool ParseIsOptimized(CompileUnit &comp_unit) { return false; }
0203
0204 virtual bool
0205 ParseImportedModules(const SymbolContext &sc,
0206 std::vector<SourceModule> &imported_modules) = 0;
0207 virtual size_t ParseBlocksRecursive(Function &func) = 0;
0208 virtual size_t ParseVariablesForContext(const SymbolContext &sc) = 0;
0209 virtual Type *ResolveTypeUID(lldb::user_id_t type_uid) = 0;
0210
0211
0212 struct ArrayInfo {
0213 int64_t first_index = 0;
0214
0215
0216
0217
0218
0219
0220
0221
0222 llvm::SmallVector<std::optional<uint64_t>, 1> element_orders;
0223 uint32_t byte_stride = 0;
0224 uint32_t bit_stride = 0;
0225 };
0226
0227
0228
0229
0230 virtual std::optional<ArrayInfo>
0231 GetDynamicArrayInfoForUID(lldb::user_id_t type_uid,
0232 const lldb_private::ExecutionContext *exe_ctx) = 0;
0233
0234 virtual bool CompleteType(CompilerType &compiler_type) = 0;
0235 virtual void ParseDeclsForContext(CompilerDeclContext decl_ctx) {}
0236 virtual CompilerDecl GetDeclForUID(lldb::user_id_t uid) { return {}; }
0237 virtual CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) {
0238 return {};
0239 }
0240 virtual CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) {
0241 return {};
0242 }
0243 virtual std::vector<CompilerContext>
0244 GetCompilerContextForUID(lldb::user_id_t uid) {
0245 return {};
0246 }
0247 virtual uint32_t ResolveSymbolContext(const Address &so_addr,
0248 lldb::SymbolContextItem resolve_scope,
0249 SymbolContext &sc) = 0;
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279 Status GetFrameVariableError(StackFrame &frame) {
0280 Status err = CalculateFrameVariableError(frame);
0281 if (err.Fail())
0282 SetDebugInfoHadFrameVariableErrors();
0283 return err;
0284 }
0285
0286
0287
0288
0289
0290
0291 virtual Status CalculateFrameVariableError(StackFrame &frame) {
0292 return Status();
0293 }
0294 virtual uint32_t
0295 ResolveSymbolContext(const SourceLocationSpec &src_location_spec,
0296 lldb::SymbolContextItem resolve_scope,
0297 SymbolContextList &sc_list);
0298
0299 virtual void DumpClangAST(Stream &s) {}
0300 virtual void FindGlobalVariables(ConstString name,
0301 const CompilerDeclContext &parent_decl_ctx,
0302 uint32_t max_matches,
0303 VariableList &variables);
0304 virtual void FindGlobalVariables(const RegularExpression ®ex,
0305 uint32_t max_matches,
0306 VariableList &variables);
0307 virtual void FindFunctions(const Module::LookupInfo &lookup_info,
0308 const CompilerDeclContext &parent_decl_ctx,
0309 bool include_inlines, SymbolContextList &sc_list);
0310 virtual void FindFunctions(const RegularExpression ®ex,
0311 bool include_inlines, SymbolContextList &sc_list);
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325 virtual void FindTypes(const TypeQuery &query, TypeResults &results) {}
0326
0327 virtual void
0328 GetMangledNamesForFunction(const std::string &scope_qualified_name,
0329 std::vector<ConstString> &mangled_names);
0330
0331 virtual void GetTypes(lldb_private::SymbolContextScope *sc_scope,
0332 lldb::TypeClass type_mask,
0333 lldb_private::TypeList &type_list) = 0;
0334
0335 virtual void PreloadSymbols();
0336
0337 virtual llvm::Expected<lldb::TypeSystemSP>
0338 GetTypeSystemForLanguage(lldb::LanguageType language) = 0;
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348 virtual CompilerDeclContext
0349 FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx,
0350 bool only_root_namespaces = false) {
0351 return CompilerDeclContext();
0352 }
0353
0354 virtual ObjectFile *GetObjectFile() = 0;
0355 virtual const ObjectFile *GetObjectFile() const = 0;
0356 virtual ObjectFile *GetMainObjectFile() = 0;
0357
0358 virtual std::vector<std::unique_ptr<CallEdge>>
0359 ParseCallEdgesInFunction(UserID func_id) {
0360 return {};
0361 }
0362
0363 virtual void AddSymbols(Symtab &symtab) {}
0364
0365
0366
0367 virtual void SectionFileAddressesChanged() = 0;
0368
0369 struct RegisterInfoResolver {
0370 virtual ~RegisterInfoResolver();
0371
0372 virtual const RegisterInfo *ResolveName(llvm::StringRef name) const = 0;
0373 virtual const RegisterInfo *ResolveNumber(lldb::RegisterKind kind,
0374 uint32_t number) const = 0;
0375 };
0376 virtual lldb::UnwindPlanSP
0377 GetUnwindPlan(const Address &address, const RegisterInfoResolver &resolver) {
0378 return nullptr;
0379 }
0380
0381
0382
0383 virtual llvm::Expected<lldb::addr_t> GetParameterStackSize(Symbol &symbol) {
0384 return llvm::createStringError(make_error_code(llvm::errc::not_supported),
0385 "Operation not supported.");
0386 }
0387
0388 virtual void Dump(Stream &s) = 0;
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410 virtual uint64_t GetDebugInfoSize(bool load_all_debug_info = false) = 0;
0411
0412
0413
0414
0415
0416 virtual StatsDuration::Duration GetDebugInfoParseTime() { return {}; }
0417
0418
0419
0420
0421
0422
0423 virtual StatsDuration::Duration GetDebugInfoIndexTime() { return {}; }
0424
0425
0426 virtual void ResetStatistics() {}
0427
0428
0429
0430
0431
0432
0433
0434
0435 virtual ModuleList GetDebugInfoModules() { return ModuleList(); }
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446 virtual bool GetDebugInfoIndexWasLoadedFromCache() const = 0;
0447 virtual void SetDebugInfoIndexWasLoadedFromCache() = 0;
0448 virtual bool GetDebugInfoIndexWasSavedToCache() const = 0;
0449 virtual void SetDebugInfoIndexWasSavedToCache() = 0;
0450
0451
0452
0453
0454
0455 virtual bool GetDebugInfoHadFrameVariableErrors() const = 0;
0456 virtual void SetDebugInfoHadFrameVariableErrors() = 0;
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470 virtual bool GetSeparateDebugInfo(StructuredData::Dictionary &d,
0471 bool errors_only) {
0472 return false;
0473 };
0474
0475 virtual lldb::TypeSP
0476 MakeType(lldb::user_id_t uid, ConstString name,
0477 std::optional<uint64_t> byte_size, SymbolContextScope *context,
0478 lldb::user_id_t encoding_uid,
0479 Type::EncodingDataType encoding_uid_type, const Declaration &decl,
0480 const CompilerType &compiler_qual_type,
0481 Type::ResolveState compiler_type_resolve_state,
0482 uint32_t opaque_payload = 0) = 0;
0483
0484 virtual lldb::TypeSP CopyType(const lldb::TypeSP &other_type) = 0;
0485
0486
0487
0488 std::unordered_map<lldb::CompUnitSP, Args> GetCompileOptions() {
0489 std::unordered_map<lldb::CompUnitSP, Args> args;
0490 GetCompileOptions(args);
0491 return args;
0492 }
0493
0494 protected:
0495 void AssertModuleLock();
0496
0497 virtual void GetCompileOptions(
0498 std::unordered_map<lldb::CompUnitSP, lldb_private::Args> &args) {}
0499
0500 private:
0501 SymbolFile(const SymbolFile &) = delete;
0502 const SymbolFile &operator=(const SymbolFile &) = delete;
0503 };
0504
0505
0506
0507 class SymbolFileCommon : public SymbolFile {
0508
0509 static char ID;
0510
0511 public:
0512
0513
0514 bool isA(const void *ClassID) const override {
0515 return ClassID == &ID || SymbolFile::isA(ClassID);
0516 }
0517 static bool classof(const SymbolFileCommon *obj) { return obj->isA(&ID); }
0518
0519
0520
0521 SymbolFileCommon(lldb::ObjectFileSP objfile_sp)
0522 : m_objfile_sp(std::move(objfile_sp)) {}
0523
0524 ~SymbolFileCommon() override = default;
0525
0526 uint32_t GetAbilities() override {
0527 if (!m_calculated_abilities) {
0528 m_abilities = CalculateAbilities();
0529 m_calculated_abilities = true;
0530 }
0531 return m_abilities;
0532 }
0533
0534 Symtab *GetSymtab() override;
0535
0536 ObjectFile *GetObjectFile() override { return m_objfile_sp.get(); }
0537 const ObjectFile *GetObjectFile() const override {
0538 return m_objfile_sp.get();
0539 }
0540 ObjectFile *GetMainObjectFile() override;
0541
0542
0543
0544 void SectionFileAddressesChanged() override;
0545
0546
0547
0548 uint32_t GetNumCompileUnits() override;
0549 lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) override;
0550
0551 llvm::Expected<lldb::TypeSystemSP>
0552 GetTypeSystemForLanguage(lldb::LanguageType language) override;
0553
0554 void Dump(Stream &s) override;
0555
0556 uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override;
0557
0558 bool GetDebugInfoIndexWasLoadedFromCache() const override {
0559 return m_index_was_loaded_from_cache;
0560 }
0561 void SetDebugInfoIndexWasLoadedFromCache() override {
0562 m_index_was_loaded_from_cache = true;
0563 }
0564 bool GetDebugInfoIndexWasSavedToCache() const override {
0565 return m_index_was_saved_to_cache;
0566 }
0567 void SetDebugInfoIndexWasSavedToCache() override {
0568 m_index_was_saved_to_cache = true;
0569 }
0570 bool GetDebugInfoHadFrameVariableErrors() const override {
0571 return m_debug_info_had_variable_errors;
0572 }
0573 void SetDebugInfoHadFrameVariableErrors() override {
0574 m_debug_info_had_variable_errors = true;
0575 }
0576
0577
0578
0579
0580 lldb::TypeSP MakeType(lldb::user_id_t uid, ConstString name,
0581 std::optional<uint64_t> byte_size,
0582 SymbolContextScope *context,
0583 lldb::user_id_t encoding_uid,
0584 Type::EncodingDataType encoding_uid_type,
0585 const Declaration &decl,
0586 const CompilerType &compiler_qual_type,
0587 Type::ResolveState compiler_type_resolve_state,
0588 uint32_t opaque_payload = 0) override {
0589 lldb::TypeSP type_sp (new Type(
0590 uid, this, name, byte_size, context, encoding_uid,
0591 encoding_uid_type, decl, compiler_qual_type,
0592 compiler_type_resolve_state, opaque_payload));
0593 m_type_list.Insert(type_sp);
0594 return type_sp;
0595 }
0596
0597 lldb::TypeSP CopyType(const lldb::TypeSP &other_type) override {
0598
0599 if (GetBackingSymbolFile() != other_type->GetSymbolFile())
0600 return lldb::TypeSP();
0601 lldb::TypeSP type_sp(new Type(*other_type));
0602 m_type_list.Insert(type_sp);
0603 return type_sp;
0604 }
0605
0606 protected:
0607 virtual uint32_t CalculateNumCompileUnits() = 0;
0608 virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t idx) = 0;
0609 virtual TypeList &GetTypeList() { return m_type_list; }
0610 void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp);
0611
0612 lldb::ObjectFileSP m_objfile_sp;
0613
0614
0615
0616 std::optional<std::vector<lldb::CompUnitSP>> m_compile_units;
0617 TypeList m_type_list;
0618 uint32_t m_abilities = 0;
0619 bool m_calculated_abilities = false;
0620 bool m_index_was_loaded_from_cache = false;
0621 bool m_index_was_saved_to_cache = false;
0622
0623
0624
0625 bool m_debug_info_had_variable_errors = false;
0626
0627 private:
0628 SymbolFileCommon(const SymbolFileCommon &) = delete;
0629 const SymbolFileCommon &operator=(const SymbolFileCommon &) = delete;
0630
0631
0632
0633 Symtab *m_symtab = nullptr;
0634 };
0635
0636 }
0637
0638 #endif