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 SymbolFileDWARF_SymbolFileDWARFDebugMap_h_
10 #define SymbolFileDWARF_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 public:
27  // Static Functions
28  static void Initialize();
29 
30  static void Terminate();
31 
33 
34  static const char *GetPluginDescriptionStatic();
35 
38 
39  // Constructors and Destructors
41  ~SymbolFileDWARFDebugMap() override;
42 
43  uint32_t CalculateAbilities() override;
44  void InitializeObject() override;
45 
46  // Compile Unit function calls
47  uint32_t GetNumCompileUnits() override;
48  lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
49 
51  ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
52 
53  size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
54 
55  bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
56 
57  bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
58 
60  lldb_private::FileSpecList &support_files) override;
61 
62  bool ParseIsOptimized(lldb_private::CompileUnit &comp_unit) override;
63 
64  size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
65 
68  std::vector<lldb_private::SourceModule> &imported_modules) override;
69  size_t ParseBlocksRecursive(lldb_private::Function &func) override;
70  size_t
72 
74  llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
75  lldb::user_id_t type_uid,
76  const lldb_private::ExecutionContext *exe_ctx) override;
77 
82  void
84 
85  bool CompleteType(lldb_private::CompilerType &compiler_type) override;
87  lldb::SymbolContextItem resolve_scope,
88  lldb_private::SymbolContext &sc) override;
89  uint32_t
91  bool check_inlines,
92  lldb::SymbolContextItem resolve_scope,
93  lldb_private::SymbolContextList &sc_list) override;
94  uint32_t
96  const lldb_private::CompilerDeclContext *parent_decl_ctx,
97  uint32_t max_matches,
98  lldb_private::VariableList &variables) override;
100  uint32_t max_matches,
101  lldb_private::VariableList &variables) override;
102  uint32_t
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;
108  bool include_inlines, bool append,
109  lldb_private::SymbolContextList &sc_list) override;
110  uint32_t
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;
118  const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
120  lldb::TypeClass type_mask,
121  lldb_private::TypeList &type_list) override;
122  std::vector<lldb_private::CallEdge>
124 
125  void DumpClangAST(lldb_private::Stream &s) override;
126 
127  // PluginInterface protocol
129 
130  uint32_t GetPluginVersion() override;
131 
132 protected:
133  enum { kHaveInitializedOSOs = (1 << 0), kNumFlags };
134 
135  friend class DebugMapModule;
136  friend struct DIERef;
137  friend class DWARFASTParserClang;
138  friend class DWARFUnit;
139  friend class SymbolFileDWARF;
140  struct OSOInfo {
141  lldb::ModuleSP module_sp;
142 
143  OSOInfo() : module_sp() {}
144  };
145 
146  typedef std::shared_ptr<OSOInfo> OSOInfoSP;
147 
149  lldb::addr_t>
151 
152  // Class specific types
156  llvm::sys::TimePoint<> oso_mod_time;
157  OSOInfoSP oso_sp;
158  lldb::CompUnitSP compile_unit_sp;
165 
167  : so_file(), oso_path(), oso_mod_time(), oso_sp(), compile_unit_sp(),
168  first_symbol_index(UINT32_MAX), last_symbol_index(UINT32_MAX),
169  first_symbol_id(UINT32_MAX), last_symbol_id(UINT32_MAX),
170  file_range_map(), file_range_map_valid(false) {}
171 
172  const FileRangeMap &GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile);
173  };
174 
175  // Protected Member Functions
176  void InitOSO();
177 
179  return (uint32_t)((uid >> 32ull) - 1ull);
180  }
181 
183 
184  bool GetFileSpecForSO(uint32_t oso_idx, lldb_private::FileSpec &file_spec);
185 
188 
189  size_t GetCompUnitInfosForModule(const lldb_private::Module *oso_module,
190  std::vector<CompileUnitInfo *> &cu_infos);
191 
193  GetModuleByCompUnitInfo(CompileUnitInfo *comp_unit_info);
194 
196 
199 
201 
202  uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info);
203 
206 
208 
210 
211  // If closure returns "false", iteration continues. If it returns
212  // "true", iteration terminates.
213  void ForEachSymbolFile(std::function<bool(SymbolFileDWARF *)> closure) {
214  for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size();
215  oso_idx < num_oso_idxs; ++oso_idx) {
216  if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex(oso_idx)) {
217  if (closure(oso_dwarf))
218  return;
219  }
220  }
221  }
222 
224  uint32_t *oso_idx_ptr);
225 
227  uint32_t *oso_idx_ptr);
228 
229  static int
230  SymbolContainsSymbolWithIndex(uint32_t *symbol_idx_ptr,
231  const CompileUnitInfo *comp_unit_info);
232 
233  static int SymbolContainsSymbolWithID(lldb::user_id_t *symbol_idx_ptr,
234  const CompileUnitInfo *comp_unit_info);
235 
238  const lldb_private::CompilerDeclContext *parent_decl_ctx,
239  const std::vector<uint32_t> &name_symbol_indexes, uint32_t max_matches,
240  lldb_private::VariableList &variables);
241 
242  void SetCompileUnit(SymbolFileDWARF *oso_dwarf,
243  const lldb::CompUnitSP &cu_sp);
244 
245  lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf);
246 
248 
249  lldb::TypeSP
251 
253 
255  const DWARFDIE &die, lldb_private::ConstString type_name,
256  bool must_be_implementation);
257 
259  return m_unique_ast_type_map;
260  }
261 
262  // OSOEntry
263  class OSOEntry {
264  public:
266  : m_exe_sym_idx(UINT32_MAX), m_oso_file_addr(LLDB_INVALID_ADDRESS) {}
267 
268  OSOEntry(uint32_t exe_sym_idx, lldb::addr_t oso_file_addr)
269  : m_exe_sym_idx(exe_sym_idx), m_oso_file_addr(oso_file_addr) {}
270 
271  uint32_t GetExeSymbolIndex() const { return m_exe_sym_idx; }
272 
273  bool operator<(const OSOEntry &rhs) const {
274  return m_exe_sym_idx < rhs.m_exe_sym_idx;
275  }
276 
277  lldb::addr_t GetOSOFileAddress() const { return m_oso_file_addr; }
278 
279  void SetOSOFileAddress(lldb::addr_t oso_file_addr) {
280  m_oso_file_addr = oso_file_addr;
281  }
282 
283  protected:
285  lldb::addr_t m_oso_file_addr;
286  };
287 
290 
291  // Member Variables
292  std::bitset<kNumFlags> m_flags;
293  std::vector<CompileUnitInfo> m_compile_unit_infos;
294  std::vector<uint32_t> m_func_indexes; // Sorted by address
295  std::vector<uint32_t> m_glob_indexes;
296  std::map<std::pair<lldb_private::ConstString, llvm::sys::TimePoint<>>,
297  OSOInfoSP>
302 
303  // When an object file from the debug map gets parsed in
304  // SymbolFileDWARF, it needs to tell the debug map about the object
305  // files addresses by calling this function once for each N_FUN,
306  // N_GSYM and N_STSYM and after all entries in the debug map have
307  // been matched up, FinalizeOSOFileRanges() should be called.
308  bool AddOSOFileRange(CompileUnitInfo *cu_info, lldb::addr_t exe_file_addr,
309  lldb::addr_t exe_byte_size, lldb::addr_t oso_file_addr,
310  lldb::addr_t oso_byte_size);
311 
312  // Called after calling AddOSOFileRange() for each object file debug
313  // map entry to finalize the info for the unlinked compile unit.
314  void FinalizeOSOFileRanges(CompileUnitInfo *cu_info);
315 
316  /// Convert \a addr from a .o file address, to an executable address.
317  ///
318  /// \param[in] addr
319  /// A section offset address from a .o file
320  ///
321  /// \return
322  /// Returns true if \a addr was converted to be an executable
323  /// section/offset address, false otherwise.
325 
326  /// Convert a .o file "file address" to an executable "file address".
327  ///
328  /// \param[in] oso_symfile
329  /// The DWARF symbol file that contains \a oso_file_addr
330  ///
331  /// \param[in] oso_file_addr
332  /// A .o file "file address" to convert.
333  ///
334  /// \return
335  /// LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the
336  /// linked executable, otherwise a valid "file address" from the
337  /// linked executable that contains the debug map.
338  lldb::addr_t LinkOSOFileAddress(SymbolFileDWARF *oso_symfile,
339  lldb::addr_t oso_file_addr);
340 
341  /// Given a line table full of lines with "file addresses" that are
342  /// for a .o file represented by \a oso_symfile, link a new line table
343  /// and return it.
344  ///
345  /// \param[in] oso_symfile
346  /// The DWARF symbol file that produced the \a line_table
347  ///
348  /// \param[in] addr
349  /// A section offset address from a .o file
350  ///
351  /// \return
352  /// Returns a valid line table full of linked addresses, or NULL
353  /// if none of the line table addresses exist in the main
354  /// executable.
356  LinkOSOLineTable(SymbolFileDWARF *oso_symfile,
357  lldb_private::LineTable *line_table);
358 
359  size_t AddOSOARanges(SymbolFileDWARF *dwarf2Data,
360  DWARFDebugAranges *debug_aranges);
361 };
362 
363 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_
static lldb_private::SymbolFile * CreateInstance(lldb_private::ObjectFile *obj_file)
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
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
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
bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override
SymbolFileDWARF * GetSymbolFile(const lldb_private::SymbolContext &sc)
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:33
A file utility class.
Definition: FileSpec.h:55
"lldb/Utility/RegularExpression.h" A C++ wrapper class for regex.
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:323
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
lldb_private::CompilerDeclContext FindNamespace(lldb_private::ConstString name, const lldb_private::CompilerDeclContext *parent_decl_ctx) override
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
Definition: DIERef.h:18
lldb_private::CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
lldb::CompUnitSP GetCompileUnit(SymbolFileDWARF *oso_dwarf)
size_t ParseBlocksRecursive(lldb_private::Function &func) override
A class that describes a compilation unit.
Definition: CompileUnit.h:35
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)
#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.
uint32_t FindFunctions(lldb_private::ConstString name, const lldb_private::CompilerDeclContext *parent_decl_ctx, lldb::FunctionNameType name_type_mask, bool include_inlines, bool append, lldb_private::SymbolContextList &sc_list) override
uint32_t FindGlobalVariables(lldb_private::ConstString name, const lldb_private::CompilerDeclContext *parent_decl_ctx, uint32_t max_matches, lldb_private::VariableList &variables) override
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:109
static const char * GetPluginDescriptionStatic()
uint32_t GetCompUnitInfoIndex(const CompileUnitInfo *comp_unit_info)
UniqueDWARFASTTypeMap m_unique_ast_type_map
std::vector< lldb_private::CallEdge > ParseCallEdgesInFunction(lldb_private::UserID func_id) override
void FinalizeOSOFileRanges(CompileUnitInfo *cu_info)
A line table class.
Definition: LineTable.h:37
SymbolFileDWARF * GetSymbolFileByCompUnitInfo(CompileUnitInfo *comp_unit_info)
lldb_private::ConstString GetPluginName() override
lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx)
uint32_t GetNumCompileUnits() override
uint32_t 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)
SymbolFileDWARF * GetSymbolFileByOSOIndex(uint32_t oso_idx)
std::vector< uint32_t > m_func_indexes
A section + offset based address class.
Definition: Address.h:80
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()
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()
A uniqued constant string class.
Definition: ConstString.h:38
lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type
std::vector< CompileUnitInfo > m_compile_unit_infos
SymbolFile(ObjectFile *obj_file)
Definition: SymbolFile.h:55
bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override
lldb_private::ObjectFile * GetObjectFileByOSOIndex(uint32_t oso_idx)
std::vector< uint32_t > m_glob_indexes
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)
SymbolFileDWARFDebugMap(lldb_private::ObjectFile *ofile)
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...
size_t GetTypes(lldb_private::SymbolContextScope *sc_scope, lldb::TypeClass type_mask, lldb_private::TypeList &type_list) override
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
bool CompleteType(lldb_private::CompilerType &compiler_type) override
uint32_t FindTypes(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
lldb_private::RangeDataVector< lldb::addr_t, lldb::addr_t, OSOEntry > DebugMap