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#include "llvm/ADT/SmallVector.h"
14
15#include "DWARFAttribute.h"
16#include "DWARFBaseDIE.h"
17#include "DWARFDebugAbbrev.h"
18#include "DWARFDebugRanges.h"
19#include <map>
20#include <optional>
21#include <set>
22#include <vector>
23
24#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
25
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
42 m_has_children(false) {}
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
52 const DWARFUnit *cu, lldb::offset_t *offset_ptr);
53
56 Recurse recurse = Recurse::yes) const {
57 DWARFAttributes attrs;
58 GetAttributes(cu, attrs, recurse, 0 /* curr_depth */);
59 return attrs;
60 }
61
63 GetAttributeValue(const DWARFUnit *cu, const dw_attr_t attr,
64 DWARFFormValue &formValue,
65 dw_offset_t *end_attr_offset_ptr = nullptr,
66 bool check_specification_or_abstract_origin = false) const;
67
68 const char *GetAttributeValueAsString(
69 const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value,
70 bool check_specification_or_abstract_origin = false) const;
71
73 const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,
74 bool check_specification_or_abstract_origin = false) const;
75
76 std::optional<uint64_t> GetAttributeValueAsOptionalUnsigned(
77 const DWARFUnit *cu, const dw_attr_t attr,
78 bool check_specification_or_abstract_origin = false) const;
79
81 const DWARFUnit *cu, const dw_attr_t attr,
82 bool check_specification_or_abstract_origin = false) const;
83
85 const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,
86 bool check_specification_or_abstract_origin = false) const;
87
89 GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value,
90 bool check_specification_or_abstract_origin = false) const;
91
93 const DWARFUnit *cu, dw_addr_t &lo_pc, dw_addr_t &hi_pc,
94 uint64_t fail_value,
95 bool check_specification_or_abstract_origin = false) const;
96
98 DWARFUnit *cu, bool check_hi_lo_pc,
99 bool check_specification_or_abstract_origin = false) const;
100
101 const char *GetName(const DWARFUnit *cu) const;
102
103 const char *GetMangledName(const DWARFUnit *cu,
104 bool substitute_name_allowed = true) const;
105
106 const char *GetPubname(const DWARFUnit *cu) const;
107
109 DWARFUnit *cu, const char *&name, const char *&mangled,
110 DWARFRangeList &rangeList, std::optional<int> &decl_file,
111 std::optional<int> &decl_line, std::optional<int> &decl_column,
112 std::optional<int> &call_file, std::optional<int> &call_line,
113 std::optional<int> &call_column,
114 lldb_private::DWARFExpressionList *frame_base = nullptr) const;
115
116 const llvm::DWARFAbbreviationDeclaration *
118
120
121 dw_tag_t Tag() const { return m_tag; }
122
123 bool IsNULL() const { return m_abbr_idx == 0; }
124
125 dw_offset_t GetOffset() const { return m_offset; }
126
127 bool HasChildren() const { return m_has_children; }
128
129 void SetHasChildren(bool b) { m_has_children = b; }
130
131 // We know we are kept in a vector of contiguous entries, so we know
132 // our parent will be some index behind "this".
134 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
135 }
137 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
138 }
139 // We know we are kept in a vector of contiguous entries, so we know
140 // our sibling will be some index after "this".
142 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
143 }
145 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
146 }
147 // We know we are kept in a vector of contiguous entries, so we know
148 // we don't need to store our child pointer, if we have a child it will
149 // be the next entry in the list...
151 return HasChildren() ? this + 1 : nullptr;
152 }
154 return HasChildren() ? this + 1 : nullptr;
155 }
156
158
161 const DWARFAttributes &attributes) const;
162
163 void SetSiblingIndex(uint32_t idx) { m_sibling_idx = idx; }
164 void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
165
166 // This function returns true if the variable scope is either
167 // global or (file-static). It will return false for static variables
168 // that are local to a function, as they have local scope.
170
171protected:
172 static DWARFDeclContext
174
175 // Up to 2TB offset within the .debug_info/.debug_types
177 // How many to subtract from "this" to get the parent. If zero this die has no
178 // parent
180 // How many to add to "this" to get the sibling.
181 // If it is zero, then the DIE doesn't have children,
182 // or the DWARF claimed it had children but the DIE
183 // only contained a single NULL terminating child.
184 uint32_t m_sibling_idx : 31, m_has_children : 1;
185 uint16_t m_abbr_idx = 0;
186 /// A copy of the DW_TAG value so we don't have to go through the compile
187 /// unit abbrev table
188 dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
189
190private:
191 void GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse,
192 uint32_t curr_depth) const;
193};
194
195#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H
DWARFDebugInfoEntry objects assume that they are living in one big vector and do pointer arithmetic o...
bool operator==(const DWARFDebugInfoEntry &rhs) const
std::optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const DWARFUnit *cu, const dw_attr_t attr, bool check_specification_or_abstract_origin=false) const
dw_offset_t GetOffset() 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.
const char * GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, bool check_specification_or_abstract_origin=false) const
dw_offset_t GetAttributeValue(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
bool operator!=(const DWARFDebugInfoEntry &rhs) const
bool Extract(const lldb_private::DWARFDataExtractor &data, const DWARFUnit *cu, lldb::offset_t *offset_ptr)
DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu) const
DWARFDeclContext GetDWARFDeclContext(DWARFUnit *cu) const
bool GetAttributeAddressRange(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
bool IsGlobalOrStaticScopeVariable() const
std::vector< DWARFDebugInfoEntry > collection
bool GetDIENamesAndRanges(DWARFUnit *cu, const char *&name, const char *&mangled, DWARFRangeList &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, lldb_private::DWARFExpressionList *frame_base=nullptr) const
const DWARFDebugInfoEntry * GetParent() const
const char * GetMangledName(const DWARFUnit *cu, bool substitute_name_allowed=true) const
dw_addr_t GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
void BuildFunctionAddressRangeTable(DWARFUnit *cu, DWARFDebugAranges *debug_aranges) const
This function is builds a table very similar to the standard .debug_aranges table,...
void SetParentIndex(uint32_t idx)
const DWARFDebugInfoEntry * GetFirstChild() const
DWARFDIE GetAttributeValueAsReference(const DWARFUnit *cu, const dw_attr_t attr, bool check_specification_or_abstract_origin=false) const
uint64_t GetAttributeValueAsUnsigned(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
collection::iterator iterator
const char * GetPubname(const DWARFUnit *cu) const
const llvm::DWARFAbbreviationDeclaration * GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const
uint64_t GetAttributeValueAsAddress(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
DWARFDebugInfoEntry * GetFirstChild()
const char * GetName(const DWARFUnit *cu) const
DWARFAttributes GetAttributes(DWARFUnit *cu, Recurse recurse=Recurse::yes) const
DWARFDebugInfoEntry * GetSibling()
void SetSiblingIndex(uint32_t idx)
const DWARFDebugInfoEntry * GetSibling() const
static DWARFDeclContext GetDWARFDeclContextStatic(const DWARFDebugInfoEntry *die, DWARFUnit *cu)
DWARFRangeList GetAttributeAddressRanges(DWARFUnit *cu, bool check_hi_lo_pc, bool check_specification_or_abstract_origin=false) const
collection::const_iterator const_iterator
lldb::offset_t GetFirstAttributeOffset() const
DWARFDebugInfoEntry * GetParent()
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
uint64_t dw_offset_t
Definition: dwarf.h:31
#define DW_INVALID_OFFSET
Definition: dwarf.h:36
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:26
#define DW_DIE_OFFSET_MAX_BITSIZE
Definition: dwarf.h:35
llvm::dwarf::Attribute dw_attr_t
Definition: dwarf.h:24
uint64_t dw_addr_t
Definition: dwarf.h:27
uint64_t offset_t
Definition: lldb-types.h:83