]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Symbol/SymbolFile.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Symbol / SymbolFile.h
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/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"
19
20 #include "llvm/ADT/DenseSet.h"
21
22 namespace lldb_private {
23
24 class SymbolFile : public PluginInterface {
25 public:
26   //------------------------------------------------------------------
27   // Symbol file ability bits.
28   //
29   // Each symbol file can claim to support one or more symbol file abilities.
30   // These get returned from SymbolFile::GetAbilities(). These help us to
31   // determine which plug-in will be best to load the debug information found
32   // in files.
33   //------------------------------------------------------------------
34   enum Abilities {
35     CompileUnits = (1u << 0),
36     LineTables = (1u << 1),
37     Functions = (1u << 2),
38     Blocks = (1u << 3),
39     GlobalVariables = (1u << 4),
40     LocalVariables = (1u << 5),
41     VariableTypes = (1u << 6),
42     kAllAbilities = ((1u << 7) - 1u)
43   };
44
45   static SymbolFile *FindPlugin(ObjectFile *obj_file);
46
47   //------------------------------------------------------------------
48   // Constructors and Destructors
49   //------------------------------------------------------------------
50   SymbolFile(ObjectFile *obj_file)
51       : m_obj_file(obj_file), m_abilities(0), m_calculated_abilities(false) {}
52
53   ~SymbolFile() override {}
54
55   //------------------------------------------------------------------
56   /// Get a mask of what this symbol file supports for the object file
57   /// that it was constructed with.
58   ///
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.
78   ///
79   /// @return
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;
88     }
89
90     return m_abilities;
91   }
92
93   virtual uint32_t CalculateAbilities() = 0;
94
95   //------------------------------------------------------------------
96   /// Initialize the SymbolFile object.
97   ///
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() {}
105
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;
112
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;
120   virtual bool
121   ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc) {
122     return false;
123   }
124   virtual bool
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();
135   }
136   virtual CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) {
137     return CompilerDeclContext();
138   }
139   virtual CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) {
140     return CompilerDeclContext();
141   }
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);
149   virtual uint32_t
150   FindGlobalVariables(const ConstString &name,
151                       const CompilerDeclContext *parent_decl_ctx,
152                       uint32_t max_matches, VariableList &variables);
153   virtual uint32_t FindGlobalVariables(const RegularExpression &regex,
154                                        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 &regex,
161                                  bool include_inlines, bool append,
162                                  SymbolContextList &sc_list);
163   virtual uint32_t
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,
168             TypeMap &types);
169   virtual size_t FindTypes(const std::vector<CompilerContext> &context,
170                            bool append, TypeMap &types);
171
172   virtual void
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&
177   //  types) = 0;
178   virtual TypeList *GetTypeList();
179   virtual size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
180                           uint32_t type_mask,
181                           lldb_private::TypeList &type_list) = 0;
182
183   virtual void PreloadSymbols();
184
185   virtual lldb_private::TypeSystem *
186   GetTypeSystemForLanguage(lldb::LanguageType language);
187
188   virtual CompilerDeclContext
189   FindNamespace(const SymbolContext &sc, const ConstString &name,
190                 const CompilerDeclContext *parent_decl_ctx) {
191     return CompilerDeclContext();
192   }
193
194   ObjectFile *GetObjectFile() { return m_obj_file; }
195   const ObjectFile *GetObjectFile() const { return m_obj_file; }
196
197   //------------------------------------------------------------------
198   /// Notify the SymbolFile that the file addresses in the Sections
199   /// for this module have been changed.
200   //------------------------------------------------------------------
201   virtual void SectionFileAddressesChanged() {}
202
203   virtual void Dump(Stream &s) {}
204
205 protected:
206   ObjectFile *m_obj_file; // The object file that symbols can be extracted from.
207   uint32_t m_abilities;
208   bool m_calculated_abilities;
209
210 private:
211   DISALLOW_COPY_AND_ASSIGN(SymbolFile);
212 };
213
214 } // namespace lldb_private
215
216 #endif // liblldb_SymbolFile_h_