1 //===-- DWARFDIE.cpp --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 #include "DWARFASTParser.h"
13 #include "DWARFCompileUnit.h"
14 #include "DWARFDIECollection.h"
15 #include "DWARFDebugAbbrev.h"
16 #include "DWARFDebugAranges.h"
17 #include "DWARFDebugInfo.h"
18 #include "DWARFDebugInfoEntry.h"
19 #include "DWARFDebugRanges.h"
20 #include "DWARFDeclContext.h"
21 #include "DWARFFormValue.h"
22 #include "SymbolFileDWARF.h"
24 #include "lldb/Core/Module.h"
25 #include "lldb/Symbol/ObjectFile.h"
26 #include "lldb/Symbol/Type.h"
27 #include "lldb/Symbol/TypeSystem.h"
29 using namespace lldb_private;
31 DIERef DWARFDIE::GetDIERef() const {
35 dw_offset_t cu_offset = m_cu->GetOffset();
36 if (m_cu->GetBaseObjOffset() != DW_INVALID_OFFSET)
37 cu_offset = m_cu->GetBaseObjOffset();
38 return DIERef(cu_offset, m_die->GetOffset());
41 dw_tag_t DWARFDIE::Tag() const {
48 const char *DWARFDIE::GetTagAsCString() const {
49 return lldb_private::DW_TAG_value_to_name(Tag());
53 DWARFDIE::GetParent() const {
55 return DWARFDIE(m_cu, m_die->GetParent());
61 DWARFDIE::GetFirstChild() const {
63 return DWARFDIE(m_cu, m_die->GetFirstChild());
69 DWARFDIE::GetSibling() const {
71 return DWARFDIE(m_cu, m_die->GetSibling());
77 DWARFDIE::GetReferencedDIE(const dw_attr_t attr) const {
78 const dw_offset_t die_offset =
79 GetAttributeValueAsReference(attr, DW_INVALID_OFFSET);
80 if (die_offset != DW_INVALID_OFFSET)
81 return GetDIE(die_offset);
87 DWARFDIE::GetDIE(dw_offset_t die_offset) const {
89 return m_cu->GetDIE(die_offset);
94 const char *DWARFDIE::GetAttributeValueAsString(const dw_attr_t attr,
95 const char *fail_value) const {
97 return m_die->GetAttributeValueAsString(GetDWARF(), GetCU(), attr,
103 uint64_t DWARFDIE::GetAttributeValueAsUnsigned(const dw_attr_t attr,
104 uint64_t fail_value) const {
106 return m_die->GetAttributeValueAsUnsigned(GetDWARF(), GetCU(), attr,
112 int64_t DWARFDIE::GetAttributeValueAsSigned(const dw_attr_t attr,
113 int64_t fail_value) const {
115 return m_die->GetAttributeValueAsSigned(GetDWARF(), GetCU(), attr,
122 DWARFDIE::GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const {
124 DWARFCompileUnit *cu = GetCU();
125 SymbolFileDWARF *dwarf = cu->GetSymbolFileDWARF();
126 const bool check_specification_or_abstract_origin = true;
127 DWARFFormValue form_value;
128 if (m_die->GetAttributeValue(dwarf, cu, attr, form_value, nullptr,
129 check_specification_or_abstract_origin))
130 return dwarf->GetDIE(DIERef(form_value));
135 uint64_t DWARFDIE::GetAttributeValueAsReference(const dw_attr_t attr,
136 uint64_t fail_value) const {
138 return m_die->GetAttributeValueAsReference(GetDWARF(), GetCU(), attr,
144 uint64_t DWARFDIE::GetAttributeValueAsAddress(const dw_attr_t attr,
145 uint64_t fail_value) const {
147 return m_die->GetAttributeValueAsAddress(GetDWARF(), GetCU(), attr,
154 DWARFDIE::LookupDeepestBlock(lldb::addr_t file_addr) const {
156 SymbolFileDWARF *dwarf = GetDWARF();
157 DWARFCompileUnit *cu = GetCU();
158 DWARFDebugInfoEntry *function_die = nullptr;
159 DWARFDebugInfoEntry *block_die = nullptr;
160 if (m_die->LookupAddress(file_addr, dwarf, cu, &function_die, &block_die)) {
161 if (block_die && block_die != function_die) {
162 if (cu->ContainsDIEOffset(block_die->GetOffset()))
163 return DWARFDIE(cu, block_die);
165 return DWARFDIE(dwarf->DebugInfo()->GetCompileUnit(
166 DIERef(cu->GetOffset(), block_die->GetOffset())),
174 lldb::user_id_t DWARFDIE::GetID() const {
175 return GetDIERef().GetUID(GetDWARF());
178 const char *DWARFDIE::GetName() const {
180 return m_die->GetName(GetDWARF(), m_cu);
185 const char *DWARFDIE::GetMangledName() const {
187 return m_die->GetMangledName(GetDWARF(), m_cu);
192 const char *DWARFDIE::GetPubname() const {
194 return m_die->GetPubname(GetDWARF(), m_cu);
199 const char *DWARFDIE::GetQualifiedName(std::string &storage) const {
201 return m_die->GetQualifiedName(GetDWARF(), m_cu, storage);
206 lldb::LanguageType DWARFDIE::GetLanguage() const {
208 return m_cu->GetLanguageType();
210 return lldb::eLanguageTypeUnknown;
213 lldb::ModuleSP DWARFDIE::GetModule() const {
214 SymbolFileDWARF *dwarf = GetDWARF();
216 return dwarf->GetObjectFile()->GetModule();
218 return lldb::ModuleSP();
221 lldb_private::CompileUnit *DWARFDIE::GetLLDBCompileUnit() const {
223 return GetDWARF()->GetCompUnitForDWARFCompUnit(GetCU());
228 lldb_private::Type *DWARFDIE::ResolveType() const {
230 return GetDWARF()->ResolveType(*this, true);
235 lldb_private::Type *DWARFDIE::ResolveTypeUID(const DIERef &die_ref) const {
236 SymbolFileDWARF *dwarf = GetDWARF();
238 return dwarf->ResolveTypeUID(dwarf->GetDIE(die_ref), true);
243 void DWARFDIE::GetDeclContextDIEs(DWARFDIECollection &decl_context_dies) const {
245 DWARFDIE parent_decl_ctx_die =
246 m_die->GetParentDeclContextDIE(GetDWARF(), GetCU());
247 if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != GetDIE()) {
248 decl_context_dies.Append(parent_decl_ctx_die);
249 parent_decl_ctx_die.GetDeclContextDIEs(decl_context_dies);
254 void DWARFDIE::GetDWARFDeclContext(DWARFDeclContext &dwarf_decl_ctx) const {
256 dwarf_decl_ctx.SetLanguage(GetLanguage());
257 m_die->GetDWARFDeclContext(GetDWARF(), GetCU(), dwarf_decl_ctx);
259 dwarf_decl_ctx.Clear();
263 void DWARFDIE::GetDWOContext(std::vector<CompilerContext> &context) const {
264 const dw_tag_t tag = Tag();
265 if (tag == DW_TAG_compile_unit)
267 DWARFDIE parent = GetParent();
269 parent.GetDWOContext(context);
273 CompilerContext(CompilerContextKind::Module, ConstString(GetName())));
275 case DW_TAG_namespace:
276 context.push_back(CompilerContext(CompilerContextKind::Namespace,
277 ConstString(GetName())));
279 case DW_TAG_structure_type:
280 context.push_back(CompilerContext(CompilerContextKind::Structure,
281 ConstString(GetName())));
283 case DW_TAG_union_type:
285 CompilerContext(CompilerContextKind::Union, ConstString(GetName())));
287 case DW_TAG_class_type:
289 CompilerContext(CompilerContextKind::Class, ConstString(GetName())));
291 case DW_TAG_enumeration_type:
292 context.push_back(CompilerContext(CompilerContextKind::Enumeration,
293 ConstString(GetName())));
295 case DW_TAG_subprogram:
296 context.push_back(CompilerContext(CompilerContextKind::Function,
297 ConstString(GetPubname())));
299 case DW_TAG_variable:
300 context.push_back(CompilerContext(CompilerContextKind::Variable,
301 ConstString(GetPubname())));
305 CompilerContext(CompilerContextKind::Typedef, ConstString(GetName())));
313 DWARFDIE::GetParentDeclContextDIE() const {
315 return m_die->GetParentDeclContextDIE(GetDWARF(), m_cu);
320 dw_offset_t DWARFDIE::GetOffset() const {
322 return m_die->GetOffset();
324 return DW_INVALID_OFFSET;
327 dw_offset_t DWARFDIE::GetCompileUnitRelativeOffset() const {
329 return m_die->GetOffset() - m_cu->GetOffset();
331 return DW_INVALID_OFFSET;
334 SymbolFileDWARF *DWARFDIE::GetDWARF() const {
336 return m_cu->GetSymbolFileDWARF();
341 lldb_private::TypeSystem *DWARFDIE::GetTypeSystem() const {
343 return m_cu->GetTypeSystem();
348 DWARFASTParser *DWARFDIE::GetDWARFParser() const {
349 lldb_private::TypeSystem *type_system = GetTypeSystem();
351 return type_system->GetDWARFParser();
356 bool DWARFDIE::IsStructOrClass() const {
357 const dw_tag_t tag = Tag();
358 return tag == DW_TAG_class_type || tag == DW_TAG_structure_type;
362 DWARFDIE::GetContainingDWOModuleDIE() const {
364 DWARFDIE top_module_die;
365 // Now make sure this DIE is scoped in a DW_TAG_module tag and return true
367 for (DWARFDIE parent = GetParent(); parent.IsValid();
368 parent = parent.GetParent()) {
369 const dw_tag_t tag = parent.Tag();
370 if (tag == DW_TAG_module)
371 top_module_die = parent;
372 else if (tag == DW_TAG_compile_unit)
376 return top_module_die;
381 lldb::ModuleSP DWARFDIE::GetContainingDWOModule() const {
383 DWARFDIE dwo_module_die = GetContainingDWOModuleDIE();
385 if (dwo_module_die) {
386 const char *module_name = dwo_module_die.GetName();
388 return GetDWARF()->GetDWOModule(lldb_private::ConstString(module_name));
391 return lldb::ModuleSP();
394 bool DWARFDIE::HasChildren() const {
395 return m_die && m_die->HasChildren();
398 bool DWARFDIE::Supports_DW_AT_APPLE_objc_complete_type() const {
399 return IsValid() && GetDWARF()->Supports_DW_AT_APPLE_objc_complete_type(m_cu);
402 size_t DWARFDIE::GetAttributes(DWARFAttributes &attributes,
403 uint32_t depth) const {
405 return m_die->GetAttributes(m_cu, m_cu->GetFixedFormSizes(), attributes,
413 bool DWARFDIE::GetDIENamesAndRanges(
414 const char *&name, const char *&mangled, DWARFRangeList &ranges,
415 int &decl_file, int &decl_line, int &decl_column, int &call_file,
416 int &call_line, int &call_column,
417 lldb_private::DWARFExpression *frame_base) const {
419 return m_die->GetDIENamesAndRanges(
420 GetDWARF(), GetCU(), name, mangled, ranges, decl_file, decl_line,
421 decl_column, call_file, call_line, call_column, frame_base);
426 void DWARFDIE::Dump(lldb_private::Stream *s,
427 const uint32_t recurse_depth) const {
429 m_die->Dump(GetDWARF(), GetCU(), *s, recurse_depth);
432 CompilerDecl DWARFDIE::GetDecl() const {
433 DWARFASTParser *dwarf_ast = GetDWARFParser();
435 return dwarf_ast->GetDeclForUIDFromDWARF(*this);
437 return CompilerDecl();
440 CompilerDeclContext DWARFDIE::GetDeclContext() const {
441 DWARFASTParser *dwarf_ast = GetDWARFParser();
443 return dwarf_ast->GetDeclContextForUIDFromDWARF(*this);
445 return CompilerDeclContext();
448 CompilerDeclContext DWARFDIE::GetContainingDeclContext() const {
449 DWARFASTParser *dwarf_ast = GetDWARFParser();
451 return dwarf_ast->GetDeclContextContainingUIDFromDWARF(*this);
453 return CompilerDeclContext();
456 bool operator==(const DWARFDIE &lhs, const DWARFDIE &rhs) {
457 return lhs.GetDIE() == rhs.GetDIE() && lhs.GetCU() == rhs.GetCU();
460 bool operator!=(const DWARFDIE &lhs, const DWARFDIE &rhs) {
461 return !(lhs == rhs);