LLDB  mainline
DWARFDebugInfoEntry.h
Go to the documentation of this file.
1 //===-- DWARFDebugInfoEntry.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_DWARFDebugInfoEntry_h_
10 #define SymbolFileDWARF_DWARFDebugInfoEntry_h_
11 
12 #include "SymbolFileDWARF.h"
13 #include "llvm/ADT/SmallVector.h"
14 
16 #include "DWARFDebugAbbrev.h"
17 #include "DWARFDebugRanges.h"
18 #include <map>
19 #include <set>
20 #include <vector>
21 
22 typedef std::map<const DWARFDebugInfoEntry *, dw_addr_t> DIEToAddressMap;
23 typedef DIEToAddressMap::iterator DIEToAddressMapIter;
24 typedef DIEToAddressMap::const_iterator DIEToAddressMapConstIter;
25 
26 typedef std::map<dw_addr_t, const DWARFDebugInfoEntry *> AddressToDIEMap;
27 typedef AddressToDIEMap::iterator AddressToDIEMapIter;
28 typedef AddressToDIEMap::const_iterator AddressToDIEMapConstIter;
29 
30 typedef std::map<dw_offset_t, dw_offset_t> DIEToDIEMap;
31 typedef DIEToDIEMap::iterator DIEToDIEMapIter;
32 typedef DIEToDIEMap::const_iterator DIEToDIEMapConstIter;
33 
34 typedef std::map<uint32_t, const DWARFDebugInfoEntry *> UInt32ToDIEMap;
35 typedef UInt32ToDIEMap::iterator UInt32ToDIEMapIter;
36 typedef UInt32ToDIEMap::const_iterator UInt32ToDIEMapConstIter;
37 
38 typedef std::multimap<uint32_t, const DWARFDebugInfoEntry *> UInt32ToDIEMMap;
39 typedef UInt32ToDIEMMap::iterator UInt32ToDIEMMapIter;
40 typedef UInt32ToDIEMMap::const_iterator UInt32ToDIEMMapConstIter;
41 
42 class DWARFDeclContext;
43 
44 #define DIE_SIBLING_IDX_BITSIZE 31
45 
47 public:
48  typedef std::vector<DWARFDebugInfoEntry> collection;
49  typedef collection::iterator iterator;
50  typedef collection::const_iterator const_iterator;
51 
52  typedef std::vector<dw_offset_t> offset_collection;
53  typedef offset_collection::iterator offset_collection_iterator;
54  typedef offset_collection::const_iterator offset_collection_const_iterator;
55 
58  m_has_children(false), m_abbr_idx(0), m_tag(0) {}
59 
60  explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; }
61  bool operator==(const DWARFDebugInfoEntry &rhs) const;
62  bool operator!=(const DWARFDebugInfoEntry &rhs) const;
63 
64  void BuildAddressRangeTable(SymbolFileDWARF *dwarf2Data,
65  const DWARFUnit *cu,
66  DWARFDebugAranges *debug_aranges) const;
67 
69  const DWARFUnit *cu,
70  DWARFDebugAranges *debug_aranges) const;
71 
72  bool FastExtract(const lldb_private::DWARFDataExtractor &debug_info_data,
73  const DWARFUnit *cu,
74  const DWARFFormValue::FixedFormSizes &fixed_form_sizes,
75  lldb::offset_t *offset_ptr);
76 
77  bool Extract(const DWARFUnit *cu, lldb::offset_t *offset_ptr);
78 
79  bool LookupAddress(const dw_addr_t address, SymbolFileDWARF *dwarf2Data,
80  const DWARFUnit *cu,
81  DWARFDebugInfoEntry **function_die,
82  DWARFDebugInfoEntry **block_die);
83 
84  size_t GetAttributes(const DWARFUnit *cu,
85  DWARFFormValue::FixedFormSizes fixed_form_sizes,
86  DWARFAttributes &attrs,
87  uint32_t curr_depth = 0)
88  const; // "curr_depth" for internal use only, don't set this yourself!!!
89 
91  GetAttributeValue(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
92  const dw_attr_t attr, DWARFFormValue &formValue,
93  dw_offset_t *end_attr_offset_ptr = nullptr,
94  bool check_specification_or_abstract_origin = false) const;
95 
96  const char *GetAttributeValueAsString(
97  SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
98  const dw_attr_t attr, const char *fail_value,
99  bool check_specification_or_abstract_origin = false) const;
100 
102  SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
103  const dw_attr_t attr, uint64_t fail_value,
104  bool check_specification_or_abstract_origin = false) const;
105 
107  SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
108  const dw_attr_t attr, uint64_t fail_value,
109  bool check_specification_or_abstract_origin = false) const;
110 
112  SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
113  const dw_attr_t attr, uint64_t fail_value,
114  bool check_specification_or_abstract_origin = false) const;
115 
116  dw_addr_t
117  GetAttributeHighPC(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
118  dw_addr_t lo_pc, uint64_t fail_value,
119  bool check_specification_or_abstract_origin = false) const;
120 
122  SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, dw_addr_t &lo_pc,
123  dw_addr_t &hi_pc, uint64_t fail_value,
124  bool check_specification_or_abstract_origin = false) const;
125 
127  SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
128  DWARFRangeList &ranges, bool check_hi_lo_pc,
129  bool check_specification_or_abstract_origin = false) const;
130 
131  const char *GetName(SymbolFileDWARF *dwarf2Data,
132  const DWARFUnit *cu) const;
133 
134  const char *GetMangledName(SymbolFileDWARF *dwarf2Data,
135  const DWARFUnit *cu,
136  bool substitute_name_allowed = true) const;
137 
138  const char *GetPubname(SymbolFileDWARF *dwarf2Data,
139  const DWARFUnit *cu) const;
140 
141  static bool GetName(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
142  const dw_offset_t die_offset, lldb_private::Stream &s);
143 
144  static bool AppendTypeName(SymbolFileDWARF *dwarf2Data,
145  const DWARFUnit *cu,
146  const dw_offset_t die_offset,
148 
149  const char *GetQualifiedName(SymbolFileDWARF *dwarf2Data,
150  DWARFUnit *cu,
151  std::string &storage) const;
152 
153  const char *GetQualifiedName(SymbolFileDWARF *dwarf2Data,
154  DWARFUnit *cu,
155  const DWARFAttributes &attributes,
156  std::string &storage) const;
157 
158  static bool OffsetLessThan(const DWARFDebugInfoEntry &a,
159  const DWARFDebugInfoEntry &b);
160 
161  void Dump(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
162  lldb_private::Stream &s, uint32_t recurse_depth) const;
163 
164  static void
165  DumpAttribute(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
166  const lldb_private::DWARFDataExtractor &debug_info_data,
167  lldb::offset_t *offset_ptr, lldb_private::Stream &s,
168  dw_attr_t attr, DWARFFormValue &form_value);
169 
170  bool
171  GetDIENamesAndRanges(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
172  const char *&name, const char *&mangled,
173  DWARFRangeList &rangeList, int &decl_file,
174  int &decl_line, int &decl_column, int &call_file,
175  int &call_line, int &call_column,
176  lldb_private::DWARFExpression *frame_base = NULL) const;
177 
180  const DWARFUnit *cu,
181  lldb::offset_t &offset) const;
182 
183  dw_tag_t Tag() const { return m_tag; }
184 
185  bool IsNULL() const { return m_abbr_idx == 0; }
186 
187  dw_offset_t GetOffset() const { return m_offset; }
188 
189  bool HasChildren() const { return m_has_children; }
190 
191  void SetHasChildren(bool b) { m_has_children = b; }
192 
193  // We know we are kept in a vector of contiguous entries, so we know
194  // our parent will be some index behind "this".
196  return m_parent_idx > 0 ? this - m_parent_idx : NULL;
197  }
199  return m_parent_idx > 0 ? this - m_parent_idx : NULL;
200  }
201  // We know we are kept in a vector of contiguous entries, so we know
202  // our sibling will be some index after "this".
204  return m_sibling_idx > 0 ? this + m_sibling_idx : NULL;
205  }
207  return m_sibling_idx > 0 ? this + m_sibling_idx : NULL;
208  }
209  // We know we are kept in a vector of contiguous entries, so we know
210  // we don't need to store our child pointer, if we have a child it will
211  // be the next entry in the list...
213  return HasChildren() ? this + 1 : NULL;
214  }
216  return HasChildren() ? this + 1 : NULL;
217  }
218 
219  std::vector<DWARFDIE> GetDeclContextDIEs(DWARFUnit *cu) const;
220 
221  void GetDWARFDeclContext(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
222  DWARFDeclContext &dwarf_decl_ctx) const;
223 
224  bool MatchesDWARFDeclContext(SymbolFileDWARF *dwarf2Data,
225  DWARFUnit *cu,
226  const DWARFDeclContext &dwarf_decl_ctx) const;
227 
229  DWARFUnit *cu) const;
231  DWARFUnit *cu,
232  const DWARFAttributes &attributes) const;
233 
235  if (parent) {
236  // We know we are kept in a vector of contiguous entries, so we know
237  // our parent will be some index behind "this".
238  m_parent_idx = this - parent;
239  } else
240  m_parent_idx = 0;
241  }
243  if (sibling) {
244  // We know we are kept in a vector of contiguous entries, so we know
245  // our sibling will be some index after "this".
246  m_sibling_idx = sibling - this;
247  sibling->SetParent(GetParent());
248  } else
249  m_sibling_idx = 0;
250  }
251 
253 
254  void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
255 
256 protected:
258  m_offset; // Offset within the .debug_info of the start of this entry
259  uint32_t m_parent_idx; // How many to subtract from "this" to get the parent.
260  // If zero this die has no parent
261  uint32_t m_sibling_idx : 31, // How many to add to "this" to get the sibling.
262  // If it is zero, then the DIE doesn't have children, or the
263  // DWARF claimed it had children but the DIE only contained
264  // a single NULL terminating child.
265  m_has_children : 1;
267  uint16_t m_tag; // A copy of the DW_TAG value so we don't have to go through
268  // the compile unit abbrev table
269 };
270 
271 #endif // SymbolFileDWARF_DWARFDebugInfoEntry_h_
static void DumpAttribute(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, const lldb_private::DWARFDataExtractor &debug_info_data, lldb::offset_t *offset_ptr, lldb_private::Stream &s, dw_attr_t attr, DWARFFormValue &form_value)
std::vector< DWARFDIE > GetDeclContextDIEs(DWARFUnit *cu) const
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
bool LookupAddress(const dw_addr_t address, SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, DWARFDebugInfoEntry **function_die, DWARFDebugInfoEntry **block_die)
std::vector< dw_offset_t > offset_collection
UInt32ToDIEMap::iterator UInt32ToDIEMapIter
"lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location expression and interprets it...
bool GetAttributeAddressRange(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, dw_addr_t &lo_pc, dw_addr_t &hi_pc, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
std::multimap< uint32_t, const DWARFDebugInfoEntry * > UInt32ToDIEMMap
const char * GetQualifiedName(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu, std::string &storage) const
collection::iterator iterator
const char * GetPubname(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu) const
std::map< dw_offset_t, dw_offset_t > DIEToDIEMap
uint64_t dw_addr_t
Definition: dwarf.h:26
void SetSibling(DWARFDebugInfoEntry *sibling)
bool FastExtract(const lldb_private::DWARFDataExtractor &debug_info_data, const DWARFUnit *cu, const DWARFFormValue::FixedFormSizes &fixed_form_sizes, lldb::offset_t *offset_ptr)
const DWARFDebugInfoEntry * GetSibling() const
UInt32ToDIEMMap::iterator UInt32ToDIEMMapIter
size_t GetAttributeAddressRanges(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, DWARFRangeList &ranges, bool check_hi_lo_pc, bool check_specification_or_abstract_origin=false) const
uint64_t GetAttributeValueAsReference(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
DIEToDIEMap::const_iterator DIEToDIEMapConstIter
void GetDWARFDeclContext(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu, DWARFDeclContext &dwarf_decl_ctx) const
DIEToDIEMap::iterator DIEToDIEMapIter
DWARFDebugInfoEntry * GetFirstChild()
size_t GetAttributes(const DWARFUnit *cu, DWARFFormValue::FixedFormSizes fixed_form_sizes, DWARFAttributes &attrs, uint32_t curr_depth=0) const
void SetParentIndex(uint32_t idx)
dw_offset_t GetAttributeValue(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, const dw_attr_t attr, DWARFFormValue &formValue, dw_offset_t *end_attr_offset_ptr=nullptr, bool check_specification_or_abstract_origin=false) const
static bool OffsetLessThan(const DWARFDebugInfoEntry &a, const DWARFDebugInfoEntry &b)
bool MatchesDWARFDeclContext(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu, const DWARFDeclContext &dwarf_decl_ctx) const
uint64_t offset_t
Definition: lldb-types.h:87
const DWARFDebugInfoEntry * GetFirstChild() const
DWARFDebugInfoEntry * GetParent()
uint64_t GetAttributeValueAsUnsigned(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
offset_collection::const_iterator offset_collection_const_iterator
std::map< dw_addr_t, const DWARFDebugInfoEntry * > AddressToDIEMap
std::map< uint32_t, const DWARFDebugInfoEntry * > UInt32ToDIEMap
dw_offset_t GetOffset() const
bool operator!=(const DWARFDebugInfoEntry &rhs) const
AddressToDIEMap::iterator AddressToDIEMapIter
DIEToAddressMap::iterator DIEToAddressMapIter
std::vector< DWARFDebugInfoEntry > collection
bool Extract(const DWARFUnit *cu, lldb::offset_t *offset_ptr)
std::map< const DWARFDebugInfoEntry *, dw_addr_t > DIEToAddressMap
static bool AppendTypeName(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, const dw_offset_t die_offset, lldb_private::Stream &s)
UInt32ToDIEMMap::const_iterator UInt32ToDIEMMapConstIter
DIEToAddressMap::const_iterator DIEToAddressMapConstIter
void SetSiblingIndex(uint32_t idx)
const char * GetAttributeValueAsString(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, bool check_specification_or_abstract_origin=false) const
void BuildFunctionAddressRangeTable(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, DWARFDebugAranges *debug_aranges) const
dw_addr_t GetAttributeHighPC(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
const DWARFAbbreviationDeclaration * GetAbbreviationDeclarationPtr(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, lldb::offset_t &offset) const
AddressToDIEMap::const_iterator AddressToDIEMapConstIter
bool GetDIENamesAndRanges(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, const char *&name, const char *&mangled, DWARFRangeList &rangeList, int &decl_file, int &decl_line, int &decl_column, int &call_file, int &call_line, int &call_column, lldb_private::DWARFExpression *frame_base=NULL) const
void SetParent(DWARFDebugInfoEntry *parent)
const DWARFDebugInfoEntry * GetParent() const
DWARFDebugInfoEntry * GetSibling()
offset_collection::iterator offset_collection_iterator
#define DW_INVALID_OFFSET
Definition: dwarf.h:34
const char * GetName(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu) const
const char * GetMangledName(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, bool substitute_name_allowed=true) const
uint64_t GetAttributeValueAsAddress(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
DWARFDIE GetParentDeclContextDIE(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu) const
void Dump(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, lldb_private::Stream &s, uint32_t recurse_depth) const
bool operator==(const DWARFDebugInfoEntry &rhs) const
UInt32ToDIEMap::const_iterator UInt32ToDIEMapConstIter
collection::const_iterator const_iterator
void BuildAddressRangeTable(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, DWARFDebugAranges *debug_aranges) const