1 //===-- DWARFDebugInfoEntry.h -----------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef SymbolFileDWARF_DWARFDebugInfoEntry_h_
10 #define SymbolFileDWARF_DWARFDebugInfoEntry_h_
12 #include "SymbolFileDWARF.h"
13 #include "llvm/ADT/SmallVector.h"
15 #include "DWARFAbbreviationDeclaration.h"
16 #include "DWARFDebugAbbrev.h"
17 #include "DWARFDebugRanges.h"
22 class DWARFDeclContext;
24 #define DIE_SIBLING_IDX_BITSIZE 31
26 class DWARFDebugInfoEntry {
28 typedef std::vector<DWARFDebugInfoEntry> collection;
29 typedef collection::iterator iterator;
30 typedef collection::const_iterator const_iterator;
33 : m_offset(DW_INVALID_OFFSET), m_parent_idx(0), m_sibling_idx(0),
34 m_has_children(false), m_abbr_idx(0), m_tag(0) {}
36 explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; }
37 bool operator==(const DWARFDebugInfoEntry &rhs) const;
38 bool operator!=(const DWARFDebugInfoEntry &rhs) const;
40 void BuildAddressRangeTable(const DWARFUnit *cu,
41 DWARFDebugAranges *debug_aranges) const;
43 void BuildFunctionAddressRangeTable(const DWARFUnit *cu,
44 DWARFDebugAranges *debug_aranges) const;
46 bool Extract(const lldb_private::DWARFDataExtractor &data,
47 const DWARFUnit *cu, lldb::offset_t *offset_ptr);
49 bool LookupAddress(const dw_addr_t address, const DWARFUnit *cu,
50 DWARFDebugInfoEntry **function_die,
51 DWARFDebugInfoEntry **block_die);
53 size_t GetAttributes(const DWARFUnit *cu,
54 DWARFAttributes &attrs,
55 uint32_t curr_depth = 0)
56 const; // "curr_depth" for internal use only, don't set this yourself!!!
59 GetAttributeValue(const DWARFUnit *cu, const dw_attr_t attr,
60 DWARFFormValue &formValue,
61 dw_offset_t *end_attr_offset_ptr = nullptr,
62 bool check_specification_or_abstract_origin = false) const;
64 const char *GetAttributeValueAsString(
65 const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value,
66 bool check_specification_or_abstract_origin = false) const;
68 uint64_t GetAttributeValueAsUnsigned(
69 const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,
70 bool check_specification_or_abstract_origin = false) const;
72 DWARFDIE GetAttributeValueAsReference(
73 const DWARFUnit *cu, const dw_attr_t attr,
74 bool check_specification_or_abstract_origin = false) const;
76 uint64_t GetAttributeValueAsAddress(
77 const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,
78 bool check_specification_or_abstract_origin = false) const;
81 GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value,
82 bool check_specification_or_abstract_origin = false) const;
84 bool GetAttributeAddressRange(
85 const DWARFUnit *cu, dw_addr_t &lo_pc, dw_addr_t &hi_pc,
87 bool check_specification_or_abstract_origin = false) const;
89 size_t GetAttributeAddressRanges(
90 const DWARFUnit *cu, DWARFRangeList &ranges, bool check_hi_lo_pc,
91 bool check_specification_or_abstract_origin = false) const;
93 const char *GetName(const DWARFUnit *cu) const;
95 const char *GetMangledName(const DWARFUnit *cu,
96 bool substitute_name_allowed = true) const;
98 const char *GetPubname(const DWARFUnit *cu) const;
100 const char *GetQualifiedName(DWARFUnit *cu, std::string &storage) const;
102 const char *GetQualifiedName(DWARFUnit *cu, const DWARFAttributes &attributes,
103 std::string &storage) const;
105 void Dump(const DWARFUnit *cu, lldb_private::Stream &s,
106 uint32_t recurse_depth) const;
109 DumpAttribute(const DWARFUnit *cu,
110 const lldb_private::DWARFDataExtractor &data,
111 lldb::offset_t *offset_ptr, lldb_private::Stream &s,
112 dw_attr_t attr, DWARFFormValue &form_value);
114 bool GetDIENamesAndRanges(
115 const DWARFUnit *cu, const char *&name, const char *&mangled,
116 DWARFRangeList &rangeList, int &decl_file, int &decl_line,
117 int &decl_column, int &call_file, int &call_line, int &call_column,
118 lldb_private::DWARFExpression *frame_base = nullptr) const;
120 const DWARFAbbreviationDeclaration *
121 GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const;
123 lldb::offset_t GetFirstAttributeOffset() const;
125 dw_tag_t Tag() const { return m_tag; }
127 bool IsNULL() const { return m_abbr_idx == 0; }
129 dw_offset_t GetOffset() const { return m_offset; }
131 bool HasChildren() const { return m_has_children; }
133 void SetHasChildren(bool b) { m_has_children = b; }
135 // We know we are kept in a vector of contiguous entries, so we know
136 // our parent will be some index behind "this".
137 DWARFDebugInfoEntry *GetParent() {
138 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
140 const DWARFDebugInfoEntry *GetParent() const {
141 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
143 // We know we are kept in a vector of contiguous entries, so we know
144 // our sibling will be some index after "this".
145 DWARFDebugInfoEntry *GetSibling() {
146 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
148 const DWARFDebugInfoEntry *GetSibling() const {
149 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
151 // We know we are kept in a vector of contiguous entries, so we know
152 // we don't need to store our child pointer, if we have a child it will
153 // be the next entry in the list...
154 DWARFDebugInfoEntry *GetFirstChild() {
155 return HasChildren() ? this + 1 : nullptr;
157 const DWARFDebugInfoEntry *GetFirstChild() const {
158 return HasChildren() ? this + 1 : nullptr;
161 void GetDWARFDeclContext(DWARFUnit *cu,
162 DWARFDeclContext &dwarf_decl_ctx) const;
164 DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu) const;
165 DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu,
166 const DWARFAttributes &attributes) const;
168 void SetSiblingIndex(uint32_t idx) { m_sibling_idx = idx; }
169 void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
172 dw_offset_t m_offset; // Offset within the .debug_info/.debug_types
173 uint32_t m_parent_idx; // How many to subtract from "this" to get the parent.
174 // If zero this die has no parent
175 uint32_t m_sibling_idx : 31, // How many to add to "this" to get the sibling.
176 // If it is zero, then the DIE doesn't have children, or the
177 // DWARF claimed it had children but the DIE only contained
178 // a single NULL terminating child.
181 uint16_t m_tag; // A copy of the DW_TAG value so we don't have to go through
182 // the compile unit abbrev table
185 #endif // SymbolFileDWARF_DWARFDebugInfoEntry_h_