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 ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
61 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
63 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
65 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
67 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,
68 lldb_private::FileSpecList &support_files) override;
70 bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override;
72 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
74 bool ParseImportedModules(
75 const lldb_private::SymbolContext &sc,
76 std::vector<lldb_private::ConstString> &imported_modules) override;
77 size_t ParseBlocksRecursive(lldb_private::Function &func) override;
79 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
81 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
82 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
83 lldb::user_id_t type_uid,
84 const lldb_private::ExecutionContext *exe_ctx) override;
86 lldb_private::CompilerDeclContext
87 GetDeclContextForUID(lldb::user_id_t uid) override;
88 lldb_private::CompilerDeclContext
89 GetDeclContextContainingUID(lldb::user_id_t uid) override;
91 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
93 bool CompleteType(lldb_private::CompilerType &compiler_type) override;
94 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
95 lldb::SymbolContextItem resolve_scope,
96 lldb_private::SymbolContext &sc) override;
98 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
100 lldb::SymbolContextItem resolve_scope,
101 lldb_private::SymbolContextList &sc_list) override;
103 FindGlobalVariables(const lldb_private::ConstString &name,
104 const lldb_private::CompilerDeclContext *parent_decl_ctx,
105 uint32_t max_matches,
106 lldb_private::VariableList &variables) override;
107 uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex,
108 uint32_t max_matches,
109 lldb_private::VariableList &variables) override;
111 FindFunctions(const lldb_private::ConstString &name,
112 const lldb_private::CompilerDeclContext *parent_decl_ctx,
113 lldb::FunctionNameType name_type_mask, bool include_inlines,
114 bool append, lldb_private::SymbolContextList &sc_list) override;
115 uint32_t FindFunctions(const lldb_private::RegularExpression ®ex,
116 bool include_inlines, bool append,
117 lldb_private::SymbolContextList &sc_list) override;
119 FindTypes(const lldb_private::ConstString &name,
120 const lldb_private::CompilerDeclContext *parent_decl_ctx,
121 bool append, uint32_t max_matches,
122 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
123 lldb_private::TypeMap &types) override;
124 lldb_private::CompilerDeclContext FindNamespace(
125 const lldb_private::ConstString &name,
126 const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
127 size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
128 lldb::TypeClass type_mask,
129 lldb_private::TypeList &type_list) override;
130 std::vector<lldb_private::CallEdge>
131 ParseCallEdgesInFunction(lldb_private::UserID func_id) override;
133 void DumpClangAST(lldb_private::Stream &s) override;
135 //------------------------------------------------------------------
136 // PluginInterface protocol
137 //------------------------------------------------------------------
138 lldb_private::ConstString GetPluginName() override;
140 uint32_t GetPluginVersion() override;
143 enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
145 friend class DebugMapModule;
146 friend struct DIERef;
147 friend class DWARFASTParserClang;
148 friend class DWARFUnit;
149 friend class SymbolFileDWARF;
151 lldb::ModuleSP module_sp;
153 OSOInfo() : module_sp() {}
156 typedef std::shared_ptr<OSOInfo> OSOInfoSP;
158 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
162 //------------------------------------------------------------------
163 // Class specific types
164 //------------------------------------------------------------------
165 struct CompileUnitInfo {
166 lldb_private::FileSpec so_file;
167 lldb_private::ConstString oso_path;
168 llvm::sys::TimePoint<> oso_mod_time;
170 lldb::CompUnitSP compile_unit_sp;
171 uint32_t first_symbol_index;
172 uint32_t last_symbol_index;
173 uint32_t first_symbol_id;
174 uint32_t last_symbol_id;
175 FileRangeMap file_range_map;
176 bool file_range_map_valid;
179 : so_file(), oso_path(), oso_mod_time(), oso_sp(), compile_unit_sp(),
180 first_symbol_index(UINT32_MAX), last_symbol_index(UINT32_MAX),
181 first_symbol_id(UINT32_MAX), last_symbol_id(UINT32_MAX),
182 file_range_map(), file_range_map_valid(false) {}
184 const FileRangeMap &GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
187 //------------------------------------------------------------------
188 // Protected Member Functions
189 //------------------------------------------------------------------
192 static uint32_t GetOSOIndexFromUserID(lldb::user_id_t uid) {
193 return (uint32_t)((uid >> 32ull) - 1ull);
196 static SymbolFileDWARF *GetSymbolFileAsSymbolFileDWARF(SymbolFile *sym_file);
198 bool GetFileSpecForSO(uint32_t oso_idx, lldb_private::FileSpec &file_spec);
200 CompileUnitInfo *GetCompUnitInfo(const lldb_private::SymbolContext &sc);
201 CompileUnitInfo *GetCompUnitInfo(const lldb_private::CompileUnit &comp_unit);
203 size_t GetCompUnitInfosForModule(const lldb_private::Module *oso_module,
204 std::vector<CompileUnitInfo *> &cu_infos);
206 lldb_private::Module *
207 GetModuleByCompUnitInfo(CompileUnitInfo *comp_unit_info);
209 lldb_private::Module *GetModuleByOSOIndex(uint32_t oso_idx);
211 lldb_private::ObjectFile *
212 GetObjectFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
214 lldb_private::ObjectFile *GetObjectFileByOSOIndex(uint32_t oso_idx);
216 uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info);
218 SymbolFileDWARF *GetSymbolFile(const lldb_private::SymbolContext &sc);
219 SymbolFileDWARF *GetSymbolFile(const lldb_private::CompileUnit &comp_unit);
221 SymbolFileDWARF *GetSymbolFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
223 SymbolFileDWARF *GetSymbolFileByOSOIndex(uint32_t oso_idx);
225 // If closure returns "false", iteration continues. If it returns
226 // "true", iteration terminates.
227 void ForEachSymbolFile(std::function<bool(SymbolFileDWARF *)> closure) {
228 for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
229 oso_idx < num_oso_idxs; ++oso_idx) {
230 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
231 if (closure(oso_dwarf))
237 CompileUnitInfo *GetCompileUnitInfoForSymbolWithIndex(uint32_t symbol_idx,
238 uint32_t *oso_idx_ptr);
240 CompileUnitInfo *GetCompileUnitInfoForSymbolWithID(lldb::user_id_t symbol_id,
241 uint32_t *oso_idx_ptr);
244 SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr,
245 const CompileUnitInfo *comp_unit_info);
247 static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr,
248 const CompileUnitInfo *comp_unit_info);
250 uint32_t PrivateFindGlobalVariables(
251 const lldb_private::ConstString &name,
252 const lldb_private::CompilerDeclContext *parent_decl_ctx,
253 const std::vector<uint32_t> &name_symbol_indexes, uint32_t max_matches,
254 lldb_private::VariableList &variables);
256 void SetCompileUnit(SymbolFileDWARF *oso_dwarf,
257 const lldb::CompUnitSP &cu_sp);
259 lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf);
261 CompileUnitInfo *GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf);
264 FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
266 bool Supports_DW_AT_APPLE_objc_complete_type(SymbolFileDWARF *skip_dwarf_oso);
268 lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
269 const DWARFDIE &die, const lldb_private::ConstString &type_name,
270 bool must_be_implementation);
272 UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() {
273 return m_unique_ast_type_map;
276 //------------------------------------------------------------------
278 //------------------------------------------------------------------
282 : m_exe_sym_idx(UINT32_MAX), m_oso_file_addr(LLDB_INVALID_ADDRESS) {}
284 OSOEntry(uint32_t exe_sym_idx, lldb::addr_t oso_file_addr)
285 : m_exe_sym_idx(exe_sym_idx), m_oso_file_addr(oso_file_addr) {}
287 uint32_t GetExeSymbolIndex() const { return m_exe_sym_idx; }
289 bool operator<(const OSOEntry &rhs) const {
290 return m_exe_sym_idx < rhs.m_exe_sym_idx;
293 lldb::addr_t GetOSOFileAddress() const { return m_oso_file_addr; }
295 void SetOSOFileAddress(lldb::addr_t oso_file_addr) {
296 m_oso_file_addr = oso_file_addr;
300 uint32_t m_exe_sym_idx;
301 lldb::addr_t m_oso_file_addr;
304 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry>
307 //------------------------------------------------------------------
309 //------------------------------------------------------------------
310 std::bitset<kNumFlags> m_flags;
311 std::vector<CompileUnitInfo> m_compile_unit_infos;
312 std::vector<uint32_t> m_func_indexes; // Sorted by address
313 std::vector<uint32_t> m_glob_indexes;
314 std::map<std::pair<lldb_private::ConstString, llvm::sys::TimePoint<>>,
317 UniqueDWARFASTTypeMap m_unique_ast_type_map;
318 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
319 DebugMap m_debug_map;
321 //------------------------------------------------------------------
322 // When an object file from the debug map gets parsed in
323 // SymbolFileDWARF, it needs to tell the debug map about the object
324 // files addresses by calling this function once for each N_FUN,
325 // N_GSYM and N_STSYM and after all entries in the debug map have
326 // been matched up, FinalizeOSOFileRanges() should be called.
327 //------------------------------------------------------------------
328 bool AddOSOFileRange(CompileUnitInfo *cu_info, lldb::addr_t exe_file_addr,
329 lldb::addr_t exe_byte_size, lldb::addr_t oso_file_addr,
330 lldb::addr_t oso_byte_size);
332 //------------------------------------------------------------------
333 // Called after calling AddOSOFileRange() for each object file debug
334 // map entry to finalize the info for the unlinked compile unit.
335 //------------------------------------------------------------------
336 void FinalizeOSOFileRanges(CompileUnitInfo *cu_info);
338 //------------------------------------------------------------------
339 /// Convert \a addr from a .o file address, to an executable address.
342 /// A section offset address from a .o file
345 /// Returns true if \a addr was converted to be an executable
346 /// section/offset address, false otherwise.
347 //------------------------------------------------------------------
348 bool LinkOSOAddress(lldb_private::Address &addr);
350 //------------------------------------------------------------------
351 /// Convert a .o file "file address" to an executable "file address".
353 /// @param[in] oso_symfile
354 /// The DWARF symbol file that contains \a oso_file_addr
356 /// @param[in] oso_file_addr
357 /// A .o file "file address" to convert.
360 /// LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the
361 /// linked executable, otherwise a valid "file address" from the
362 /// linked executable that contains the debug map.
363 //------------------------------------------------------------------
364 lldb::addr_t LinkOSOFileAddress(SymbolFileDWARF *oso_symfile,
365 lldb::addr_t oso_file_addr);
367 //------------------------------------------------------------------
368 /// Given a line table full of lines with "file addresses" that are
369 /// for a .o file represented by \a oso_symfile, link a new line table
372 /// @param[in] oso_symfile
373 /// The DWARF symbol file that produced the \a line_table
376 /// A section offset address from a .o file
379 /// Returns a valid line table full of linked addresses, or NULL
380 /// if none of the line table addresses exist in the main
382 //------------------------------------------------------------------
383 lldb_private::LineTable *
384 LinkOSOLineTable(SymbolFileDWARF *oso_symfile,
385 lldb_private::LineTable *line_table);
387 size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data,
388 DWARFDebugAranges *debug_aranges);
391 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_