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_private::ObjectFile *obj_file);
39 // Constructors and Destructors
40 SymbolFileDWARFDebugMap(lldb_private::ObjectFile *ofile);
41 ~SymbolFileDWARFDebugMap() override;
43 uint32_t CalculateAbilities() override;
44 void InitializeObject() override;
46 // Compile Unit function calls
47 uint32_t GetNumCompileUnits() override;
48 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
51 ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
53 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
55 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
57 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
59 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,
60 lldb_private::FileSpecList &support_files) override;
62 bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override;
64 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
66 bool ParseImportedModules(
67 const lldb_private::SymbolContext &sc,
68 std::vector<lldb_private::SourceModule> &imported_modules) override;
69 size_t ParseBlocksRecursive(lldb_private::Function &func) override;
71 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
73 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
74 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
75 lldb::user_id_t type_uid,
76 const lldb_private::ExecutionContext *exe_ctx) override;
78 lldb_private::CompilerDeclContext
79 GetDeclContextForUID(lldb::user_id_t uid) override;
80 lldb_private::CompilerDeclContext
81 GetDeclContextContainingUID(lldb::user_id_t uid) override;
83 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
85 bool CompleteType(lldb_private::CompilerType &compiler_type) override;
86 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
87 lldb::SymbolContextItem resolve_scope,
88 lldb_private::SymbolContext &sc) override;
90 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
92 lldb::SymbolContextItem resolve_scope,
93 lldb_private::SymbolContextList &sc_list) override;
95 FindGlobalVariables(lldb_private::ConstString name,
96 const lldb_private::CompilerDeclContext *parent_decl_ctx,
98 lldb_private::VariableList &variables) override;
99 uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex,
100 uint32_t max_matches,
101 lldb_private::VariableList &variables) override;
103 FindFunctions(lldb_private::ConstString name,
104 const lldb_private::CompilerDeclContext *parent_decl_ctx,
105 lldb::FunctionNameType name_type_mask, bool include_inlines,
106 bool append, lldb_private::SymbolContextList &sc_list) override;
107 uint32_t FindFunctions(const lldb_private::RegularExpression ®ex,
108 bool include_inlines, bool append,
109 lldb_private::SymbolContextList &sc_list) override;
111 FindTypes(lldb_private::ConstString name,
112 const lldb_private::CompilerDeclContext *parent_decl_ctx,
113 bool append, uint32_t max_matches,
114 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
115 lldb_private::TypeMap &types) override;
116 lldb_private::CompilerDeclContext FindNamespace(
117 lldb_private::ConstString name,
118 const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
119 size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
120 lldb::TypeClass type_mask,
121 lldb_private::TypeList &type_list) override;
122 std::vector<lldb_private::CallEdge>
123 ParseCallEdgesInFunction(lldb_private::UserID func_id) override;
125 void DumpClangAST(lldb_private::Stream &s) override;
127 // PluginInterface protocol
128 lldb_private::ConstString GetPluginName() override;
130 uint32_t GetPluginVersion() override;
133 enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
135 friend class DebugMapModule;
136 friend class DWARFASTParserClang;
137 friend class DWARFCompileUnit;
138 friend class SymbolFileDWARF;
140 lldb::ModuleSP module_sp;
142 OSOInfo() : module_sp() {}
145 typedef std::shared_ptr<OSOInfo> OSOInfoSP;
147 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
151 // Class specific types
152 struct CompileUnitInfo {
153 lldb_private::FileSpec so_file;
154 lldb_private::ConstString oso_path;
155 llvm::sys::TimePoint<> oso_mod_time;
157 lldb::CompUnitSP compile_unit_sp;
158 uint32_t first_symbol_index;
159 uint32_t last_symbol_index;
160 uint32_t first_symbol_id;
161 uint32_t last_symbol_id;
162 FileRangeMap file_range_map;
163 bool file_range_map_valid;
166 : so_file(), oso_path(), oso_mod_time(), oso_sp(), compile_unit_sp(),
167 first_symbol_index(UINT32_MAX), last_symbol_index(UINT32_MAX),
168 first_symbol_id(UINT32_MAX), last_symbol_id(UINT32_MAX),
169 file_range_map(), file_range_map_valid(false) {}
171 const FileRangeMap &GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
174 // Protected Member Functions
177 static uint32_t GetOSOIndexFromUserID(lldb::user_id_t uid) {
178 return (uint32_t)((uid >> 32ull) - 1ull);
181 static SymbolFileDWARF *GetSymbolFileAsSymbolFileDWARF(SymbolFile *sym_file);
183 bool GetFileSpecForSO(uint32_t oso_idx, lldb_private::FileSpec &file_spec);
185 CompileUnitInfo *GetCompUnitInfo(const lldb_private::SymbolContext &sc);
186 CompileUnitInfo *GetCompUnitInfo(const lldb_private::CompileUnit &comp_unit);
188 size_t GetCompUnitInfosForModule(const lldb_private::Module *oso_module,
189 std::vector<CompileUnitInfo *> &cu_infos);
191 lldb_private::Module *
192 GetModuleByCompUnitInfo(CompileUnitInfo *comp_unit_info);
194 lldb_private::Module *GetModuleByOSOIndex(uint32_t oso_idx);
196 lldb_private::ObjectFile *
197 GetObjectFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
199 lldb_private::ObjectFile *GetObjectFileByOSOIndex(uint32_t oso_idx);
201 uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info);
203 SymbolFileDWARF *GetSymbolFile(const lldb_private::SymbolContext &sc);
204 SymbolFileDWARF *GetSymbolFile(const lldb_private::CompileUnit &comp_unit);
206 SymbolFileDWARF *GetSymbolFileByCompUnitInfo(CompileUnitInfo *comp_unit_info);
208 SymbolFileDWARF *GetSymbolFileByOSOIndex(uint32_t oso_idx);
210 // If closure returns "false", iteration continues. If it returns
211 // "true", iteration terminates.
212 void ForEachSymbolFile(std::function<bool(SymbolFileDWARF *)> closure) {
213 for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
214 oso_idx < num_oso_idxs; ++oso_idx) {
215 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
216 if (closure(oso_dwarf))
222 CompileUnitInfo *GetCompileUnitInfoForSymbolWithIndex(uint32_t symbol_idx,
223 uint32_t *oso_idx_ptr);
225 CompileUnitInfo *GetCompileUnitInfoForSymbolWithID(lldb::user_id_t symbol_id,
226 uint32_t *oso_idx_ptr);
229 SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr,
230 const CompileUnitInfo *comp_unit_info);
232 static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr,
233 const CompileUnitInfo *comp_unit_info);
235 uint32_t PrivateFindGlobalVariables(
236 lldb_private::ConstString name,
237 const lldb_private::CompilerDeclContext *parent_decl_ctx,
238 const std::vector<uint32_t> &name_symbol_indexes, uint32_t max_matches,
239 lldb_private::VariableList &variables);
241 void SetCompileUnit(SymbolFileDWARF *oso_dwarf,
242 const lldb::CompUnitSP &cu_sp);
244 lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf);
246 CompileUnitInfo *GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf);
249 FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx);
251 bool Supports_DW_AT_APPLE_objc_complete_type(SymbolFileDWARF *skip_dwarf_oso);
253 lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(
254 const DWARFDIE &die, lldb_private::ConstString type_name,
255 bool must_be_implementation);
257 UniqueDWARFASTTypeMap &GetUniqueDWARFASTTypeMap() {
258 return m_unique_ast_type_map;
265 : m_exe_sym_idx(UINT32_MAX), m_oso_file_addr(LLDB_INVALID_ADDRESS) {}
267 OSOEntry(uint32_t exe_sym_idx, lldb::addr_t oso_file_addr)
268 : m_exe_sym_idx(exe_sym_idx), m_oso_file_addr(oso_file_addr) {}
270 uint32_t GetExeSymbolIndex() const { return m_exe_sym_idx; }
272 bool operator<(const OSOEntry &rhs) const {
273 return m_exe_sym_idx < rhs.m_exe_sym_idx;
276 lldb::addr_t GetOSOFileAddress() const { return m_oso_file_addr; }
278 void SetOSOFileAddress(lldb::addr_t oso_file_addr) {
279 m_oso_file_addr = oso_file_addr;
283 uint32_t m_exe_sym_idx;
284 lldb::addr_t m_oso_file_addr;
287 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry>
291 std::bitset<kNumFlags> m_flags;
292 std::vector<CompileUnitInfo> m_compile_unit_infos;
293 std::vector<uint32_t> m_func_indexes; // Sorted by address
294 std::vector<uint32_t> m_glob_indexes;
295 std::map<std::pair<lldb_private::ConstString, llvm::sys::TimePoint<>>,
298 UniqueDWARFASTTypeMap m_unique_ast_type_map;
299 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
300 DebugMap m_debug_map;
302 // When an object file from the debug map gets parsed in
303 // SymbolFileDWARF, it needs to tell the debug map about the object
304 // files addresses by calling this function once for each N_FUN,
305 // N_GSYM and N_STSYM and after all entries in the debug map have
306 // been matched up, FinalizeOSOFileRanges() should be called.
307 bool AddOSOFileRange(CompileUnitInfo *cu_info, lldb::addr_t exe_file_addr,
308 lldb::addr_t exe_byte_size, lldb::addr_t oso_file_addr,
309 lldb::addr_t oso_byte_size);
311 // Called after calling AddOSOFileRange() for each object file debug
312 // map entry to finalize the info for the unlinked compile unit.
313 void FinalizeOSOFileRanges(CompileUnitInfo *cu_info);
315 /// Convert \a addr from a .o file address, to an executable address.
318 /// A section offset address from a .o file
321 /// Returns true if \a addr was converted to be an executable
322 /// section/offset address, false otherwise.
323 bool LinkOSOAddress(lldb_private::Address &addr);
325 /// Convert a .o file "file address" to an executable "file address".
327 /// \param[in] oso_symfile
328 /// The DWARF symbol file that contains \a oso_file_addr
330 /// \param[in] oso_file_addr
331 /// A .o file "file address" to convert.
334 /// LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the
335 /// linked executable, otherwise a valid "file address" from the
336 /// linked executable that contains the debug map.
337 lldb::addr_t LinkOSOFileAddress(SymbolFileDWARF *oso_symfile,
338 lldb::addr_t oso_file_addr);
340 /// Given a line table full of lines with "file addresses" that are
341 /// for a .o file represented by \a oso_symfile, link a new line table
344 /// \param[in] oso_symfile
345 /// The DWARF symbol file that produced the \a line_table
348 /// A section offset address from a .o file
351 /// Returns a valid line table full of linked addresses, or NULL
352 /// if none of the line table addresses exist in the main
354 lldb_private::LineTable *
355 LinkOSOLineTable(SymbolFileDWARF *oso_symfile,
356 lldb_private::LineTable *line_table);
358 size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data,
359 DWARFDebugAranges *debug_aranges);
362 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_