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 LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H
11
12#include "SymbolFileDWARF.h"
13
14#include "DWARFAttribute.h"
15#include "DWARFBaseDIE.h"
16#include <map>
17#include <optional>
18#include <set>
19#include <vector>
20
21#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
22#include "llvm/DebugInfo/DWARF/DWARFAddressRange.h"
23
24namespace lldb_private::plugin {
25namespace dwarf {
27
28#define DIE_SIBLING_IDX_BITSIZE 31
29
30/// DWARFDebugInfoEntry objects assume that they are living in one big
31/// vector and do pointer arithmetic on their this pointers. Don't
32/// pass them by value. Due to the way they are constructed in a
33/// std::vector, we cannot delete the copy constructor.
35public:
36 typedef std::vector<DWARFDebugInfoEntry> collection;
37 typedef collection::iterator iterator;
38 typedef collection::const_iterator const_iterator;
39
43
44 explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; }
45 bool operator==(const DWARFDebugInfoEntry &rhs) const;
46 bool operator!=(const DWARFDebugInfoEntry &rhs) const;
47
49 DWARFDebugAranges *debug_aranges) const;
50
51 bool Extract(const DWARFDataExtractor &data, const DWARFUnit &cu,
52 lldb::offset_t *offset_ptr);
53
55
56 /// Get all attribute values for a given DIE, optionally following any
57 /// specifications and abstract origins and including their attributes
58 /// in the result too.
59 ///
60 /// When following specifications/abstract origins, the attributes
61 /// on the referring DIE are guaranteed to be visited before the attributes of
62 /// the referenced DIE.
63 ///
64 /// \param[in] cu DWARFUnit that this entry belongs to.
65 ///
66 /// \param[in] recurse If set to \c Recurse::yes, will include attributes
67 /// on DIEs referenced via \c DW_AT_specification and \c DW_AT_abstract_origin
68 /// (including across multiple levels of indirection).
69 ///
70 /// \returns DWARFAttributes that include all attributes found on this DIE
71 /// (and possibly referenced DIEs). Attributes may appear multiple times
72 /// (e.g., if a declaration and definition both specify the same attribute).
73 /// On failure, the returned DWARFAttributes will be empty.
74 ///
76 Recurse recurse = Recurse::yes) const;
77
79 DWARFFormValue &formValue,
80 dw_offset_t *end_attr_offset_ptr = nullptr,
81 bool check_elaborating_dies = false) const;
82
83 const char *
84 GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr,
85 const char *fail_value,
86 bool check_elaborating_dies = false) const;
87
88 uint64_t
90 uint64_t fail_value,
91 bool check_elaborating_dies = false) const;
92
93 std::optional<uint64_t> GetAttributeValueAsOptionalUnsigned(
94 const DWARFUnit *cu, const dw_attr_t attr,
95 bool check_elaborating_dies = false) const;
96
99 bool check_elaborating_dies = false) const;
100
101 uint64_t
102 GetAttributeValueAsAddress(const DWARFUnit *cu, const dw_attr_t attr,
103 uint64_t fail_value,
104 bool check_elaborating_dies = false) const;
105
107 uint64_t fail_value,
108 bool check_elaborating_dies = false) const;
109
110 bool GetAttributeAddressRange(const DWARFUnit *cu, dw_addr_t &lo_pc,
111 dw_addr_t &hi_pc, uint64_t fail_value,
112 bool check_elaborating_dies = false) const;
113
114 llvm::Expected<llvm::DWARFAddressRangesVector>
115 GetAttributeAddressRanges(DWARFUnit *cu, bool check_hi_lo_pc,
116 bool check_elaborating_dies = false) const;
117
118 const char *GetName(const DWARFUnit *cu) const;
119
120 const char *GetMangledName(const DWARFUnit *cu,
121 bool substitute_name_allowed = true) const;
122
123 const char *GetPubname(const DWARFUnit *cu) const;
124
126 DWARFUnit *cu, const char *&name, const char *&mangled,
127 llvm::DWARFAddressRangesVector &rangeList, std::optional<int> &decl_file,
128 std::optional<int> &decl_line, std::optional<int> &decl_column,
129 std::optional<int> &call_file, std::optional<int> &call_line,
130 std::optional<int> &call_column,
131 DWARFExpressionList *frame_base = nullptr) const;
132
133 const llvm::DWARFAbbreviationDeclaration *
135
137
138 dw_tag_t Tag() const { return m_tag; }
139
140 bool IsNULL() const { return m_abbr_idx == 0; }
141
142 dw_offset_t GetOffset() const { return m_offset; }
143
144 bool HasChildren() const { return m_has_children; }
145
146 void SetHasChildren(bool b) { m_has_children = b; }
147
148 // We know we are kept in a vector of contiguous entries, so we know
149 // our parent will be some index behind "this".
151 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
152 }
154 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
155 }
156 // We know we are kept in a vector of contiguous entries, so we know
157 // our sibling will be some index after "this".
159 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
160 }
162 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
163 }
164 // We know we are kept in a vector of contiguous entries, so we know
165 // we don't need to store our child pointer, if we have a child it will
166 // be the next entry in the list...
168 return HasChildren() ? this + 1 : nullptr;
169 }
171 return HasChildren() ? this + 1 : nullptr;
172 }
173
174 void SetSiblingIndex(uint32_t idx) { m_sibling_idx = idx; }
175 void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
176
177 // This function returns true if the variable scope is either
178 // global or (file-static). It will return false for static variables
179 // that are local to a function, as they have local scope.
181
182protected:
183 // Up to 2TB offset within the .debug_info/.debug_types
185 // How many to subtract from "this" to get the parent. If zero this die has no
186 // parent
188 // How many to add to "this" to get the sibling.
189 // If it is zero, then the DIE doesn't have children,
190 // or the DWARF claimed it had children but the DIE
191 // only contained a single NULL terminating child.
192 uint32_t m_sibling_idx : 31, m_has_children : 1;
193 uint16_t m_abbr_idx = 0;
194 /// A copy of the DW_TAG value so we don't have to go through the compile
195 /// unit abbrev table
196 dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
197};
198} // namespace dwarf
199} // namespace lldb_private::plugin
200
201#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
bool operator==(const DWARFDebugInfoEntry &rhs) const
dw_tag_t m_tag
A copy of the DW_TAG value so we don't have to go through the compile unit abbrev table.
bool GetAttributeAddressRange(const DWARFUnit *cu, dw_addr_t &lo_pc, dw_addr_t &hi_pc, uint64_t fail_value, bool check_elaborating_dies=false) const
dw_addr_t GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value, bool check_elaborating_dies=false) const
bool operator!=(const DWARFDebugInfoEntry &rhs) const
llvm::Expected< llvm::DWARFAddressRangesVector > GetAttributeAddressRanges(DWARFUnit *cu, bool check_hi_lo_pc, bool check_elaborating_dies=false) const
DWARFAttributes GetAttributes(const DWARFUnit *cu, Recurse recurse=Recurse::yes) const
Get all attribute values for a given DIE, optionally following any specifications and abstract origin...
const char * GetMangledName(const DWARFUnit *cu, bool substitute_name_allowed=true) const
std::optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const DWARFUnit *cu, const dw_attr_t attr, bool check_elaborating_dies=false) const
const llvm::DWARFAbbreviationDeclaration * GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const
void BuildFunctionAddressRangeTable(DWARFUnit *cu, DWARFDebugAranges *debug_aranges) const
This function is builds a table very similar to the standard .debug_aranges table,...
const DWARFDebugInfoEntry * GetFirstChild() const
DWARFDIE GetAttributeValueAsReference(const DWARFUnit *cu, const dw_attr_t attr, bool check_elaborating_dies=false) const
const char * GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, bool check_elaborating_dies=false) const
bool GetDIENamesAndRanges(DWARFUnit *cu, const char *&name, const char *&mangled, llvm::DWARFAddressRangesVector &rangeList, std::optional< int > &decl_file, std::optional< int > &decl_line, std::optional< int > &decl_column, std::optional< int > &call_file, std::optional< int > &call_line, std::optional< int > &call_column, DWARFExpressionList *frame_base=nullptr) const
uint64_t GetAttributeValueAsAddress(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_elaborating_dies=false) const
uint64_t GetAttributeValueAsUnsigned(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_elaborating_dies=false) const
const char * GetPubname(const DWARFUnit *cu) const
bool Extract(const DWARFDataExtractor &data, const DWARFUnit &cu, lldb::offset_t *offset_ptr)
dw_offset_t GetAttributeValue(const DWARFUnit *cu, const dw_attr_t attr, DWARFFormValue &formValue, dw_offset_t *end_attr_offset_ptr=nullptr, bool check_elaborating_dies=false) const
std::vector< DWARFDebugInfoEntry > collection
const char * GetName(const DWARFUnit *cu) const
const DWARFDebugInfoEntry * GetParent() const
const DWARFDebugInfoEntry * GetSibling() const
uint64_t dw_offset_t
Definition dwarf.h:24
#define DW_INVALID_OFFSET
Definition dwarf.h:29
llvm::dwarf::Tag dw_tag_t
Definition dwarf.h:19
#define DW_DIE_OFFSET_MAX_BITSIZE
Definition dwarf.h:28
llvm::dwarf::Attribute dw_attr_t
Definition dwarf.h:17
uint64_t dw_addr_t
Definition dwarf.h:20
uint64_t offset_t
Definition lldb-types.h:85