1 //===-- DWARFBaseDIE.h -----------------------------------------*- C++ -*-===//
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
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"
18 namespace lldb_private::plugin
{
22 class DWARFAttributes
;
24 class DWARFDebugInfoEntry
;
25 class DWARFDeclContext
;
26 class SymbolFileDWARF
;
30 DWARFBaseDIE() = default;
32 DWARFBaseDIE(DWARFUnit
*cu
, DWARFDebugInfoEntry
*die
)
33 : m_cu(cu
), m_die(die
) {}
35 DWARFBaseDIE(const DWARFUnit
*cu
, DWARFDebugInfoEntry
*die
)
36 : m_cu(const_cast<DWARFUnit
*>(cu
)), m_die(die
) {}
38 DWARFBaseDIE(DWARFUnit
*cu
, const DWARFDebugInfoEntry
*die
)
39 : m_cu(cu
), m_die(const_cast<DWARFDebugInfoEntry
*>(die
)) {}
41 DWARFBaseDIE(const DWARFUnit
*cu
, const DWARFDebugInfoEntry
*die
)
42 : m_cu(const_cast<DWARFUnit
*>(cu
)),
43 m_die(const_cast<DWARFDebugInfoEntry
*>(die
)) {}
46 explicit operator bool() const { return IsValid(); }
48 bool IsValid() const { return m_cu
&& m_die
; }
50 bool HasChildren() const;
52 bool Supports_DW_AT_APPLE_objc_complete_type() const;
55 SymbolFileDWARF
*GetDWARF() const;
57 DWARFUnit
*GetCU() const { return m_cu
; }
59 DWARFDebugInfoEntry
*GetDIE() const { return m_die
; }
61 std::optional
<DIERef
> GetDIERef() const;
63 void Set(DWARFUnit
*cu
, DWARFDebugInfoEntry
*die
) {
77 // Get the data that contains the attribute values for this DIE. Support
78 // for .debug_types means that any DIE can have its data either in the
79 // .debug_info or the .debug_types section; this method will return the
80 // correct section data.
82 // Clients must validate that this object is valid before calling this.
83 const DWARFDataExtractor
&GetData() const;
85 // Accessing information about a DIE
88 dw_offset_t
GetOffset() const;
90 // Get the LLDB user ID for this DIE. This is often just the DIE offset,
91 // but it might have a SymbolFileDWARF::GetID() in the high 32 bits if
92 // we are doing Darwin DWARF in .o file, or DWARF stand alone debug
94 lldb::user_id_t
GetID() const;
96 const char *GetName() const;
98 lldb::ModuleSP
GetModule() const;
100 // Getting attribute values from the DIE.
102 // GetAttributeValueAsXXX() functions should only be used if you are
103 // looking for one or two attributes on a DIE. If you are trying to
104 // parse all attributes, use GetAttributes (...) instead
105 const char *GetAttributeValueAsString(const dw_attr_t attr
,
106 const char *fail_value
) const;
108 uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr
,
109 uint64_t fail_value
) const;
111 std::optional
<uint64_t>
112 GetAttributeValueAsOptionalUnsigned(const dw_attr_t attr
) const;
114 uint64_t GetAttributeValueAsAddress(const dw_attr_t attr
,
115 uint64_t fail_value
) const;
117 enum class Recurse
: bool { no
, yes
};
118 DWARFAttributes
GetAttributes(Recurse recurse
= Recurse::yes
) const;
121 DWARFUnit
*m_cu
= nullptr;
122 DWARFDebugInfoEntry
*m_die
= nullptr;
125 bool operator==(const DWARFBaseDIE
&lhs
, const DWARFBaseDIE
&rhs
);
126 bool operator!=(const DWARFBaseDIE
&lhs
, const DWARFBaseDIE
&rhs
);
128 } // namespace lldb_private::plugin
130 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFBASEDIE_H