1 //===-- SymbolFile.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_SymbolFile_h_
11 #define liblldb_SymbolFile_h_
13 #include "lldb/Core/PluginInterface.h"
14 #include "lldb/Symbol/CompilerDecl.h"
15 #include "lldb/Symbol/CompilerDeclContext.h"
16 #include "lldb/Symbol/CompilerType.h"
17 #include "lldb/Symbol/Type.h"
18 #include "lldb/lldb-private.h"
20 #include "llvm/ADT/DenseSet.h"
22 namespace lldb_private {
24 class SymbolFile : public PluginInterface {
26 //------------------------------------------------------------------
27 // Symbol file ability bits.
29 // Each symbol file can claim to support one or more symbol file
30 // abilities. These get returned from SymbolFile::GetAbilities().
31 // These help us to determine which plug-in will be best to load
32 // the debug information found in files.
33 //------------------------------------------------------------------
35 CompileUnits = (1u << 0),
36 LineTables = (1u << 1),
37 Functions = (1u << 2),
39 GlobalVariables = (1u << 4),
40 LocalVariables = (1u << 5),
41 VariableTypes = (1u << 6),
42 kAllAbilities = ((1u << 7) - 1u)
45 static SymbolFile *FindPlugin(ObjectFile *obj_file);
47 //------------------------------------------------------------------
48 // Constructors and Destructors
49 //------------------------------------------------------------------
50 SymbolFile(ObjectFile *obj_file)
51 : m_obj_file(obj_file), m_abilities(0), m_calculated_abilities(false) {}
53 ~SymbolFile() override {}
55 //------------------------------------------------------------------
56 /// Get a mask of what this symbol file supports for the object file
57 /// that it was constructed with.
59 /// Each symbol file gets to respond with a mask of abilities that
60 /// it supports for each object file. This happens when we are
61 /// trying to figure out which symbol file plug-in will get used
62 /// for a given object file. The plug-in that responds with the
63 /// best mix of "SymbolFile::Abilities" bits set, will get chosen to
64 /// be the symbol file parser. This allows each plug-in to check for
65 /// sections that contain data a symbol file plug-in would need. For
66 /// example the DWARF plug-in requires DWARF sections in a file that
67 /// contain debug information. If the DWARF plug-in doesn't find
68 /// these sections, it won't respond with many ability bits set, and
69 /// we will probably fall back to the symbol table SymbolFile plug-in
70 /// which uses any information in the symbol table. Also, plug-ins
71 /// might check for some specific symbols in a symbol table in the
72 /// case where the symbol table contains debug information (STABS
73 /// and COFF). Not a lot of work should happen in these functions
74 /// as the plug-in might not get selected due to another plug-in
75 /// having more abilities. Any initialization work should be saved
76 /// for "void SymbolFile::InitializeObject()" which will get called
77 /// on the SymbolFile object with the best set of abilities.
80 /// A uint32_t mask containing bits from the SymbolFile::Abilities
81 /// enumeration. Any bits that are set represent an ability that
82 /// this symbol plug-in can parse from the object file.
83 ///------------------------------------------------------------------
84 uint32_t GetAbilities() {
85 if (!m_calculated_abilities) {
86 m_abilities = CalculateAbilities();
87 m_calculated_abilities = true;
93 virtual uint32_t CalculateAbilities() = 0;
95 //------------------------------------------------------------------
96 /// Initialize the SymbolFile object.
98 /// The SymbolFile object with the best set of abilities (detected
99 /// in "uint32_t SymbolFile::GetAbilities()) will have this function
100 /// called if it is chosen to parse an object file. More complete
101 /// initialization can happen in this function which will get called
102 /// prior to any other functions in the SymbolFile protocol.
103 //------------------------------------------------------------------
104 virtual void InitializeObject() {}
106 //------------------------------------------------------------------
107 // Compile Unit function calls
108 //------------------------------------------------------------------
109 // Approach 1 - iterator
110 virtual uint32_t GetNumCompileUnits() = 0;
111 virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) = 0;
113 virtual lldb::LanguageType
114 ParseCompileUnitLanguage(const SymbolContext &sc) = 0;
115 virtual size_t ParseCompileUnitFunctions(const SymbolContext &sc) = 0;
116 virtual bool ParseCompileUnitLineTable(const SymbolContext &sc) = 0;
117 virtual bool ParseCompileUnitDebugMacros(const SymbolContext &sc) = 0;
118 virtual bool ParseCompileUnitSupportFiles(const SymbolContext &sc,
119 FileSpecList &support_files) = 0;
121 ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc) {
125 ParseImportedModules(const SymbolContext &sc,
126 std::vector<ConstString> &imported_modules) = 0;
127 virtual size_t ParseFunctionBlocks(const SymbolContext &sc) = 0;
128 virtual size_t ParseTypes(const SymbolContext &sc) = 0;
129 virtual size_t ParseVariablesForContext(const SymbolContext &sc) = 0;
130 virtual Type *ResolveTypeUID(lldb::user_id_t type_uid) = 0;
131 virtual bool CompleteType(CompilerType &compiler_type) = 0;
132 virtual void ParseDeclsForContext(CompilerDeclContext decl_ctx) {}
133 virtual CompilerDecl GetDeclForUID(lldb::user_id_t uid) {
134 return CompilerDecl();
136 virtual CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) {
137 return CompilerDeclContext();
139 virtual CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) {
140 return CompilerDeclContext();
142 virtual uint32_t ResolveSymbolContext(const Address &so_addr,
143 uint32_t resolve_scope,
144 SymbolContext &sc) = 0;
145 virtual uint32_t ResolveSymbolContext(const FileSpec &file_spec,
146 uint32_t line, bool check_inlines,
147 uint32_t resolve_scope,
148 SymbolContextList &sc_list);
150 FindGlobalVariables(const ConstString &name,
151 const CompilerDeclContext *parent_decl_ctx, bool append,
152 uint32_t max_matches, VariableList &variables);
153 virtual uint32_t FindGlobalVariables(const RegularExpression ®ex,
154 bool append, uint32_t max_matches,
155 VariableList &variables);
156 virtual uint32_t FindFunctions(const ConstString &name,
157 const CompilerDeclContext *parent_decl_ctx,
158 uint32_t name_type_mask, bool include_inlines,
159 bool append, SymbolContextList &sc_list);
160 virtual uint32_t FindFunctions(const RegularExpression ®ex,
161 bool include_inlines, bool append,
162 SymbolContextList &sc_list);
164 FindTypes(const SymbolContext &sc, const ConstString &name,
165 const CompilerDeclContext *parent_decl_ctx, bool append,
166 uint32_t max_matches,
167 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
169 virtual size_t FindTypes(const std::vector<CompilerContext> &context,
170 bool append, TypeMap &types);
173 GetMangledNamesForFunction(const std::string &scope_qualified_name,
174 std::vector<ConstString> &mangled_names);
175 // virtual uint32_t FindTypes (const SymbolContext& sc, const
176 // RegularExpression& regex, bool append, uint32_t max_matches, TypeList&
178 virtual TypeList *GetTypeList();
179 virtual size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
181 lldb_private::TypeList &type_list) = 0;
183 virtual void PreloadSymbols();
185 virtual lldb_private::TypeSystem *
186 GetTypeSystemForLanguage(lldb::LanguageType language);
188 virtual CompilerDeclContext
189 FindNamespace(const SymbolContext &sc, const ConstString &name,
190 const CompilerDeclContext *parent_decl_ctx) {
191 return CompilerDeclContext();
194 ObjectFile *GetObjectFile() { return m_obj_file; }
195 const ObjectFile *GetObjectFile() const { return m_obj_file; }
197 //------------------------------------------------------------------
198 /// Notify the SymbolFile that the file addresses in the Sections
199 /// for this module have been changed.
200 //------------------------------------------------------------------
201 virtual void SectionFileAddressesChanged() {}
204 ObjectFile *m_obj_file; // The object file that symbols can be extracted from.
205 uint32_t m_abilities;
206 bool m_calculated_abilities;
209 DISALLOW_COPY_AND_ASSIGN(SymbolFile);
212 } // namespace lldb_private
214 #endif // liblldb_SymbolFile_h_