]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
Import Amazon Elastic Network Adapter (ENA) HAL to sys/contrib/
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / SymbolFileDWARFDebugMap.h
1 //===-- SymbolFileDWARFDebugMap.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 SymbolFileDWARF_SymbolFileDWARFDebugMap_h_
11 #define SymbolFileDWARF_SymbolFileDWARFDebugMap_h_
12
13 #include <bitset>
14 #include <vector>
15
16 #include "lldb/Core/RangeMap.h"
17 #include "lldb/Symbol/SymbolFile.h"
18 #include "llvm/Support/Chrono.h"
19
20 #include "UniqueDWARFASTType.h"
21
22 class SymbolFileDWARF;
23 class DWARFDebugAranges;
24 class DWARFDeclContext;
25
26 class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
27 public:
28   //------------------------------------------------------------------
29   // Static Functions
30   //------------------------------------------------------------------
31   static void Initialize();
32
33   static void Terminate();
34
35   static lldb_private::ConstString GetPluginNameStatic();
36
37   static const char *GetPluginDescriptionStatic();
38
39   static lldb_private::SymbolFile *
40   CreateInstance(lldb_private::ObjectFile *obj_file);
41
42   //------------------------------------------------------------------
43   // Constructors and Destructors
44   //------------------------------------------------------------------
45   SymbolFileDWARFDebugMap(lldb_private::ObjectFile *ofile);
46   ~SymbolFileDWARFDebugMap() override;
47
48   uint32_t CalculateAbilities() override;
49   void InitializeObject() override;
50
51   //------------------------------------------------------------------
52   // Compile Unit function calls
53   //------------------------------------------------------------------
54   uint32_t GetNumCompileUnits() override;
55   lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
56
57   lldb::LanguageType
58   ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override;
59   size_t
60   ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override;
61   bool
62   ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override;
63   bool
64   ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override;
65   bool ParseCompileUnitSupportFiles(
66       const lldb_private::SymbolContext &sc,
67       lldb_private::FileSpecList &support_files) override;
68   bool
69   ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc) override;
70   bool ParseImportedModules(
71       const lldb_private::SymbolContext &sc,
72       std::vector<lldb_private::ConstString> &imported_modules) override;
73   size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
74   size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
75   size_t
76   ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
77
78   lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
79   lldb_private::CompilerDeclContext
80   GetDeclContextForUID(lldb::user_id_t uid) override;
81   lldb_private::CompilerDeclContext
82   GetDeclContextContainingUID(lldb::user_id_t uid) override;
83   void
84   ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
85
86   bool CompleteType(lldb_private::CompilerType &compiler_type) override;
87   uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
88                                 uint32_t resolve_scope,
89                                 lldb_private::SymbolContext &sc) override;
90   uint32_t
91   ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
92                        bool check_inlines, uint32_t resolve_scope,
93                        lldb_private::SymbolContextList &sc_list) override;
94   uint32_t
95   FindGlobalVariables(const lldb_private::ConstString &name,
96                       const lldb_private::CompilerDeclContext *parent_decl_ctx,
97                       bool append, uint32_t max_matches,
98                       lldb_private::VariableList &variables) override;
99   uint32_t FindGlobalVariables(const lldb_private::RegularExpression &regex,
100                                bool append, uint32_t max_matches,
101                                lldb_private::VariableList &variables) override;
102   uint32_t
103   FindFunctions(const lldb_private::ConstString &name,
104                 const lldb_private::CompilerDeclContext *parent_decl_ctx,
105                 uint32_t name_type_mask, bool include_inlines, bool append,
106                 lldb_private::SymbolContextList &sc_list) override;
107   uint32_t FindFunctions(const lldb_private::RegularExpression &regex,
108                          bool include_inlines, bool append,
109                          lldb_private::SymbolContextList &sc_list) override;
110   uint32_t
111   FindTypes(const lldb_private::SymbolContext &sc,
112             const lldb_private::ConstString &name,
113             const lldb_private::CompilerDeclContext *parent_decl_ctx,
114             bool append, uint32_t max_matches,
115             llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
116             lldb_private::TypeMap &types) override;
117   lldb_private::CompilerDeclContext FindNamespace(
118       const lldb_private::SymbolContext &sc,
119       const lldb_private::ConstString &name,
120       const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
121   size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
122                   uint32_t type_mask,
123                   lldb_private::TypeList &type_list) override;
124
125   //------------------------------------------------------------------
126   // PluginInterface protocol
127   //------------------------------------------------------------------
128   lldb_private::ConstString GetPluginName() override;
129
130   uint32_t GetPluginVersion() override;
131
132 protected:
133   enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
134
135   friend class DebugMapModule;
136   friend struct DIERef;
137   friend class DWARFASTParserClang;
138   friend class DWARFCompileUnit;
139   friend class SymbolFileDWARF;
140   struct OSOInfo {
141     lldb::ModuleSP module_sp;
142
143     OSOInfo() : module_sp() {}
144   };
145
146   typedef std::shared_ptr<OSOInfo> OSOInfoSP;
147
148   typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
149                                         lldb::addr_t>
150       FileRangeMap;
151
152   //------------------------------------------------------------------
153   // Class specific types
154   //------------------------------------------------------------------
155   struct CompileUnitInfo {
156     lldb_private::FileSpec so_file;
157     lldb_private::ConstString oso_path;
158     llvm::sys::TimePoint<> oso_mod_time;
159     OSOInfoSP oso_sp;
160     lldb::CompUnitSP compile_unit_sp;
161     uint32_t first_symbol_index;
162     uint32_t last_symbol_index;
163     uint32_t first_symbol_id;
164     uint32_t last_symbol_id;
165     FileRangeMap file_range_map;
166     bool file_range_map_valid;
167
168     CompileUnitInfo()
169         : so_file(), oso_path(), oso_mod_time(), oso_sp(), compile_unit_sp(),
170           first_symbol_index(UINT32_MAX), last_symbol_index(UINT32_MAX),
171           first_symbol_id(UINT32_MAX), last_symbol_id(UINT32_MAX),
172           file_range_map(), file_range_map_valid(false) {}
173
174     const FileRangeMap &GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
175   };
176
177   //------------------------------------------------------------------
178   // Protected Member Functions
179   //------------------------------------------------------------------
180   void InitOSO();
181
182   static uint32_t GetOSOIndexFromUserID(lldb::user_id_t uid) {
183     return (uint32_t)((uid >> 32ull) - 1ull);
184   }
185
186   static SymbolFileDWARF *GetSymbolFileAsSymbolFileDWARF(SymbolFile *sym_file);
187
188   bool GetFileSpecForSO(uint32_t oso_idx, lldb_private::FileSpec &file_spec);
189
190   CompileUnitInfo *GetCompUnitInfo(const lldb_private::SymbolContext &sc);
191
192   size_t GetCompUnitInfosForModule(const lldb_private::Module *oso_module,
193                                    std::vector<CompileUnitInfo *> &cu_infos);
194
195   lldb_private::Module *
196   GetModuleByCompUnitInfo(CompileUnitInfo *comp_unit_info);
197
198   lldb_private::Module *GetModuleByOSOIndex(uint32_t oso_idx);
199
200   lldb_private::ObjectFile *
201   GetObjectFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
202
203   lldb_private::ObjectFile *GetObjectFileByOSOIndex(uint32_t oso_idx);
204
205   uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info);
206
207   SymbolFileDWARF *GetSymbolFile(const lldb_private::SymbolContext &sc);
208
209   SymbolFileDWARF *GetSymbolFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
210
211   SymbolFileDWARF *GetSymbolFileByOSOIndex(uint32_t oso_idx);
212
213   // If closure returns "false", iteration continues.  If it returns
214   // "true", iteration terminates.
215   void ForEachSymbolFile(std::function<bool(SymbolFileDWARF *)> closure) {
216     for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
217          oso_idx < num_oso_idxs; ++oso_idx) {
218       if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
219         if (closure(oso_dwarf))
220           return;
221       }
222     }
223   }
224
225   CompileUnitInfo *GetCompileUnitInfoForSymbolWithIndex(uint32_t symbol_idx,
226                                                         uint32_t *oso_idx_ptr);
227
228   CompileUnitInfo *GetCompileUnitInfoForSymbolWithID(lldb::user_id_t symbol_id,
229                                                      uint32_t *oso_idx_ptr);
230
231   static int
232   SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr,
233                                 const CompileUnitInfo *comp_unit_info);
234
235   static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr,
236                                         const CompileUnitInfo *comp_unit_info);
237
238   uint32_t PrivateFindGlobalVariables(
239       const lldb_private::ConstString &name,
240       const lldb_private::CompilerDeclContext *parent_decl_ctx,
241       const std::vector<uint32_t> &name_symbol_indexes, uint32_t max_matches,
242       lldb_private::VariableList &variables);
243
244   void SetCompileUnit(SymbolFileDWARF *oso_dwarf,
245                       const lldb::CompUnitSP &cu_sp);
246
247   lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf);
248
249   CompileUnitInfo *GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf);
250
251   lldb::TypeSP
252   FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
253
254   bool Supports_DW_AT_APPLE_objc_complete_type(SymbolFileDWARF *skip_dwarf_oso);
255
256   lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
257       const DWARFDIE &die, const lldb_private::ConstString &type_name,
258       bool must_be_implementation);
259
260   UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() {
261     return m_unique_ast_type_map;
262   }
263
264   //------------------------------------------------------------------
265   // OSOEntry
266   //------------------------------------------------------------------
267   class OSOEntry {
268   public:
269     OSOEntry()
270         : m_exe_sym_idx(UINT32_MAX), m_oso_file_addr(LLDB_INVALID_ADDRESS) {}
271
272     OSOEntry(uint32_t exe_sym_idx, lldb::addr_t oso_file_addr)
273         : m_exe_sym_idx(exe_sym_idx), m_oso_file_addr(oso_file_addr) {}
274
275     uint32_t GetExeSymbolIndex() const { return m_exe_sym_idx; }
276
277     bool operator<(const OSOEntry &rhs) const {
278       return m_exe_sym_idx < rhs.m_exe_sym_idx;
279     }
280
281     lldb::addr_t GetOSOFileAddress() const { return m_oso_file_addr; }
282
283     void SetOSOFileAddress(lldb::addr_t oso_file_addr) {
284       m_oso_file_addr = oso_file_addr;
285     }
286
287   protected:
288     uint32_t m_exe_sym_idx;
289     lldb::addr_t m_oso_file_addr;
290   };
291
292   typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry>
293       DebugMap;
294
295   //------------------------------------------------------------------
296   // Member Variables
297   //------------------------------------------------------------------
298   std::bitset<kNumFlags> m_flags;
299   std::vector<CompileUnitInfo> m_compile_unit_infos;
300   std::vector<uint32_t> m_func_indexes; // Sorted by address
301   std::vector<uint32_t> m_glob_indexes;
302   std::map<lldb_private::ConstString, OSOInfoSP> m_oso_map;
303   UniqueDWARFASTTypeMap m_unique_ast_type_map;
304   lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
305   DebugMap m_debug_map;
306
307   //------------------------------------------------------------------
308   // When an object file from the debug map gets parsed in
309   // SymbolFileDWARF, it needs to tell the debug map about the object
310   // files addresses by calling this function once for each N_FUN,
311   // N_GSYM and N_STSYM and after all entries in the debug map have
312   // been matched up, FinalizeOSOFileRanges() should be called.
313   //------------------------------------------------------------------
314   bool AddOSOFileRange(CompileUnitInfo *cu_info, lldb::addr_t exe_file_addr,
315                        lldb::addr_t exe_byte_size, lldb::addr_t oso_file_addr,
316                        lldb::addr_t oso_byte_size);
317
318   //------------------------------------------------------------------
319   // Called after calling AddOSOFileRange() for each object file debug
320   // map entry to finalize the info for the unlinked compile unit.
321   //------------------------------------------------------------------
322   void FinalizeOSOFileRanges(CompileUnitInfo *cu_info);
323
324   //------------------------------------------------------------------
325   /// Convert \a addr from a .o file address, to an executable address.
326   ///
327   /// @param[in] addr
328   ///     A section offset address from a .o file
329   ///
330   /// @return
331   ///     Returns true if \a addr was converted to be an executable
332   ///     section/offset address, false otherwise.
333   //------------------------------------------------------------------
334   bool LinkOSOAddress(lldb_private::Address &addr);
335
336   //------------------------------------------------------------------
337   /// Convert a .o file "file address" to an executable "file address".
338   ///
339   /// @param[in] oso_symfile
340   ///     The DWARF symbol file that contains \a oso_file_addr
341   ///
342   /// @param[in] oso_file_addr
343   ///     A .o file "file address" to convert.
344   ///
345   /// @return
346   ///     LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the
347   ///     linked executable, otherwise a valid "file address" from the
348   ///     linked executable that contains the debug map.
349   //------------------------------------------------------------------
350   lldb::addr_t LinkOSOFileAddress(SymbolFileDWARF *oso_symfile,
351                                   lldb::addr_t oso_file_addr);
352
353   //------------------------------------------------------------------
354   /// Given a line table full of lines with "file addresses" that are
355   /// for a .o file represented by \a oso_symfile, link a new line table
356   /// and return it.
357   ///
358   /// @param[in] oso_symfile
359   ///     The DWARF symbol file that produced the \a line_table
360   ///
361   /// @param[in] addr
362   ///     A section offset address from a .o file
363   ///
364   /// @return
365   ///     Returns a valid line table full of linked addresses, or NULL
366   ///     if none of the line table addresses exist in the main
367   ///     executable.
368   //------------------------------------------------------------------
369   lldb_private::LineTable *
370   LinkOSOLineTable(SymbolFileDWARF *oso_symfile,
371                    lldb_private::LineTable *line_table);
372
373   size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data,
374                        DWARFDebugAranges *debug_aranges);
375 };
376
377 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_