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/Function.h"
18 #include "lldb/Symbol/Type.h"
19 #include "lldb/lldb-private.h"
21 #include "llvm/ADT/DenseSet.h"
25 #if defined(LLDB_CONFIGURATION_DEBUG)
26 #define ASSERT_MODULE_LOCK(expr) (expr->AssertModuleLock())
28 #define ASSERT_MODULE_LOCK(expr) ((void)0)
31 namespace lldb_private {
33 class SymbolFile : public PluginInterface {
35 //------------------------------------------------------------------
36 // Symbol file ability bits.
38 // Each symbol file can claim to support one or more symbol file abilities.
39 // These get returned from SymbolFile::GetAbilities(). These help us to
40 // determine which plug-in will be best to load the debug information found
42 //------------------------------------------------------------------
44 CompileUnits = (1u << 0),
45 LineTables = (1u << 1),
46 Functions = (1u << 2),
48 GlobalVariables = (1u << 4),
49 LocalVariables = (1u << 5),
50 VariableTypes = (1u << 6),
51 kAllAbilities = ((1u << 7) - 1u)
54 static SymbolFile *FindPlugin(ObjectFile *obj_file);
56 //------------------------------------------------------------------
57 // Constructors and Destructors
58 //------------------------------------------------------------------
59 SymbolFile(ObjectFile *obj_file)
60 : m_obj_file(obj_file), m_abilities(0), m_calculated_abilities(false) {}
62 ~SymbolFile() override {}
64 //------------------------------------------------------------------
65 /// Get a mask of what this symbol file supports for the object file
66 /// that it was constructed with.
68 /// Each symbol file gets to respond with a mask of abilities that
69 /// it supports for each object file. This happens when we are
70 /// trying to figure out which symbol file plug-in will get used
71 /// for a given object file. The plug-in that responds with the
72 /// best mix of "SymbolFile::Abilities" bits set, will get chosen to
73 /// be the symbol file parser. This allows each plug-in to check for
74 /// sections that contain data a symbol file plug-in would need. For
75 /// example the DWARF plug-in requires DWARF sections in a file that
76 /// contain debug information. If the DWARF plug-in doesn't find
77 /// these sections, it won't respond with many ability bits set, and
78 /// we will probably fall back to the symbol table SymbolFile plug-in
79 /// which uses any information in the symbol table. Also, plug-ins
80 /// might check for some specific symbols in a symbol table in the
81 /// case where the symbol table contains debug information (STABS
82 /// and COFF). Not a lot of work should happen in these functions
83 /// as the plug-in might not get selected due to another plug-in
84 /// having more abilities. Any initialization work should be saved
85 /// for "void SymbolFile::InitializeObject()" which will get called
86 /// on the SymbolFile object with the best set of abilities.
89 /// A uint32_t mask containing bits from the SymbolFile::Abilities
90 /// enumeration. Any bits that are set represent an ability that
91 /// this symbol plug-in can parse from the object file.
92 ///------------------------------------------------------------------
93 uint32_t GetAbilities() {
94 if (!m_calculated_abilities) {
95 m_abilities = CalculateAbilities();
96 m_calculated_abilities = true;
102 virtual uint32_t CalculateAbilities() = 0;
104 //------------------------------------------------------------------
105 /// Symbols file subclasses should override this to return the Module that
106 /// owns the TypeSystem that this symbol file modifies type information in.
107 //------------------------------------------------------------------
108 virtual std::recursive_mutex &GetModuleMutex() const;
110 //------------------------------------------------------------------
111 /// Initialize the SymbolFile object.
113 /// The SymbolFile object with the best set of abilities (detected
114 /// in "uint32_t SymbolFile::GetAbilities()) will have this function
115 /// called if it is chosen to parse an object file. More complete
116 /// initialization can happen in this function which will get called
117 /// prior to any other functions in the SymbolFile protocol.
118 //------------------------------------------------------------------
119 virtual void InitializeObject() {}
121 //------------------------------------------------------------------
122 // Compile Unit function calls
123 //------------------------------------------------------------------
124 // Approach 1 - iterator
125 virtual uint32_t GetNumCompileUnits() = 0;
126 virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) = 0;
128 virtual lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) = 0;
129 virtual size_t ParseFunctions(CompileUnit &comp_unit) = 0;
130 virtual bool ParseLineTable(CompileUnit &comp_unit) = 0;
131 virtual bool ParseDebugMacros(CompileUnit &comp_unit) = 0;
132 virtual bool ParseSupportFiles(CompileUnit &comp_unit,
133 FileSpecList &support_files) = 0;
134 virtual size_t ParseTypes(CompileUnit &comp_unit) = 0;
135 virtual bool ParseIsOptimized(CompileUnit &comp_unit) { return false; }
138 ParseImportedModules(const SymbolContext &sc,
139 std::vector<ConstString> &imported_modules) = 0;
140 virtual size_t ParseBlocksRecursive(Function &func) = 0;
141 virtual size_t ParseVariablesForContext(const SymbolContext &sc) = 0;
142 virtual Type *ResolveTypeUID(lldb::user_id_t type_uid) = 0;
145 /// The characteristics of an array type.
148 llvm::SmallVector<uint64_t, 1> element_orders;
149 uint32_t byte_stride;
152 /// If \c type_uid points to an array type, return its characteristics.
153 /// To support variable-length array types, this function takes an
154 /// optional \p ExtecutionContext. If \c exe_ctx is non-null, the
155 /// dynamic characteristics for that context are returned.
156 virtual llvm::Optional<ArrayInfo>
157 GetDynamicArrayInfoForUID(lldb::user_id_t type_uid,
158 const lldb_private::ExecutionContext *exe_ctx) = 0;
160 virtual bool CompleteType(CompilerType &compiler_type) = 0;
161 virtual void ParseDeclsForContext(CompilerDeclContext decl_ctx) {}
162 virtual CompilerDecl GetDeclForUID(lldb::user_id_t uid) {
163 return CompilerDecl();
165 virtual CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) {
166 return CompilerDeclContext();
168 virtual CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) {
169 return CompilerDeclContext();
171 virtual uint32_t ResolveSymbolContext(const Address &so_addr,
172 lldb::SymbolContextItem resolve_scope,
173 SymbolContext &sc) = 0;
174 virtual uint32_t ResolveSymbolContext(const FileSpec &file_spec,
175 uint32_t line, bool check_inlines,
176 lldb::SymbolContextItem resolve_scope,
177 SymbolContextList &sc_list);
179 virtual void DumpClangAST(Stream &s) {}
181 FindGlobalVariables(const ConstString &name,
182 const CompilerDeclContext *parent_decl_ctx,
183 uint32_t max_matches, VariableList &variables);
184 virtual uint32_t FindGlobalVariables(const RegularExpression ®ex,
185 uint32_t max_matches,
186 VariableList &variables);
187 virtual uint32_t FindFunctions(const ConstString &name,
188 const CompilerDeclContext *parent_decl_ctx,
189 lldb::FunctionNameType name_type_mask,
190 bool include_inlines, bool append,
191 SymbolContextList &sc_list);
192 virtual uint32_t FindFunctions(const RegularExpression ®ex,
193 bool include_inlines, bool append,
194 SymbolContextList &sc_list);
196 FindTypes(const ConstString &name, const CompilerDeclContext *parent_decl_ctx,
197 bool append, uint32_t max_matches,
198 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
200 virtual size_t FindTypes(const std::vector<CompilerContext> &context,
201 bool append, TypeMap &types);
204 GetMangledNamesForFunction(const std::string &scope_qualified_name,
205 std::vector<ConstString> &mangled_names);
206 // virtual uint32_t FindTypes (const SymbolContext& sc, const
207 // RegularExpression& regex, bool append, uint32_t max_matches, TypeList&
209 virtual TypeList *GetTypeList();
210 virtual size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
211 lldb::TypeClass type_mask,
212 lldb_private::TypeList &type_list) = 0;
214 virtual void PreloadSymbols();
216 virtual lldb_private::TypeSystem *
217 GetTypeSystemForLanguage(lldb::LanguageType language);
219 virtual CompilerDeclContext
220 FindNamespace(const ConstString &name,
221 const CompilerDeclContext *parent_decl_ctx) {
222 return CompilerDeclContext();
225 ObjectFile *GetObjectFile() { return m_obj_file; }
226 const ObjectFile *GetObjectFile() const { return m_obj_file; }
228 virtual std::vector<CallEdge> ParseCallEdgesInFunction(UserID func_id) {
232 virtual void AddSymbols(Symtab &symtab) {}
234 //------------------------------------------------------------------
235 /// Notify the SymbolFile that the file addresses in the Sections
236 /// for this module have been changed.
237 //------------------------------------------------------------------
238 virtual void SectionFileAddressesChanged() {}
240 virtual void Dump(Stream &s) {}
243 void AssertModuleLock();
245 ObjectFile *m_obj_file; // The object file that symbols can be extracted from.
246 uint32_t m_abilities;
247 bool m_calculated_abilities;
250 DISALLOW_COPY_AND_ASSIGN(SymbolFile);
253 } // namespace lldb_private
255 #endif // liblldb_SymbolFile_h_