1 //===-- SymbolFileDWARFDebugMap.h ------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_SYMBOLFILEDWARFDEBUGMAP_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_SYMBOLFILEDWARFDEBUGMAP_H
12 #include "lldb/Symbol/SymbolFile.h"
13 #include "lldb/Utility/RangeMap.h"
14 #include "llvm/Support/Chrono.h"
19 #include "UniqueDWARFASTType.h"
21 class SymbolFileDWARF;
22 class DWARFDebugAranges;
23 class DWARFDeclContext;
25 class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile {
26 /// LLVM RTTI support.
30 /// LLVM RTTI support.
32 bool isA(const void *ClassID) const override {
33 return ClassID == &ID || SymbolFile::isA(ClassID);
35 static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
39 static void Initialize();
41 static void Terminate();
43 static lldb_private::ConstString GetPluginNameStatic();
45 static const char *GetPluginDescriptionStatic();
47 static lldb_private::SymbolFile *
48 CreateInstance(lldb::ObjectFileSP objfile_sp);
50 // Constructors and Destructors
51 SymbolFileDWARFDebugMap(lldb::ObjectFileSP objfile_sp);
52 ~SymbolFileDWARFDebugMap() override;
54 uint32_t CalculateAbilities() override;
55 void InitializeObject() override;
57 // Compile Unit function calls
59 ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
60 lldb_private::XcodeSDK
61 ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override;
62 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
63 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
64 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
66 bool ForEachExternalModule(
67 lldb_private::CompileUnit &, llvm::DenseSet<lldb_private::SymbolFile *> &,
68 llvm::function_ref<bool(lldb_private::Module &)>) override;
70 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,
71 lldb_private::FileSpecList &support_files) override;
73 bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override;
75 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
77 bool ParseImportedModules(
78 const lldb_private::SymbolContext &sc,
79 std::vector<lldb_private::SourceModule> &imported_modules) override;
80 size_t ParseBlocksRecursive(lldb_private::Function &func) override;
82 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
84 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
85 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
86 lldb::user_id_t type_uid,
87 const lldb_private::ExecutionContext *exe_ctx) override;
89 lldb_private::CompilerDeclContext
90 GetDeclContextForUID(lldb::user_id_t uid) override;
91 lldb_private::CompilerDeclContext
92 GetDeclContextContainingUID(lldb::user_id_t uid) override;
94 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
96 bool CompleteType(lldb_private::CompilerType &compiler_type) override;
97 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
98 lldb::SymbolContextItem resolve_scope,
99 lldb_private::SymbolContext &sc) override;
101 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
103 lldb::SymbolContextItem resolve_scope,
104 lldb_private::SymbolContextList &sc_list) override;
106 FindGlobalVariables(lldb_private::ConstString name,
107 const lldb_private::CompilerDeclContext &parent_decl_ctx,
108 uint32_t max_matches,
109 lldb_private::VariableList &variables) override;
110 void FindGlobalVariables(const lldb_private::RegularExpression ®ex,
111 uint32_t max_matches,
112 lldb_private::VariableList &variables) override;
113 void FindFunctions(lldb_private::ConstString name,
114 const lldb_private::CompilerDeclContext &parent_decl_ctx,
115 lldb::FunctionNameType name_type_mask,
116 bool include_inlines,
117 lldb_private::SymbolContextList &sc_list) override;
118 void FindFunctions(const lldb_private::RegularExpression ®ex,
119 bool include_inlines,
120 lldb_private::SymbolContextList &sc_list) override;
122 FindTypes(lldb_private::ConstString name,
123 const lldb_private::CompilerDeclContext &parent_decl_ctx,
124 uint32_t max_matches,
125 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
126 lldb_private::TypeMap &types) override;
128 FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> context,
129 lldb_private::LanguageSet languages,
130 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
131 lldb_private::TypeMap &types) override;
132 lldb_private::CompilerDeclContext FindNamespace(
133 lldb_private::ConstString name,
134 const lldb_private::CompilerDeclContext &parent_decl_ctx) override;
135 void GetTypes(lldb_private::SymbolContextScope *sc_scope,
136 lldb::TypeClass type_mask,
137 lldb_private::TypeList &type_list) override;
138 std::vector<std::unique_ptr<lldb_private::CallEdge>>
139 ParseCallEdgesInFunction(lldb_private::UserID func_id) override;
141 void DumpClangAST(lldb_private::Stream &s) override;
143 // PluginInterface protocol
144 lldb_private::ConstString GetPluginName() override;
146 uint32_t GetPluginVersion() override;
149 enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
151 friend class DebugMapModule;
152 friend class DWARFASTParserClang;
153 friend class DWARFCompileUnit;
154 friend class SymbolFileDWARF;
156 lldb::ModuleSP module_sp;
158 OSOInfo() : module_sp() {}
161 typedef std::shared_ptr<OSOInfo> OSOInfoSP;
163 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
167 // Class specific types
168 struct CompileUnitInfo {
169 lldb_private::FileSpec so_file;
170 lldb_private::ConstString oso_path;
171 llvm::sys::TimePoint<> oso_mod_time;
173 lldb::CompUnitSP compile_unit_sp;
174 uint32_t first_symbol_index;
175 uint32_t last_symbol_index;
176 uint32_t first_symbol_id;
177 uint32_t last_symbol_id;
178 FileRangeMap file_range_map;
179 bool file_range_map_valid;
182 : so_file(), oso_path(), oso_mod_time(), oso_sp(), compile_unit_sp(),
183 first_symbol_index(UINT32_MAX), last_symbol_index(UINT32_MAX),
184 first_symbol_id(UINT32_MAX), last_symbol_id(UINT32_MAX),
185 file_range_map(), file_range_map_valid(false) {}
187 const FileRangeMap &GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
190 // Protected Member Functions
193 uint32_t CalculateNumCompileUnits() override;
194 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
196 static uint32_t GetOSOIndexFromUserID(lldb::user_id_t uid) {
197 return (uint32_t)((uid >> 32ull) - 1ull);
200 static SymbolFileDWARF *GetSymbolFileAsSymbolFileDWARF(SymbolFile *sym_file);
202 bool GetFileSpecForSO(uint32_t oso_idx, lldb_private::FileSpec &file_spec);
204 CompileUnitInfo *GetCompUnitInfo(const lldb_private::SymbolContext &sc);
205 CompileUnitInfo *GetCompUnitInfo(const lldb_private::CompileUnit &comp_unit);
207 size_t GetCompUnitInfosForModule(const lldb_private::Module *oso_module,
208 std::vector<CompileUnitInfo *> &cu_infos);
210 lldb_private::Module *
211 GetModuleByCompUnitInfo(CompileUnitInfo *comp_unit_info);
213 lldb_private::Module *GetModuleByOSOIndex(uint32_t oso_idx);
215 lldb_private::ObjectFile *
216 GetObjectFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
218 lldb_private::ObjectFile *GetObjectFileByOSOIndex(uint32_t oso_idx);
220 uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info);
222 SymbolFileDWARF *GetSymbolFile(const lldb_private::SymbolContext &sc);
223 SymbolFileDWARF *GetSymbolFile(const lldb_private::CompileUnit &comp_unit);
225 SymbolFileDWARF *GetSymbolFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
227 SymbolFileDWARF *GetSymbolFileByOSOIndex(uint32_t oso_idx);
229 // If closure returns "false", iteration continues. If it returns
230 // "true", iteration terminates.
231 void ForEachSymbolFile(std::function<bool(SymbolFileDWARF *)> closure) {
232 for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
233 oso_idx < num_oso_idxs; ++oso_idx) {
234 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
235 if (closure(oso_dwarf))
241 CompileUnitInfo *GetCompileUnitInfoForSymbolWithIndex(uint32_t symbol_idx,
242 uint32_t *oso_idx_ptr);
244 CompileUnitInfo *GetCompileUnitInfoForSymbolWithID(lldb::user_id_t symbol_id,
245 uint32_t *oso_idx_ptr);
248 SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr,
249 const CompileUnitInfo *comp_unit_info);
251 static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr,
252 const CompileUnitInfo *comp_unit_info);
254 void PrivateFindGlobalVariables(
255 lldb_private::ConstString name,
256 const lldb_private::CompilerDeclContext &parent_decl_ctx,
257 const std::vector<uint32_t> &name_symbol_indexes, uint32_t max_matches,
258 lldb_private::VariableList &variables);
260 void SetCompileUnit(SymbolFileDWARF *oso_dwarf,
261 const lldb::CompUnitSP &cu_sp);
263 lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf);
265 CompileUnitInfo *GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf);
268 FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
270 bool Supports_DW_AT_APPLE_objc_complete_type(SymbolFileDWARF *skip_dwarf_oso);
272 lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
273 const DWARFDIE &die, lldb_private::ConstString type_name,
274 bool must_be_implementation);
276 UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() {
277 return m_unique_ast_type_map;
284 : m_exe_sym_idx(UINT32_MAX), m_oso_file_addr(LLDB_INVALID_ADDRESS) {}
286 OSOEntry(uint32_t exe_sym_idx, lldb::addr_t oso_file_addr)
287 : m_exe_sym_idx(exe_sym_idx), m_oso_file_addr(oso_file_addr) {}
289 uint32_t GetExeSymbolIndex() const { return m_exe_sym_idx; }
291 bool operator<(const OSOEntry &rhs) const {
292 return m_exe_sym_idx < rhs.m_exe_sym_idx;
295 lldb::addr_t GetOSOFileAddress() const { return m_oso_file_addr; }
297 void SetOSOFileAddress(lldb::addr_t oso_file_addr) {
298 m_oso_file_addr = oso_file_addr;
302 uint32_t m_exe_sym_idx;
303 lldb::addr_t m_oso_file_addr;
306 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry>
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 // When an object file from the debug map gets parsed in
322 // SymbolFileDWARF, it needs to tell the debug map about the object
323 // files addresses by calling this function once for each N_FUN,
324 // N_GSYM and N_STSYM and after all entries in the debug map have
325 // been matched up, FinalizeOSOFileRanges() should be called.
326 bool AddOSOFileRange(CompileUnitInfo *cu_info, lldb::addr_t exe_file_addr,
327 lldb::addr_t exe_byte_size, lldb::addr_t oso_file_addr,
328 lldb::addr_t oso_byte_size);
330 // Called after calling AddOSOFileRange() for each object file debug
331 // map entry to finalize the info for the unlinked compile unit.
332 void FinalizeOSOFileRanges(CompileUnitInfo *cu_info);
334 /// Convert \a addr from a .o file address, to an executable address.
337 /// A section offset address from a .o file
340 /// Returns true if \a addr was converted to be an executable
341 /// section/offset address, false otherwise.
342 bool LinkOSOAddress(lldb_private::Address &addr);
344 /// Convert a .o file "file address" to an executable "file address".
346 /// \param[in] oso_symfile
347 /// The DWARF symbol file that contains \a oso_file_addr
349 /// \param[in] oso_file_addr
350 /// A .o file "file address" to convert.
353 /// LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the
354 /// linked executable, otherwise a valid "file address" from the
355 /// linked executable that contains the debug map.
356 lldb::addr_t LinkOSOFileAddress(SymbolFileDWARF *oso_symfile,
357 lldb::addr_t oso_file_addr);
359 /// Given a line table full of lines with "file addresses" that are
360 /// for a .o file represented by \a oso_symfile, link a new line table
363 /// \param[in] oso_symfile
364 /// The DWARF symbol file that produced the \a line_table
366 /// \param[in] line_table
367 /// A pointer to the line table.
370 /// Returns a valid line table full of linked addresses, or NULL
371 /// if none of the line table addresses exist in the main
373 lldb_private::LineTable *
374 LinkOSOLineTable(SymbolFileDWARF *oso_symfile,
375 lldb_private::LineTable *line_table);
377 size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data,
378 DWARFDebugAranges *debug_aranges);
381 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_SYMBOLFILEDWARFDEBUGMAP_H