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 "lldb/Core/RangeMap.h"
18 #include "lldb/Symbol/SymbolFile.h"
20 #include "UniqueDWARFASTType.h"
22 class SymbolFileDWARF;
23 class DWARFDebugAranges;
24 class DWARFDeclContext;
26 class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile
30 //------------------------------------------------------------------
32 //------------------------------------------------------------------
39 static lldb_private::ConstString
40 GetPluginNameStatic();
43 GetPluginDescriptionStatic();
45 static lldb_private::SymbolFile *
46 CreateInstance (lldb_private::ObjectFile* obj_file);
48 //------------------------------------------------------------------
49 // Constructors and Destructors
50 //------------------------------------------------------------------
51 SymbolFileDWARFDebugMap (lldb_private::ObjectFile* ofile);
52 ~SymbolFileDWARFDebugMap () override;
54 uint32_t CalculateAbilities () override;
55 void InitializeObject() override;
57 //------------------------------------------------------------------
58 // Compile Unit function calls
59 //------------------------------------------------------------------
60 uint32_t GetNumCompileUnits () override;
61 lldb::CompUnitSP ParseCompileUnitAtIndex (uint32_t index) override;
63 lldb::LanguageType ParseCompileUnitLanguage (const lldb_private::SymbolContext& sc) override;
64 size_t ParseCompileUnitFunctions (const lldb_private::SymbolContext& sc) override;
65 bool ParseCompileUnitLineTable (const lldb_private::SymbolContext& sc) override;
66 bool ParseCompileUnitDebugMacros (const lldb_private::SymbolContext& sc) override;
67 bool ParseCompileUnitSupportFiles (const lldb_private::SymbolContext& sc, lldb_private::FileSpecList &support_files) override;
69 ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc) override;
70 bool ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules) override;
71 size_t ParseFunctionBlocks (const lldb_private::SymbolContext& sc) override;
72 size_t ParseTypes (const lldb_private::SymbolContext& sc) override;
73 size_t ParseVariablesForContext (const lldb_private::SymbolContext& sc) override;
75 lldb_private::Type* ResolveTypeUID (lldb::user_id_t type_uid) override;
76 lldb_private::CompilerDeclContext GetDeclContextForUID (lldb::user_id_t uid) override;
77 lldb_private::CompilerDeclContext GetDeclContextContainingUID (lldb::user_id_t uid) override;
78 void ParseDeclsForContext (lldb_private::CompilerDeclContext decl_ctx) override;
80 bool CompleteType (lldb_private::CompilerType& compiler_type) override;
81 uint32_t ResolveSymbolContext (const lldb_private::Address& so_addr, uint32_t resolve_scope, lldb_private::SymbolContext& sc) override;
82 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;
83 uint32_t FindGlobalVariables (const lldb_private::ConstString &name, const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, lldb_private::VariableList& variables) override;
84 uint32_t FindGlobalVariables (const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb_private::VariableList& variables) override;
85 uint32_t FindFunctions (const lldb_private::ConstString &name, const lldb_private::CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list) override;
86 uint32_t FindFunctions (const lldb_private::RegularExpression& regex, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list) override;
87 uint32_t FindTypes (const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, lldb_private::TypeMap& types) override;
88 lldb_private::CompilerDeclContext
89 FindNamespace (const lldb_private::SymbolContext& sc,
90 const lldb_private::ConstString &name,
91 const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
92 size_t GetTypes (lldb_private::SymbolContextScope *sc_scope,
94 lldb_private::TypeList &type_list) override;
96 //------------------------------------------------------------------
97 // PluginInterface protocol
98 //------------------------------------------------------------------
99 lldb_private::ConstString
100 GetPluginName() override;
103 GetPluginVersion() override;
108 kHaveInitializedOSOs = (1 << 0),
112 friend class DebugMapModule;
113 friend struct DIERef;
114 friend class DWARFASTParserClang;
115 friend class DWARFCompileUnit;
116 friend class SymbolFileDWARF;
119 lldb::ModuleSP module_sp;
127 typedef std::shared_ptr<OSOInfo> OSOInfoSP;
129 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, lldb::addr_t> FileRangeMap;
131 //------------------------------------------------------------------
132 // Class specific types
133 //------------------------------------------------------------------
134 struct CompileUnitInfo
136 lldb_private::FileSpec so_file;
137 lldb_private::ConstString oso_path;
138 lldb_private::TimeValue oso_mod_time;
140 lldb::CompUnitSP compile_unit_sp;
141 uint32_t first_symbol_index;
142 uint32_t last_symbol_index;
143 uint32_t first_symbol_id;
144 uint32_t last_symbol_id;
145 FileRangeMap file_range_map;
146 bool file_range_map_valid;
155 first_symbol_index (UINT32_MAX),
156 last_symbol_index (UINT32_MAX),
157 first_symbol_id (UINT32_MAX),
158 last_symbol_id (UINT32_MAX),
160 file_range_map_valid (false)
165 GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
168 //------------------------------------------------------------------
169 // Protected Member Functions
170 //------------------------------------------------------------------
175 GetOSOIndexFromUserID (lldb::user_id_t uid)
177 return (uint32_t)((uid >> 32ull) - 1ull);
180 static SymbolFileDWARF *
181 GetSymbolFileAsSymbolFileDWARF (SymbolFile *sym_file);
184 GetFileSpecForSO (uint32_t oso_idx, lldb_private::FileSpec &file_spec);
187 GetCompUnitInfo (const lldb_private::SymbolContext& sc);
190 GetCompUnitInfosForModule (const lldb_private::Module *oso_module,
191 std::vector<CompileUnitInfo *>& cu_infos);
193 lldb_private::Module *
194 GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info);
196 lldb_private::Module *
197 GetModuleByOSOIndex (uint32_t oso_idx);
199 lldb_private::ObjectFile *
200 GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
202 lldb_private::ObjectFile *
203 GetObjectFileByOSOIndex (uint32_t oso_idx);
206 GetCompUnitInfoIndex (const CompileUnitInfo *comp_unit_info);
209 GetSymbolFile (const lldb_private::SymbolContext& sc);
212 GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
215 GetSymbolFileByOSOIndex (uint32_t oso_idx);
217 // If closure returns "false", iteration continues. If it returns
218 // "true", iteration terminates.
220 ForEachSymbolFile (std::function<bool (SymbolFileDWARF *)> closure)
222 for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
223 oso_idx < num_oso_idxs;
226 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx))
228 if (closure(oso_dwarf))
235 GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr);
238 GetCompileUnitInfoForSymbolWithID (lldb::user_id_t symbol_id, uint32_t *oso_idx_ptr);
241 SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
244 SymbolContainsSymbolWithID (lldb::user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
247 PrivateFindGlobalVariables (const lldb_private::ConstString &name,
248 const lldb_private::CompilerDeclContext *parent_decl_ctx,
249 const std::vector<uint32_t> &name_symbol_indexes,
250 uint32_t max_matches,
251 lldb_private::VariableList& variables);
255 SetCompileUnit (SymbolFileDWARF *oso_dwarf, const lldb::CompUnitSP &cu_sp);
258 GetCompileUnit (SymbolFileDWARF *oso_dwarf);
261 GetCompileUnitInfo (SymbolFileDWARF *oso_dwarf);
264 FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx);
267 Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso);
270 FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die,
271 const lldb_private::ConstString &type_name,
272 bool must_be_implementation);
275 UniqueDWARFASTTypeMap &
276 GetUniqueDWARFASTTypeMap ()
278 return m_unique_ast_type_map;
282 //------------------------------------------------------------------
284 //------------------------------------------------------------------
290 m_exe_sym_idx (UINT32_MAX),
291 m_oso_file_addr (LLDB_INVALID_ADDRESS)
295 OSOEntry (uint32_t exe_sym_idx,
296 lldb::addr_t oso_file_addr) :
297 m_exe_sym_idx (exe_sym_idx),
298 m_oso_file_addr (oso_file_addr)
303 GetExeSymbolIndex () const
305 return m_exe_sym_idx;
309 operator < (const OSOEntry &rhs) const
311 return m_exe_sym_idx < rhs.m_exe_sym_idx;
315 GetOSOFileAddress () const
317 return m_oso_file_addr;
321 SetOSOFileAddress (lldb::addr_t oso_file_addr)
323 m_oso_file_addr = oso_file_addr;
326 uint32_t m_exe_sym_idx;
327 lldb::addr_t m_oso_file_addr;
330 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry> DebugMap;
332 //------------------------------------------------------------------
334 //------------------------------------------------------------------
335 std::bitset<kNumFlags> m_flags;
336 std::vector<CompileUnitInfo> m_compile_unit_infos;
337 std::vector<uint32_t> m_func_indexes; // Sorted by address
338 std::vector<uint32_t> m_glob_indexes;
339 std::map<lldb_private::ConstString, OSOInfoSP> m_oso_map;
340 UniqueDWARFASTTypeMap m_unique_ast_type_map;
341 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
342 DebugMap m_debug_map;
344 //------------------------------------------------------------------
345 // When an object file from the debug map gets parsed in
346 // SymbolFileDWARF, it needs to tell the debug map about the object
347 // files addresses by calling this function once for each N_FUN,
348 // N_GSYM and N_STSYM and after all entries in the debug map have
349 // been matched up, FinalizeOSOFileRanges() should be called.
350 //------------------------------------------------------------------
352 AddOSOFileRange (CompileUnitInfo *cu_info,
353 lldb::addr_t exe_file_addr,
354 lldb::addr_t exe_byte_size,
355 lldb::addr_t oso_file_addr,
356 lldb::addr_t oso_byte_size);
358 //------------------------------------------------------------------
359 // Called after calling AddOSOFileRange() for each object file debug
360 // map entry to finalize the info for the unlinked compile unit.
361 //------------------------------------------------------------------
363 FinalizeOSOFileRanges (CompileUnitInfo *cu_info);
365 //------------------------------------------------------------------
366 /// Convert \a addr from a .o file address, to an executable address.
369 /// A section offset address from a .o file
372 /// Returns true if \a addr was converted to be an executable
373 /// section/offset address, false otherwise.
374 //------------------------------------------------------------------
376 LinkOSOAddress (lldb_private::Address &addr);
378 //------------------------------------------------------------------
379 /// Convert a .o file "file address" to an executable "file address".
381 /// @param[in] oso_symfile
382 /// The DWARF symbol file that contains \a oso_file_addr
384 /// @param[in] oso_file_addr
385 /// A .o file "file address" to convert.
388 /// LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the
389 /// linked executable, otherwise a valid "file address" from the
390 /// linked executable that contains the debug map.
391 //------------------------------------------------------------------
393 LinkOSOFileAddress (SymbolFileDWARF *oso_symfile, lldb::addr_t oso_file_addr);
395 //------------------------------------------------------------------
396 /// Given a line table full of lines with "file addresses" that are
397 /// for a .o file represented by \a oso_symfile, link a new line table
400 /// @param[in] oso_symfile
401 /// The DWARF symbol file that produced the \a line_table
404 /// A section offset address from a .o file
407 /// Returns a valid line table full of linked addresses, or NULL
408 /// if none of the line table addresses exist in the main
410 //------------------------------------------------------------------
411 lldb_private::LineTable *
412 LinkOSOLineTable (SymbolFileDWARF *oso_symfile,
413 lldb_private::LineTable *line_table);
416 AddOSOARanges (SymbolFileDWARF* dwarf2Data,
417 DWARFDebugAranges* debug_aranges);
420 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_