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 "clang/AST/CharUnits.h"
19 #include "lldb/Core/RangeMap.h"
20 #include "lldb/Symbol/SymbolFile.h"
22 #include "UniqueDWARFASTType.h"
24 class SymbolFileDWARF;
25 class DWARFCompileUnit;
26 class DWARFDebugAranges;
27 class DWARFDebugInfoEntry;
28 class DWARFDeclContext;
31 class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile
35 //------------------------------------------------------------------
37 //------------------------------------------------------------------
44 static lldb_private::ConstString
45 GetPluginNameStatic();
48 GetPluginDescriptionStatic();
50 static lldb_private::SymbolFile *
51 CreateInstance (lldb_private::ObjectFile* obj_file);
53 //------------------------------------------------------------------
54 // Constructors and Destructors
55 //------------------------------------------------------------------
56 SymbolFileDWARFDebugMap (lldb_private::ObjectFile* ofile);
57 ~SymbolFileDWARFDebugMap () override;
59 uint32_t CalculateAbilities () override;
61 void InitializeObject() override;
63 //------------------------------------------------------------------
64 // Compile Unit function calls
65 //------------------------------------------------------------------
66 uint32_t GetNumCompileUnits () override;
67 lldb::CompUnitSP ParseCompileUnitAtIndex (uint32_t index) override;
69 lldb::LanguageType ParseCompileUnitLanguage (const lldb_private::SymbolContext& sc) override;
70 size_t ParseCompileUnitFunctions (const lldb_private::SymbolContext& sc) override;
71 bool ParseCompileUnitLineTable (const lldb_private::SymbolContext& sc) override;
72 bool ParseCompileUnitSupportFiles (const lldb_private::SymbolContext& sc, lldb_private::FileSpecList &support_files) override;
73 bool ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules) override;
74 size_t ParseFunctionBlocks (const lldb_private::SymbolContext& sc) override;
75 size_t ParseTypes (const lldb_private::SymbolContext& sc) override;
76 size_t ParseVariablesForContext (const lldb_private::SymbolContext& sc) override;
78 lldb_private::Type* ResolveTypeUID (lldb::user_id_t type_uid) override;
79 clang::DeclContext* GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid) override;
80 clang::DeclContext* GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid) override;
81 bool ResolveClangOpaqueTypeDefinition (lldb_private::ClangASTType& clang_type) override;
82 uint32_t ResolveSymbolContext (const lldb_private::Address& so_addr, uint32_t resolve_scope, lldb_private::SymbolContext& sc) override;
83 uint32_t ResolveSymbolContext (const lldb_private::FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, lldb_private::SymbolContextList& sc_list) override;
84 uint32_t FindGlobalVariables (const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, lldb_private::VariableList& variables) override;
85 uint32_t FindGlobalVariables (const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb_private::VariableList& variables) override;
86 uint32_t FindFunctions (const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list) override;
87 uint32_t FindFunctions (const lldb_private::RegularExpression& regex, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list) override;
88 uint32_t FindTypes (const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, lldb_private::TypeList& types) override;
89 lldb_private::ClangNamespaceDecl
90 FindNamespace (const lldb_private::SymbolContext& sc,
91 const lldb_private::ConstString &name,
92 const lldb_private::ClangNamespaceDecl *parent_namespace_decl) override;
93 size_t GetTypes (lldb_private::SymbolContextScope *sc_scope,
95 lldb_private::TypeList &type_list) override;
98 //------------------------------------------------------------------
99 // ClangASTContext callbacks for external source lookups.
100 //------------------------------------------------------------------
102 CompleteTagDecl (void *baton, clang::TagDecl *);
105 CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *);
107 static bool LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size, uint64_t &alignment,
108 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
109 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
110 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets);
112 //------------------------------------------------------------------
113 // PluginInterface protocol
114 //------------------------------------------------------------------
115 lldb_private::ConstString
116 GetPluginName() override;
119 GetPluginVersion() override;
124 kHaveInitializedOSOs = (1 << 0),
128 friend class DWARFCompileUnit;
129 friend class SymbolFileDWARF;
130 friend class DebugMapModule;
133 lldb::ModuleSP module_sp;
141 typedef std::shared_ptr<OSOInfo> OSOInfoSP;
143 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, lldb::addr_t> FileRangeMap;
145 //------------------------------------------------------------------
146 // Class specific types
147 //------------------------------------------------------------------
148 struct CompileUnitInfo
150 lldb_private::FileSpec so_file;
151 lldb_private::ConstString oso_path;
152 lldb_private::TimeValue oso_mod_time;
154 lldb::CompUnitSP compile_unit_sp;
155 uint32_t first_symbol_index;
156 uint32_t last_symbol_index;
157 uint32_t first_symbol_id;
158 uint32_t last_symbol_id;
159 FileRangeMap file_range_map;
160 bool file_range_map_valid;
169 first_symbol_index (UINT32_MAX),
170 last_symbol_index (UINT32_MAX),
171 first_symbol_id (UINT32_MAX),
172 last_symbol_id (UINT32_MAX),
174 file_range_map_valid (false)
179 GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
182 //------------------------------------------------------------------
183 // Protected Member Functions
184 //------------------------------------------------------------------
189 GetOSOIndexFromUserID (lldb::user_id_t uid)
191 return (uint32_t)((uid >> 32ull) - 1ull);
194 static SymbolFileDWARF *
195 GetSymbolFileAsSymbolFileDWARF (SymbolFile *sym_file);
198 GetFileSpecForSO (uint32_t oso_idx, lldb_private::FileSpec &file_spec);
201 GetCompUnitInfo (const lldb_private::SymbolContext& sc);
204 GetCompUnitInfosForModule (const lldb_private::Module *oso_module,
205 std::vector<CompileUnitInfo *>& cu_infos);
207 lldb_private::Module *
208 GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info);
210 lldb_private::Module *
211 GetModuleByOSOIndex (uint32_t oso_idx);
213 lldb_private::ObjectFile *
214 GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
216 lldb_private::ObjectFile *
217 GetObjectFileByOSOIndex (uint32_t oso_idx);
220 GetCompUnitInfoIndex (const CompileUnitInfo *comp_unit_info);
223 GetSymbolFile (const lldb_private::SymbolContext& sc);
226 GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
229 GetSymbolFileByOSOIndex (uint32_t oso_idx);
231 // If closure returns "false", iteration continues. If it returns
232 // "true", iteration terminates.
234 ForEachSymbolFile (std::function<bool (SymbolFileDWARF *)> closure)
236 for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
237 oso_idx < num_oso_idxs;
240 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx))
242 if (closure(oso_dwarf))
249 GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr);
252 GetCompileUnitInfoForSymbolWithID (lldb::user_id_t symbol_id, uint32_t *oso_idx_ptr);
255 SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
258 SymbolContainsSymbolWithID (lldb::user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
261 PrivateFindGlobalVariables (const lldb_private::ConstString &name,
262 const lldb_private::ClangNamespaceDecl *namespace_decl,
263 const std::vector<uint32_t> &name_symbol_indexes,
264 uint32_t max_matches,
265 lldb_private::VariableList& variables);
269 SetCompileUnit (SymbolFileDWARF *oso_dwarf, const lldb::CompUnitSP &cu_sp);
272 GetCompileUnit (SymbolFileDWARF *oso_dwarf);
275 GetCompileUnitInfo (SymbolFileDWARF *oso_dwarf);
278 FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx);
281 Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso);
284 FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
285 const lldb_private::ConstString &type_name,
286 bool must_be_implementation);
289 UniqueDWARFASTTypeMap &
290 GetUniqueDWARFASTTypeMap ()
292 return m_unique_ast_type_map;
296 //------------------------------------------------------------------
298 //------------------------------------------------------------------
304 m_exe_sym_idx (UINT32_MAX),
305 m_oso_file_addr (LLDB_INVALID_ADDRESS)
309 OSOEntry (uint32_t exe_sym_idx,
310 lldb::addr_t oso_file_addr) :
311 m_exe_sym_idx (exe_sym_idx),
312 m_oso_file_addr (oso_file_addr)
317 GetExeSymbolIndex () const
319 return m_exe_sym_idx;
323 operator < (const OSOEntry &rhs) const
325 return m_exe_sym_idx < rhs.m_exe_sym_idx;
329 GetOSOFileAddress () const
331 return m_oso_file_addr;
335 SetOSOFileAddress (lldb::addr_t oso_file_addr)
337 m_oso_file_addr = oso_file_addr;
340 uint32_t m_exe_sym_idx;
341 lldb::addr_t m_oso_file_addr;
344 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry> DebugMap;
346 //------------------------------------------------------------------
348 //------------------------------------------------------------------
349 std::bitset<kNumFlags> m_flags;
350 std::vector<CompileUnitInfo> m_compile_unit_infos;
351 std::vector<uint32_t> m_func_indexes; // Sorted by address
352 std::vector<uint32_t> m_glob_indexes;
353 std::map<lldb_private::ConstString, OSOInfoSP> m_oso_map;
354 UniqueDWARFASTTypeMap m_unique_ast_type_map;
355 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
356 DebugMap m_debug_map;
358 //------------------------------------------------------------------
359 // When an object file from the debug map gets parsed in
360 // SymbolFileDWARF, it needs to tell the debug map about the object
361 // files addresses by calling this function once for each N_FUN,
362 // N_GSYM and N_STSYM and after all entries in the debug map have
363 // been matched up, FinalizeOSOFileRanges() should be called.
364 //------------------------------------------------------------------
366 AddOSOFileRange (CompileUnitInfo *cu_info,
367 lldb::addr_t exe_file_addr,
368 lldb::addr_t oso_file_addr,
369 lldb::addr_t oso_byte_size);
371 //------------------------------------------------------------------
372 // Called after calling AddOSOFileRange() for each object file debug
373 // map entry to finalize the info for the unlinked compile unit.
374 //------------------------------------------------------------------
376 FinalizeOSOFileRanges (CompileUnitInfo *cu_info);
378 //------------------------------------------------------------------
379 /// Convert \a addr from a .o file address, to an executable address.
382 /// A section offset address from a .o file
385 /// Returns true if \a addr was converted to be an executable
386 /// section/offset address, false otherwise.
387 //------------------------------------------------------------------
389 LinkOSOAddress (lldb_private::Address &addr);
391 //------------------------------------------------------------------
392 /// Convert a .o file "file address" to an executable "file address".
394 /// @param[in] oso_symfile
395 /// The DWARF symbol file that contains \a oso_file_addr
397 /// @param[in] oso_file_addr
398 /// A .o file "file address" to convert.
401 /// LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the
402 /// linked executable, otherwise a valid "file address" from the
403 /// linked executable that contains the debug map.
404 //------------------------------------------------------------------
406 LinkOSOFileAddress (SymbolFileDWARF *oso_symfile, lldb::addr_t oso_file_addr);
408 //------------------------------------------------------------------
409 /// Given a line table full of lines with "file addresses" that are
410 /// for a .o file represented by \a oso_symfile, link a new line table
413 /// @param[in] oso_symfile
414 /// The DWARF symbol file that produced the \a line_table
417 /// A section offset address from a .o file
420 /// Returns a valid line table full of linked addresses, or NULL
421 /// if none of the line table addresses exist in the main
423 //------------------------------------------------------------------
424 lldb_private::LineTable *
425 LinkOSOLineTable (SymbolFileDWARF *oso_symfile,
426 lldb_private::LineTable *line_table);
429 AddOSOARanges (SymbolFileDWARF* dwarf2Data,
430 DWARFDebugAranges* debug_aranges);
433 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_