diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -726,8 +726,7 @@ if (type_sp) return type_sp; - DWARFDeclContext die_decl_ctx; - SymbolFileDWARF::GetDWARFDeclContext(die, die_decl_ctx); + DWARFDeclContext die_decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die); type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx); @@ -1515,8 +1514,7 @@ if (type_sp) return type_sp; - DWARFDeclContext die_decl_ctx; - SymbolFileDWARF::GetDWARFDeclContext(die, die_decl_ctx); + DWARFDeclContext die_decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die); // type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, // type_name_const_str); @@ -2325,10 +2323,9 @@ unsigned type_quals = 0; std::vector param_types; std::vector param_decls; - DWARFDeclContext decl_ctx; StreamString sstr; - SymbolFileDWARF::GetDWARFDeclContext(die, decl_ctx); + DWARFDeclContext decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die); sstr << decl_ctx.GetQualifiedName(); clang::DeclContext *containing_decl_ctx = diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h @@ -158,8 +158,7 @@ return HasChildren() ? this + 1 : nullptr; } - void GetDWARFDeclContext(DWARFUnit *cu, - DWARFDeclContext &dwarf_decl_ctx) const; + DWARFDeclContext GetDWARFDeclContext(DWARFUnit *cu) const; DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu) const; DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu, @@ -169,6 +168,9 @@ void SetParentIndex(uint32_t idx) { m_parent_idx = idx; } protected: + void DWARFDebugInfoEntry::GetDWARFDeclContext( + DWARFUnit *cu, DWARFDeclContext &dwarf_decl_ctx) const; + dw_offset_t m_offset; // Offset within the .debug_info/.debug_types uint32_t m_parent_idx; // How many to subtract from "this" to get the parent. // If zero this die has no parent diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -883,6 +883,12 @@ } } +DWARFDeclContext DWARFDebugInfoEntry::GetDWARFDeclContext(DWARFUnit *cu) const { + DWARFDeclContext dwarf_decl_ctx; + GetDWARFDeclContext(cu, dwarf_decl_ctx); + return dwarf_decl_ctx; +} + DWARFDIE DWARFDebugInfoEntry::GetParentDeclContextDIE(DWARFUnit *cu) const { DWARFAttributes attributes; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -315,8 +315,7 @@ static lldb_private::CompilerDeclContext GetContainingDeclContext(const DWARFDIE &die); - static void GetDWARFDeclContext(const DWARFDIE &die, - DWARFDeclContext &dwarf_decl_ctx); + static DWARFDeclContext GetDWARFDeclContext(const DWARFDIE &die); static lldb::LanguageType LanguageTypeFromDWARF(uint64_t val); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -2956,8 +2956,8 @@ } if (try_resolving_type) { - DWARFDeclContext type_dwarf_decl_ctx; - GetDWARFDeclContext(type_die, type_dwarf_decl_ctx); + DWARFDeclContext type_dwarf_decl_ctx = + GetDWARFDeclContext(type_die); if (log) { GetObjectFile()->GetModule()->LogMessage( @@ -3374,12 +3374,10 @@ // declaration context. if ((parent_tag == DW_TAG_compile_unit || parent_tag == DW_TAG_partial_unit) && - Language::LanguageIsCPlusPlus(GetLanguage(*die.GetCU()))) { - DWARFDeclContext decl_ctx; - - GetDWARFDeclContext(die, decl_ctx); - mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString(); - } + Language::LanguageIsCPlusPlus(GetLanguage(*die.GetCU()))) + mangled = GetDWARFDeclContext(die) + .GetQualifiedNameAsConstString() + .GetCString(); } if (tag == DW_TAG_formal_parameter) @@ -3981,14 +3979,13 @@ return CompilerDeclContext(); } -void SymbolFileDWARF::GetDWARFDeclContext(const DWARFDIE &die, - DWARFDeclContext &dwarf_decl_ctx) { - if (!die.IsValid()) { - dwarf_decl_ctx.Clear(); - return; - } +DWARFDeclContext SymbolFileDWARF::GetDWARFDeclContext(const DWARFDIE &die) { + if (!die.IsValid()) + return {}; + DWARFDeclContext dwarf_decl_ctx = + die.GetDIE()->GetDWARFDeclContext(die.GetCU()); dwarf_decl_ctx.SetLanguage(GetLanguage(*die.GetCU())); - die.GetDIE()->GetDWARFDeclContext(die.GetCU(), dwarf_decl_ctx); + return dwarf_decl_ctx; } LanguageType SymbolFileDWARF::LanguageTypeFromDWARF(uint64_t val) {