LLDB  mainline
SymbolFileDWARFDebugMap.h
Go to the documentation of this file.
1 //===-- SymbolFileDWARFDebugMap.h ------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_SYMBOLFILEDWARFDEBUGMAP_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_SYMBOLFILEDWARFDEBUGMAP_H
11 
12 #include "lldb/Symbol/SymbolFile.h"
13 #include "lldb/Utility/RangeMap.h"
14 #include "llvm/Support/Chrono.h"
15 #include <bitset>
16 #include <map>
17 #include <vector>
18 
19 #include "UniqueDWARFASTType.h"
20 
21 class SymbolFileDWARF;
22 class DWARFDebugAranges;
23 class DWARFDeclContext;
24 
26  /// LLVM RTTI support.
27  static char ID;
28 
29 public:
30  /// LLVM RTTI support.
31  /// \{
32  bool isA(const void *ClassID) const override {
33  return ClassID == &ID || SymbolFile::isA(ClassID);
34  }
35  static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
36  /// \}
37 
38  // Static Functions
39  static void Initialize();
40 
41  static void Terminate();
42 
44 
45  static const char *GetPluginDescriptionStatic();
46 
48  CreateInstance(lldb::ObjectFileSP objfile_sp);
49 
50  // Constructors and Destructors
51  SymbolFileDWARFDebugMap(lldb::ObjectFileSP objfile_sp);
52  ~SymbolFileDWARFDebugMap() override;
53 
54  uint32_t CalculateAbilities() override;
55  void InitializeObject() override;
56 
57  // Compile Unit function calls
59  ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
61  ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override;
62  size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
63  bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
64  bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
65 
67  lldb_private::CompileUnit &, llvm::DenseSet<lldb_private::SymbolFile *> &,
68  llvm::function_ref<bool(lldb_private::Module &)>) override;
69 
71  lldb_private::FileSpecList &support_files) override;
72 
73  bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override;
74 
75  size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
76 
79  std::vector<lldb_private::SourceModule> &imported_modules) override;
80  size_t ParseBlocksRecursive(lldb_private::Function &func) override;
81  size_t
83 
85  llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
86  lldb::user_id_t type_uid,
87  const lldb_private::ExecutionContext *exe_ctx) override;
88 
93  void
95 
96  bool CompleteType(lldb_private::CompilerType &compiler_type) override;
98  lldb::SymbolContextItem resolve_scope,
99  lldb_private::SymbolContext &sc) override;
100  uint32_t
102  bool check_inlines,
103  lldb::SymbolContextItem resolve_scope,
104  lldb_private::SymbolContextList &sc_list) override;
105  void
107  const lldb_private::CompilerDeclContext &parent_decl_ctx,
108  uint32_t max_matches,
109  lldb_private::VariableList &variables) override;
111  uint32_t max_matches,
112  lldb_private::VariableList &variables) override;
114  const lldb_private::CompilerDeclContext &parent_decl_ctx,
115  lldb::FunctionNameType name_type_mask,
116  bool include_inlines,
117  lldb_private::SymbolContextList &sc_list) override;
119  bool include_inlines,
120  lldb_private::SymbolContextList &sc_list) override;
121  void
123  const lldb_private::CompilerDeclContext &parent_decl_ctx,
124  uint32_t max_matches,
125  llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
126  lldb_private::TypeMap &types) override;
127  void
128  FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> context,
129  lldb_private::LanguageSet languages,
130  llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
131  lldb_private::TypeMap &types) override;
134  const lldb_private::CompilerDeclContext &parent_decl_ctx) override;
136  lldb::TypeClass type_mask,
137  lldb_private::TypeList &type_list) override;
138  std::vector<std::unique_ptr<lldb_private::CallEdge>>
140 
141  void DumpClangAST(lldb_private::Stream &s) override;
142 
143  // PluginInterface protocol
145 
146  uint32_t GetPluginVersion() override;
147 
148 protected:
149  enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
150 
151  friend class DebugMapModule;
152  friend class DWARFASTParserClang;
153  friend class DWARFCompileUnit;
154  friend class SymbolFileDWARF;
155  struct OSOInfo {
156  lldb::ModuleSP module_sp;
157 
158  OSOInfo() : module_sp() {}
159  };
160 
161  typedef std::shared_ptr<OSOInfo> OSOInfoSP;
162 
164  lldb::addr_t>
166 
167  // Class specific types
171  llvm::sys::TimePoint<> oso_mod_time;
172  OSOInfoSP oso_sp;
173  lldb::CompUnitSP compile_unit_sp;
180 
182  : so_file(), oso_path(), oso_mod_time(), oso_sp(), compile_unit_sp(),
183  first_symbol_index(UINT32_MAX), last_symbol_index(UINT32_MAX),
184  first_symbol_id(UINT32_MAX), last_symbol_id(UINT32_MAX),
185  file_range_map(), file_range_map_valid(false) {}
186 
187  const FileRangeMap &GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
188  };
189 
190  // Protected Member Functions
191  void InitOSO();
192 
194  lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
195 
197  return (uint32_t)((uid >> 32ull) - 1ull);
198  }
199 
201 
202  bool GetFileSpecForSO(uint32_t oso_idx, lldb_private::FileSpec &file_spec);
203 
206 
207  size_t GetCompUnitInfosForModule(const lldb_private::Module *oso_module,
208  std::vector<CompileUnitInfo *> &cu_infos);
209 
211  GetModuleByCompUnitInfo(CompileUnitInfo *comp_unit_info);
212 
214 
217 
219 
220  uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info);
221 
224 
226 
228 
229  // If closure returns "false", iteration continues. If it returns
230  // "true", iteration terminates.
231  void ForEachSymbolFile(std::function<bool(SymbolFileDWARF *)> closure) {
232  for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
233  oso_idx < num_oso_idxs; ++oso_idx) {
234  if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
235  if (closure(oso_dwarf))
236  return;
237  }
238  }
239  }
240 
242  uint32_t *oso_idx_ptr);
243 
245  uint32_t *oso_idx_ptr);
246 
247  static int
248  SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr,
249  const CompileUnitInfo *comp_unit_info);
250 
251  static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr,
252  const CompileUnitInfo *comp_unit_info);
253 
256  const lldb_private::CompilerDeclContext &parent_decl_ctx,
257  const std::vector<uint32_t> &name_symbol_indexes, uint32_t max_matches,
258  lldb_private::VariableList &variables);
259 
260  void SetCompileUnit(SymbolFileDWARF *oso_dwarf,
261  const lldb::CompUnitSP &cu_sp);
262 
263  lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf);
264 
266 
267  lldb::TypeSP
269 
271 
273  const DWARFDIE &die, lldb_private::ConstString type_name,
274  bool must_be_implementation);
275 
277  return m_unique_ast_type_map;
278  }
279 
280  // OSOEntry
281  class OSOEntry {
282  public:
284  : m_exe_sym_idx(UINT32_MAX), m_oso_file_addr(LLDB_INVALID_ADDRESS) {}
285 
286  OSOEntry(uint32_t exe_sym_idx, lldb::addr_t oso_file_addr)
287  : m_exe_sym_idx(exe_sym_idx), m_oso_file_addr(oso_file_addr) {}
288 
289  uint32_t GetExeSymbolIndex() const { return m_exe_sym_idx; }
290 
291  bool operator<(const OSOEntry &rhs) const {
292  return m_exe_sym_idx < rhs.m_exe_sym_idx;
293  }
294 
295  lldb::addr_t GetOSOFileAddress() const { return m_oso_file_addr; }
296 
297  void SetOSOFileAddress(lldb::addr_t oso_file_addr) {
298  m_oso_file_addr = oso_file_addr;
299  }
300 
301  protected:
303  lldb::addr_t m_oso_file_addr;
304  };
305 
308 
309  // Member Variables
310  std::bitset<kNumFlags> m_flags;
311  std::vector<CompileUnitInfo> m_compile_unit_infos;
312  std::vector<uint32_t> m_func_indexes; // Sorted by address
313  std::vector<uint32_t> m_glob_indexes;
314  std::map<std::pair<lldb_private::ConstString, llvm::sys::TimePoint<>>,
315  OSOInfoSP>
320 
321  // When an object file from the debug map gets parsed in
322  // SymbolFileDWARF, it needs to tell the debug map about the object
323  // files addresses by calling this function once for each N_FUN,
324  // N_GSYM and N_STSYM and after all entries in the debug map have
325  // been matched up, FinalizeOSOFileRanges() should be called.
326  bool AddOSOFileRange(CompileUnitInfo *cu_info, lldb::addr_t exe_file_addr,
327  lldb::addr_t exe_byte_size, lldb::addr_t oso_file_addr,
328  lldb::addr_t oso_byte_size);
329 
330  // Called after calling AddOSOFileRange() for each object file debug
331  // map entry to finalize the info for the unlinked compile unit.
332  void FinalizeOSOFileRanges(CompileUnitInfo *cu_info);
333 
334  /// Convert \a addr from a .o file address, to an executable address.
335  ///
336  /// \param[in] addr
337  /// A section offset address from a .o file
338  ///
339  /// \return
340  /// Returns true if \a addr was converted to be an executable
341  /// section/offset address, false otherwise.
343 
344  /// Convert a .o file "file address" to an executable "file address".
345  ///
346  /// \param[in] oso_symfile
347  /// The DWARF symbol file that contains \a oso_file_addr
348  ///
349  /// \param[in] oso_file_addr
350  /// A .o file "file address" to convert.
351  ///
352  /// \return
353  /// LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the
354  /// linked executable, otherwise a valid "file address" from the
355  /// linked executable that contains the debug map.
356  lldb::addr_t LinkOSOFileAddress(SymbolFileDWARF *oso_symfile,
357  lldb::addr_t oso_file_addr);
358 
359  /// Given a line table full of lines with "file addresses" that are
360  /// for a .o file represented by \a oso_symfile, link a new line table
361  /// and return it.
362  ///
363  /// \param[in] oso_symfile
364  /// The DWARF symbol file that produced the \a line_table
365  ///
366  /// \param[in] line_table
367  /// A pointer to the line table.
368  ///
369  /// \return
370  /// Returns a valid line table full of linked addresses, or NULL
371  /// if none of the line table addresses exist in the main
372  /// executable.
374  LinkOSOLineTable(SymbolFileDWARF *oso_symfile,
375  lldb_private::LineTable *line_table);
376 
377  size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data,
378  DWARFDebugAranges *debug_aranges);
379 };
380 
381 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_SYMBOLFILEDWARFDEBUGMAP_H
lldb_private::CompilerDeclContext FindNamespace(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx) override
lldb::addr_t LinkOSOFileAddress(SymbolFileDWARF *oso_symfile, lldb::addr_t oso_file_addr)
Convert a .o file "file address" to an executable "file address".
static uint32_t GetOSOIndexFromUserID(lldb::user_id_t uid)
Defines a list of symbol context objects.
static SymbolFileDWARF * GetSymbolFileAsSymbolFileDWARF(SymbolFile *sym_file)
std::map< std::pair< lldb_private::ConstString, llvm::sys::TimePoint<> >, OSOInfoSP > m_oso_map
void GetTypes(lldb_private::SymbolContextScope *sc_scope, lldb::TypeClass type_mask, lldb_private::TypeList &type_list) override
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
Represents a generic declaration context in a program.
void SetCompileUnit(SymbolFileDWARF *oso_dwarf, const lldb::CompUnitSP &cu_sp)
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
static bool classof(const SymbolFile *obj)
void PrivateFindGlobalVariables(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, const std::vector< uint32_t > &name_symbol_indexes, uint32_t max_matches, lldb_private::VariableList &variables)
bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override
SymbolFileDWARF * GetSymbolFile(const lldb_private::SymbolContext &sc)
static lldb_private::SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
std::shared_ptr< OSOInfo > OSOInfoSP
OSOEntry(uint32_t exe_sym_idx, lldb::addr_t oso_file_addr)
A mix in class that contains a generic user ID.
Definition: UserID.h:31
A file utility class.
Definition: FileSpec.h:56
void SetOSOFileAddress(lldb::addr_t oso_file_addr)
static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
A class that describes a function.
Definition: Function.h:409
std::bitset< kNumFlags > m_flags
bool ParseImportedModules(const lldb_private::SymbolContext &sc, std::vector< lldb_private::SourceModule > &imported_modules) override
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:58
bool isA(const void *ClassID) const override
LLVM RTTI support.
size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data, DWARFDebugAranges *debug_aranges)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, lldb_private::ConstString type_name, bool must_be_implementation)
CompileUnitInfo * GetCompileUnitInfoForSymbolWithIndex(uint32_t symbol_idx, uint32_t *oso_idx_ptr)
uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, lldb::SymbolContextItem resolve_scope, lldb_private::SymbolContext &sc) override
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition: TypeSystem.h:40
lldb_private::CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf)
std::vector< std::unique_ptr< lldb_private::CallEdge > > ParseCallEdgesInFunction(lldb_private::UserID func_id) override
size_t ParseBlocksRecursive(lldb_private::Function &func) override
A class that describes a compilation unit.
Definition: CompileUnit.h:37
bool operator<(const OSOEntry &rhs) const
uint32_t CalculateAbilities() override
void InitializeObject() override
Initialize the SymbolFile object.
bool Supports_DW_AT_APPLE_objc_complete_type(SymbolFileDWARF *skip_dwarf_oso)
llvm::Optional< ArrayInfo > GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override
If type_uid points to an array type, return its characteristics.
void ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override
size_t GetCompUnitInfosForModule(const lldb_private::Module *oso_module, std::vector< CompileUnitInfo *> &cu_infos)
bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb_private::CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override
lldb_private::Module * GetModuleByCompUnitInfo(CompileUnitInfo *comp_unit_info)
void FindGlobalVariables(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, lldb_private::VariableList &variables) override
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
uint64_t user_id_t
Definition: lldb-types.h:84
LanguageType
Programming language type.
bool GetFileSpecForSO(uint32_t oso_idx, lldb_private::FileSpec &file_spec)
CompileUnitInfo * GetCompileUnitInfo(SymbolFileDWARF *oso_dwarf)
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:75
static const char * GetPluginDescriptionStatic()
uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info)
UniqueDWARFASTTypeMap m_unique_ast_type_map
void FinalizeOSOFileRanges(CompileUnitInfo *cu_info)
A line table class.
Definition: LineTable.h:38
SymbolFileDWARF * GetSymbolFileByCompUnitInfo(CompileUnitInfo *comp_unit_info)
lldb_private::ConstString GetPluginName() override
bool ForEachExternalModule(lldb_private::CompileUnit &, llvm::DenseSet< lldb_private::SymbolFile *> &, llvm::function_ref< bool(lldb_private::Module &)>) override
lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx)
SymbolFileDWARFDebugMap(lldb::ObjectFileSP objfile_sp)
SymbolFileDWARF * GetSymbolFileByOSOIndex(uint32_t oso_idx)
std::vector< uint32_t > m_func_indexes
A section + offset based address class.
Definition: Address.h:59
bool AddOSOFileRange(CompileUnitInfo *cu_info, lldb::addr_t exe_file_addr, lldb::addr_t exe_byte_size, lldb::addr_t oso_file_addr, lldb::addr_t oso_byte_size)
size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override
size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override
void ForEachSymbolFile(std::function< bool(SymbolFileDWARF *)> closure)
bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, lldb_private::FileSpecList &support_files) override
lldb_private::RangeDataVector< lldb::addr_t, lldb::addr_t, lldb::addr_t > FileRangeMap
lldb::LanguageType ParseLanguage(lldb_private::CompileUnit &comp_unit) override
UniqueDWARFASTTypeMap & GetUniqueDWARFASTTypeMap()
static char ID
LLVM RTTI support.
uint32_t CalculateNumCompileUnits() override
CompileUnitInfo * GetCompileUnitInfoForSymbolWithID(lldb::user_id_t symbol_id, uint32_t *oso_idx_ptr)
lldb_private::LineTable * LinkOSOLineTable(SymbolFileDWARF *oso_symfile, lldb_private::LineTable *line_table)
Given a line table full of lines with "file addresses" that are for a .o file represented by oso_symf...
static int SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info)
uint64_t addr_t
Definition: lldb-types.h:83
bool LinkOSOAddress(lldb_private::Address &addr)
Convert addr from a .o file address, to an executable address.
static lldb_private::ConstString GetPluginNameStatic()
SymbolFile(lldb::ObjectFileSP objfile_sp)
Definition: SymbolFile.h:67
A uniqued constant string class.
Definition: ConstString.h:40
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition: XcodeSDK.h:24
lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type
Represents a generic type in a programming language.
Definition: CompilerType.h:33
void FindTypes(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, llvm::DenseSet< lldb_private::SymbolFile *> &searched_symbol_files, lldb_private::TypeMap &types) override
std::vector< CompileUnitInfo > m_compile_unit_infos
bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override
lldb_private::ObjectFile * GetObjectFileByOSOIndex(uint32_t oso_idx)
std::vector< uint32_t > m_glob_indexes
void FindFunctions(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, lldb::FunctionNameType name_type_mask, bool include_inlines, lldb_private::SymbolContextList &sc_list) override
lldb_private::Module * GetModuleByOSOIndex(uint32_t oso_idx)
lldb_private::ObjectFile * GetObjectFileByCompUnitInfo(CompileUnitInfo *comp_unit_info)
void DumpClangAST(lldb_private::Stream &s) override
CompileUnitInfo * GetCompUnitInfo(const lldb_private::SymbolContext &sc)
lldb_private::XcodeSDK ParseXcodeSDK(lldb_private::CompileUnit &comp_unit) override
Return the Xcode SDK comp_unit was compiled against.
size_t ParseVariablesForContext(const lldb_private::SymbolContext &sc) override
lldb_private::Type * ResolveTypeUID(lldb::user_id_t type_uid) override
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
bool CompleteType(lldb_private::CompilerType &compiler_type) override
lldb_private::RangeDataVector< lldb::addr_t, lldb::addr_t, OSOEntry > DebugMap