SymbolFile.h revision cc152b20d7b07aa4c229977b7b0d8d94cbda2ff5
1//===-- SymbolFile.h --------------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef liblldb_SymbolFile_h_ 11#define liblldb_SymbolFile_h_ 12 13#include "lldb/lldb-private.h" 14#include "lldb/Core/PluginInterface.h" 15#include "lldb/Symbol/ClangASTType.h" 16#include "lldb/Symbol/ClangNamespaceDecl.h" 17#include "lldb/Symbol/Type.h" 18 19namespace lldb_private { 20 21class SymbolFile : 22 public PluginInterface 23{ 24public: 25 enum Abilities 26 { 27 Labels = (1 << 0), 28 AddressAcceleratorTable = (1 << 1), 29 FunctionAcceleratorTable = (1 << 2), 30 TypeAcceleratorTable = (1 << 3), 31 MacroInformation = (1 << 4), 32 CallFrameInformation = (1 << 5), 33 RuntimeTypes = (1 << 6), 34 CompileUnits = (1 << 7), 35 LineTables = (1 << 8), 36 LineColumns = (1 << 9), 37 Functions = (1 << 10), 38 Blocks = (1 << 11), 39 GlobalVariables = (1 << 12), 40 LocalVariables = (1 << 13), 41 VariableTypes = (1 << 14) 42 }; 43 44 static SymbolFile * 45 FindPlugin (ObjectFile* obj_file); 46 47 //------------------------------------------------------------------ 48 // Constructors and Destructors 49 //------------------------------------------------------------------ 50 SymbolFile(ObjectFile* obj_file) : 51 m_obj_file(obj_file), 52 m_abilities(0), 53 m_calculated_abilities(false) 54 { 55 } 56 57 virtual 58 ~SymbolFile() 59 { 60 } 61 62 //------------------------------------------------------------------ 63 /// Get a mask of what this symbol file supports for the object file 64 /// that it was constructed with. 65 /// 66 /// Each symbol file gets to respond with a mask of abilities that 67 /// it supports for each object file. This happens when we are 68 /// trying to figure out which symbol file plug-in will get used 69 /// for a given object file. The plug-in that resoonds with the 70 /// best mix of "SymbolFile::Abilities" bits set, will get chosen to 71 /// be the symbol file parser. This allows each plug-in to check for 72 /// sections that contain data a symbol file plug-in would need. For 73 /// example the DWARF plug-in requires DWARF sections in a file that 74 /// contain debug information. If the DWARF plug-in doesn't find 75 /// these sections, it won't respond with many ability bits set, and 76 /// we will probably fall back to the symbol table SymbolFile plug-in 77 /// which uses any information in the symbol table. Also, plug-ins 78 /// might check for some specific symbols in a symbol table in the 79 /// case where the symbol table contains debug information (STABS 80 /// and COFF). Not a lot of work should happen in these functions 81 /// as the plug-in might not get selected due to another plug-in 82 /// having more abilities. Any initialization work should be saved 83 /// for "void SymbolFile::InitializeObject()" which will get called 84 /// on the SymbolFile object with the best set of abilities. 85 /// 86 /// @return 87 /// A uint32_t mask containing bits from the SymbolFile::Abilities 88 /// enumeration. Any bits that are set represent an ability that 89 /// this symbol plug-in can parse from the object file. 90 ///------------------------------------------------------------------ 91 uint32_t GetAbilities () 92 { 93 if (!m_calculated_abilities) 94 { 95 m_abilities = CalculateAbilities(); 96 m_calculated_abilities = true; 97 } 98 99 return m_abilities; 100 } 101 102 virtual uint32_t CalculateAbilities() = 0; 103 104 //------------------------------------------------------------------ 105 /// Initialize the SymbolFile object. 106 /// 107 /// The SymbolFile object with the best set of abilities (detected 108 /// in "uint32_t SymbolFile::GetAbilities()) will have this function 109 /// called if it is chosen to parse an object file. More complete 110 /// initialization can happen in this function which will get called 111 /// prior to any other functions in the SymbolFile protocol. 112 //------------------------------------------------------------------ 113 virtual void InitializeObject() {} 114 115 //------------------------------------------------------------------ 116 // Compile Unit function calls 117 //------------------------------------------------------------------ 118 // Approach 1 - iterator 119 virtual uint32_t GetNumCompileUnits() = 0; 120 virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) = 0; 121 122 virtual size_t ParseCompileUnitFunctions (const SymbolContext& sc) = 0; 123 virtual bool ParseCompileUnitLineTable (const SymbolContext& sc) = 0; 124 virtual bool ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) = 0; 125 virtual size_t ParseFunctionBlocks (const SymbolContext& sc) = 0; 126 virtual size_t ParseTypes (const SymbolContext& sc) = 0; 127 virtual size_t ParseVariablesForContext (const SymbolContext& sc) = 0; 128 virtual Type* ResolveTypeUID (lldb::user_id_t type_uid) = 0; 129 virtual lldb::clang_type_t ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type) = 0; 130 virtual clang::DeclContext* GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) { return NULL; } 131 virtual clang::DeclContext* GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) { return NULL; } 132 virtual uint32_t ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc) = 0; 133 virtual uint32_t ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list) = 0; 134 virtual uint32_t FindGlobalVariables (const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables) = 0; 135 virtual uint32_t FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) = 0; 136 virtual uint32_t FindFunctions (const ConstString &name, const ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool append, SymbolContextList& sc_list) = 0; 137 virtual uint32_t FindFunctions (const RegularExpression& regex, bool append, SymbolContextList& sc_list) = 0; 138 virtual uint32_t FindTypes (const SymbolContext& sc, const ConstString &name, const ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, TypeList& types) = 0; 139// virtual uint32_t FindTypes (const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, TypeList& types) = 0; 140 virtual TypeList * GetTypeList (); 141 virtual ClangASTContext & 142 GetClangASTContext (); 143 virtual ClangNamespaceDecl 144 FindNamespace (const SymbolContext& sc, 145 const ConstString &name, 146 const ClangNamespaceDecl *parent_namespace_decl) = 0; 147 148 ObjectFile* GetObjectFile() { return m_obj_file; } 149 const ObjectFile* GetObjectFile() const { return m_obj_file; } 150 151protected: 152 ObjectFile* m_obj_file; // The object file that symbols can be extracted from. 153 uint32_t m_abilities; 154 bool m_calculated_abilities; 155private: 156 DISALLOW_COPY_AND_ASSIGN (SymbolFile); 157}; 158 159 160} // namespace lldb_private 161 162#endif // liblldb_SymbolFile_h_ 163