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_
17 #include "lldb/Core/RangeMap.h"
18 #include "lldb/Symbol/SymbolFile.h"
19 #include "llvm/Support/Chrono.h"
21 #include "UniqueDWARFASTType.h"
23 class SymbolFileDWARF;
24 class DWARFDebugAranges;
25 class DWARFDeclContext;
27 class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
29 //------------------------------------------------------------------
31 //------------------------------------------------------------------
32 static void Initialize();
34 static void Terminate();
36 static lldb_private::ConstString GetPluginNameStatic();
38 static const char *GetPluginDescriptionStatic();
40 static lldb_private::SymbolFile *
41 CreateInstance(lldb_private::ObjectFile *obj_file);
43 //------------------------------------------------------------------
44 // Constructors and Destructors
45 //------------------------------------------------------------------
46 SymbolFileDWARFDebugMap(lldb_private::ObjectFile *ofile);
47 ~SymbolFileDWARFDebugMap() override;
49 uint32_t CalculateAbilities() override;
50 void InitializeObject() override;
52 //------------------------------------------------------------------
53 // Compile Unit function calls
54 //------------------------------------------------------------------
55 uint32_t GetNumCompileUnits() override;
56 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
59 ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override;
61 ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override;
63 ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override;
65 ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override;
66 bool ParseCompileUnitSupportFiles(
67 const lldb_private::SymbolContext &sc,
68 lldb_private::FileSpecList &support_files) override;
70 ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc) override;
71 bool ParseImportedModules(
72 const lldb_private::SymbolContext &sc,
73 std::vector<lldb_private::ConstString> &imported_modules) override;
74 size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
75 size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
77 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
79 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
80 lldb_private::CompilerDeclContext
81 GetDeclContextForUID(lldb::user_id_t uid) override;
82 lldb_private::CompilerDeclContext
83 GetDeclContextContainingUID(lldb::user_id_t uid) override;
85 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
87 bool CompleteType(lldb_private::CompilerType &compiler_type) override;
88 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
89 uint32_t resolve_scope,
90 lldb_private::SymbolContext &sc) override;
92 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
93 bool check_inlines, uint32_t resolve_scope,
94 lldb_private::SymbolContextList &sc_list) override;
96 FindGlobalVariables(const lldb_private::ConstString &name,
97 const lldb_private::CompilerDeclContext *parent_decl_ctx,
98 bool append, uint32_t max_matches,
99 lldb_private::VariableList &variables) override;
100 uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex,
101 bool append, uint32_t max_matches,
102 lldb_private::VariableList &variables) override;
104 FindFunctions(const lldb_private::ConstString &name,
105 const lldb_private::CompilerDeclContext *parent_decl_ctx,
106 uint32_t name_type_mask, bool include_inlines, bool append,
107 lldb_private::SymbolContextList &sc_list) override;
108 uint32_t FindFunctions(const lldb_private::RegularExpression ®ex,
109 bool include_inlines, bool append,
110 lldb_private::SymbolContextList &sc_list) override;
112 FindTypes(const lldb_private::SymbolContext &sc,
113 const lldb_private::ConstString &name,
114 const lldb_private::CompilerDeclContext *parent_decl_ctx,
115 bool append, uint32_t max_matches,
116 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
117 lldb_private::TypeMap &types) override;
118 lldb_private::CompilerDeclContext FindNamespace(
119 const lldb_private::SymbolContext &sc,
120 const lldb_private::ConstString &name,
121 const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
122 size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
124 lldb_private::TypeList &type_list) override;
126 //------------------------------------------------------------------
127 // PluginInterface protocol
128 //------------------------------------------------------------------
129 lldb_private::ConstString GetPluginName() override;
131 uint32_t GetPluginVersion() override;
134 enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
136 friend class DebugMapModule;
137 friend struct DIERef;
138 friend class DWARFASTParserClang;
139 friend class DWARFCompileUnit;
140 friend class SymbolFileDWARF;
142 lldb::ModuleSP module_sp;
144 OSOInfo() : module_sp() {}
147 typedef std::shared_ptr<OSOInfo> OSOInfoSP;
149 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
153 //------------------------------------------------------------------
154 // Class specific types
155 //------------------------------------------------------------------
156 struct CompileUnitInfo {
157 lldb_private::FileSpec so_file;
158 lldb_private::ConstString oso_path;
159 llvm::sys::TimePoint<> oso_mod_time;
161 lldb::CompUnitSP compile_unit_sp;
162 uint32_t first_symbol_index;
163 uint32_t last_symbol_index;
164 uint32_t first_symbol_id;
165 uint32_t last_symbol_id;
166 FileRangeMap file_range_map;
167 bool file_range_map_valid;
170 : so_file(), oso_path(), oso_mod_time(), oso_sp(), compile_unit_sp(),
171 first_symbol_index(UINT32_MAX), last_symbol_index(UINT32_MAX),
172 first_symbol_id(UINT32_MAX), last_symbol_id(UINT32_MAX),
173 file_range_map(), file_range_map_valid(false) {}
175 const FileRangeMap &GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
178 //------------------------------------------------------------------
179 // Protected Member Functions
180 //------------------------------------------------------------------
183 static uint32_t GetOSOIndexFromUserID(lldb::user_id_t uid) {
184 return (uint32_t)((uid >> 32ull) - 1ull);
187 static SymbolFileDWARF *GetSymbolFileAsSymbolFileDWARF(SymbolFile *sym_file);
189 bool GetFileSpecForSO(uint32_t oso_idx, lldb_private::FileSpec &file_spec);
191 CompileUnitInfo *GetCompUnitInfo(const lldb_private::SymbolContext &sc);
193 size_t GetCompUnitInfosForModule(const lldb_private::Module *oso_module,
194 std::vector<CompileUnitInfo *> &cu_infos);
196 lldb_private::Module *
197 GetModuleByCompUnitInfo(CompileUnitInfo *comp_unit_info);
199 lldb_private::Module *GetModuleByOSOIndex(uint32_t oso_idx);
201 lldb_private::ObjectFile *
202 GetObjectFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
204 lldb_private::ObjectFile *GetObjectFileByOSOIndex(uint32_t oso_idx);
206 uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info);
208 SymbolFileDWARF *GetSymbolFile(const lldb_private::SymbolContext &sc);
210 SymbolFileDWARF *GetSymbolFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
212 SymbolFileDWARF *GetSymbolFileByOSOIndex(uint32_t oso_idx);
214 // If closure returns "false", iteration continues. If it returns
215 // "true", iteration terminates.
216 void ForEachSymbolFile(std::function<bool(SymbolFileDWARF *)> closure) {
217 for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
218 oso_idx < num_oso_idxs; ++oso_idx) {
219 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
220 if (closure(oso_dwarf))
226 CompileUnitInfo *GetCompileUnitInfoForSymbolWithIndex(uint32_t symbol_idx,
227 uint32_t *oso_idx_ptr);
229 CompileUnitInfo *GetCompileUnitInfoForSymbolWithID(lldb::user_id_t symbol_id,
230 uint32_t *oso_idx_ptr);
233 SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr,
234 const CompileUnitInfo *comp_unit_info);
236 static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr,
237 const CompileUnitInfo *comp_unit_info);
239 uint32_t PrivateFindGlobalVariables(
240 const lldb_private::ConstString &name,
241 const lldb_private::CompilerDeclContext *parent_decl_ctx,
242 const std::vector<uint32_t> &name_symbol_indexes, uint32_t max_matches,
243 lldb_private::VariableList &variables);
245 void SetCompileUnit(SymbolFileDWARF *oso_dwarf,
246 const lldb::CompUnitSP &cu_sp);
248 lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf);
250 CompileUnitInfo *GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf);
253 FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
255 bool Supports_DW_AT_APPLE_objc_complete_type(SymbolFileDWARF *skip_dwarf_oso);
257 lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
258 const DWARFDIE &die, const lldb_private::ConstString &type_name,
259 bool must_be_implementation);
261 UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() {
262 return m_unique_ast_type_map;
265 //------------------------------------------------------------------
267 //------------------------------------------------------------------
271 : m_exe_sym_idx(UINT32_MAX), m_oso_file_addr(LLDB_INVALID_ADDRESS) {}
273 OSOEntry(uint32_t exe_sym_idx, lldb::addr_t oso_file_addr)
274 : m_exe_sym_idx(exe_sym_idx), m_oso_file_addr(oso_file_addr) {}
276 uint32_t GetExeSymbolIndex() const { return m_exe_sym_idx; }
278 bool operator<(const OSOEntry &rhs) const {
279 return m_exe_sym_idx < rhs.m_exe_sym_idx;
282 lldb::addr_t GetOSOFileAddress() const { return m_oso_file_addr; }
284 void SetOSOFileAddress(lldb::addr_t oso_file_addr) {
285 m_oso_file_addr = oso_file_addr;
289 uint32_t m_exe_sym_idx;
290 lldb::addr_t m_oso_file_addr;
293 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry>
296 //------------------------------------------------------------------
298 //------------------------------------------------------------------
299 std::bitset<kNumFlags> m_flags;
300 std::vector<CompileUnitInfo> m_compile_unit_infos;
301 std::vector<uint32_t> m_func_indexes; // Sorted by address
302 std::vector<uint32_t> m_glob_indexes;
303 std::map<lldb_private::ConstString, OSOInfoSP> m_oso_map;
304 UniqueDWARFASTTypeMap m_unique_ast_type_map;
305 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
306 DebugMap m_debug_map;
308 //------------------------------------------------------------------
309 // When an object file from the debug map gets parsed in
310 // SymbolFileDWARF, it needs to tell the debug map about the object
311 // files addresses by calling this function once for each N_FUN,
312 // N_GSYM and N_STSYM and after all entries in the debug map have
313 // been matched up, FinalizeOSOFileRanges() should be called.
314 //------------------------------------------------------------------
315 bool AddOSOFileRange(CompileUnitInfo *cu_info, lldb::addr_t exe_file_addr,
316 lldb::addr_t exe_byte_size, lldb::addr_t oso_file_addr,
317 lldb::addr_t oso_byte_size);
319 //------------------------------------------------------------------
320 // Called after calling AddOSOFileRange() for each object file debug
321 // map entry to finalize the info for the unlinked compile unit.
322 //------------------------------------------------------------------
323 void FinalizeOSOFileRanges(CompileUnitInfo *cu_info);
325 //------------------------------------------------------------------
326 /// Convert \a addr from a .o file address, to an executable address.
329 /// A section offset address from a .o file
332 /// Returns true if \a addr was converted to be an executable
333 /// section/offset address, false otherwise.
334 //------------------------------------------------------------------
335 bool LinkOSOAddress(lldb_private::Address &addr);
337 //------------------------------------------------------------------
338 /// Convert a .o file "file address" to an executable "file address".
340 /// @param[in] oso_symfile
341 /// The DWARF symbol file that contains \a oso_file_addr
343 /// @param[in] oso_file_addr
344 /// A .o file "file address" to convert.
347 /// LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the
348 /// linked executable, otherwise a valid "file address" from the
349 /// linked executable that contains the debug map.
350 //------------------------------------------------------------------
351 lldb::addr_t LinkOSOFileAddress(SymbolFileDWARF *oso_symfile,
352 lldb::addr_t oso_file_addr);
354 //------------------------------------------------------------------
355 /// Given a line table full of lines with "file addresses" that are
356 /// for a .o file represented by \a oso_symfile, link a new line table
359 /// @param[in] oso_symfile
360 /// The DWARF symbol file that produced the \a line_table
363 /// A section offset address from a .o file
366 /// Returns a valid line table full of linked addresses, or NULL
367 /// if none of the line table addresses exist in the main
369 //------------------------------------------------------------------
370 lldb_private::LineTable *
371 LinkOSOLineTable(SymbolFileDWARF *oso_symfile,
372 lldb_private::LineTable *line_table);
374 size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data,
375 DWARFDebugAranges *debug_aranges);
378 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_