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;
21using namespace lldb_private::plugin::dwarf;
22
23std::optional<DIERef> DWARFBaseDIE::GetDIERef() const {
24 if (!IsValid())
25 return std::nullopt;
26
29}
30
32 if (m_die)
33 return m_die->Tag();
34 else
35 return llvm::dwarf::DW_TAG_null;
36}
37
39 const char *fail_value) const {
40 if (IsValid())
41 return m_die->GetAttributeValueAsString(GetCU(), attr, fail_value);
42 else
43 return fail_value;
44}
45
47 uint64_t fail_value) const {
48 if (IsValid())
49 return m_die->GetAttributeValueAsUnsigned(GetCU(), attr, fail_value);
50 else
51 return fail_value;
52}
53
54std::optional<uint64_t>
56 if (IsValid())
58 return std::nullopt;
59}
60
62 uint64_t fail_value) const {
63 if (IsValid())
64 return m_die->GetAttributeValueAsAddress(GetCU(), attr, fail_value);
65 else
66 return fail_value;
67}
68
70 const std::optional<DIERef> &ref = this->GetDIERef();
71 if (ref)
72 return ref->get_id();
73
74 return LLDB_INVALID_UID;
75}
76
77const char *DWARFBaseDIE::GetName() const {
78 if (IsValid())
79 return m_die->GetName(m_cu);
80 else
81 return nullptr;
82}
83
86 if (dwarf)
87 return dwarf->GetObjectFile()->GetModule();
88 else
89 return lldb::ModuleSP();
90}
91
93 if (IsValid())
94 return m_die->GetOffset();
95 else
96 return DW_INVALID_OFFSET;
97}
100 if (m_cu)
101 return &m_cu->GetSymbolFileDWARF();
102 else
103 return nullptr;
104}
105
107 return m_die && m_die->HasChildren();
108}
109
111 if (IsValid())
112 return m_die->GetAttributes(m_cu, recurse);
113 return DWARFAttributes();
114}
115
116namespace lldb_private::plugin {
117namespace dwarf {
118bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs) {
119 return lhs.GetDIE() == rhs.GetDIE() && lhs.GetCU() == rhs.GetCU();
120}
121
122bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs) {
123 return !(lhs == rhs);
124}
125} // namespace dwarf
126} // namespace lldb_private::plugin
127
129 // Clients must check if this DIE is valid before calling this function.
130 assert(IsValid());
131 return m_cu->GetData();
132}
Identifies a DWARF debug info entry within a given Module.
Definition: DIERef.h:31
DWARFAttributes GetAttributes(Recurse recurse=Recurse::yes) const
std::optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const dw_attr_t attr) const
const DWARFDataExtractor & GetData() const
const char * GetAttributeValueAsString(const dw_attr_t attr, const char *fail_value) const
std::optional< DIERef > GetDIERef() const
DWARFDebugInfoEntry * GetDIE() const
Definition: DWARFBaseDIE.h:61
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
uint64_t GetAttributeValueAsAddress(const dw_attr_t attr, uint64_t fail_value) const
DWARFAttributes GetAttributes(DWARFUnit *cu, Recurse recurse=Recurse::yes) const
std::optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const DWARFUnit *cu, const dw_attr_t attr, bool check_elaborating_dies=false) const
const char * GetAttributeValueAsString(const DWARFUnit *cu, const dw_attr_t attr, const char *fail_value, bool check_elaborating_dies=false) const
uint64_t GetAttributeValueAsAddress(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_elaborating_dies=false) const
uint64_t GetAttributeValueAsUnsigned(const DWARFUnit *cu, const dw_attr_t attr, uint64_t fail_value, bool check_elaborating_dies=false) const
const char * GetName(const DWARFUnit *cu) const
SymbolFileDWARF & GetSymbolFileDWARF() const
Definition: DWARFUnit.h:177
DIERef::Section GetDebugSection() const
Definition: DWARFUnit.h:199
const DWARFDataExtractor & GetData() const
Get the data that contains the DIE information for this unit.
Definition: DWARFUnit.cpp:989
std::optional< uint64_t > GetFileIndex() const
uint64_t dw_offset_t
Definition: dwarf.h:30
#define DW_INVALID_OFFSET
Definition: dwarf.h:35
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:25
llvm::dwarf::Attribute dw_attr_t
Definition: dwarf.h:23
#define LLDB_INVALID_UID
Definition: lldb-defines.h:88
A class that represents a running process on the host machine.
bool operator!=(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1029
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1023
uint64_t user_id_t
Definition: lldb-types.h:82
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373