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
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
25
26#define DIE_SIBLING_IDX_BITSIZE 31
27
28/// DWARFDebugInfoEntry objects assume that they are living in one big
29/// vector and do pointer arithmetic on their this pointers. Don't
30/// pass them by value. Due to the way they are constructed in a
31/// std::vector, we cannot delete the copy constructor.
33public:
34 typedef std::vector<DWARFDebugInfoEntry> collection;
35 typedef collection::iterator iterator;
36 typedef collection::const_iterator const_iterator;
37
40 m_has_children(false) {}
41
42 explicit operator bool() const { return m_offset != DW_INVALID_OFFSET; }
43 bool operator==(const DWARFDebugInfoEntry &rhs) const;
44 bool operator!=(const DWARFDebugInfoEntry &rhs) const;
45
47 DWARFDebugAranges *debug_aranges) const;
48
50 const DWARFUnit *cu, lldb::offset_t *offset_ptr);
51
54 Recurse recurse = Recurse::yes) const {
55 return GetAttributes(cu, attrs, recurse, 0 /* curr_depth */);
56 }
57
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;
63
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;
67
69 const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value,
70 bool check_specification_or_abstract_origin = false) const;
71
72 std::optional<uint64_t> GetAttributeValueAsOptionalUnsigned(
73 const DWARFUnit *cu, const dw_attr_t attr,
74 bool check_specification_or_abstract_origin = false) const;
75
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, uint64_t fail_value,
82 bool check_specification_or_abstract_origin = false) const;
83
85 GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc, uint64_t fail_value,
86 bool check_specification_or_abstract_origin = false) const;
87
89 const DWARFUnit *cu, dw_addr_t &lo_pc, dw_addr_t &hi_pc,
90 uint64_t fail_value,
91 bool check_specification_or_abstract_origin = false) const;
92
94 DWARFUnit *cu, DWARFRangeList &ranges, bool check_hi_lo_pc,
95 bool check_specification_or_abstract_origin = false) const;
96
97 const char *GetName(const DWARFUnit *cu) const;
98
99 const char *GetMangledName(const DWARFUnit *cu,
100 bool substitute_name_allowed = true) const;
101
102 const char *GetPubname(const DWARFUnit *cu) const;
103
105 DWARFUnit *cu, const char *&name, const char *&mangled,
106 DWARFRangeList &rangeList, std::optional<int> &decl_file,
107 std::optional<int> &decl_line, std::optional<int> &decl_column,
108 std::optional<int> &call_file, std::optional<int> &call_line,
109 std::optional<int> &call_column,
110 lldb_private::DWARFExpressionList *frame_base = nullptr) const;
111
114
116
117 dw_tag_t Tag() const { return m_tag; }
118
119 bool IsNULL() const { return m_abbr_idx == 0; }
120
121 dw_offset_t GetOffset() const { return m_offset; }
122
123 bool HasChildren() const { return m_has_children; }
124
125 void SetHasChildren(bool b) { m_has_children = b; }
126
127 // We know we are kept in a vector of contiguous entries, so we know
128 // our parent will be some index behind "this".
130 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
131 }
133 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
134 }
135 // We know we are kept in a vector of contiguous entries, so we know
136 // our sibling will be some index after "this".
138 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
139 }
141 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
142 }
143 // We know we are kept in a vector of contiguous entries, so we know
144 // we don't need to store our child pointer, if we have a child it will
145 // be the next entry in the list...
147 return HasChildren() ? this + 1 : nullptr;
148 }
150 return HasChildren() ? this + 1 : nullptr;
151 }
152
154
157 const DWARFAttributes &attributes) const;
158
161
162 // This function returns true if the variable scope is either
163 // global or (file-static). It will return false for static variables
164 // that are local to a function, as they have local scope.
166
167protected:
168 static DWARFDeclContext
170
171 // Up to 2TB offset within the .debug_info/.debug_types
173 // How many to subtract from "this" to get the parent. If zero this die has no
174 // parent
176 // How many to add to "this" to get the sibling.
177 // If it is zero, then the DIE doesn't have children,
178 // or the DWARF claimed it had children but the DIE
179 // only contained a single NULL terminating child.
182 /// A copy of the DW_TAG value so we don't have to go through the compile
183 /// unit abbrev table
184 dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
185
186private:
187 size_t GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse,
188 uint32_t curr_depth) const;
189};
190
191#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
size_t GetAttributeAddressRanges(DWARFUnit *cu, DWARFRangeList &ranges, bool check_hi_lo_pc, bool check_specification_or_abstract_origin=false) const
dw_offset_t GetOffset() const
size_t GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse=Recurse::yes) 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 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
DWARFDebugInfoEntry * GetSibling()
void SetSiblingIndex(uint32_t idx)
const DWARFDebugInfoEntry * GetSibling() const
static DWARFDeclContext GetDWARFDeclContextStatic(const DWARFDebugInfoEntry *die, DWARFUnit *cu)
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:33
#define DW_INVALID_OFFSET
Definition: dwarf.h:38
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:28
#define DW_DIE_OFFSET_MAX_BITSIZE
Definition: dwarf.h:37
uint64_t dw_addr_t
Definition: dwarf.h:29
uint64_t offset_t
Definition: lldb-types.h:87