blob: 109da631d7719ad338f1b6fce26f0b9d48403876 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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
Greg Claytona76dd622011-09-12 04:20:38 +000010#ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_
11#define SymbolFileDWARF_SymbolFileDWARFDebugMap_h_
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013#include <bitset>
Kate Stoneb9c1b512016-09-06 20:57:50 +000014#include <vector>
Greg Claytoncaab74e2012-01-28 00:48:57 +000015
Greg Clayton9422dd62013-03-04 21:46:16 +000016#include "lldb/Core/RangeMap.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Symbol/SymbolFile.h"
Pavel Labath7e2cfbf2016-11-09 09:59:18 +000018#include "llvm/Support/Chrono.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019
Greg Claytone576ab22011-02-15 00:19:15 +000020#include "UniqueDWARFASTType.h"
21
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022class SymbolFileDWARF;
Enrico Granatac76e60b2013-06-27 01:43:09 +000023class DWARFDebugAranges;
Greg Claytona8022fa2012-04-24 21:22:41 +000024class DWARFDeclContext;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025
Kate Stoneb9c1b512016-09-06 20:57:50 +000026class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000028 //------------------------------------------------------------------
29 // Static Functions
30 //------------------------------------------------------------------
31 static void Initialize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Kate Stoneb9c1b512016-09-06 20:57:50 +000033 static void Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034
Kate Stoneb9c1b512016-09-06 20:57:50 +000035 static lldb_private::ConstString GetPluginNameStatic();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000036
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 static const char *GetPluginDescriptionStatic();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038
Kate Stoneb9c1b512016-09-06 20:57:50 +000039 static lldb_private::SymbolFile *
40 CreateInstance(lldb_private::ObjectFile *obj_file);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041
Kate Stoneb9c1b512016-09-06 20:57:50 +000042 //------------------------------------------------------------------
43 // Constructors and Destructors
44 //------------------------------------------------------------------
45 SymbolFileDWARFDebugMap(lldb_private::ObjectFile *ofile);
46 ~SymbolFileDWARFDebugMap() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 uint32_t CalculateAbilities() override;
49 void InitializeObject() override;
Greg Clayton6beaaa62011-01-17 03:46:26 +000050
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 //------------------------------------------------------------------
52 // Compile Unit function calls
53 //------------------------------------------------------------------
54 uint32_t GetNumCompileUnits() override;
55 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056
Kate Stoneb9c1b512016-09-06 20:57:50 +000057 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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077
Kate Stoneb9c1b512016-09-06 20:57:50 +000078 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;
Greg Clayton2bd8e7b2015-10-07 22:07:33 +000085
Kate Stoneb9c1b512016-09-06 20:57:50 +000086 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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124
Kate Stoneb9c1b512016-09-06 20:57:50 +0000125 //------------------------------------------------------------------
126 // PluginInterface protocol
127 //------------------------------------------------------------------
128 lldb_private::ConstString GetPluginName() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000129
Kate Stoneb9c1b512016-09-06 20:57:50 +0000130 uint32_t GetPluginVersion() override;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000133 enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000134
Kate Stoneb9c1b512016-09-06 20:57:50 +0000135 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;
Greg Clayton906ba472013-02-06 00:38:25 +0000142
Kate Stoneb9c1b512016-09-06 20:57:50 +0000143 OSOInfo() : module_sp() {}
144 };
Greg Clayton9422dd62013-03-04 21:46:16 +0000145
Kate Stoneb9c1b512016-09-06 20:57:50 +0000146 typedef std::shared_ptr<OSOInfo> OSOInfoSP;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147
Kate Stoneb9c1b512016-09-06 20:57:50 +0000148 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
149 lldb::addr_t>
150 FileRangeMap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151
Kate Stoneb9c1b512016-09-06 20:57:50 +0000152 //------------------------------------------------------------------
153 // Class specific types
154 //------------------------------------------------------------------
155 struct CompileUnitInfo {
156 lldb_private::FileSpec so_file;
157 lldb_private::ConstString oso_path;
Pavel Labath7e2cfbf2016-11-09 09:59:18 +0000158 llvm::sys::TimePoint<> oso_mod_time;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000159 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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000167
Kate Stoneb9c1b512016-09-06 20:57:50 +0000168 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 }
Greg Clayton81c22f62011-10-19 18:09:39 +0000222 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000223 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000224
Kate Stoneb9c1b512016-09-06 20:57:50 +0000225 CompileUnitInfo *GetCompileUnitInfoForSymbolWithIndex(uint32_t symbol_idx,
226 uint32_t *oso_idx_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000227
Kate Stoneb9c1b512016-09-06 20:57:50 +0000228 CompileUnitInfo *GetCompileUnitInfoForSymbolWithID(lldb::user_id_t symbol_id,
229 uint32_t *oso_idx_ptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000230
Kate Stoneb9c1b512016-09-06 20:57:50 +0000231 static int
232 SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr,
233 const CompileUnitInfo *comp_unit_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000234
Kate Stoneb9c1b512016-09-06 20:57:50 +0000235 static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr,
236 const CompileUnitInfo *comp_unit_info);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000237
Kate Stoneb9c1b512016-09-06 20:57:50 +0000238 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);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000243
Kate Stoneb9c1b512016-09-06 20:57:50 +0000244 void SetCompileUnit(SymbolFileDWARF *oso_dwarf,
245 const lldb::CompUnitSP &cu_sp);
Greg Clayton81c22f62011-10-19 18:09:39 +0000246
Kate Stoneb9c1b512016-09-06 20:57:50 +0000247 lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000248
Kate Stoneb9c1b512016-09-06 20:57:50 +0000249 CompileUnitInfo *GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250
Kate Stoneb9c1b512016-09-06 20:57:50 +0000251 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;
Sean Callanan0dc848c2015-04-01 20:43:23 +0000279 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280
Kate Stoneb9c1b512016-09-06 20:57:50 +0000281 lldb::addr_t GetOSOFileAddress() const { return m_oso_file_addr; }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282
Kate Stoneb9c1b512016-09-06 20:57:50 +0000283 void SetOSOFileAddress(lldb::addr_t oso_file_addr) {
284 m_oso_file_addr = oso_file_addr;
Greg Claytone576ab22011-02-15 00:19:15 +0000285 }
Greg Clayton9422dd62013-03-04 21:46:16 +0000286
Kate Stoneb9c1b512016-09-06 20:57:50 +0000287 protected:
288 uint32_t m_exe_sym_idx;
289 lldb::addr_t m_oso_file_addr;
290 };
Greg Clayton9422dd62013-03-04 21:46:16 +0000291
Kate Stoneb9c1b512016-09-06 20:57:50 +0000292 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry>
293 DebugMap;
Greg Clayton9422dd62013-03-04 21:46:16 +0000294
Kate Stoneb9c1b512016-09-06 20:57:50 +0000295 //------------------------------------------------------------------
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);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375};
376
Greg Claytona76dd622011-09-12 04:20:38 +0000377#endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_