10b57cec5SDimitry Andric //===-- SymbolFile.h --------------------------------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #ifndef liblldb_SymbolFile_h_ 100b57cec5SDimitry Andric #define liblldb_SymbolFile_h_ 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #include "lldb/Core/PluginInterface.h" 130b57cec5SDimitry Andric #include "lldb/Symbol/CompilerDecl.h" 140b57cec5SDimitry Andric #include "lldb/Symbol/CompilerDeclContext.h" 150b57cec5SDimitry Andric #include "lldb/Symbol/CompilerType.h" 160b57cec5SDimitry Andric #include "lldb/Symbol/Function.h" 170b57cec5SDimitry Andric #include "lldb/Symbol/SourceModule.h" 180b57cec5SDimitry Andric #include "lldb/Symbol/Type.h" 19*9dba64beSDimitry Andric #include "lldb/Symbol/TypeList.h" 20*9dba64beSDimitry Andric #include "lldb/Symbol/TypeSystem.h" 210b57cec5SDimitry Andric #include "lldb/lldb-private.h" 220b57cec5SDimitry Andric #include "llvm/ADT/DenseSet.h" 23*9dba64beSDimitry Andric #include "llvm/Support/Errc.h" 240b57cec5SDimitry Andric 250b57cec5SDimitry Andric #include <mutex> 260b57cec5SDimitry Andric 270b57cec5SDimitry Andric #if defined(LLDB_CONFIGURATION_DEBUG) 280b57cec5SDimitry Andric #define ASSERT_MODULE_LOCK(expr) (expr->AssertModuleLock()) 290b57cec5SDimitry Andric #else 300b57cec5SDimitry Andric #define ASSERT_MODULE_LOCK(expr) ((void)0) 310b57cec5SDimitry Andric #endif 320b57cec5SDimitry Andric 330b57cec5SDimitry Andric namespace lldb_private { 340b57cec5SDimitry Andric 350b57cec5SDimitry Andric class SymbolFile : public PluginInterface { 360b57cec5SDimitry Andric public: 370b57cec5SDimitry Andric // Symbol file ability bits. 380b57cec5SDimitry Andric // 390b57cec5SDimitry Andric // Each symbol file can claim to support one or more symbol file abilities. 400b57cec5SDimitry Andric // These get returned from SymbolFile::GetAbilities(). These help us to 410b57cec5SDimitry Andric // determine which plug-in will be best to load the debug information found 420b57cec5SDimitry Andric // in files. 430b57cec5SDimitry Andric enum Abilities { 440b57cec5SDimitry Andric CompileUnits = (1u << 0), 450b57cec5SDimitry Andric LineTables = (1u << 1), 460b57cec5SDimitry Andric Functions = (1u << 2), 470b57cec5SDimitry Andric Blocks = (1u << 3), 480b57cec5SDimitry Andric GlobalVariables = (1u << 4), 490b57cec5SDimitry Andric LocalVariables = (1u << 5), 500b57cec5SDimitry Andric VariableTypes = (1u << 6), 510b57cec5SDimitry Andric kAllAbilities = ((1u << 7) - 1u) 520b57cec5SDimitry Andric }; 530b57cec5SDimitry Andric 54*9dba64beSDimitry Andric static SymbolFile *FindPlugin(lldb::ObjectFileSP objfile_sp); 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric // Constructors and Destructors 57*9dba64beSDimitry Andric SymbolFile(lldb::ObjectFileSP objfile_sp) 58*9dba64beSDimitry Andric : m_objfile_sp(std::move(objfile_sp)), m_abilities(0), 59*9dba64beSDimitry Andric m_calculated_abilities(false) {} 600b57cec5SDimitry Andric 610b57cec5SDimitry Andric ~SymbolFile() override {} 620b57cec5SDimitry Andric 630b57cec5SDimitry Andric /// Get a mask of what this symbol file supports for the object file 640b57cec5SDimitry Andric /// that it was constructed with. 650b57cec5SDimitry Andric /// 660b57cec5SDimitry Andric /// Each symbol file gets to respond with a mask of abilities that 670b57cec5SDimitry Andric /// it supports for each object file. This happens when we are 680b57cec5SDimitry Andric /// trying to figure out which symbol file plug-in will get used 690b57cec5SDimitry Andric /// for a given object file. The plug-in that responds with the 700b57cec5SDimitry Andric /// best mix of "SymbolFile::Abilities" bits set, will get chosen to 710b57cec5SDimitry Andric /// be the symbol file parser. This allows each plug-in to check for 720b57cec5SDimitry Andric /// sections that contain data a symbol file plug-in would need. For 730b57cec5SDimitry Andric /// example the DWARF plug-in requires DWARF sections in a file that 740b57cec5SDimitry Andric /// contain debug information. If the DWARF plug-in doesn't find 750b57cec5SDimitry Andric /// these sections, it won't respond with many ability bits set, and 760b57cec5SDimitry Andric /// we will probably fall back to the symbol table SymbolFile plug-in 770b57cec5SDimitry Andric /// which uses any information in the symbol table. Also, plug-ins 780b57cec5SDimitry Andric /// might check for some specific symbols in a symbol table in the 790b57cec5SDimitry Andric /// case where the symbol table contains debug information (STABS 800b57cec5SDimitry Andric /// and COFF). Not a lot of work should happen in these functions 810b57cec5SDimitry Andric /// as the plug-in might not get selected due to another plug-in 820b57cec5SDimitry Andric /// having more abilities. Any initialization work should be saved 830b57cec5SDimitry Andric /// for "void SymbolFile::InitializeObject()" which will get called 840b57cec5SDimitry Andric /// on the SymbolFile object with the best set of abilities. 850b57cec5SDimitry Andric /// 860b57cec5SDimitry Andric /// \return 870b57cec5SDimitry Andric /// A uint32_t mask containing bits from the SymbolFile::Abilities 880b57cec5SDimitry Andric /// enumeration. Any bits that are set represent an ability that 890b57cec5SDimitry Andric /// this symbol plug-in can parse from the object file. 900b57cec5SDimitry Andric uint32_t GetAbilities() { 910b57cec5SDimitry Andric if (!m_calculated_abilities) { 920b57cec5SDimitry Andric m_abilities = CalculateAbilities(); 930b57cec5SDimitry Andric m_calculated_abilities = true; 940b57cec5SDimitry Andric } 950b57cec5SDimitry Andric 960b57cec5SDimitry Andric return m_abilities; 970b57cec5SDimitry Andric } 980b57cec5SDimitry Andric 990b57cec5SDimitry Andric virtual uint32_t CalculateAbilities() = 0; 1000b57cec5SDimitry Andric 1010b57cec5SDimitry Andric /// Symbols file subclasses should override this to return the Module that 1020b57cec5SDimitry Andric /// owns the TypeSystem that this symbol file modifies type information in. 1030b57cec5SDimitry Andric virtual std::recursive_mutex &GetModuleMutex() const; 1040b57cec5SDimitry Andric 1050b57cec5SDimitry Andric /// Initialize the SymbolFile object. 1060b57cec5SDimitry Andric /// 1070b57cec5SDimitry Andric /// The SymbolFile object with the best set of abilities (detected 1080b57cec5SDimitry Andric /// in "uint32_t SymbolFile::GetAbilities()) will have this function 1090b57cec5SDimitry Andric /// called if it is chosen to parse an object file. More complete 1100b57cec5SDimitry Andric /// initialization can happen in this function which will get called 1110b57cec5SDimitry Andric /// prior to any other functions in the SymbolFile protocol. 1120b57cec5SDimitry Andric virtual void InitializeObject() {} 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric // Compile Unit function calls 1150b57cec5SDimitry Andric // Approach 1 - iterator 116*9dba64beSDimitry Andric uint32_t GetNumCompileUnits(); 117*9dba64beSDimitry Andric lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx); 118*9dba64beSDimitry Andric 119*9dba64beSDimitry Andric Symtab *GetSymtab(); 1200b57cec5SDimitry Andric 1210b57cec5SDimitry Andric virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0; 1220b57cec5SDimitry Andric virtual size_t ParseFunctions(CompileUnit &comp_unit) = 0; 1230b57cec5SDimitry Andric virtual bool ParseLineTable(CompileUnit &comp_unit) = 0; 1240b57cec5SDimitry Andric virtual bool ParseDebugMacros(CompileUnit &comp_unit) = 0; 125*9dba64beSDimitry Andric virtual void 126*9dba64beSDimitry Andric ForEachExternalModule(CompileUnit &comp_unit, 127*9dba64beSDimitry Andric llvm::function_ref<void(lldb::ModuleSP)> f) {} 1280b57cec5SDimitry Andric virtual bool ParseSupportFiles(CompileUnit &comp_unit, 1290b57cec5SDimitry Andric FileSpecList &support_files) = 0; 1300b57cec5SDimitry Andric virtual size_t ParseTypes(CompileUnit &comp_unit) = 0; 1310b57cec5SDimitry Andric virtual bool ParseIsOptimized(CompileUnit &comp_unit) { return false; } 1320b57cec5SDimitry Andric 1330b57cec5SDimitry Andric virtual bool 1340b57cec5SDimitry Andric ParseImportedModules(const SymbolContext &sc, 1350b57cec5SDimitry Andric std::vector<SourceModule> &imported_modules) = 0; 1360b57cec5SDimitry Andric virtual size_t ParseBlocksRecursive(Function &func) = 0; 1370b57cec5SDimitry Andric virtual size_t ParseVariablesForContext(const SymbolContext &sc) = 0; 1380b57cec5SDimitry Andric virtual Type *ResolveTypeUID(lldb::user_id_t type_uid) = 0; 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andric 1410b57cec5SDimitry Andric /// The characteristics of an array type. 1420b57cec5SDimitry Andric struct ArrayInfo { 1430b57cec5SDimitry Andric int64_t first_index = 0; 1440b57cec5SDimitry Andric llvm::SmallVector<uint64_t, 1> element_orders; 1450b57cec5SDimitry Andric uint32_t byte_stride = 0; 1460b57cec5SDimitry Andric uint32_t bit_stride = 0; 1470b57cec5SDimitry Andric }; 1480b57cec5SDimitry Andric /// If \c type_uid points to an array type, return its characteristics. 1490b57cec5SDimitry Andric /// To support variable-length array types, this function takes an 1500b57cec5SDimitry Andric /// optional \p ExtecutionContext. If \c exe_ctx is non-null, the 1510b57cec5SDimitry Andric /// dynamic characteristics for that context are returned. 1520b57cec5SDimitry Andric virtual llvm::Optional<ArrayInfo> 1530b57cec5SDimitry Andric GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, 1540b57cec5SDimitry Andric const lldb_private::ExecutionContext *exe_ctx) = 0; 1550b57cec5SDimitry Andric 1560b57cec5SDimitry Andric virtual bool CompleteType(CompilerType &compiler_type) = 0; 1570b57cec5SDimitry Andric virtual void ParseDeclsForContext(CompilerDeclContext decl_ctx) {} 1580b57cec5SDimitry Andric virtual CompilerDecl GetDeclForUID(lldb::user_id_t uid) { 1590b57cec5SDimitry Andric return CompilerDecl(); 1600b57cec5SDimitry Andric } 1610b57cec5SDimitry Andric virtual CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) { 1620b57cec5SDimitry Andric return CompilerDeclContext(); 1630b57cec5SDimitry Andric } 1640b57cec5SDimitry Andric virtual CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) { 1650b57cec5SDimitry Andric return CompilerDeclContext(); 1660b57cec5SDimitry Andric } 1670b57cec5SDimitry Andric virtual uint32_t ResolveSymbolContext(const Address &so_addr, 1680b57cec5SDimitry Andric lldb::SymbolContextItem resolve_scope, 1690b57cec5SDimitry Andric SymbolContext &sc) = 0; 1700b57cec5SDimitry Andric virtual uint32_t ResolveSymbolContext(const FileSpec &file_spec, 1710b57cec5SDimitry Andric uint32_t line, bool check_inlines, 1720b57cec5SDimitry Andric lldb::SymbolContextItem resolve_scope, 1730b57cec5SDimitry Andric SymbolContextList &sc_list); 1740b57cec5SDimitry Andric 1750b57cec5SDimitry Andric virtual void DumpClangAST(Stream &s) {} 176*9dba64beSDimitry Andric virtual void 1770b57cec5SDimitry Andric FindGlobalVariables(ConstString name, 1780b57cec5SDimitry Andric const CompilerDeclContext *parent_decl_ctx, 1790b57cec5SDimitry Andric uint32_t max_matches, VariableList &variables); 180*9dba64beSDimitry Andric virtual void FindGlobalVariables(const RegularExpression ®ex, 1810b57cec5SDimitry Andric uint32_t max_matches, 1820b57cec5SDimitry Andric VariableList &variables); 183*9dba64beSDimitry Andric virtual void FindFunctions(ConstString name, 1840b57cec5SDimitry Andric const CompilerDeclContext *parent_decl_ctx, 1850b57cec5SDimitry Andric lldb::FunctionNameType name_type_mask, 186*9dba64beSDimitry Andric bool include_inlines, SymbolContextList &sc_list); 187*9dba64beSDimitry Andric virtual void FindFunctions(const RegularExpression ®ex, 188*9dba64beSDimitry Andric bool include_inlines, SymbolContextList &sc_list); 189*9dba64beSDimitry Andric virtual void 1900b57cec5SDimitry Andric FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx, 191*9dba64beSDimitry Andric uint32_t max_matches, 1920b57cec5SDimitry Andric llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, 1930b57cec5SDimitry Andric TypeMap &types); 194*9dba64beSDimitry Andric 195*9dba64beSDimitry Andric /// Find types specified by a CompilerContextPattern. 196*9dba64beSDimitry Andric /// \param languages Only return results in these languages. 197*9dba64beSDimitry Andric virtual void FindTypes(llvm::ArrayRef<CompilerContext> pattern, 198*9dba64beSDimitry Andric LanguageSet languages, TypeMap &types); 1990b57cec5SDimitry Andric 2000b57cec5SDimitry Andric virtual void 2010b57cec5SDimitry Andric GetMangledNamesForFunction(const std::string &scope_qualified_name, 2020b57cec5SDimitry Andric std::vector<ConstString> &mangled_names); 203*9dba64beSDimitry Andric 204*9dba64beSDimitry Andric virtual void GetTypes(lldb_private::SymbolContextScope *sc_scope, 2050b57cec5SDimitry Andric lldb::TypeClass type_mask, 2060b57cec5SDimitry Andric lldb_private::TypeList &type_list) = 0; 2070b57cec5SDimitry Andric 2080b57cec5SDimitry Andric virtual void PreloadSymbols(); 2090b57cec5SDimitry Andric 210*9dba64beSDimitry Andric virtual llvm::Expected<lldb_private::TypeSystem &> 2110b57cec5SDimitry Andric GetTypeSystemForLanguage(lldb::LanguageType language); 2120b57cec5SDimitry Andric 2130b57cec5SDimitry Andric virtual CompilerDeclContext 2140b57cec5SDimitry Andric FindNamespace(ConstString name, 2150b57cec5SDimitry Andric const CompilerDeclContext *parent_decl_ctx) { 2160b57cec5SDimitry Andric return CompilerDeclContext(); 2170b57cec5SDimitry Andric } 2180b57cec5SDimitry Andric 219*9dba64beSDimitry Andric ObjectFile *GetObjectFile() { return m_objfile_sp.get(); } 220*9dba64beSDimitry Andric const ObjectFile *GetObjectFile() const { return m_objfile_sp.get(); } 221*9dba64beSDimitry Andric ObjectFile *GetMainObjectFile(); 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andric virtual std::vector<CallEdge> ParseCallEdgesInFunction(UserID func_id) { 2240b57cec5SDimitry Andric return {}; 2250b57cec5SDimitry Andric } 2260b57cec5SDimitry Andric 2270b57cec5SDimitry Andric virtual void AddSymbols(Symtab &symtab) {} 2280b57cec5SDimitry Andric 2290b57cec5SDimitry Andric /// Notify the SymbolFile that the file addresses in the Sections 2300b57cec5SDimitry Andric /// for this module have been changed. 231*9dba64beSDimitry Andric virtual void SectionFileAddressesChanged(); 2320b57cec5SDimitry Andric 2330b57cec5SDimitry Andric struct RegisterInfoResolver { 2340b57cec5SDimitry Andric virtual ~RegisterInfoResolver(); // anchor 2350b57cec5SDimitry Andric 2360b57cec5SDimitry Andric virtual const RegisterInfo *ResolveName(llvm::StringRef name) const = 0; 2370b57cec5SDimitry Andric virtual const RegisterInfo *ResolveNumber(lldb::RegisterKind kind, 2380b57cec5SDimitry Andric uint32_t number) const = 0; 2390b57cec5SDimitry Andric }; 2400b57cec5SDimitry Andric virtual lldb::UnwindPlanSP 2410b57cec5SDimitry Andric GetUnwindPlan(const Address &address, const RegisterInfoResolver &resolver) { 2420b57cec5SDimitry Andric return nullptr; 2430b57cec5SDimitry Andric } 2440b57cec5SDimitry Andric 245*9dba64beSDimitry Andric /// Return the number of stack bytes taken up by the parameters to this 246*9dba64beSDimitry Andric /// function. 247*9dba64beSDimitry Andric virtual llvm::Expected<lldb::addr_t> GetParameterStackSize(Symbol &symbol) { 248*9dba64beSDimitry Andric return llvm::createStringError(make_error_code(llvm::errc::not_supported), 249*9dba64beSDimitry Andric "Operation not supported."); 250*9dba64beSDimitry Andric } 251*9dba64beSDimitry Andric 252*9dba64beSDimitry Andric virtual void Dump(Stream &s); 2530b57cec5SDimitry Andric 2540b57cec5SDimitry Andric protected: 2550b57cec5SDimitry Andric void AssertModuleLock(); 256*9dba64beSDimitry Andric virtual uint32_t CalculateNumCompileUnits() = 0; 257*9dba64beSDimitry Andric virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t idx) = 0; 258*9dba64beSDimitry Andric virtual TypeList &GetTypeList() { return m_type_list; } 2590b57cec5SDimitry Andric 260*9dba64beSDimitry Andric void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp); 261*9dba64beSDimitry Andric 262*9dba64beSDimitry Andric lldb::ObjectFileSP m_objfile_sp; // Keep a reference to the object file in 263*9dba64beSDimitry Andric // case it isn't the same as the module 264*9dba64beSDimitry Andric // object file (debug symbols in a separate 265*9dba64beSDimitry Andric // file) 266*9dba64beSDimitry Andric llvm::Optional<std::vector<lldb::CompUnitSP>> m_compile_units; 267*9dba64beSDimitry Andric TypeList m_type_list; 268*9dba64beSDimitry Andric Symtab *m_symtab = nullptr; 2690b57cec5SDimitry Andric uint32_t m_abilities; 2700b57cec5SDimitry Andric bool m_calculated_abilities; 2710b57cec5SDimitry Andric 2720b57cec5SDimitry Andric private: 2730b57cec5SDimitry Andric DISALLOW_COPY_AND_ASSIGN(SymbolFile); 2740b57cec5SDimitry Andric }; 2750b57cec5SDimitry Andric 2760b57cec5SDimitry Andric } // namespace lldb_private 2770b57cec5SDimitry Andric 2780b57cec5SDimitry Andric #endif // liblldb_SymbolFile_h_ 279