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