1 //===-- DWARFDebugInfoEntry.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_DWARFDebugInfoEntry_h_
11 #define SymbolFileDWARF_DWARFDebugInfoEntry_h_
13 #include "SymbolFileDWARF.h"
14 #include "llvm/ADT/SmallVector.h"
16 #include "DWARFAbbreviationDeclaration.h"
17 #include "DWARFDebugAbbrev.h"
18 #include "DWARFDebugRanges.h"
23 typedef std::map<const DWARFDebugInfoEntry *, dw_addr_t> DIEToAddressMap;
24 typedef DIEToAddressMap::iterator DIEToAddressMapIter;
25 typedef DIEToAddressMap::const_iterator DIEToAddressMapConstIter;
27 typedef std::map<dw_addr_t, const DWARFDebugInfoEntry *> AddressToDIEMap;
28 typedef AddressToDIEMap::iterator AddressToDIEMapIter;
29 typedef AddressToDIEMap::const_iterator AddressToDIEMapConstIter;
31 typedef std::map<dw_offset_t, dw_offset_t> DIEToDIEMap;
32 typedef DIEToDIEMap::iterator DIEToDIEMapIter;
33 typedef DIEToDIEMap::const_iterator DIEToDIEMapConstIter;
35 typedef std::map<uint32_t, const DWARFDebugInfoEntry *> UInt32ToDIEMap;
36 typedef UInt32ToDIEMap::iterator UInt32ToDIEMapIter;
37 typedef UInt32ToDIEMap::const_iterator UInt32ToDIEMapConstIter;
39 typedef std::multimap<uint32_t, const DWARFDebugInfoEntry *> UInt32ToDIEMMap;
40 typedef UInt32ToDIEMMap::iterator UInt32ToDIEMMapIter;
41 typedef UInt32ToDIEMMap::const_iterator UInt32ToDIEMMapConstIter;
43 class DWARFDeclContext;
45 #define DIE_SIBLING_IDX_BITSIZE 31
47 class DWARFDebugInfoEntry {
49 typedef std::vector<DWARFDebugInfoEntry> collection;
50 typedef collection::iterator iterator;
51 typedef collection::const_iterator const_iterator;
53 typedef std::vector<dw_offset_t> offset_collection;
54 typedef offset_collection::iterator offset_collection_iterator;
55 typedef offset_collection::const_iterator offset_collection_const_iterator;
58 : m_offset(DW_INVALID_OFFSET), m_parent_idx(0), m_sibling_idx(0),
59 m_has_children(false), m_abbr_idx(0), m_tag(0) {}
61 explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; }
62 bool operator==(const DWARFDebugInfoEntry &rhs) const;
63 bool operator!=(const DWARFDebugInfoEntry &rhs) const;
65 void BuildAddressRangeTable(SymbolFileDWARF *dwarf2Data,
67 DWARFDebugAranges *debug_aranges) const;
69 void BuildFunctionAddressRangeTable(SymbolFileDWARF *dwarf2Data,
71 DWARFDebugAranges *debug_aranges) const;
73 bool FastExtract(const lldb_private::DWARFDataExtractor &debug_info_data,
75 const DWARFFormValue::FixedFormSizes &fixed_form_sizes,
76 lldb::offset_t *offset_ptr);
78 bool Extract(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
79 lldb::offset_t *offset_ptr);
81 bool LookupAddress(const dw_addr_t address, SymbolFileDWARF *dwarf2Data,
83 DWARFDebugInfoEntry **function_die,
84 DWARFDebugInfoEntry **block_die);
86 size_t GetAttributes(const DWARFUnit *cu,
87 DWARFFormValue::FixedFormSizes fixed_form_sizes,
88 DWARFAttributes &attrs,
89 uint32_t curr_depth = 0)
90 const; // "curr_depth" for internal use only, don't set this yourself!!!
93 GetAttributeValue(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
94 const dw_attr_t attr, DWARFFormValue &formValue,
95 dw_offset_t *end_attr_offset_ptr = nullptr,
96 bool check_specification_or_abstract_origin = false) const;
98 const char *GetAttributeValueAsString(
99 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
100 const dw_attr_t attr, const char *fail_value,
101 bool check_specification_or_abstract_origin = false) const;
103 uint64_t GetAttributeValueAsUnsigned(
104 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
105 const dw_attr_t attr, uint64_t fail_value,
106 bool check_specification_or_abstract_origin = false) const;
108 uint64_t GetAttributeValueAsReference(
109 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
110 const dw_attr_t attr, uint64_t fail_value,
111 bool check_specification_or_abstract_origin = false) const;
113 int64_t GetAttributeValueAsSigned(
114 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
115 const dw_attr_t attr, int64_t fail_value,
116 bool check_specification_or_abstract_origin = false) const;
118 uint64_t GetAttributeValueAsAddress(
119 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
120 const dw_attr_t attr, uint64_t fail_value,
121 bool check_specification_or_abstract_origin = false) const;
124 GetAttributeHighPC(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
125 dw_addr_t lo_pc, uint64_t fail_value,
126 bool check_specification_or_abstract_origin = false) const;
128 bool GetAttributeAddressRange(
129 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu, dw_addr_t &lo_pc,
130 dw_addr_t &hi_pc, uint64_t fail_value,
131 bool check_specification_or_abstract_origin = false) const;
133 size_t GetAttributeAddressRanges(
134 SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
135 DWARFRangeList &ranges, bool check_hi_lo_pc,
136 bool check_specification_or_abstract_origin = false) const;
138 const char *GetName(SymbolFileDWARF *dwarf2Data,
139 const DWARFUnit *cu) const;
141 const char *GetMangledName(SymbolFileDWARF *dwarf2Data,
143 bool substitute_name_allowed = true) const;
145 const char *GetPubname(SymbolFileDWARF *dwarf2Data,
146 const DWARFUnit *cu) const;
148 static bool GetName(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
149 const dw_offset_t die_offset, lldb_private::Stream &s);
151 static bool AppendTypeName(SymbolFileDWARF *dwarf2Data,
153 const dw_offset_t die_offset,
154 lldb_private::Stream &s);
156 const char *GetQualifiedName(SymbolFileDWARF *dwarf2Data,
158 std::string &storage) const;
160 const char *GetQualifiedName(SymbolFileDWARF *dwarf2Data,
162 const DWARFAttributes &attributes,
163 std::string &storage) const;
165 static bool OffsetLessThan(const DWARFDebugInfoEntry &a,
166 const DWARFDebugInfoEntry &b);
168 void Dump(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
169 lldb_private::Stream &s, uint32_t recurse_depth) const;
171 void DumpAncestry(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
172 const DWARFDebugInfoEntry *oldest, lldb_private::Stream &s,
173 uint32_t recurse_depth) const;
176 DumpAttribute(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
177 const lldb_private::DWARFDataExtractor &debug_info_data,
178 lldb::offset_t *offset_ptr, lldb_private::Stream &s,
179 dw_attr_t attr, DWARFFormValue &form_value);
180 // This one dumps the comp unit name, objfile name and die offset for this die
182 void DumpLocation(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
183 lldb_private::Stream &s) const;
186 GetDIENamesAndRanges(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
187 const char *&name, const char *&mangled,
188 DWARFRangeList &rangeList, int &decl_file,
189 int &decl_line, int &decl_column, int &call_file,
190 int &call_line, int &call_column,
191 lldb_private::DWARFExpression *frame_base = NULL) const;
193 const DWARFAbbreviationDeclaration *
194 GetAbbreviationDeclarationPtr(SymbolFileDWARF *dwarf2Data,
196 lldb::offset_t &offset) const;
198 dw_tag_t Tag() const { return m_tag; }
200 bool IsNULL() const { return m_abbr_idx == 0; }
202 dw_offset_t GetOffset() const { return m_offset; }
204 bool HasChildren() const { return m_has_children; }
206 void SetHasChildren(bool b) { m_has_children = b; }
208 // We know we are kept in a vector of contiguous entries, so we know
209 // our parent will be some index behind "this".
210 DWARFDebugInfoEntry *GetParent() {
211 return m_parent_idx > 0 ? this - m_parent_idx : NULL;
213 const DWARFDebugInfoEntry *GetParent() const {
214 return m_parent_idx > 0 ? this - m_parent_idx : NULL;
216 // We know we are kept in a vector of contiguous entries, so we know
217 // our sibling will be some index after "this".
218 DWARFDebugInfoEntry *GetSibling() {
219 return m_sibling_idx > 0 ? this + m_sibling_idx : NULL;
221 const DWARFDebugInfoEntry *GetSibling() const {
222 return m_sibling_idx > 0 ? this + m_sibling_idx : NULL;
224 // We know we are kept in a vector of contiguous entries, so we know
225 // we don't need to store our child pointer, if we have a child it will
226 // be the next entry in the list...
227 DWARFDebugInfoEntry *GetFirstChild() {
228 return HasChildren() ? this + 1 : NULL;
230 const DWARFDebugInfoEntry *GetFirstChild() const {
231 return HasChildren() ? this + 1 : NULL;
234 void GetDeclContextDIEs(DWARFUnit *cu,
235 DWARFDIECollection &decl_context_dies) const;
237 void GetDWARFDeclContext(SymbolFileDWARF *dwarf2Data, DWARFUnit *cu,
238 DWARFDeclContext &dwarf_decl_ctx) const;
240 bool MatchesDWARFDeclContext(SymbolFileDWARF *dwarf2Data,
242 const DWARFDeclContext &dwarf_decl_ctx) const;
244 DWARFDIE GetParentDeclContextDIE(SymbolFileDWARF *dwarf2Data,
245 DWARFUnit *cu) const;
246 DWARFDIE GetParentDeclContextDIE(SymbolFileDWARF *dwarf2Data,
248 const DWARFAttributes &attributes) const;
250 void SetParent(DWARFDebugInfoEntry *parent) {
252 // We know we are kept in a vector of contiguous entries, so we know
253 // our parent will be some index behind "this".
254 m_parent_idx = this - parent;
258 void SetSibling(DWARFDebugInfoEntry *sibling) {
260 // We know we are kept in a vector of contiguous entries, so we know
261 // our sibling will be some index after "this".
262 m_sibling_idx = sibling - this;
263 sibling->SetParent(GetParent());
268 void SetSiblingIndex(uint32_t idx) { m_sibling_idx = idx; }
270 void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
273 DumpDIECollection(lldb_private::Stream &strm,
274 DWARFDebugInfoEntry::collection &die_collection);
278 m_offset; // Offset within the .debug_info of the start of this entry
279 uint32_t m_parent_idx; // How many to subtract from "this" to get the parent.
280 // If zero this die has no parent
281 uint32_t m_sibling_idx : 31, // How many to add to "this" to get the sibling.
282 // If it is zero, then the DIE doesn't have children, or the
283 // DWARF claimed it had children but the DIE only contained
284 // a single NULL terminating child.
287 uint16_t m_tag; // A copy of the DW_TAG value so we don't have to go through
288 // the compile unit abbrev table
291 #endif // SymbolFileDWARF_DWARFDebugInfoEntry_h_