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 {
28 static void Initialize();
30 static void Terminate();
32 static lldb_private::ConstString GetPluginNameStatic();
34 static const char *GetPluginDescriptionStatic();
36 static lldb_private::SymbolFile *
37 CreateInstance(lldb::ObjectFileSP objfile_sp);
39 // Constructors and Destructors
40 SymbolFileDWARFDebugMap(lldb::ObjectFileSP objfile_sp);
41 ~SymbolFileDWARFDebugMap() override;
43 uint32_t CalculateAbilities() override;
44 void InitializeObject() override;
46 // Compile Unit function calls
48 ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
50 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
52 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
54 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
57 ForEachExternalModule(lldb_private::CompileUnit &comp_unit,
58 llvm::function_ref<void(lldb::ModuleSP)> f) override;
60 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,
61 lldb_private::FileSpecList &support_files) override;
63 bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override;
65 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
67 bool ParseImportedModules(
68 const lldb_private::SymbolContext &sc,
69 std::vector<lldb_private::SourceModule> &imported_modules) override;
70 size_t ParseBlocksRecursive(lldb_private::Function &func) override;
72 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
74 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
75 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
76 lldb::user_id_t type_uid,
77 const lldb_private::ExecutionContext *exe_ctx) 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 lldb::SymbolContextItem resolve_scope,
89 lldb_private::SymbolContext &sc) override;
91 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
93 lldb::SymbolContextItem resolve_scope,
94 lldb_private::SymbolContextList &sc_list) override;
96 FindGlobalVariables(lldb_private::ConstString name,
97 const lldb_private::CompilerDeclContext *parent_decl_ctx,
99 lldb_private::VariableList &variables) override;
100 void FindGlobalVariables(const lldb_private::RegularExpression ®ex,
101 uint32_t max_matches,
102 lldb_private::VariableList &variables) override;
103 void FindFunctions(lldb_private::ConstString name,
104 const lldb_private::CompilerDeclContext *parent_decl_ctx,
105 lldb::FunctionNameType name_type_mask,
106 bool include_inlines,
107 lldb_private::SymbolContextList &sc_list) override;
108 void FindFunctions(const lldb_private::RegularExpression ®ex,
109 bool include_inlines,
110 lldb_private::SymbolContextList &sc_list) override;
112 FindTypes(lldb_private::ConstString name,
113 const lldb_private::CompilerDeclContext *parent_decl_ctx,
114 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 lldb_private::ConstString name,
119 const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
120 void GetTypes(lldb_private::SymbolContextScope *sc_scope,
121 lldb::TypeClass type_mask,
122 lldb_private::TypeList &type_list) override;
123 std::vector<lldb_private::CallEdge>
124 ParseCallEdgesInFunction(lldb_private::UserID func_id) override;
126 void DumpClangAST(lldb_private::Stream &s) override;
128 // PluginInterface protocol
129 lldb_private::ConstString GetPluginName() override;
131 uint32_t GetPluginVersion() override;
134 enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
136 friend class DebugMapModule;
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 // Class specific types
153 struct CompileUnitInfo {
154 lldb_private::FileSpec so_file;
155 lldb_private::ConstString oso_path;
156 llvm::sys::TimePoint<> oso_mod_time;
158 lldb::CompUnitSP compile_unit_sp;
159 uint32_t first_symbol_index;
160 uint32_t last_symbol_index;
161 uint32_t first_symbol_id;
162 uint32_t last_symbol_id;
163 FileRangeMap file_range_map;
164 bool file_range_map_valid;
167 : so_file(), oso_path(), oso_mod_time(), oso_sp(), compile_unit_sp(),
168 first_symbol_index(UINT32_MAX), last_symbol_index(UINT32_MAX),
169 first_symbol_id(UINT32_MAX), last_symbol_id(UINT32_MAX),
170 file_range_map(), file_range_map_valid(false) {}
172 const FileRangeMap &GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
175 // Protected Member Functions
178 uint32_t CalculateNumCompileUnits() override;
179 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
181 static uint32_t GetOSOIndexFromUserID(lldb::user_id_t uid) {
182 return (uint32_t)((uid >> 32ull) - 1ull);
185 static SymbolFileDWARF *GetSymbolFileAsSymbolFileDWARF(SymbolFile *sym_file);
187 bool GetFileSpecForSO(uint32_t oso_idx, lldb_private::FileSpec &file_spec);
189 CompileUnitInfo *GetCompUnitInfo(const lldb_private::SymbolContext &sc);
190 CompileUnitInfo *GetCompUnitInfo(const lldb_private::CompileUnit &comp_unit);
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);
208 SymbolFileDWARF *GetSymbolFile(const lldb_private::CompileUnit &comp_unit);
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 void PrivateFindGlobalVariables(
240 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, lldb_private::ConstString type_name,
259 bool must_be_implementation);
261 UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() {
262 return m_unique_ast_type_map;
269 : m_exe_sym_idx(UINT32_MAX), m_oso_file_addr(LLDB_INVALID_ADDRESS) {}
271 OSOEntry(uint32_t exe_sym_idx, lldb::addr_t oso_file_addr)
272 : m_exe_sym_idx(exe_sym_idx), m_oso_file_addr(oso_file_addr) {}
274 uint32_t GetExeSymbolIndex() const { return m_exe_sym_idx; }
276 bool operator<(const OSOEntry &rhs) const {
277 return m_exe_sym_idx < rhs.m_exe_sym_idx;
280 lldb::addr_t GetOSOFileAddress() const { return m_oso_file_addr; }
282 void SetOSOFileAddress(lldb::addr_t oso_file_addr) {
283 m_oso_file_addr = oso_file_addr;
287 uint32_t m_exe_sym_idx;
288 lldb::addr_t m_oso_file_addr;
291 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry>
295 std::bitset<kNumFlags> m_flags;
296 std::vector<CompileUnitInfo> m_compile_unit_infos;
297 std::vector<uint32_t> m_func_indexes; // Sorted by address
298 std::vector<uint32_t> m_glob_indexes;
299 std::map<std::pair<lldb_private::ConstString, llvm::sys::TimePoint<>>,
302 UniqueDWARFASTTypeMap m_unique_ast_type_map;
303 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
304 DebugMap m_debug_map;
306 // When an object file from the debug map gets parsed in
307 // SymbolFileDWARF, it needs to tell the debug map about the object
308 // files addresses by calling this function once for each N_FUN,
309 // N_GSYM and N_STSYM and after all entries in the debug map have
310 // been matched up, FinalizeOSOFileRanges() should be called.
311 bool AddOSOFileRange(CompileUnitInfo *cu_info, lldb::addr_t exe_file_addr,
312 lldb::addr_t exe_byte_size, lldb::addr_t oso_file_addr,
313 lldb::addr_t oso_byte_size);
315 // Called after calling AddOSOFileRange() for each object file debug
316 // map entry to finalize the info for the unlinked compile unit.
317 void FinalizeOSOFileRanges(CompileUnitInfo *cu_info);
319 /// Convert \a addr from a .o file address, to an executable address.
322 /// A section offset address from a .o file
325 /// Returns true if \a addr was converted to be an executable
326 /// section/offset address, false otherwise.
327 bool LinkOSOAddress(lldb_private::Address &addr);
329 /// Convert a .o file "file address" to an executable "file address".
331 /// \param[in] oso_symfile
332 /// The DWARF symbol file that contains \a oso_file_addr
334 /// \param[in] oso_file_addr
335 /// A .o file "file address" to convert.
338 /// LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the
339 /// linked executable, otherwise a valid "file address" from the
340 /// linked executable that contains the debug map.
341 lldb::addr_t LinkOSOFileAddress(SymbolFileDWARF *oso_symfile,
342 lldb::addr_t oso_file_addr);
344 /// Given a line table full of lines with "file addresses" that are
345 /// for a .o file represented by \a oso_symfile, link a new line table
348 /// \param[in] oso_symfile
349 /// The DWARF symbol file that produced the \a line_table
352 /// A section offset address from a .o file
355 /// Returns a valid line table full of linked addresses, or NULL
356 /// if none of the line table addresses exist in the main
358 lldb_private::LineTable *
359 LinkOSOLineTable(SymbolFileDWARF *oso_symfile,
360 lldb_private::LineTable *line_table);
362 size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data,
363 DWARFDebugAranges *debug_aranges);
366 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_