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 "DWARFDebugRanges.h"
18#include <map>
19#include <optional>
20#include <set>
21#include <vector>
22
23#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
24
25namespace lldb_private::plugin {
26namespace dwarf {
27class DWARFDeclContext;
28
29#define DIE_SIBLING_IDX_BITSIZE 31
30
31/// DWARFDebugInfoEntry objects assume that they are living in one big
32/// vector and do pointer arithmetic on their this pointers. Don't
33/// pass them by value. Due to the way they are constructed in a
34/// std::vector, we cannot delete the copy constructor.
36public:
37 typedef std::vector<DWARFDebugInfoEntry> collection;
38 typedef collection::iterator iterator;
39 typedef collection::const_iterator const_iterator;
40
43 m_has_children(false) {}
44
45 explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; }
46 bool operator==(const DWARFDebugInfoEntry &rhs) const;
47 bool operator!=(const DWARFDebugInfoEntry &rhs) const;
48
50 DWARFDebugAranges *debug_aranges) const;
51
52 bool Extract(const DWARFDataExtractor &data, const DWARFUnit &cu,
53 lldb::offset_t *offset_ptr);
54
57 Recurse recurse = Recurse::yes) const {
58 DWARFAttributes attrs;
59 GetAttributes(cu, attrs, recurse, 0 /* curr_depth */);
60 return attrs;
61 }
62
64 GetAttributeValue(const DWARFUnit *cu, const dw_attr_t attr,
65 DWARFFormValue &formValue,
66 dw_offset_t *end_attr_offset_ptr = nullptr,
67 bool check_specification_or_abstract_origin = false) const;
68
69 const char *GetAttributeValueAsString(
70 const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value,
71 bool check_specification_or_abstract_origin = false) const;
72
74 const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,
75 bool check_specification_or_abstract_origin = false) const;
76
77 std::optional<uint64_t> GetAttributeValueAsOptionalUnsigned(
78 const DWARFUnit *cu, const dw_attr_t attr,
79 bool check_specification_or_abstract_origin = false) const;
80
82 const DWARFUnit *cu, const dw_attr_t attr,
83 bool check_specification_or_abstract_origin = false) const;
84
86 const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,
87 bool check_specification_or_abstract_origin = false) const;
88
90 GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value,
91 bool check_specification_or_abstract_origin = false) const;
92
94 const DWARFUnit *cu, dw_addr_t &lo_pc, dw_addr_t &hi_pc,
95 uint64_t fail_value,
96 bool check_specification_or_abstract_origin = false) const;
97
99 DWARFUnit *cu, bool check_hi_lo_pc,
100 bool check_specification_or_abstract_origin = false) const;
101
102 const char *GetName(const DWARFUnit *cu) const;
103
104 const char *GetMangledName(const DWARFUnit *cu,
105 bool substitute_name_allowed = true) const;
106
107 const char *GetPubname(const DWARFUnit *cu) const;
108
109 bool GetDIENamesAndRanges(DWARFUnit *cu, const char *&name,
110 const char *&mangled, DWARFRangeList &rangeList,
111 std::optional<int> &decl_file,
112 std::optional<int> &decl_line,
113 std::optional<int> &decl_column,
114 std::optional<int> &call_file,
115 std::optional<int> &call_line,
116 std::optional<int> &call_column,
117 DWARFExpressionList *frame_base = nullptr) const;
118
119 const llvm::DWARFAbbreviationDeclaration *
121
123
124 dw_tag_t Tag() const { return m_tag; }
125
126 bool IsNULL() const { return m_abbr_idx == 0; }
127
128 dw_offset_t GetOffset() const { return m_offset; }
129
130 bool HasChildren() const { return m_has_children; }
131
132 void SetHasChildren(bool b) { m_has_children = b; }
133
134 // We know we are kept in a vector of contiguous entries, so we know
135 // our parent will be some index behind "this".
137 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
138 }
140 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
141 }
142 // We know we are kept in a vector of contiguous entries, so we know
143 // our sibling will be some index after "this".
145 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
146 }
148 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
149 }
150 // We know we are kept in a vector of contiguous entries, so we know
151 // we don't need to store our child pointer, if we have a child it will
152 // be the next entry in the list...
154 return HasChildren() ? this + 1 : nullptr;
155 }
157 return HasChildren() ? this + 1 : nullptr;
158 }
159
160 void SetSiblingIndex(uint32_t idx) { m_sibling_idx = idx; }
161 void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
162
163 // This function returns true if the variable scope is either
164 // global or (file-static). It will return false for static variables
165 // that are local to a function, as they have local scope.
167
168protected:
169 // Up to 2TB offset within the .debug_info/.debug_types
171 // How many to subtract from "this" to get the parent. If zero this die has no
172 // parent
174 // How many to add to "this" to get the sibling.
175 // If it is zero, then the DIE doesn't have children,
176 // or the DWARF claimed it had children but the DIE
177 // only contained a single NULL terminating child.
178 uint32_t m_sibling_idx : 31, m_has_children : 1;
179 uint16_t m_abbr_idx = 0;
180 /// A copy of the DW_TAG value so we don't have to go through the compile
181 /// unit abbrev table
182 dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
183
184private:
185 void GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse,
186 uint32_t curr_depth) const;
187};
188} // namespace dwarf
189} // namespace lldb_private::plugin
190
191#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
std::optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const DWARFUnit *cu, const dw_attr_t attr, bool check_specification_or_abstract_origin=false) 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 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
DWARFAttributes GetAttributes(DWARFUnit *cu, Recurse recurse=Recurse::yes) const
const char * GetMangledName(const DWARFUnit *cu, bool substitute_name_allowed=true) const
const llvm::DWARFAbbreviationDeclaration * GetAbbreviationDeclarationPtr(const DWARFUnit *cu) 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,...
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
const char * GetPubname(const DWARFUnit *cu) const
bool Extract(const DWARFDataExtractor &data, const DWARFUnit &cu, lldb::offset_t *offset_ptr)
uint64_t GetAttributeValueAsAddress(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
std::vector< DWARFDebugInfoEntry > collection
const char * GetName(const DWARFUnit *cu) const
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, DWARFExpressionList *frame_base=nullptr) const
const DWARFDebugInfoEntry * GetParent() const
DWARFRangeList GetAttributeAddressRanges(DWARFUnit *cu, bool check_hi_lo_pc, bool check_specification_or_abstract_origin=false) const
const DWARFDebugInfoEntry * GetSibling() const
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:85