[LoongArch] Supports FP_TO_SINT operation for fp16 (#118303)
[llvm-project.git] / lldb / source / Plugins / SymbolFile / DWARF / DWARFBaseDIE.h
blobd92de658a49e8998d07800cbfb76a95a86779faf
1 //===-- DWARFBaseDIE.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_DWARFBASEDIE_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFBASEDIE_H
12 #include "lldb/Core/dwarf.h"
13 #include "lldb/lldb-types.h"
15 #include "llvm/Support/Error.h"
16 #include <optional>
18 namespace lldb_private::plugin {
19 namespace dwarf {
20 class DIERef;
21 class DWARFASTParser;
22 class DWARFAttributes;
23 class DWARFUnit;
24 class DWARFDebugInfoEntry;
25 class DWARFDeclContext;
26 class SymbolFileDWARF;
27 class DWARFFormValue;
29 class DWARFBaseDIE {
30 public:
31 using DWARFFormValue = dwarf::DWARFFormValue;
32 DWARFBaseDIE() = default;
34 DWARFBaseDIE(DWARFUnit *cu, DWARFDebugInfoEntry *die)
35 : m_cu(cu), m_die(die) {}
37 DWARFBaseDIE(const DWARFUnit *cu, DWARFDebugInfoEntry *die)
38 : m_cu(const_cast<DWARFUnit *>(cu)), m_die(die) {}
40 DWARFBaseDIE(DWARFUnit *cu, const DWARFDebugInfoEntry *die)
41 : m_cu(cu), m_die(const_cast<DWARFDebugInfoEntry *>(die)) {}
43 DWARFBaseDIE(const DWARFUnit *cu, const DWARFDebugInfoEntry *die)
44 : m_cu(const_cast<DWARFUnit *>(cu)),
45 m_die(const_cast<DWARFDebugInfoEntry *>(die)) {}
47 // Tests
48 explicit operator bool() const { return IsValid(); }
50 bool IsValid() const { return m_cu && m_die; }
52 bool HasChildren() const;
54 bool Supports_DW_AT_APPLE_objc_complete_type() const;
56 // Accessors
57 SymbolFileDWARF *GetDWARF() const;
59 DWARFUnit *GetCU() const { return m_cu; }
61 DWARFDebugInfoEntry *GetDIE() const { return m_die; }
63 std::optional<DIERef> GetDIERef() const;
65 void Set(DWARFUnit *cu, DWARFDebugInfoEntry *die) {
66 if (cu && die) {
67 m_cu = cu;
68 m_die = die;
69 } else {
70 Clear();
74 void Clear() {
75 m_cu = nullptr;
76 m_die = nullptr;
79 // Get the data that contains the attribute values for this DIE. Support
80 // for .debug_types means that any DIE can have its data either in the
81 // .debug_info or the .debug_types section; this method will return the
82 // correct section data.
84 // Clients must validate that this object is valid before calling this.
85 const DWARFDataExtractor &GetData() const;
87 // Accessing information about a DIE
88 dw_tag_t Tag() const;
90 dw_offset_t GetOffset() const;
92 // Get the LLDB user ID for this DIE. This is often just the DIE offset,
93 // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if
94 // we are doing Darwin DWARF in .o file, or DWARF stand alone debug
95 // info.
96 lldb::user_id_t GetID() const;
98 const char *GetName() const;
100 lldb::ModuleSP GetModule() const;
102 // Getting attribute values from the DIE.
104 // GetAttributeValueAsXXX() functions should only be used if you are
105 // looking for one or two attributes on a DIE. If you are trying to
106 // parse all attributes, use GetAttributes (...) instead
107 const char *GetAttributeValueAsString(const dw_attr_t attr,
108 const char *fail_value) const;
110 uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr,
111 uint64_t fail_value) const;
113 std::optional<uint64_t>
114 GetAttributeValueAsOptionalUnsigned(const dw_attr_t attr) const;
116 uint64_t GetAttributeValueAsAddress(const dw_attr_t attr,
117 uint64_t fail_value) const;
119 enum class Recurse : bool { no, yes };
120 DWARFAttributes GetAttributes(Recurse recurse = Recurse::yes) const;
122 // The following methods use LLVM naming convension in order to be are used by
123 // LLVM libraries.
124 dw_tag_t getTag() const { return Tag(); }
126 const char *getShortName() const { return GetName(); }
128 protected:
129 DWARFUnit *m_cu = nullptr;
130 DWARFDebugInfoEntry *m_die = nullptr;
133 bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs);
134 bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs);
135 } // namespace dwarf
136 } // namespace lldb_private::plugin
138 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFBASEDIE_H