SymbolFile.h revision 288943
1214503Srpaulo//===-- SymbolFile.h --------------------------------------------*- C++ -*-===// 2214503Srpaulo// 3214503Srpaulo// The LLVM Compiler Infrastructure 4214503Srpaulo// 5214503Srpaulo// This file is distributed under the University of Illinois Open Source 6214503Srpaulo// License. See LICENSE.TXT for details. 7214503Srpaulo// 8214503Srpaulo//===----------------------------------------------------------------------===// 9214503Srpaulo 10214503Srpaulo#ifndef liblldb_SymbolFile_h_ 11214503Srpaulo#define liblldb_SymbolFile_h_ 12214503Srpaulo 13214503Srpaulo#include "lldb/lldb-private.h" 14214503Srpaulo#include "lldb/Core/PluginInterface.h" 15214503Srpaulo#include "lldb/Symbol/ClangASTType.h" 16214503Srpaulo#include "lldb/Symbol/ClangNamespaceDecl.h" 17214503Srpaulo#include "lldb/Symbol/Type.h" 18214503Srpaulo 19214503Srpaulonamespace lldb_private { 20214503Srpaulo 21214503Srpauloclass SymbolFile : 22214503Srpaulo public PluginInterface 23214503Srpaulo{ 24214503Srpaulopublic: 25214503Srpaulo //------------------------------------------------------------------ 26214503Srpaulo // Symbol file ability bits. 27214503Srpaulo // 28214503Srpaulo // Each symbol file can claim to support one or more symbol file 29214503Srpaulo // abilities. These get returned from SymbolFile::GetAbilities(). 30214503Srpaulo // These help us to determine which plug-in will be best to load 31214503Srpaulo // the debug information found in files. 32214503Srpaulo //------------------------------------------------------------------ 33214503Srpaulo enum Abilities 34214503Srpaulo { 35214503Srpaulo CompileUnits = (1u << 0), 36214503Srpaulo LineTables = (1u << 1), 37214503Srpaulo Functions = (1u << 2), 38214503Srpaulo Blocks = (1u << 3), 39214503Srpaulo GlobalVariables = (1u << 4), 40214503Srpaulo LocalVariables = (1u << 5), 41214503Srpaulo VariableTypes = (1u << 6), 42214503Srpaulo kAllAbilities =((1u << 7) - 1u) 43214503Srpaulo }; 44214503Srpaulo 45214503Srpaulo static SymbolFile * 46214503Srpaulo FindPlugin (ObjectFile* obj_file); 47214503Srpaulo 48214503Srpaulo //------------------------------------------------------------------ 49214503Srpaulo // Constructors and Destructors 50214503Srpaulo //------------------------------------------------------------------ 51214503Srpaulo SymbolFile(ObjectFile* obj_file) : 52214503Srpaulo m_obj_file(obj_file), 53214503Srpaulo m_abilities(0), 54214503Srpaulo m_calculated_abilities(false) 55214503Srpaulo { 56214503Srpaulo } 57214503Srpaulo 58214503Srpaulo virtual 59214503Srpaulo ~SymbolFile() 60214503Srpaulo { 61214503Srpaulo } 62214503Srpaulo 63214503Srpaulo //------------------------------------------------------------------ 64214503Srpaulo /// Get a mask of what this symbol file supports for the object file 65214503Srpaulo /// that it was constructed with. 66214503Srpaulo /// 67214503Srpaulo /// Each symbol file gets to respond with a mask of abilities that 68214503Srpaulo /// it supports for each object file. This happens when we are 69214503Srpaulo /// trying to figure out which symbol file plug-in will get used 70214503Srpaulo /// for a given object file. The plug-in that responds with the 71214503Srpaulo /// best mix of "SymbolFile::Abilities" bits set, will get chosen to 72214503Srpaulo /// be the symbol file parser. This allows each plug-in to check for 73214503Srpaulo /// sections that contain data a symbol file plug-in would need. For 74214503Srpaulo /// example the DWARF plug-in requires DWARF sections in a file that 75214503Srpaulo /// contain debug information. If the DWARF plug-in doesn't find 76214503Srpaulo /// these sections, it won't respond with many ability bits set, and 77214503Srpaulo /// we will probably fall back to the symbol table SymbolFile plug-in 78214503Srpaulo /// which uses any information in the symbol table. Also, plug-ins 79214503Srpaulo /// might check for some specific symbols in a symbol table in the 80214503Srpaulo /// case where the symbol table contains debug information (STABS 81214503Srpaulo /// and COFF). Not a lot of work should happen in these functions 82214503Srpaulo /// as the plug-in might not get selected due to another plug-in 83214503Srpaulo /// having more abilities. Any initialization work should be saved 84214503Srpaulo /// for "void SymbolFile::InitializeObject()" which will get called 85214503Srpaulo /// on the SymbolFile object with the best set of abilities. 86214503Srpaulo /// 87214503Srpaulo /// @return 88214503Srpaulo /// A uint32_t mask containing bits from the SymbolFile::Abilities 89214503Srpaulo /// enumeration. Any bits that are set represent an ability that 90214503Srpaulo /// this symbol plug-in can parse from the object file. 91214503Srpaulo ///------------------------------------------------------------------ 92214503Srpaulo uint32_t GetAbilities () 93214503Srpaulo { 94214503Srpaulo if (!m_calculated_abilities) 95214503Srpaulo { 96214503Srpaulo m_abilities = CalculateAbilities(); 97214503Srpaulo m_calculated_abilities = true; 98214503Srpaulo } 99214503Srpaulo 100214503Srpaulo return m_abilities; 101214503Srpaulo } 102214503Srpaulo 103214503Srpaulo virtual uint32_t CalculateAbilities() = 0; 104214503Srpaulo 105214503Srpaulo //------------------------------------------------------------------ 106214503Srpaulo /// Initialize the SymbolFile object. 107214503Srpaulo /// 108214503Srpaulo /// The SymbolFile object with the best set of abilities (detected 109214503Srpaulo /// in "uint32_t SymbolFile::GetAbilities()) will have this function 110214503Srpaulo /// called if it is chosen to parse an object file. More complete 111214503Srpaulo /// initialization can happen in this function which will get called 112214503Srpaulo /// prior to any other functions in the SymbolFile protocol. 113214503Srpaulo //------------------------------------------------------------------ 114214503Srpaulo virtual void InitializeObject() {} 115214503Srpaulo 116214503Srpaulo //------------------------------------------------------------------ 117214503Srpaulo // Compile Unit function calls 118214503Srpaulo //------------------------------------------------------------------ 119214503Srpaulo // Approach 1 - iterator 120214503Srpaulo virtual uint32_t GetNumCompileUnits() = 0; 121214503Srpaulo virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) = 0; 122214503Srpaulo 123214503Srpaulo virtual lldb::LanguageType ParseCompileUnitLanguage (const SymbolContext& sc) = 0; 124214503Srpaulo virtual size_t ParseCompileUnitFunctions (const SymbolContext& sc) = 0; 125214503Srpaulo virtual bool ParseCompileUnitLineTable (const SymbolContext& sc) = 0; 126214503Srpaulo virtual bool ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) = 0; 127214503Srpaulo virtual bool ParseImportedModules (const SymbolContext &sc, std::vector<ConstString> &imported_modules) = 0; 128214503Srpaulo virtual size_t ParseFunctionBlocks (const SymbolContext& sc) = 0; 129214503Srpaulo virtual size_t ParseTypes (const SymbolContext& sc) = 0; 130214503Srpaulo virtual size_t ParseVariablesForContext (const SymbolContext& sc) = 0; 131214503Srpaulo virtual Type* ResolveTypeUID (lldb::user_id_t type_uid) = 0; 132214503Srpaulo virtual bool ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type) = 0; 133214503Srpaulo virtual clang::DeclContext* GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) { return NULL; } 134214503Srpaulo virtual clang::DeclContext* GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) { return NULL; } 135214503Srpaulo virtual uint32_t ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) = 0; 136214503Srpaulo virtual uint32_t ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) = 0; 137214503Srpaulo virtual uint32_t FindGlobalVariables (const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables) = 0; 138214503Srpaulo virtual uint32_t FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) = 0; 139214503Srpaulo virtual uint32_t FindFunctions (const ConstString &name, const ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list) = 0; 140214503Srpaulo virtual uint32_t FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list) = 0; 141214503Srpaulo virtual uint32_t FindTypes (const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, TypeList& types) = 0; 142214503Srpaulo// virtual uint32_t FindTypes (const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, TypeList& types) = 0; 143214503Srpaulo virtual TypeList * GetTypeList (); 144214503Srpaulo virtual size_t GetTypes (lldb_private::SymbolContextScope *sc_scope, 145214503Srpaulo uint32_t type_mask, 146214503Srpaulo lldb_private::TypeList &type_list) = 0; 147214503Srpaulo virtual ClangASTContext & 148214503Srpaulo GetClangASTContext (); 149214503Srpaulo virtual ClangNamespaceDecl 150214503Srpaulo FindNamespace (const SymbolContext& sc, 151214503Srpaulo const ConstString &name, 152214503Srpaulo const ClangNamespaceDecl *parent_namespace_decl) = 0; 153214503Srpaulo 154214503Srpaulo ObjectFile* GetObjectFile() { return m_obj_file; } 155214503Srpaulo const ObjectFile* GetObjectFile() const { return m_obj_file; } 156214503Srpaulo 157214503Srpaulo //------------------------------------------------------------------ 158214503Srpaulo /// Notify the SymbolFile that the file addresses in the Sections 159214503Srpaulo /// for this module have been changed. 160214503Srpaulo //------------------------------------------------------------------ 161214503Srpaulo virtual void 162214503Srpaulo SectionFileAddressesChanged () 163214503Srpaulo { 164214503Srpaulo } 165214503Srpaulo 166214503Srpaulo 167214503Srpauloprotected: 168214503Srpaulo ObjectFile* m_obj_file; // The object file that symbols can be extracted from. 169214503Srpaulo uint32_t m_abilities; 170214503Srpaulo bool m_calculated_abilities; 171214503Srpauloprivate: 172214503Srpaulo DISALLOW_COPY_AND_ASSIGN (SymbolFile); 173214503Srpaulo}; 174214503Srpaulo 175214503Srpaulo 176214503Srpaulo} // namespace lldb_private 177214503Srpaulo 178214503Srpaulo#endif // liblldb_SymbolFile_h_ 179214503Srpaulo