LLDB mainline
DWARFBaseDIE.cpp
Go to the documentation of this file.
1//===-- DWARFBaseDIE.cpp --------------------------------------------------===//
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//===----------------------------------------------------------------------===//
8
9#include "DWARFBaseDIE.h"
10
11#include "DWARFUnit.h"
12#include "DWARFDebugInfoEntry.h"
13#include "SymbolFileDWARF.h"
14
15#include "lldb/Core/Module.h"
17#include "lldb/Utility/Log.h"
18#include <optional>
19
20using namespace lldb_private;
21
22std::optional<DIERef> DWARFBaseDIE::GetDIERef() const {
23 if (!IsValid())
24 return std::nullopt;
25
27 m_die->GetOffset());
28}
29
31 if (m_die)
32 return m_die->Tag();
33 else
34 return llvm::dwarf::DW_TAG_null;
35}
36
37const char *DWARFBaseDIE::GetTagAsCString() const {
39}
40
42 const char *fail_value) const {
43 if (IsValid())
44 return m_die->GetAttributeValueAsString(GetCU(), attr, fail_value);
45 else
46 return fail_value;
47}
48
50 uint64_t fail_value) const {
51 if (IsValid())
52 return m_die->GetAttributeValueAsUnsigned(GetCU(), attr, fail_value);
53 else
54 return fail_value;
55}
56
57std::optional<uint64_t>
59 if (IsValid())
61 return std::nullopt;
62}
63
65 uint64_t fail_value) const {
66 if (IsValid())
67 return m_die->GetAttributeValueAsAddress(GetCU(), attr, fail_value);
68 else
69 return fail_value;
70}
71
73 if (IsValid())
74 return GetDWARF()->GetUID(*this);
75 return LLDB_INVALID_UID;
76}
77
78const char *DWARFBaseDIE::GetName() const {
79 if (IsValid())
80 return m_die->GetName(m_cu);
81 else
82 return nullptr;
83}
84
85lldb::ModuleSP DWARFBaseDIE::GetModule() const {
87 if (dwarf)
88 return dwarf->GetObjectFile()->GetModule();
89 else
90 return lldb::ModuleSP();
91}
92
94 if (IsValid())
95 return m_die->GetOffset();
96 else
97 return DW_INVALID_OFFSET;
98}
99
101 if (m_cu)
102 return &m_cu->GetSymbolFileDWARF();
103 else
104 return nullptr;
105}
106
108 return m_die && m_die->HasChildren();
109}
110
113}
114
116 Recurse recurse) const {
117 if (IsValid())
118 return m_die->GetAttributes(m_cu, attributes, recurse);
119 attributes.Clear();
120 return 0;
121}
122
123bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs) {
124 return lhs.GetDIE() == rhs.GetDIE() && lhs.GetCU() == rhs.GetCU();
125}
126
127bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs) {
128 return !(lhs == rhs);
129}
130
132 // Clients must check if this DIE is valid before calling this function.
133 assert(IsValid());
134 return m_cu->GetData();
135}
bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs)
bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs)
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:26
dw_tag_t Tag() const
DWARFDebugInfoEntry * m_die
Definition: DWARFBaseDIE.h:123
const char * GetTagAsCString() const
bool HasChildren() const
size_t GetAttributes(DWARFAttributes &attributes, Recurse recurse=Recurse::yes) const
DWARFDebugInfoEntry * GetDIE() const
Definition: DWARFBaseDIE.h:57
std::optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const dw_attr_t attr) const
const lldb_private::DWARFDataExtractor & GetData() const
bool IsValid() const
Definition: DWARFBaseDIE.h:46
DWARFUnit * m_cu
Definition: DWARFBaseDIE.h:122
const char * GetAttributeValueAsString(const dw_attr_t attr, const char *fail_value) const
DWARFUnit * GetCU() const
Definition: DWARFBaseDIE.h:55
std::optional< DIERef > GetDIERef() const
lldb::ModuleSP GetModule() const
SymbolFileDWARF * GetDWARF() const
bool Supports_DW_AT_APPLE_objc_complete_type() const
const char * GetName() const
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
dw_offset_t GetOffset() const
uint64_t GetAttributeValueAsAddress(const dw_attr_t attr, uint64_t fail_value) const
lldb::user_id_t GetID() const
std::optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const DWARFUnit *cu, const dw_attr_t attr, bool check_specification_or_abstract_origin=false) const
dw_offset_t GetOffset() const
size_t GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse=Recurse::yes) const
const char * GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, bool check_specification_or_abstract_origin=false) const
uint64_t GetAttributeValueAsUnsigned(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
uint64_t GetAttributeValueAsAddress(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_specification_or_abstract_origin=false) const
const char * GetName(const DWARFUnit *cu) const
DIERef::Section GetDebugSection() const
Definition: DWARFUnit.h:222
SymbolFileDWARF & GetSymbolFileDWARF() const
Definition: DWARFUnit.h:200
const lldb_private::DWARFDataExtractor & GetData() const
Get the data that contains the DIE information for this unit.
Definition: DWARFUnit.cpp:1000
bool Supports_DW_AT_APPLE_objc_complete_type(DWARFUnit *cu)
lldb::user_id_t GetUID(const DWARFBaseDIE &die)
virtual std::optional< uint32_t > GetDwoNum()
#define DW_INVALID_OFFSET
Definition: dwarf.h:37
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:28
#define LLDB_INVALID_UID
Definition: lldb-defines.h:80
A class that represents a running process on the host machine.
const char * DW_TAG_value_to_name(uint32_t val)
uint64_t user_id_t
Definition: lldb-types.h:84