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 SymbolFileDWARF_SymbolFileDWARFDebugMap_h_
10 #define SymbolFileDWARF_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;
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 ForEachExternalModule(
68 lldb_private::CompileUnit &, llvm::DenseSet<lldb_private::SymbolFile *> &,
69 llvm::function_ref<bool(lldb_private::Module &)>) override;
71 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,
72 lldb_private::FileSpecList &support_files) override;
74 bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override;
76 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
78 bool ParseImportedModules(
79 const lldb_private::SymbolContext &sc,
80 std::vector<lldb_private::SourceModule> &imported_modules) override;
81 size_t ParseBlocksRecursive(lldb_private::Function &func) override;
83 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
85 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
86 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
87 lldb::user_id_t type_uid,
88 const lldb_private::ExecutionContext *exe_ctx) override;
90 lldb_private::CompilerDeclContext
91 GetDeclContextForUID(lldb::user_id_t uid) override;
92 lldb_private::CompilerDeclContext
93 GetDeclContextContainingUID(lldb::user_id_t uid) override;
95 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
97 bool CompleteType(lldb_private::CompilerType &compiler_type) override;
98 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
99 lldb::SymbolContextItem resolve_scope,
100 lldb_private::SymbolContext &sc) override;
102 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
104 lldb::SymbolContextItem resolve_scope,
105 lldb_private::SymbolContextList &sc_list) override;
107 FindGlobalVariables(lldb_private::ConstString name,
108 const lldb_private::CompilerDeclContext *parent_decl_ctx,
109 uint32_t max_matches,
110 lldb_private::VariableList &variables) override;
111 void FindGlobalVariables(const lldb_private::RegularExpression ®ex,
112 uint32_t max_matches,
113 lldb_private::VariableList &variables) override;
114 void FindFunctions(lldb_private::ConstString name,
115 const lldb_private::CompilerDeclContext *parent_decl_ctx,
116 lldb::FunctionNameType name_type_mask,
117 bool include_inlines,
118 lldb_private::SymbolContextList &sc_list) override;
119 void FindFunctions(const lldb_private::RegularExpression ®ex,
120 bool include_inlines,
121 lldb_private::SymbolContextList &sc_list) override;
123 FindTypes(lldb_private::ConstString name,
124 const lldb_private::CompilerDeclContext *parent_decl_ctx,
125 uint32_t max_matches,
126 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
127 lldb_private::TypeMap &types) override;
129 FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> context,
130 lldb_private::LanguageSet languages,
131 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
132 lldb_private::TypeMap &types) override;
133 lldb_private::CompilerDeclContext FindNamespace(
134 lldb_private::ConstString name,
135 const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
136 void GetTypes(lldb_private::SymbolContextScope *sc_scope,
137 lldb::TypeClass type_mask,
138 lldb_private::TypeList &type_list) override;
139 std::vector<std::unique_ptr<lldb_private::CallEdge>>
140 ParseCallEdgesInFunction(lldb_private::UserID func_id) override;
142 void DumpClangAST(lldb_private::Stream &s) override;
144 // PluginInterface protocol
145 lldb_private::ConstString GetPluginName() override;
147 uint32_t GetPluginVersion() override;
150 enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
152 friend class DebugMapModule;
153 friend class DWARFASTParserClang;
154 friend class DWARFCompileUnit;
155 friend class SymbolFileDWARF;
157 lldb::ModuleSP module_sp;
159 OSOInfo() : module_sp() {}
162 typedef std::shared_ptr<OSOInfo> OSOInfoSP;
164 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
168 // Class specific types
169 struct CompileUnitInfo {
170 lldb_private::FileSpec so_file;
171 lldb_private::ConstString oso_path;
172 llvm::sys::TimePoint<> oso_mod_time;
174 lldb::CompUnitSP compile_unit_sp;
175 uint32_t first_symbol_index;
176 uint32_t last_symbol_index;
177 uint32_t first_symbol_id;
178 uint32_t last_symbol_id;
179 FileRangeMap file_range_map;
180 bool file_range_map_valid;
183 : so_file(), oso_path(), oso_mod_time(), oso_sp(), compile_unit_sp(),
184 first_symbol_index(UINT32_MAX), last_symbol_index(UINT32_MAX),
185 first_symbol_id(UINT32_MAX), last_symbol_id(UINT32_MAX),
186 file_range_map(), file_range_map_valid(false) {}
188 const FileRangeMap &GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
191 // Protected Member Functions
194 uint32_t CalculateNumCompileUnits() override;
195 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
197 static uint32_t GetOSOIndexFromUserID(lldb::user_id_t uid) {
198 return (uint32_t)((uid >> 32ull) - 1ull);
201 static SymbolFileDWARF *GetSymbolFileAsSymbolFileDWARF(SymbolFile *sym_file);
203 bool GetFileSpecForSO(uint32_t oso_idx, lldb_private::FileSpec &file_spec);
205 CompileUnitInfo *GetCompUnitInfo(const lldb_private::SymbolContext &sc);
206 CompileUnitInfo *GetCompUnitInfo(const lldb_private::CompileUnit &comp_unit);
208 size_t GetCompUnitInfosForModule(const lldb_private::Module *oso_module,
209 std::vector<CompileUnitInfo *> &cu_infos);
211 lldb_private::Module *
212 GetModuleByCompUnitInfo(CompileUnitInfo *comp_unit_info);
214 lldb_private::Module *GetModuleByOSOIndex(uint32_t oso_idx);
216 lldb_private::ObjectFile *
217 GetObjectFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
219 lldb_private::ObjectFile *GetObjectFileByOSOIndex(uint32_t oso_idx);
221 uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info);
223 SymbolFileDWARF *GetSymbolFile(const lldb_private::SymbolContext &sc);
224 SymbolFileDWARF *GetSymbolFile(const lldb_private::CompileUnit &comp_unit);
226 SymbolFileDWARF *GetSymbolFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
228 SymbolFileDWARF *GetSymbolFileByOSOIndex(uint32_t oso_idx);
230 // If closure returns "false", iteration continues. If it returns
231 // "true", iteration terminates.
232 void ForEachSymbolFile(std::function<bool(SymbolFileDWARF *)> closure) {
233 for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
234 oso_idx < num_oso_idxs; ++oso_idx) {
235 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
236 if (closure(oso_dwarf))
242 CompileUnitInfo *GetCompileUnitInfoForSymbolWithIndex(uint32_t symbol_idx,
243 uint32_t *oso_idx_ptr);
245 CompileUnitInfo *GetCompileUnitInfoForSymbolWithID(lldb::user_id_t symbol_id,
246 uint32_t *oso_idx_ptr);
249 SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr,
250 const CompileUnitInfo *comp_unit_info);
252 static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr,
253 const CompileUnitInfo *comp_unit_info);
255 void PrivateFindGlobalVariables(
256 lldb_private::ConstString name,
257 const lldb_private::CompilerDeclContext *parent_decl_ctx,
258 const std::vector<uint32_t> &name_symbol_indexes, uint32_t max_matches,
259 lldb_private::VariableList &variables);
261 void SetCompileUnit(SymbolFileDWARF *oso_dwarf,
262 const lldb::CompUnitSP &cu_sp);
264 lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf);
266 CompileUnitInfo *GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf);
269 FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
271 bool Supports_DW_AT_APPLE_objc_complete_type(SymbolFileDWARF *skip_dwarf_oso);
273 lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
274 const DWARFDIE &die, lldb_private::ConstString type_name,
275 bool must_be_implementation);
277 UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() {
278 return m_unique_ast_type_map;
285 : m_exe_sym_idx(UINT32_MAX), m_oso_file_addr(LLDB_INVALID_ADDRESS) {}
287 OSOEntry(uint32_t exe_sym_idx, lldb::addr_t oso_file_addr)
288 : m_exe_sym_idx(exe_sym_idx), m_oso_file_addr(oso_file_addr) {}
290 uint32_t GetExeSymbolIndex() const { return m_exe_sym_idx; }
292 bool operator<(const OSOEntry &rhs) const {
293 return m_exe_sym_idx < rhs.m_exe_sym_idx;
296 lldb::addr_t GetOSOFileAddress() const { return m_oso_file_addr; }
298 void SetOSOFileAddress(lldb::addr_t oso_file_addr) {
299 m_oso_file_addr = oso_file_addr;
303 uint32_t m_exe_sym_idx;
304 lldb::addr_t m_oso_file_addr;
307 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry>
311 std::bitset<kNumFlags> m_flags;
312 std::vector<CompileUnitInfo> m_compile_unit_infos;
313 std::vector<uint32_t> m_func_indexes; // Sorted by address
314 std::vector<uint32_t> m_glob_indexes;
315 std::map<std::pair<lldb_private::ConstString, llvm::sys::TimePoint<>>,
318 UniqueDWARFASTTypeMap m_unique_ast_type_map;
319 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
320 DebugMap m_debug_map;
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 bool AddOSOFileRange(CompileUnitInfo *cu_info, lldb::addr_t exe_file_addr,
328 lldb::addr_t exe_byte_size, lldb::addr_t oso_file_addr,
329 lldb::addr_t oso_byte_size);
331 // Called after calling AddOSOFileRange() for each object file debug
332 // map entry to finalize the info for the unlinked compile unit.
333 void FinalizeOSOFileRanges(CompileUnitInfo *cu_info);
335 /// Convert \a addr from a .o file address, to an executable address.
338 /// A section offset address from a .o file
341 /// Returns true if \a addr was converted to be an executable
342 /// section/offset address, false otherwise.
343 bool LinkOSOAddress(lldb_private::Address &addr);
345 /// Convert a .o file "file address" to an executable "file address".
347 /// \param[in] oso_symfile
348 /// The DWARF symbol file that contains \a oso_file_addr
350 /// \param[in] oso_file_addr
351 /// A .o file "file address" to convert.
354 /// LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the
355 /// linked executable, otherwise a valid "file address" from the
356 /// linked executable that contains the debug map.
357 lldb::addr_t LinkOSOFileAddress(SymbolFileDWARF *oso_symfile,
358 lldb::addr_t oso_file_addr);
360 /// Given a line table full of lines with "file addresses" that are
361 /// for a .o file represented by \a oso_symfile, link a new line table
364 /// \param[in] oso_symfile
365 /// The DWARF symbol file that produced the \a line_table
367 /// \param[in] line_table
368 /// A pointer to the line table.
371 /// Returns a valid line table full of linked addresses, or NULL
372 /// if none of the line table addresses exist in the main
374 lldb_private::LineTable *
375 LinkOSOLineTable(SymbolFileDWARF *oso_symfile,
376 lldb_private::LineTable *line_table);
378 size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data,
379 DWARFDebugAranges *debug_aranges);
382 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_