Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- SymbolFile.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_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 /// Provides public interface for all SymbolFiles. Any protected
0045 /// virtual members should go into SymbolFileCommon; most SymbolFile
0046 /// implementations should inherit from SymbolFileCommon to override
0047 /// the behaviors except SymbolFileOnDemand which inherits
0048 /// public interfaces from SymbolFile and forward to underlying concrete
0049 /// SymbolFile implementation.
0050 class SymbolFile : public PluginInterface {
0051   /// LLVM RTTI support.
0052   static char ID;
0053 
0054 public:
0055   /// LLVM RTTI support.
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   // Symbol file ability bits.
0062   //
0063   // Each symbol file can claim to support one or more symbol file abilities.
0064   // These get returned from SymbolFile::GetAbilities(). These help us to
0065   // determine which plug-in will be best to load the debug information found
0066   // in files.
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   // Constructors and Destructors
0081   SymbolFile() = default;
0082 
0083   ~SymbolFile() override = default;
0084 
0085   /// SymbolFileOnDemand class overrides this to return the underlying
0086   /// backing SymbolFile implementation that loads on-demand.
0087   virtual SymbolFile *GetBackingSymbolFile() { return this; }
0088 
0089   /// Get a mask of what this symbol file supports for the object file
0090   /// that it was constructed with.
0091   ///
0092   /// Each symbol file gets to respond with a mask of abilities that
0093   /// it supports for each object file. This happens when we are
0094   /// trying to figure out which symbol file plug-in will get used
0095   /// for a given object file. The plug-in that responds with the
0096   /// best mix of "SymbolFile::Abilities" bits set, will get chosen to
0097   /// be the symbol file parser. This allows each plug-in to check for
0098   /// sections that contain data a symbol file plug-in would need. For
0099   /// example the DWARF plug-in requires DWARF sections in a file that
0100   /// contain debug information. If the DWARF plug-in doesn't find
0101   /// these sections, it won't respond with many ability bits set, and
0102   /// we will probably fall back to the symbol table SymbolFile plug-in
0103   /// which uses any information in the symbol table. Also, plug-ins
0104   /// might check for some specific symbols in a symbol table in the
0105   /// case where the symbol table contains debug information (STABS
0106   /// and COFF). Not a lot of work should happen in these functions
0107   /// as the plug-in might not get selected due to another plug-in
0108   /// having more abilities. Any initialization work should be saved
0109   /// for "void SymbolFile::InitializeObject()" which will get called
0110   /// on the SymbolFile object with the best set of abilities.
0111   ///
0112   /// \return
0113   ///     A uint32_t mask containing bits from the SymbolFile::Abilities
0114   ///     enumeration. Any bits that are set represent an ability that
0115   ///     this symbol plug-in can parse from the object file.
0116   virtual uint32_t GetAbilities() = 0;
0117   virtual uint32_t CalculateAbilities() = 0;
0118 
0119   /// Symbols file subclasses should override this to return the Module that
0120   /// owns the TypeSystem that this symbol file modifies type information in.
0121   virtual std::recursive_mutex &GetModuleMutex() const;
0122 
0123   /// Initialize the SymbolFile object.
0124   ///
0125   /// The SymbolFile object with the best set of abilities (detected
0126   /// in "uint32_t SymbolFile::GetAbilities()) will have this function
0127   /// called if it is chosen to parse an object file. More complete
0128   /// initialization can happen in this function which will get called
0129   /// prior to any other functions in the SymbolFile protocol.
0130   virtual void InitializeObject() {}
0131 
0132   /// Whether debug info will be loaded or not.
0133   ///
0134   /// It will be true for most implementations except SymbolFileOnDemand.
0135   virtual bool GetLoadDebugInfoEnabled() { return true; }
0136 
0137   /// Specify debug info should be loaded.
0138   ///
0139   /// It will be no-op for most implementations except SymbolFileOnDemand.
0140   virtual void SetLoadDebugInfoEnabled() {}
0141 
0142   // Compile Unit function calls
0143   // Approach 1 - iterator
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   /// Return the Xcode SDK comp_unit was compiled against.
0151   virtual XcodeSDK ParseXcodeSDK(CompileUnit &comp_unit) { return {}; }
0152 
0153   /// This function exists because SymbolFileDWARFDebugMap may extra compile
0154   /// units which aren't exposed as "real" compile units. In every other
0155   /// case this function should behave identically as ParseLanguage.
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   /// Apply a lambda to each external lldb::Module referenced by this
0168   /// \p comp_unit. Recursively also descends into the referenced external
0169   /// modules of any encountered compilation unit.
0170   ///
0171   /// This function can be used to traverse Clang -gmodules debug
0172   /// information, which is stored in DWARF files separate from the
0173   /// object files.
0174   ///
0175   /// \param comp_unit
0176   ///     When this SymbolFile consists of multiple auxilliary
0177   ///     SymbolFiles, for example, a Darwin debug map that references
0178   ///     multiple .o files, comp_unit helps choose the auxilliary
0179   ///     file. In most other cases comp_unit's symbol file is
0180   ///     identical with *this.
0181   ///
0182   /// \param[in] lambda
0183   ///     The lambda that should be applied to every function. The lambda can
0184   ///     return true if the iteration should be aborted earlier.
0185   ///
0186   /// \param visited_symbol_files
0187   ///     A set of SymbolFiles that were already visited to avoid
0188   ///     visiting one file more than once.
0189   ///
0190   /// \return
0191   ///     If the lambda early-exited, this function returns true to
0192   ///     propagate the early exit.
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   /// The characteristics of an array type.
0212   struct ArrayInfo {
0213     int64_t first_index = 0;
0214 
0215     ///< Each entry belongs to a distinct DW_TAG_subrange_type.
0216     ///< For multi-dimensional DW_TAG_array_types we would have
0217     ///< an entry for each dimension. An entry represents the
0218     ///< optional element count of the subrange.
0219     ///
0220     ///< The order of entries follows the order of the DW_TAG_subrange_type
0221     ///< children of this DW_TAG_array_type.
0222     llvm::SmallVector<std::optional<uint64_t>, 1> element_orders;
0223     uint32_t byte_stride = 0;
0224     uint32_t bit_stride = 0;
0225   };
0226   /// If \c type_uid points to an array type, return its characteristics.
0227   /// To support variable-length array types, this function takes an
0228   /// optional \p ExecutionContext. If \c exe_ctx is non-null, the
0229   /// dynamic characteristics for that context are returned.
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   /// Get an error that describes why variables might be missing for a given
0252   /// symbol context.
0253   ///
0254   /// If there is an error in the debug information that prevents variables from
0255   /// being fetched, this error will get filled in. If there is no debug
0256   /// informaiton, no error should be returned. But if there is debug
0257   /// information and something prevents the variables from being available a
0258   /// valid error should be returned. Valid cases include:
0259   /// - compiler option that removes variables (-gline-tables-only)
0260   /// - missing external files
0261   ///   - .dwo files in fission are not accessible or missing
0262   ///   - .o files on darwin when not using dSYM files that are not accessible
0263   ///     or missing
0264   /// - mismatched exteral files
0265   ///   - .dwo files in fission where the DWO ID doesn't match
0266   ///   - .o files on darwin when modification timestamp doesn't match
0267   /// - corrupted debug info
0268   ///
0269   /// \param[in] frame
0270   ///   The stack frame to use as a basis for the context to check. The frame
0271   ///   address can be used if there is not debug info due to it not being able
0272   ///   to be loaded, or if there is a debug info context, like a compile unit,
0273   ///   or function, it can be used to track down more information on why
0274   ///   variables are missing.
0275   ///
0276   /// \returns
0277   ///   An error specifying why there should have been debug info with variable
0278   ///   information but the variables were not able to be resolved.
0279   Status GetFrameVariableError(StackFrame &frame) {
0280     Status err = CalculateFrameVariableError(frame);
0281     if (err.Fail())
0282       SetDebugInfoHadFrameVariableErrors();
0283     return err;
0284   }
0285 
0286   /// Subclasses will override this function to for GetFrameVariableError().
0287   ///
0288   /// This allows GetFrameVariableError() to set the member variable
0289   /// m_debug_info_had_variable_errors correctly without users having to do it
0290   /// manually which is error prone.
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 &regex,
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 &regex,
0311                              bool include_inlines, SymbolContextList &sc_list);
0312 
0313   /// Find types using a type-matching object that contains all search
0314   /// parameters.
0315   ///
0316   /// \see lldb_private::TypeQuery
0317   ///
0318   /// \param[in] query
0319   ///     A type matching object that contains all of the details of the type
0320   ///     search.
0321   ///
0322   /// \param[in] results
0323   ///     Any matching types will be populated into the \a results object using
0324   ///     TypeMap::InsertUnique(...).
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   /// Finds a namespace of name \ref name and whose parent
0341   /// context is \ref parent_decl_ctx.
0342   ///
0343   /// If \code{.cpp} !parent_decl_ctx.IsValid() \endcode
0344   /// then this function will consider all namespaces that
0345   /// match the name. If \ref only_root_namespaces is
0346   /// true, only consider in the search those DIEs that
0347   /// represent top-level namespaces.
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   /// Notify the SymbolFile that the file addresses in the Sections
0366   /// for this module have been changed.
0367   virtual void SectionFileAddressesChanged() = 0;
0368 
0369   struct RegisterInfoResolver {
0370     virtual ~RegisterInfoResolver(); // anchor
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   /// Return the number of stack bytes taken up by the parameters to this
0382   /// function.
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   /// Metrics gathering functions
0391 
0392   /// Return the size in bytes of all loaded debug information or total possible
0393   /// debug info in the symbol file.
0394   ///
0395   /// If the debug information is contained in sections of an ObjectFile, then
0396   /// this call should add the size of all sections that contain debug
0397   /// information. Symbols the symbol tables are not considered debug
0398   /// information for this call to make it easy and quick for this number to be
0399   /// calculated. If the symbol file is all debug information, the size of the
0400   /// entire file should be returned. The default implementation of this
0401   /// function will iterate over all sections in a module and add up their
0402   /// debug info only section byte sizes.
0403   ///
0404   /// \param load_all_debug_info
0405   ///   If true, force loading any symbol files if they are not yet loaded and
0406   ///   add to the total size. Default to false.
0407   ///
0408   /// \returns
0409   ///   Total currently loaded debug info size in bytes
0410   virtual uint64_t GetDebugInfoSize(bool load_all_debug_info = false) = 0;
0411 
0412   /// Return the time taken to parse the debug information.
0413   ///
0414   /// \returns 0.0 if no information has been parsed or if there is
0415   /// no computational cost to parsing the debug information.
0416   virtual StatsDuration::Duration GetDebugInfoParseTime() { return {}; }
0417 
0418   /// Return the time it took to index the debug information in the object
0419   /// file.
0420   ///
0421   /// \returns 0.0 if the file doesn't need to be indexed or if it
0422   /// hasn't been indexed yet, or a valid duration if it has.
0423   virtual StatsDuration::Duration GetDebugInfoIndexTime() { return {}; }
0424 
0425   /// Reset the statistics for the symbol file.
0426   virtual void ResetStatistics() {}
0427 
0428   /// Get the additional modules that this symbol file uses to parse debug info.
0429   ///
0430   /// Some debug info is stored in stand alone object files that are represented
0431   /// by unique modules that will show up in the statistics module list. Return
0432   /// a list of modules that are not in the target module list that this symbol
0433   /// file is currently using so that they can be tracked and assoicated with
0434   /// the module in the statistics.
0435   virtual ModuleList GetDebugInfoModules() { return ModuleList(); }
0436 
0437   /// Accessors for the bool that indicates if the debug info index was loaded
0438   /// from, or saved to the module index cache.
0439   ///
0440   /// In statistics it is handy to know if a module's debug info was loaded from
0441   /// or saved to the cache. When the debug info index is loaded from the cache
0442   /// startup times can be faster. When the cache is enabled and the debug info
0443   /// index is saved to the cache, debug sessions can be slower. These accessors
0444   /// can be accessed by the statistics and emitted to help track these costs.
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   /// Accessors for the bool that indicates if there was debug info, but errors
0453   /// stopped variables from being able to be displayed correctly. See
0454   /// GetFrameVariableError() for details on what are considered errors.
0455   virtual bool GetDebugInfoHadFrameVariableErrors() const = 0;
0456   virtual void SetDebugInfoHadFrameVariableErrors() = 0;
0457 
0458   /// Return true if separate debug info files are supported and this function
0459   /// succeeded, false otherwise.
0460   ///
0461   /// \param[out] d
0462   ///     If this function succeeded, then this will be a dictionary that
0463   ///     contains the keys "type", "symfile", and "separate-debug-info-files".
0464   ///     "type" can be used to assume the structure of each object in
0465   ///     "separate-debug-info-files".
0466   /// \param errors_only
0467   ///     If true, then only return separate debug info files that encountered
0468   ///     errors during loading. If false, then return all expected separate
0469   ///     debug info files, regardless of whether they were successfully loaded.
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   /// Returns a map of compilation unit to the compile option arguments
0487   /// associated with that compilation unit.
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 /// Containing protected virtual methods for child classes to override.
0506 /// Most actual SymbolFile implementations should inherit from this class.
0507 class SymbolFileCommon : public SymbolFile {
0508   /// LLVM RTTI support.
0509   static char ID;
0510 
0511 public:
0512   /// LLVM RTTI support.
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   // Constructors and Destructors
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   /// Notify the SymbolFile that the file addresses in the Sections
0543   /// for this module have been changed.
0544   void SectionFileAddressesChanged() override;
0545 
0546   // Compile Unit function calls
0547   // Approach 1 - iterator
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   /// This function is used to create types that belong to a SymbolFile. The
0578   /// symbol file will own a strong reference to the type in an internal type
0579   /// list.
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      // Make sure the real symbol file matches when copying types.
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; // Keep a reference to the object file in
0613                                    // case it isn't the same as the module
0614                                    // object file (debug symbols in a separate
0615                                    // file)
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   /// Set to true if any variable feteching errors have been found when calling
0623   /// GetFrameVariableError(). This will be emitted in the "statistics dump"
0624   /// information for a module.
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   /// Do not use m_symtab directly, as it may be freed. Use GetSymtab()
0632   /// to access it instead.
0633   Symtab *m_symtab = nullptr;
0634 };
0635 
0636 } // namespace lldb_private
0637 
0638 #endif // LLDB_SYMBOL_SYMBOLFILE_H