1 //===-- DWARFBaseDIE.cpp --------------------------------------------------===//
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 #include "DWARFBaseDIE.h"
11 #include "DWARFUnit.h"
12 #include "DWARFDebugInfoEntry.h"
13 #include "SymbolFileDWARF.h"
15 #include "lldb/Core/Module.h"
16 #include "lldb/Symbol/ObjectFile.h"
17 #include "lldb/Utility/Log.h"
20 using namespace lldb_private
;
21 using namespace lldb_private::plugin::dwarf
;
23 std::optional
<DIERef
> DWARFBaseDIE::GetDIERef() const {
27 return DIERef(m_cu
->GetSymbolFileDWARF().GetFileIndex(),
28 m_cu
->GetDebugSection(), m_die
->GetOffset());
31 dw_tag_t
DWARFBaseDIE::Tag() const {
35 return llvm::dwarf::DW_TAG_null
;
38 const char *DWARFBaseDIE::GetAttributeValueAsString(const dw_attr_t attr
,
39 const char *fail_value
) const {
41 return m_die
->GetAttributeValueAsString(GetCU(), attr
, fail_value
);
46 uint64_t DWARFBaseDIE::GetAttributeValueAsUnsigned(const dw_attr_t attr
,
47 uint64_t fail_value
) const {
49 return m_die
->GetAttributeValueAsUnsigned(GetCU(), attr
, fail_value
);
54 std::optional
<uint64_t>
55 DWARFBaseDIE::GetAttributeValueAsOptionalUnsigned(const dw_attr_t attr
) const {
57 return m_die
->GetAttributeValueAsOptionalUnsigned(GetCU(), attr
);
61 uint64_t DWARFBaseDIE::GetAttributeValueAsAddress(const dw_attr_t attr
,
62 uint64_t fail_value
) const {
64 return m_die
->GetAttributeValueAsAddress(GetCU(), attr
, fail_value
);
69 lldb::user_id_t
DWARFBaseDIE::GetID() const {
70 const std::optional
<DIERef
> &ref
= this->GetDIERef();
74 return LLDB_INVALID_UID
;
77 const char *DWARFBaseDIE::GetName() const {
79 return m_die
->GetName(m_cu
);
84 lldb::ModuleSP
DWARFBaseDIE::GetModule() const {
85 SymbolFileDWARF
*dwarf
= GetDWARF();
87 return dwarf
->GetObjectFile()->GetModule();
89 return lldb::ModuleSP();
92 dw_offset_t
DWARFBaseDIE::GetOffset() const {
94 return m_die
->GetOffset();
96 return DW_INVALID_OFFSET
;
99 SymbolFileDWARF
*DWARFBaseDIE::GetDWARF() const {
101 return &m_cu
->GetSymbolFileDWARF();
106 bool DWARFBaseDIE::HasChildren() const {
107 return m_die
&& m_die
->HasChildren();
110 bool DWARFBaseDIE::Supports_DW_AT_APPLE_objc_complete_type() const {
111 return IsValid() && GetDWARF()->Supports_DW_AT_APPLE_objc_complete_type(m_cu
);
114 DWARFAttributes
DWARFBaseDIE::GetAttributes(Recurse recurse
) const {
116 return m_die
->GetAttributes(m_cu
, recurse
);
117 return DWARFAttributes();
120 namespace lldb_private::plugin
{
122 bool operator==(const DWARFBaseDIE
&lhs
, const DWARFBaseDIE
&rhs
) {
123 return lhs
.GetDIE() == rhs
.GetDIE() && lhs
.GetCU() == rhs
.GetCU();
126 bool operator!=(const DWARFBaseDIE
&lhs
, const DWARFBaseDIE
&rhs
) {
127 return !(lhs
== rhs
);
130 } // namespace lldb_private::plugin
132 const DWARFDataExtractor
&DWARFBaseDIE::GetData() const {
133 // Clients must check if this DIE is valid before calling this function.
135 return m_cu
->GetData();