[LoongArch][Clang] Make the parameters and return value of {x,}vorn.v builti ns ...
[llvm-project.git] / lldb / source / Plugins / SymbolFile / DWARF / DWARFDebugInfoEntry.h
blob0e50aab3292ae6e148d23af3db11fc904fc7591d
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 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H
12 #include "SymbolFileDWARF.h"
13 #include "llvm/ADT/SmallVector.h"
15 #include "DWARFAttribute.h"
16 #include "DWARFBaseDIE.h"
17 #include <map>
18 #include <optional>
19 #include <set>
20 #include <vector>
22 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
24 namespace lldb_private::plugin {
25 namespace dwarf {
26 class DWARFDeclContext;
28 #define DIE_SIBLING_IDX_BITSIZE 31
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.
34 class DWARFDebugInfoEntry {
35 public:
36 typedef std::vector<DWARFDebugInfoEntry> collection;
37 typedef collection::iterator iterator;
38 typedef collection::const_iterator const_iterator;
40 DWARFDebugInfoEntry()
41 : m_offset(DW_INVALID_OFFSET), m_parent_idx(0), m_sibling_idx(0),
42 m_has_children(false) {}
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;
48 void BuildFunctionAddressRangeTable(DWARFUnit *cu,
49 DWARFDebugAranges *debug_aranges) const;
51 bool Extract(const DWARFDataExtractor &data, const DWARFUnit &cu,
52 lldb::offset_t *offset_ptr);
54 using Recurse = DWARFBaseDIE::Recurse;
55 DWARFAttributes GetAttributes(DWARFUnit *cu,
56 Recurse recurse = Recurse::yes) const {
57 DWARFAttributes attrs;
58 GetAttributes(cu, attrs, recurse, 0 /* curr_depth */);
59 return attrs;
62 dw_offset_t GetAttributeValue(const DWARFUnit *cu, const dw_attr_t attr,
63 DWARFFormValue &formValue,
64 dw_offset_t *end_attr_offset_ptr = nullptr,
65 bool check_elaborating_dies = false) const;
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;
72 uint64_t
73 GetAttributeValueAsUnsigned(const DWARFUnit *cu, const dw_attr_t attr,
74 uint64_t fail_value,
75 bool check_elaborating_dies = false) const;
77 std::optional<uint64_t> GetAttributeValueAsOptionalUnsigned(
78 const DWARFUnit *cu, const dw_attr_t attr,
79 bool check_elaborating_dies = false) const;
81 DWARFDIE
82 GetAttributeValueAsReference(const DWARFUnit *cu, const dw_attr_t attr,
83 bool check_elaborating_dies = false) const;
85 uint64_t
86 GetAttributeValueAsAddress(const DWARFUnit *cu, const dw_attr_t attr,
87 uint64_t fail_value,
88 bool check_elaborating_dies = false) const;
90 dw_addr_t GetAttributeHighPC(const DWARFUnit *cu, dw_addr_t lo_pc,
91 uint64_t fail_value,
92 bool check_elaborating_dies = false) const;
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;
98 DWARFRangeList
99 GetAttributeAddressRanges(DWARFUnit *cu, bool check_hi_lo_pc,
100 bool check_elaborating_dies = false) const;
102 const char *GetName(const DWARFUnit *cu) const;
104 const char *GetMangledName(const DWARFUnit *cu,
105 bool substitute_name_allowed = true) const;
107 const char *GetPubname(const DWARFUnit *cu) const;
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;
119 const llvm::DWARFAbbreviationDeclaration *
120 GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const;
122 lldb::offset_t GetFirstAttributeOffset() const;
124 dw_tag_t Tag() const { return m_tag; }
126 bool IsNULL() const { return m_abbr_idx == 0; }
128 dw_offset_t GetOffset() const { return m_offset; }
130 bool HasChildren() const { return m_has_children; }
132 void SetHasChildren(bool b) { m_has_children = b; }
134 // We know we are kept in a vector of contiguous entries, so we know
135 // our parent will be some index behind "this".
136 DWARFDebugInfoEntry *GetParent() {
137 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
139 const DWARFDebugInfoEntry *GetParent() const {
140 return m_parent_idx > 0 ? this - m_parent_idx : nullptr;
142 // We know we are kept in a vector of contiguous entries, so we know
143 // our sibling will be some index after "this".
144 DWARFDebugInfoEntry *GetSibling() {
145 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
147 const DWARFDebugInfoEntry *GetSibling() const {
148 return m_sibling_idx > 0 ? this + m_sibling_idx : nullptr;
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...
153 DWARFDebugInfoEntry *GetFirstChild() {
154 return HasChildren() ? this + 1 : nullptr;
156 const DWARFDebugInfoEntry *GetFirstChild() const {
157 return HasChildren() ? this + 1 : nullptr;
160 void SetSiblingIndex(uint32_t idx) { m_sibling_idx = idx; }
161 void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
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.
166 bool IsGlobalOrStaticScopeVariable() const;
168 protected:
169 // Up to 2TB offset within the .debug_info/.debug_types
170 dw_offset_t m_offset : DW_DIE_OFFSET_MAX_BITSIZE;
171 // How many to subtract from "this" to get the parent. If zero this die has no
172 // parent
173 dw_offset_t m_parent_idx : 64 - DW_DIE_OFFSET_MAX_BITSIZE;
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;
184 private:
185 void GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse,
186 uint32_t curr_depth) const;
188 } // namespace dwarf
189 } // namespace lldb_private::plugin
191 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H