Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:52

0001 //===-- SymbolFileOnDemand.h ------------------------------------*- C++-*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_SYMBOL_SYMBOLFILEONDEMAND_H
0010 #define LLDB_SYMBOL_SYMBOLFILEONDEMAND_H
0011 
0012 #include <mutex>
0013 #include <optional>
0014 #include <vector>
0015 
0016 #include "lldb/Symbol/ObjectFile.h"
0017 #include "lldb/Symbol/SymbolContext.h"
0018 #include "lldb/Symbol/SymbolFile.h"
0019 #include "lldb/Target/Statistics.h"
0020 #include "lldb/Utility/ConstString.h"
0021 #include "lldb/Utility/Flags.h"
0022 #include "lldb/Utility/LLDBLog.h"
0023 #include "lldb/Utility/Log.h"
0024 #include "lldb/lldb-private.h"
0025 
0026 namespace lldb_private {
0027 
0028 /// SymbolFileOnDemand wraps an actual SymbolFile by providing
0029 /// on demand symbol parsing/indexing to improve performance.
0030 /// By default SymbolFileOnDemand will skip load the underlying
0031 /// symbols. Any client can on demand hydrate the underlying
0032 /// SymbolFile via SymbolFile::SetLoadDebugInfoEnabled().
0033 class SymbolFileOnDemand : public lldb_private::SymbolFile {
0034   /// LLVM RTTI support.
0035   static char ID;
0036 
0037 public:
0038   /// LLVM RTTI support.
0039   /// \{
0040   bool isA(const void *ClassID) const override {
0041     return ClassID == &ID || SymbolFile::isA(ClassID);
0042   }
0043   static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
0044   /// \}
0045 
0046   SymbolFileOnDemand(std::unique_ptr<SymbolFile> &&symbol_file);
0047   ~SymbolFileOnDemand() override;
0048 
0049   // PluginInterface protocol
0050   llvm::StringRef GetPluginName() override { return "ondemand"; }
0051 
0052   bool GetLoadDebugInfoEnabled() override { return m_debug_info_enabled; }
0053 
0054   void SetLoadDebugInfoEnabled() override;
0055 
0056   uint32_t GetNumCompileUnits() override;
0057   lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) override;
0058 
0059   SymbolFile *GetBackingSymbolFile() override { return m_sym_file_impl.get(); }
0060 
0061   uint32_t CalculateAbilities() override;
0062 
0063   std::recursive_mutex &GetModuleMutex() const override;
0064 
0065   lldb::LanguageType
0066   ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
0067 
0068   lldb_private::XcodeSDK
0069   ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override;
0070 
0071   void InitializeObject() override;
0072 
0073   size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
0074 
0075   bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
0076 
0077   bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
0078 
0079   bool ForEachExternalModule(
0080       lldb_private::CompileUnit &, llvm::DenseSet<lldb_private::SymbolFile *> &,
0081       llvm::function_ref<bool(lldb_private::Module &)>) override;
0082 
0083   bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,
0084                          lldb_private::SupportFileList &support_files) override;
0085 
0086   bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override;
0087 
0088   size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
0089 
0090   bool ParseImportedModules(
0091       const lldb_private::SymbolContext &sc,
0092       std::vector<lldb_private::SourceModule> &imported_modules) override;
0093 
0094   size_t ParseBlocksRecursive(lldb_private::Function &func) override;
0095 
0096   size_t
0097   ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
0098 
0099   lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
0100   std::optional<ArrayInfo> GetDynamicArrayInfoForUID(
0101       lldb::user_id_t type_uid,
0102       const lldb_private::ExecutionContext *exe_ctx) override;
0103 
0104   bool CompleteType(lldb_private::CompilerType &compiler_type) override;
0105 
0106   lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
0107 
0108   lldb_private::CompilerDeclContext
0109   GetDeclContextForUID(lldb::user_id_t uid) override;
0110 
0111   lldb_private::CompilerDeclContext
0112   GetDeclContextContainingUID(lldb::user_id_t uid) override;
0113 
0114   void
0115   ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
0116 
0117   uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
0118                                 lldb::SymbolContextItem resolve_scope,
0119                                 lldb_private::SymbolContext &sc) override;
0120 
0121   lldb_private::Status
0122   CalculateFrameVariableError(lldb_private::StackFrame &frame) override;
0123 
0124   uint32_t ResolveSymbolContext(
0125       const lldb_private::SourceLocationSpec &src_location_spec,
0126       lldb::SymbolContextItem resolve_scope,
0127       lldb_private::SymbolContextList &sc_list) override;
0128 
0129   void Dump(lldb_private::Stream &s) override;
0130   void DumpClangAST(lldb_private::Stream &s) override;
0131 
0132   void
0133   FindGlobalVariables(lldb_private::ConstString name,
0134                       const lldb_private::CompilerDeclContext &parent_decl_ctx,
0135                       uint32_t max_matches,
0136                       lldb_private::VariableList &variables) override;
0137 
0138   void FindGlobalVariables(const lldb_private::RegularExpression &regex,
0139                            uint32_t max_matches,
0140                            lldb_private::VariableList &variables) override;
0141 
0142   void FindFunctions(const lldb_private::Module::LookupInfo &lookup_info,
0143                      const lldb_private::CompilerDeclContext &parent_decl_ctx,
0144                      bool include_inlines,
0145                      lldb_private::SymbolContextList &sc_list) override;
0146 
0147   void FindFunctions(const lldb_private::RegularExpression &regex,
0148                      bool include_inlines,
0149                      lldb_private::SymbolContextList &sc_list) override;
0150 
0151   void GetMangledNamesForFunction(
0152       const std::string &scope_qualified_name,
0153       std::vector<lldb_private::ConstString> &mangled_names) override;
0154 
0155   void FindTypes(const lldb_private::TypeQuery &query,
0156                  lldb_private::TypeResults &results) override;
0157 
0158   void GetTypes(lldb_private::SymbolContextScope *sc_scope,
0159                 lldb::TypeClass type_mask,
0160                 lldb_private::TypeList &type_list) override;
0161 
0162   llvm::Expected<lldb::TypeSystemSP>
0163   GetTypeSystemForLanguage(lldb::LanguageType language) override;
0164 
0165   lldb_private::CompilerDeclContext
0166   FindNamespace(lldb_private::ConstString name,
0167                 const lldb_private::CompilerDeclContext &parent_decl_ctx,
0168                 bool only_root_namespaces) override;
0169 
0170   std::vector<std::unique_ptr<lldb_private::CallEdge>>
0171   ParseCallEdgesInFunction(UserID func_id) override;
0172 
0173   lldb::UnwindPlanSP
0174   GetUnwindPlan(const Address &address,
0175                 const RegisterInfoResolver &resolver) override;
0176 
0177   llvm::Expected<lldb::addr_t> GetParameterStackSize(Symbol &symbol) override;
0178 
0179   void PreloadSymbols() override;
0180 
0181   uint64_t GetDebugInfoSize(bool load_all_debug_info = false) override;
0182   lldb_private::StatsDuration::Duration GetDebugInfoParseTime() override;
0183   lldb_private::StatsDuration::Duration GetDebugInfoIndexTime() override;
0184 
0185   void ResetStatistics() override;
0186 
0187   uint32_t GetAbilities() override;
0188 
0189   Symtab *GetSymtab() override { return m_sym_file_impl->GetSymtab(); }
0190 
0191   ObjectFile *GetObjectFile() override {
0192     return m_sym_file_impl->GetObjectFile();
0193   }
0194   const ObjectFile *GetObjectFile() const override {
0195     return m_sym_file_impl->GetObjectFile();
0196   }
0197   ObjectFile *GetMainObjectFile() override {
0198     return m_sym_file_impl->GetMainObjectFile();
0199   }
0200 
0201   void SectionFileAddressesChanged() override {
0202     return m_sym_file_impl->SectionFileAddressesChanged();
0203   }
0204 
0205   bool GetDebugInfoIndexWasLoadedFromCache() const override {
0206     return m_sym_file_impl->GetDebugInfoIndexWasLoadedFromCache();
0207   }
0208   void SetDebugInfoIndexWasLoadedFromCache() override {
0209     m_sym_file_impl->SetDebugInfoIndexWasLoadedFromCache();
0210   }
0211   bool GetDebugInfoIndexWasSavedToCache() const override {
0212     return m_sym_file_impl->GetDebugInfoIndexWasSavedToCache();
0213   }
0214   void SetDebugInfoIndexWasSavedToCache() override {
0215     m_sym_file_impl->SetDebugInfoIndexWasSavedToCache();
0216   }
0217   bool GetDebugInfoHadFrameVariableErrors() const override {
0218     return m_sym_file_impl->GetDebugInfoHadFrameVariableErrors();
0219   }
0220   void SetDebugInfoHadFrameVariableErrors() override {
0221     return m_sym_file_impl->SetDebugInfoHadFrameVariableErrors();
0222   }
0223 
0224   bool GetSeparateDebugInfo(StructuredData::Dictionary &d,
0225                             bool errors_only) override {
0226     return m_sym_file_impl->GetSeparateDebugInfo(d, errors_only);
0227   }
0228 
0229   lldb::TypeSP MakeType(lldb::user_id_t uid, ConstString name,
0230                         std::optional<uint64_t> byte_size,
0231                         SymbolContextScope *context,
0232                         lldb::user_id_t encoding_uid,
0233                         Type::EncodingDataType encoding_uid_type,
0234                         const Declaration &decl,
0235                         const CompilerType &compiler_qual_type,
0236                         Type::ResolveState compiler_type_resolve_state,
0237                         uint32_t opaque_payload = 0) override {
0238     return m_sym_file_impl->MakeType(
0239         uid, name, byte_size, context, encoding_uid, encoding_uid_type, decl,
0240         compiler_qual_type, compiler_type_resolve_state, opaque_payload);
0241   }
0242 
0243   lldb::TypeSP CopyType(const lldb::TypeSP &other_type) override {
0244     return m_sym_file_impl->CopyType(other_type);
0245   }
0246 
0247 private:
0248   Log *GetLog() const { return ::lldb_private::GetLog(LLDBLog::OnDemand); }
0249 
0250   ConstString GetSymbolFileName() {
0251     return GetObjectFile()->GetFileSpec().GetFilename();
0252   }
0253 
0254 private:
0255   bool m_debug_info_enabled = false;
0256   bool m_preload_symbols = false;
0257   std::unique_ptr<SymbolFile> m_sym_file_impl;
0258 };
0259 } // namespace lldb_private
0260 
0261 #endif // LLDB_SYMBOL_SYMBOLFILEONDEMAND_H