1 //===-- SymbolFileDWARFDebugMap.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 SymbolFileDWARF_SymbolFileDWARFDebugMap_h_
11 #define SymbolFileDWARF_SymbolFileDWARFDebugMap_h_
16 #include "lldb/Core/RangeMap.h"
17 #include "lldb/Symbol/SymbolFile.h"
18 #include "llvm/Support/Chrono.h"
20 #include "UniqueDWARFASTType.h"
22 class SymbolFileDWARF;
23 class DWARFDebugAranges;
24 class DWARFDeclContext;
26 class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
28 //------------------------------------------------------------------
30 //------------------------------------------------------------------
31 static void Initialize();
33 static void Terminate();
35 static lldb_private::ConstString GetPluginNameStatic();
37 static const char *GetPluginDescriptionStatic();
39 static lldb_private::SymbolFile *
40 CreateInstance(lldb_private::ObjectFile *obj_file);
42 //------------------------------------------------------------------
43 // Constructors and Destructors
44 //------------------------------------------------------------------
45 SymbolFileDWARFDebugMap(lldb_private::ObjectFile *ofile);
46 ~SymbolFileDWARFDebugMap() override;
48 uint32_t CalculateAbilities() override;
49 void InitializeObject() override;
51 //------------------------------------------------------------------
52 // Compile Unit function calls
53 //------------------------------------------------------------------
54 uint32_t GetNumCompileUnits() override;
55 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
58 ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override;
60 ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override;
62 ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override;
64 ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override;
65 bool ParseCompileUnitSupportFiles(
66 const lldb_private::SymbolContext &sc,
67 lldb_private::FileSpecList &support_files) override;
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;
76 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
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;
84 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
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;
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;
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 ®ex,
100 bool append, uint32_t max_matches,
101 lldb_private::VariableList &variables) override;
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 ®ex,
108 bool include_inlines, bool append,
109 lldb_private::SymbolContextList &sc_list) override;
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,
123 lldb_private::TypeList &type_list) override;
125 //------------------------------------------------------------------
126 // PluginInterface protocol
127 //------------------------------------------------------------------
128 lldb_private::ConstString GetPluginName() override;
130 uint32_t GetPluginVersion() override;
133 enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
135 friend class DebugMapModule;
136 friend struct DIERef;
137 friend class DWARFASTParserClang;
138 friend class DWARFCompileUnit;
139 friend class SymbolFileDWARF;
141 lldb::ModuleSP module_sp;
143 OSOInfo() : module_sp() {}
146 typedef std::shared_ptr<OSOInfo> OSOInfoSP;
148 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
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;
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;
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) {}
174 const FileRangeMap &GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
177 //------------------------------------------------------------------
178 // Protected Member Functions
179 //------------------------------------------------------------------
182 static uint32_t GetOSOIndexFromUserID(lldb::user_id_t uid) {
183 return (uint32_t)((uid >> 32ull) - 1ull);
186 static SymbolFileDWARF *GetSymbolFileAsSymbolFileDWARF(SymbolFile *sym_file);
188 bool GetFileSpecForSO(uint32_t oso_idx, lldb_private::FileSpec &file_spec);
190 CompileUnitInfo *GetCompUnitInfo(const lldb_private::SymbolContext &sc);
192 size_t GetCompUnitInfosForModule(const lldb_private::Module *oso_module,
193 std::vector<CompileUnitInfo *> &cu_infos);
195 lldb_private::Module *
196 GetModuleByCompUnitInfo(CompileUnitInfo *comp_unit_info);
198 lldb_private::Module *GetModuleByOSOIndex(uint32_t oso_idx);
200 lldb_private::ObjectFile *
201 GetObjectFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
203 lldb_private::ObjectFile *GetObjectFileByOSOIndex(uint32_t oso_idx);
205 uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info);
207 SymbolFileDWARF *GetSymbolFile(const lldb_private::SymbolContext &sc);
209 SymbolFileDWARF *GetSymbolFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
211 SymbolFileDWARF *GetSymbolFileByOSOIndex(uint32_t oso_idx);
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))
225 CompileUnitInfo *GetCompileUnitInfoForSymbolWithIndex(uint32_t symbol_idx,
226 uint32_t *oso_idx_ptr);
228 CompileUnitInfo *GetCompileUnitInfoForSymbolWithID(lldb::user_id_t symbol_id,
229 uint32_t *oso_idx_ptr);
232 SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr,
233 const CompileUnitInfo *comp_unit_info);
235 static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr,
236 const CompileUnitInfo *comp_unit_info);
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);
244 void SetCompileUnit(SymbolFileDWARF *oso_dwarf,
245 const lldb::CompUnitSP &cu_sp);
247 lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf);
249 CompileUnitInfo *GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf);
252 FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
254 bool Supports_DW_AT_APPLE_objc_complete_type(SymbolFileDWARF *skip_dwarf_oso);
256 lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
257 const DWARFDIE &die, const lldb_private::ConstString &type_name,
258 bool must_be_implementation);
260 UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() {
261 return m_unique_ast_type_map;
264 //------------------------------------------------------------------
266 //------------------------------------------------------------------
270 : m_exe_sym_idx(UINT32_MAX), m_oso_file_addr(LLDB_INVALID_ADDRESS) {}
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) {}
275 uint32_t GetExeSymbolIndex() const { return m_exe_sym_idx; }
277 bool operator<(const OSOEntry &rhs) const {
278 return m_exe_sym_idx < rhs.m_exe_sym_idx;
281 lldb::addr_t GetOSOFileAddress() const { return m_oso_file_addr; }
283 void SetOSOFileAddress(lldb::addr_t oso_file_addr) {
284 m_oso_file_addr = oso_file_addr;
288 uint32_t m_exe_sym_idx;
289 lldb::addr_t m_oso_file_addr;
292 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry>
295 //------------------------------------------------------------------
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;
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);
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);
324 //------------------------------------------------------------------
325 /// Convert \a addr from a .o file address, to an executable address.
328 /// A section offset address from a .o file
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);
336 //------------------------------------------------------------------
337 /// Convert a .o file "file address" to an executable "file address".
339 /// @param[in] oso_symfile
340 /// The DWARF symbol file that contains \a oso_file_addr
342 /// @param[in] oso_file_addr
343 /// A .o file "file address" to convert.
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);
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
358 /// @param[in] oso_symfile
359 /// The DWARF symbol file that produced the \a line_table
362 /// A section offset address from a .o file
365 /// Returns a valid line table full of linked addresses, or NULL
366 /// if none of the line table addresses exist in the main
368 //------------------------------------------------------------------
369 lldb_private::LineTable *
370 LinkOSOLineTable(SymbolFileDWARF *oso_symfile,
371 lldb_private::LineTable *line_table);
373 size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data,
374 DWARFDebugAranges *debug_aranges);
377 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_