[LoongArch] Supports FP_TO_SINT operation for fp16 (#118303)
[llvm-project.git] / lldb / source / Plugins / SymbolFile / DWARF / DWARFDIE.h
blob5c1d381930c4ed46d07d1e88cceefc07e929bf26
1 //===-- DWARFDIE.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_DWARFDIE_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H
12 #include "DWARFBaseDIE.h"
13 #include "llvm/ADT/SmallSet.h"
14 #include "llvm/ADT/iterator_range.h"
16 namespace lldb_private::plugin {
17 namespace dwarf {
18 class DWARFDIE : public DWARFBaseDIE {
19 public:
20 class child_iterator;
21 using DWARFBaseDIE::DWARFBaseDIE;
23 // Tests
24 bool IsStructUnionOrClass() const;
26 bool IsMethod() const;
28 // Accessors
30 // Accessing information about a DIE
31 const char *GetMangledName(bool substitute_name_allowed = true) const;
33 const char *GetPubname() const;
35 using DWARFBaseDIE::GetName;
36 void GetName(Stream &s) const;
38 void AppendTypeName(Stream &s) const;
40 Type *ResolveType() const;
42 // Resolve a type by UID using this DIE's DWARF file
43 Type *ResolveTypeUID(const DWARFDIE &die) const;
45 // Functions for obtaining DIE relations and references
47 DWARFDIE
48 GetParent() const;
50 DWARFDIE
51 GetFirstChild() const;
53 DWARFDIE
54 GetSibling() const;
56 DWARFDIE
57 GetReferencedDIE(const dw_attr_t attr) const;
59 // Get a another DIE from the same DWARF file as this DIE. This will
60 // check the current DIE's compile unit first to see if "die_offset" is
61 // in the same compile unit, and fall back to checking the DWARF file.
62 DWARFDIE
63 GetDIE(dw_offset_t die_offset) const;
64 using DWARFBaseDIE::GetDIE;
66 DWARFDIE
67 LookupDeepestBlock(lldb::addr_t file_addr) const;
69 DWARFDIE
70 GetParentDeclContextDIE() const;
72 /// Return this DIE's decl context as it is needed to look up types
73 /// in Clang modules. This context will include any modules or functions that
74 /// the type is declared in so an exact module match can be efficiently made.
75 std::vector<CompilerContext> GetDeclContext() const;
77 /// Get a context to a type so it can be looked up.
78 ///
79 /// This function uses the current DIE to fill in a CompilerContext array
80 /// that is suitable for type lookup for comparison to a TypeQuery's compiler
81 /// context (TypeQuery::GetContextRef()). If this DIE represents a named type,
82 /// it should fill out the compiler context with the type itself as the last
83 /// entry. The declaration context should be above the type and stop at an
84 /// appropriate time, like either the translation unit or at a function
85 /// context. This is designed to allow users to efficiently look for types
86 /// using a full or partial CompilerContext array.
87 std::vector<CompilerContext> GetTypeLookupContext() const;
89 DWARFDeclContext GetDWARFDeclContext() const;
91 // Getting attribute values from the DIE.
93 // GetAttributeValueAsXXX() functions should only be used if you are
94 // looking for one or two attributes on a DIE. If you are trying to
95 // parse all attributes, use GetAttributes (...) instead
96 DWARFDIE
97 GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const;
99 bool GetDIENamesAndRanges(
100 const char *&name, const char *&mangled, DWARFRangeList &ranges,
101 std::optional<int> &decl_file, std::optional<int> &decl_line,
102 std::optional<int> &decl_column, std::optional<int> &call_file,
103 std::optional<int> &call_line, std::optional<int> &call_column,
104 DWARFExpressionList *frame_base) const;
106 // The following methods use LLVM naming convension in order to be are used by
107 // LLVM libraries.
108 std::optional<uint64_t> getLanguage() const;
110 DWARFDIE getParent() const { return GetParent(); }
112 DWARFDIE resolveReferencedType(dw_attr_t attr) const;
114 DWARFDIE resolveReferencedType(DWARFFormValue v) const;
116 DWARFDIE resolveTypeUnitReference() const;
118 std::optional<DWARFFormValue> find(const dw_attr_t attr) const;
120 /// The range of all the children of this DIE.
121 llvm::iterator_range<child_iterator> children() const;
123 child_iterator begin() const;
124 child_iterator end() const;
127 class DWARFDIE::child_iterator
128 : public llvm::iterator_facade_base<DWARFDIE::child_iterator,
129 std::forward_iterator_tag, DWARFDIE> {
130 /// The current child or an invalid DWARFDie.
131 DWARFDIE m_die;
133 public:
134 child_iterator() = default;
135 child_iterator(const DWARFDIE &parent) : m_die(parent.GetFirstChild()) {}
136 bool operator==(const child_iterator &it) const {
137 // DWARFDIE's operator== differentiates between an invalid DWARFDIE that
138 // has a CU but no DIE and one that has neither CU nor DIE. The 'end'
139 // iterator could be default constructed, so explicitly allow
140 // (CU, (DIE)nullptr) == (nullptr, nullptr) -> true
141 if (!m_die.IsValid() && !it.m_die.IsValid())
142 return true;
143 return m_die == it.m_die;
145 const DWARFDIE &operator*() const {
146 assert(m_die.IsValid() && "Derefencing invalid iterator?");
147 return m_die;
149 DWARFDIE &operator*() {
150 assert(m_die.IsValid() && "Derefencing invalid iterator?");
151 return m_die;
153 child_iterator &operator++() {
154 assert(m_die.IsValid() && "Incrementing invalid iterator?");
155 m_die = m_die.GetSibling();
156 return *this;
159 } // namespace dwarf
160 } // namespace lldb_private::plugin
162 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDIE_H