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 {
26class DWARFDeclContext;
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
51 bool Extract(const DWARFDataExtractor &data, const DWARFUnit &cu,
52 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 DWARFFormValue &formValue,
64 dw_offset_t *end_attr_offset_ptr = nullptr,
65 bool check_elaborating_dies = false) const;
66
67 const char *
68 GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr,
69 const char *fail_value,
70 bool check_elaborating_dies = false) const;
71
72 uint64_t
74 uint64_t fail_value,
75 bool check_elaborating_dies = false) const;
76
77 std::optional<uint64_t> GetAttributeValueAsOptionalUnsigned(
78 const DWARFUnit *cu, const dw_attr_t attr,
79 bool check_elaborating_dies = false) const;
80
83 bool check_elaborating_dies = false) const;
84
85 uint64_t
87 uint64_t fail_value,
88 bool check_elaborating_dies = false) const;
89
91 uint64_t fail_value,
92 bool check_elaborating_dies = false) const;
93
94 bool GetAttributeAddressRange(const DWARFUnit *cu, dw_addr_t &lo_pc,
95 dw_addr_t &hi_pc, uint64_t fail_value,
96 bool check_elaborating_dies = false) const;
97
98 llvm::Expected<llvm::DWARFAddressRangesVector>
99 GetAttributeAddressRanges(DWARFUnit *cu, bool check_hi_lo_pc,
100 bool check_elaborating_dies = 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
110 DWARFUnit *cu, const char *&name, const char *&mangled,
111 llvm::DWARFAddressRangesVector &rangeList, std::optional<int> &decl_file,
112 std::optional<int> &decl_line, std::optional<int> &decl_column,
113 std::optional<int> &call_file, std::optional<int> &call_line,
114 std::optional<int> &call_column,
115 DWARFExpressionList *frame_base = nullptr) const;
116
117 const llvm::DWARFAbbreviationDeclaration *
119
121
122 dw_tag_t Tag() const { return m_tag; }
123
124 bool IsNULL() const { return m_abbr_idx == 0; }
125
126 dw_offset_t GetOffset() const { return m_offset; }
127
128 bool HasChildren() const { return m_has_children; }
129
130 void SetHasChildren(bool b) { m_has_children = b; }
131
132 // We know we are kept in a vector of contiguous entries, so we know
133 // our parent will be some index behind "this".
135 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
136 }
138 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
139 }
140 // We know we are kept in a vector of contiguous entries, so we know
141 // our sibling will be some index after "this".
143 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
144 }
146 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
147 }
148 // We know we are kept in a vector of contiguous entries, so we know
149 // we don't need to store our child pointer, if we have a child it will
150 // be the next entry in the list...
152 return HasChildren() ? this + 1 : nullptr;
153 }
155 return HasChildren() ? this + 1 : nullptr;
156 }
157
158 void SetSiblingIndex(uint32_t idx) { m_sibling_idx = idx; }
159 void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
160
161 // This function returns true if the variable scope is either
162 // global or (file-static). It will return false for static variables
163 // that are local to a function, as they have local scope.
165
166protected:
167 // Up to 2TB offset within the .debug_info/.debug_types
169 // How many to subtract from "this" to get the parent. If zero this die has no
170 // parent
172 // How many to add to "this" to get the sibling.
173 // If it is zero, then the DIE doesn't have children,
174 // or the DWARF claimed it had children but the DIE
175 // only contained a single NULL terminating child.
176 uint32_t m_sibling_idx : 31, m_has_children : 1;
177 uint16_t m_abbr_idx = 0;
178 /// A copy of the DW_TAG value so we don't have to go through the compile
179 /// unit abbrev table
180 dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
181
182private:
183 void GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse,
184 uint32_t curr_depth) const;
185};
186} // namespace dwarf
187} // namespace lldb_private::plugin
188
189#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(DWARFUnit *cu, Recurse recurse=Recurse::yes) const
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:30
#define DW_INVALID_OFFSET
Definition: dwarf.h:35
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:25
#define DW_DIE_OFFSET_MAX_BITSIZE
Definition: dwarf.h:34
llvm::dwarf::Attribute dw_attr_t
Definition: dwarf.h:23
uint64_t dw_addr_t
Definition: dwarf.h:26
uint64_t offset_t
Definition: lldb-types.h:85