]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / DWARFBaseDIE.cpp
1 //===-- DWARFBaseDIE.cpp ---------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "DWARFBaseDIE.h"
11
12 #include "DWARFUnit.h"
13 #include "DWARFDebugInfoEntry.h"
14 #include "SymbolFileDWARF.h"
15
16 #include "lldb/Core/Module.h"
17 #include "lldb/Symbol/ObjectFile.h"
18
19 using namespace lldb_private;
20
21 DIERef DWARFBaseDIE::GetDIERef() const {
22   if (!IsValid())
23     return DIERef();
24
25   dw_offset_t cu_offset = m_cu->GetOffset();
26   if (m_cu->GetBaseObjOffset() != DW_INVALID_OFFSET)
27     cu_offset = m_cu->GetBaseObjOffset();
28   return DIERef(cu_offset, m_die->GetOffset());
29 }
30
31 dw_tag_t DWARFBaseDIE::Tag() const {
32   if (m_die)
33     return m_die->Tag();
34   else
35     return 0;
36 }
37
38 const char *DWARFBaseDIE::GetTagAsCString() const {
39   return lldb_private::DW_TAG_value_to_name(Tag());
40 }
41
42 const char *DWARFBaseDIE::GetAttributeValueAsString(const dw_attr_t attr,
43                                                 const char *fail_value) const {
44   if (IsValid())
45     return m_die->GetAttributeValueAsString(GetDWARF(), GetCU(), attr,
46                                             fail_value);
47   else
48     return fail_value;
49 }
50
51 uint64_t DWARFBaseDIE::GetAttributeValueAsUnsigned(const dw_attr_t attr,
52                                                uint64_t fail_value) const {
53   if (IsValid())
54     return m_die->GetAttributeValueAsUnsigned(GetDWARF(), GetCU(), attr,
55                                               fail_value);
56   else
57     return fail_value;
58 }
59
60 int64_t DWARFBaseDIE::GetAttributeValueAsSigned(const dw_attr_t attr,
61                                             int64_t fail_value) const {
62   if (IsValid())
63     return m_die->GetAttributeValueAsSigned(GetDWARF(), GetCU(), attr,
64                                             fail_value);
65   else
66     return fail_value;
67 }
68
69 uint64_t DWARFBaseDIE::GetAttributeValueAsReference(const dw_attr_t attr,
70                                                 uint64_t fail_value) const {
71   if (IsValid())
72     return m_die->GetAttributeValueAsReference(GetDWARF(), GetCU(), attr,
73                                                fail_value);
74   else
75     return fail_value;
76 }
77
78 uint64_t DWARFBaseDIE::GetAttributeValueAsAddress(const dw_attr_t attr,
79                                               uint64_t fail_value) const {
80   if (IsValid())
81     return m_die->GetAttributeValueAsAddress(GetDWARF(), GetCU(), attr,
82                                              fail_value);
83   else
84     return fail_value;
85 }
86
87 lldb::user_id_t DWARFBaseDIE::GetID() const {
88   return GetDIERef().GetUID(GetDWARF());
89 }
90
91 const char *DWARFBaseDIE::GetName() const {
92   if (IsValid())
93     return m_die->GetName(GetDWARF(), m_cu);
94   else
95     return nullptr;
96 }
97
98 lldb::LanguageType DWARFBaseDIE::GetLanguage() const {
99   if (IsValid())
100     return m_cu->GetLanguageType();
101   else
102     return lldb::eLanguageTypeUnknown;
103 }
104
105 lldb::ModuleSP DWARFBaseDIE::GetModule() const {
106   SymbolFileDWARF *dwarf = GetDWARF();
107   if (dwarf)
108     return dwarf->GetObjectFile()->GetModule();
109   else
110     return lldb::ModuleSP();
111 }
112
113 lldb_private::CompileUnit *DWARFBaseDIE::GetLLDBCompileUnit() const {
114   if (IsValid())
115     return GetDWARF()->GetCompUnitForDWARFCompUnit(GetCU());
116   else
117     return nullptr;
118 }
119
120 dw_offset_t DWARFBaseDIE::GetOffset() const {
121   if (IsValid())
122     return m_die->GetOffset();
123   else
124     return DW_INVALID_OFFSET;
125 }
126
127 dw_offset_t DWARFBaseDIE::GetCompileUnitRelativeOffset() const {
128   if (IsValid())
129     return m_die->GetOffset() - m_cu->GetOffset();
130   else
131     return DW_INVALID_OFFSET;
132 }
133
134 SymbolFileDWARF *DWARFBaseDIE::GetDWARF() const {
135   if (m_cu)
136     return m_cu->GetSymbolFileDWARF();
137   else
138     return nullptr;
139 }
140
141 lldb_private::TypeSystem *DWARFBaseDIE::GetTypeSystem() const {
142   if (m_cu)
143     return m_cu->GetTypeSystem();
144   else
145     return nullptr;
146 }
147
148 DWARFASTParser *DWARFBaseDIE::GetDWARFParser() const {
149   lldb_private::TypeSystem *type_system = GetTypeSystem();
150   if (type_system)
151     return type_system->GetDWARFParser();
152   else
153     return nullptr;
154 }
155
156 bool DWARFBaseDIE::HasChildren() const {
157   return m_die && m_die->HasChildren();
158 }
159
160 bool DWARFBaseDIE::Supports_DW_AT_APPLE_objc_complete_type() const {
161   return IsValid() && GetDWARF()->Supports_DW_AT_APPLE_objc_complete_type(m_cu);
162 }
163
164 size_t DWARFBaseDIE::GetAttributes(DWARFAttributes &attributes,
165                                uint32_t depth) const {
166   if (IsValid()) {
167     return m_die->GetAttributes(m_cu, m_cu->GetFixedFormSizes(), attributes,
168                                 depth);
169   }
170   if (depth == 0)
171     attributes.Clear();
172   return 0;
173 }
174
175 void DWARFBaseDIE::Dump(lldb_private::Stream *s,
176                     const uint32_t recurse_depth) const {
177   if (s && IsValid())
178     m_die->Dump(GetDWARF(), GetCU(), *s, recurse_depth);
179 }
180
181 bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs) {
182   return lhs.GetDIE() == rhs.GetDIE() && lhs.GetCU() == rhs.GetCU();
183 }
184
185 bool operator!=(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs) {
186   return !(lhs == rhs);
187 }
188
189 const DWARFDataExtractor &DWARFBaseDIE::GetData() const {
190   // Clients must check if this DIE is valid before calling this function.
191   assert(IsValid());
192   return m_cu->GetData();
193 }