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;
68 bool ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules) override;
69 size_t ParseFunctionBlocks (const lldb_private::SymbolContext& sc) override;
70 size_t ParseTypes (const lldb_private::SymbolContext& sc) override;
71 size_t ParseVariablesForContext (const lldb_private::SymbolContext& sc) override;
73 lldb_private::Type* ResolveTypeUID (lldb::user_id_t type_uid) override;
74 lldb_private::CompilerDeclContext GetDeclContextForUID (lldb::user_id_t uid) override;
75 lldb_private::CompilerDeclContext GetDeclContextContainingUID (lldb::user_id_t uid) override;
76 void ParseDeclsForContext (lldb_private::CompilerDeclContext decl_ctx) override;
78 bool CompleteType (lldb_private::CompilerType& compiler_type) override;
79 uint32_t ResolveSymbolContext (const lldb_private::Address& so_addr, uint32_t resolve_scope, lldb_private::SymbolContext& sc) override;
80 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;
81 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;
82 uint32_t FindGlobalVariables (const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb_private::VariableList& variables) override;
83 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;
84 uint32_t FindFunctions (const lldb_private::RegularExpression& regex, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list) override;
85 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, lldb_private::TypeMap& types) override;
86 lldb_private::CompilerDeclContext
87 FindNamespace (const lldb_private::SymbolContext& sc,
88 const lldb_private::ConstString &name,
89 const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
90 size_t GetTypes (lldb_private::SymbolContextScope *sc_scope,
92 lldb_private::TypeList &type_list) override;
94 //------------------------------------------------------------------
95 // PluginInterface protocol
96 //------------------------------------------------------------------
97 lldb_private::ConstString
98 GetPluginName() override;
101 GetPluginVersion() override;
106 kHaveInitializedOSOs = (1 << 0),
110 friend class DWARFCompileUnit;
111 friend class SymbolFileDWARF;
112 friend class DebugMapModule;
113 friend class DWARFASTParserClang;
116 lldb::ModuleSP module_sp;
124 typedef std::shared_ptr<OSOInfo> OSOInfoSP;
126 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, lldb::addr_t> FileRangeMap;
128 //------------------------------------------------------------------
129 // Class specific types
130 //------------------------------------------------------------------
131 struct CompileUnitInfo
133 lldb_private::FileSpec so_file;
134 lldb_private::ConstString oso_path;
135 lldb_private::TimeValue oso_mod_time;
137 lldb::CompUnitSP compile_unit_sp;
138 uint32_t first_symbol_index;
139 uint32_t last_symbol_index;
140 uint32_t first_symbol_id;
141 uint32_t last_symbol_id;
142 FileRangeMap file_range_map;
143 bool file_range_map_valid;
152 first_symbol_index (UINT32_MAX),
153 last_symbol_index (UINT32_MAX),
154 first_symbol_id (UINT32_MAX),
155 last_symbol_id (UINT32_MAX),
157 file_range_map_valid (false)
162 GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
165 //------------------------------------------------------------------
166 // Protected Member Functions
167 //------------------------------------------------------------------
172 GetOSOIndexFromUserID (lldb::user_id_t uid)
174 return (uint32_t)((uid >> 32ull) - 1ull);
177 static SymbolFileDWARF *
178 GetSymbolFileAsSymbolFileDWARF (SymbolFile *sym_file);
181 GetFileSpecForSO (uint32_t oso_idx, lldb_private::FileSpec &file_spec);
184 GetCompUnitInfo (const lldb_private::SymbolContext& sc);
187 GetCompUnitInfosForModule (const lldb_private::Module *oso_module,
188 std::vector<CompileUnitInfo *>& cu_infos);
190 lldb_private::Module *
191 GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info);
193 lldb_private::Module *
194 GetModuleByOSOIndex (uint32_t oso_idx);
196 lldb_private::ObjectFile *
197 GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
199 lldb_private::ObjectFile *
200 GetObjectFileByOSOIndex (uint32_t oso_idx);
203 GetCompUnitInfoIndex (const CompileUnitInfo *comp_unit_info);
206 GetSymbolFile (const lldb_private::SymbolContext& sc);
209 GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info);
212 GetSymbolFileByOSOIndex (uint32_t oso_idx);
214 // If closure returns "false", iteration continues. If it returns
215 // "true", iteration terminates.
217 ForEachSymbolFile (std::function<bool (SymbolFileDWARF *)> closure)
219 for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
220 oso_idx < num_oso_idxs;
223 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx))
225 if (closure(oso_dwarf))
232 GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr);
235 GetCompileUnitInfoForSymbolWithID (lldb::user_id_t symbol_id, uint32_t *oso_idx_ptr);
238 SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
241 SymbolContainsSymbolWithID (lldb::user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info);
244 PrivateFindGlobalVariables (const lldb_private::ConstString &name,
245 const lldb_private::CompilerDeclContext *parent_decl_ctx,
246 const std::vector<uint32_t> &name_symbol_indexes,
247 uint32_t max_matches,
248 lldb_private::VariableList& variables);
252 SetCompileUnit (SymbolFileDWARF *oso_dwarf, const lldb::CompUnitSP &cu_sp);
255 GetCompileUnit (SymbolFileDWARF *oso_dwarf);
258 GetCompileUnitInfo (SymbolFileDWARF *oso_dwarf);
261 FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx);
264 Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso);
267 FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die,
268 const lldb_private::ConstString &type_name,
269 bool must_be_implementation);
272 UniqueDWARFASTTypeMap &
273 GetUniqueDWARFASTTypeMap ()
275 return m_unique_ast_type_map;
279 //------------------------------------------------------------------
281 //------------------------------------------------------------------
287 m_exe_sym_idx (UINT32_MAX),
288 m_oso_file_addr (LLDB_INVALID_ADDRESS)
292 OSOEntry (uint32_t exe_sym_idx,
293 lldb::addr_t oso_file_addr) :
294 m_exe_sym_idx (exe_sym_idx),
295 m_oso_file_addr (oso_file_addr)
300 GetExeSymbolIndex () const
302 return m_exe_sym_idx;
306 operator < (const OSOEntry &rhs) const
308 return m_exe_sym_idx < rhs.m_exe_sym_idx;
312 GetOSOFileAddress () const
314 return m_oso_file_addr;
318 SetOSOFileAddress (lldb::addr_t oso_file_addr)
320 m_oso_file_addr = oso_file_addr;
323 uint32_t m_exe_sym_idx;
324 lldb::addr_t m_oso_file_addr;
327 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry> DebugMap;
329 //------------------------------------------------------------------
331 //------------------------------------------------------------------
332 std::bitset<kNumFlags> m_flags;
333 std::vector<CompileUnitInfo> m_compile_unit_infos;
334 std::vector<uint32_t> m_func_indexes; // Sorted by address
335 std::vector<uint32_t> m_glob_indexes;
336 std::map<lldb_private::ConstString, OSOInfoSP> m_oso_map;
337 UniqueDWARFASTTypeMap m_unique_ast_type_map;
338 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type;
339 DebugMap m_debug_map;
341 //------------------------------------------------------------------
342 // When an object file from the debug map gets parsed in
343 // SymbolFileDWARF, it needs to tell the debug map about the object
344 // files addresses by calling this function once for each N_FUN,
345 // N_GSYM and N_STSYM and after all entries in the debug map have
346 // been matched up, FinalizeOSOFileRanges() should be called.
347 //------------------------------------------------------------------
349 AddOSOFileRange (CompileUnitInfo *cu_info,
350 lldb::addr_t exe_file_addr,
351 lldb::addr_t oso_file_addr,
352 lldb::addr_t oso_byte_size);
354 //------------------------------------------------------------------
355 // Called after calling AddOSOFileRange() for each object file debug
356 // map entry to finalize the info for the unlinked compile unit.
357 //------------------------------------------------------------------
359 FinalizeOSOFileRanges (CompileUnitInfo *cu_info);
361 //------------------------------------------------------------------
362 /// Convert \a addr from a .o file address, to an executable address.
365 /// A section offset address from a .o file
368 /// Returns true if \a addr was converted to be an executable
369 /// section/offset address, false otherwise.
370 //------------------------------------------------------------------
372 LinkOSOAddress (lldb_private::Address &addr);
374 //------------------------------------------------------------------
375 /// Convert a .o file "file address" to an executable "file address".
377 /// @param[in] oso_symfile
378 /// The DWARF symbol file that contains \a oso_file_addr
380 /// @param[in] oso_file_addr
381 /// A .o file "file address" to convert.
384 /// LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the
385 /// linked executable, otherwise a valid "file address" from the
386 /// linked executable that contains the debug map.
387 //------------------------------------------------------------------
389 LinkOSOFileAddress (SymbolFileDWARF *oso_symfile, lldb::addr_t oso_file_addr);
391 //------------------------------------------------------------------
392 /// Given a line table full of lines with "file addresses" that are
393 /// for a .o file represented by \a oso_symfile, link a new line table
396 /// @param[in] oso_symfile
397 /// The DWARF symbol file that produced the \a line_table
400 /// A section offset address from a .o file
403 /// Returns a valid line table full of linked addresses, or NULL
404 /// if none of the line table addresses exist in the main
406 //------------------------------------------------------------------
407 lldb_private::LineTable *
408 LinkOSOLineTable (SymbolFileDWARF *oso_symfile,
409 lldb_private::LineTable *line_table);
412 AddOSOARanges (SymbolFileDWARF* dwarf2Data,
413 DWARFDebugAranges* debug_aranges);
416 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_