SymbolVendor.h revision 355940
1//===-- SymbolVendor.h ------------------------------------------*- C++ -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9#ifndef liblldb_SymbolVendor_h_ 10#define liblldb_SymbolVendor_h_ 11 12#include <vector> 13 14#include "lldb/Core/ModuleChild.h" 15#include "lldb/Core/PluginInterface.h" 16#include "lldb/Symbol/SourceModule.h" 17#include "lldb/Symbol/TypeList.h" 18#include "lldb/Symbol/TypeMap.h" 19#include "lldb/lldb-private.h" 20#include "llvm/ADT/DenseSet.h" 21 22namespace lldb_private { 23 24// The symbol vendor class is designed to abstract the process of searching for 25// debug information for a given module. Platforms can subclass this class and 26// provide extra ways to find debug information. Examples would be a subclass 27// that would allow for locating a stand alone debug file, parsing debug maps, 28// or runtime data in the object files. A symbol vendor can use multiple 29// sources (SymbolFile objects) to provide the information and only parse as 30// deep as needed in order to provide the information that is requested. 31class SymbolVendor : public ModuleChild, public PluginInterface { 32public: 33 static SymbolVendor *FindPlugin(const lldb::ModuleSP &module_sp, 34 Stream *feedback_strm); 35 36 // Constructors and Destructors 37 SymbolVendor(const lldb::ModuleSP &module_sp); 38 39 ~SymbolVendor() override; 40 41 void AddSymbolFileRepresentation(const lldb::ObjectFileSP &objfile_sp); 42 43 virtual void Dump(Stream *s); 44 45 virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit); 46 47 virtual size_t ParseFunctions(CompileUnit &comp_unit); 48 49 virtual bool ParseLineTable(CompileUnit &comp_unit); 50 51 virtual bool ParseDebugMacros(CompileUnit &comp_unit); 52 53 virtual bool ParseSupportFiles(CompileUnit &comp_unit, 54 FileSpecList &support_files); 55 56 virtual bool ParseIsOptimized(CompileUnit &comp_unit); 57 58 virtual size_t ParseTypes(CompileUnit &comp_unit); 59 60 virtual bool 61 ParseImportedModules(const SymbolContext &sc, 62 std::vector<SourceModule> &imported_modules); 63 64 virtual size_t ParseBlocksRecursive(Function &func); 65 66 virtual size_t ParseVariablesForContext(const SymbolContext &sc); 67 68 virtual Type *ResolveTypeUID(lldb::user_id_t type_uid); 69 70 virtual uint32_t ResolveSymbolContext(const Address &so_addr, 71 lldb::SymbolContextItem resolve_scope, 72 SymbolContext &sc); 73 74 virtual uint32_t ResolveSymbolContext(const FileSpec &file_spec, 75 uint32_t line, bool check_inlines, 76 lldb::SymbolContextItem resolve_scope, 77 SymbolContextList &sc_list); 78 79 virtual size_t FindGlobalVariables(ConstString name, 80 const CompilerDeclContext *parent_decl_ctx, 81 size_t max_matches, 82 VariableList &variables); 83 84 virtual size_t FindGlobalVariables(const RegularExpression ®ex, 85 size_t max_matches, 86 VariableList &variables); 87 88 virtual size_t FindFunctions(ConstString name, 89 const CompilerDeclContext *parent_decl_ctx, 90 lldb::FunctionNameType name_type_mask, 91 bool include_inlines, bool append, 92 SymbolContextList &sc_list); 93 94 virtual size_t FindFunctions(const RegularExpression ®ex, 95 bool include_inlines, bool append, 96 SymbolContextList &sc_list); 97 98 virtual size_t 99 FindTypes(ConstString name, const CompilerDeclContext *parent_decl_ctx, 100 bool append, size_t max_matches, 101 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, 102 TypeMap &types); 103 104 virtual size_t FindTypes(const std::vector<CompilerContext> &context, 105 bool append, TypeMap &types); 106 107 virtual CompilerDeclContext 108 FindNamespace(ConstString name, 109 const CompilerDeclContext *parent_decl_ctx); 110 111 virtual size_t GetNumCompileUnits(); 112 113 virtual bool SetCompileUnitAtIndex(size_t cu_idx, 114 const lldb::CompUnitSP &cu_sp); 115 116 virtual lldb::CompUnitSP GetCompileUnitAtIndex(size_t idx); 117 118 TypeList &GetTypeList() { return m_type_list; } 119 120 const TypeList &GetTypeList() const { return m_type_list; } 121 122 virtual size_t GetTypes(SymbolContextScope *sc_scope, 123 lldb::TypeClass type_mask, TypeList &type_list); 124 125 SymbolFile *GetSymbolFile() { return m_sym_file_up.get(); } 126 127 FileSpec GetMainFileSpec() const; 128 129 // Get module unified section list symbol table. 130 virtual Symtab *GetSymtab(); 131 132 // Clear module unified section list symbol table. 133 virtual void ClearSymtab(); 134 135 /// Notify the SymbolVendor that the file addresses in the Sections 136 /// for this module have been changed. 137 virtual void SectionFileAddressesChanged(); 138 139 // PluginInterface protocol 140 ConstString GetPluginName() override; 141 142 uint32_t GetPluginVersion() override; 143 144protected: 145 // Classes that inherit from SymbolVendor can see and modify these 146 typedef std::vector<lldb::CompUnitSP> CompileUnits; 147 typedef CompileUnits::iterator CompileUnitIter; 148 typedef CompileUnits::const_iterator CompileUnitConstIter; 149 150 TypeList m_type_list; // Uniqued types for all parsers owned by this module 151 CompileUnits m_compile_units; // The current compile units 152 lldb::ObjectFileSP m_objfile_sp; // Keep a reference to the object file in 153 // case it isn't the same as the module 154 // object file (debug symbols in a separate 155 // file) 156 std::unique_ptr<SymbolFile> m_sym_file_up; // A single symbol file. Subclasses 157 // can add more of these if needed. 158 Symtab *m_symtab; // Save a symtab once to not pass it through `AddSymbols` of 159 // the symbol file each time when it is needed 160 161private: 162 // For SymbolVendor only 163 DISALLOW_COPY_AND_ASSIGN(SymbolVendor); 164}; 165 166} // namespace lldb_private 167 168#endif // liblldb_SymbolVendor_h_ 169