Author: Alex Langford Date: 2023-05-12T12:17:21-07:00 New Revision: c909b491cb5f392147de4490749abc1e5372a571
URL: https://github.com/llvm/llvm-project/commit/c909b491cb5f392147de4490749abc1e5372a571 DIFF: https://github.com/llvm/llvm-project/commit/c909b491cb5f392147de4490749abc1e5372a571.diff LOG: [lldb][NFCI] Change return type of DWARFDebugInfoEntry::GetAttributes The purpose of this method is to get the list of attributes of a DebugInfoEntry. Prior to this change we were passing in a mutable reference to a DWARFAttributes object and having the method fill it in for us while returning the size of the filled out list. But instead of doing that, we can just return a `DWARFAttributes` object ourselves since every caller creates a new list before calling GetAttributes. Differential Revision: https://reviews.llvm.org/D150402 Added: Modified: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Removed: ################################################################################ diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp index dbece346b99a..a68b7cd110eb 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp @@ -31,71 +31,70 @@ DWARFASTParser::ParseChildArrayInfo(const DWARFDIE &parent_die, if (tag != DW_TAG_subrange_type) continue; - DWARFAttributes attributes; - const size_t num_child_attributes = die.GetAttributes(attributes); - if (num_child_attributes > 0) { - uint64_t num_elements = 0; - uint64_t lower_bound = 0; - uint64_t upper_bound = 0; - bool upper_bound_valid = false; - uint32_t i; - for (i = 0; i < num_child_attributes; ++i) { - const dw_attr_t attr = attributes.AttributeAtIndex(i); - DWARFFormValue form_value; - if (attributes.ExtractFormValueAtIndex(i, form_value)) { - switch (attr) { - case DW_AT_name: - break; - - case DW_AT_count: - if (DWARFDIE var_die = die.GetReferencedDIE(DW_AT_count)) { - if (var_die.Tag() == DW_TAG_variable) - if (exe_ctx) { - if (auto frame = exe_ctx->GetFrameSP()) { - Status error; - lldb::VariableSP var_sp; - auto valobj_sp = frame->GetValueForVariableExpressionPath( - var_die.GetName(), eNoDynamicValues, 0, var_sp, error); - if (valobj_sp) { - num_elements = valobj_sp->GetValueAsUnsigned(0); - break; - } + DWARFAttributes attributes = die.GetAttributes(); + if (attributes.Size() == 0) + continue; + + uint64_t num_elements = 0; + uint64_t lower_bound = 0; + uint64_t upper_bound = 0; + bool upper_bound_valid = false; + for (size_t i = 0; i < attributes.Size(); ++i) { + const dw_attr_t attr = attributes.AttributeAtIndex(i); + DWARFFormValue form_value; + if (attributes.ExtractFormValueAtIndex(i, form_value)) { + switch (attr) { + case DW_AT_name: + break; + + case DW_AT_count: + if (DWARFDIE var_die = die.GetReferencedDIE(DW_AT_count)) { + if (var_die.Tag() == DW_TAG_variable) + if (exe_ctx) { + if (auto frame = exe_ctx->GetFrameSP()) { + Status error; + lldb::VariableSP var_sp; + auto valobj_sp = frame->GetValueForVariableExpressionPath( + var_die.GetName(), eNoDynamicValues, 0, var_sp, error); + if (valobj_sp) { + num_elements = valobj_sp->GetValueAsUnsigned(0); + break; } } - } else - num_elements = form_value.Unsigned(); - break; - - case DW_AT_bit_stride: - array_info.bit_stride = form_value.Unsigned(); - break; - - case DW_AT_byte_stride: - array_info.byte_stride = form_value.Unsigned(); - break; - - case DW_AT_lower_bound: - lower_bound = form_value.Unsigned(); - break; - - case DW_AT_upper_bound: - upper_bound_valid = true; - upper_bound = form_value.Unsigned(); - break; - - default: - break; - } - } - } + } + } else + num_elements = form_value.Unsigned(); + break; + + case DW_AT_bit_stride: + array_info.bit_stride = form_value.Unsigned(); + break; - if (num_elements == 0) { - if (upper_bound_valid && upper_bound >= lower_bound) - num_elements = upper_bound - lower_bound + 1; + case DW_AT_byte_stride: + array_info.byte_stride = form_value.Unsigned(); + break; + + case DW_AT_lower_bound: + lower_bound = form_value.Unsigned(); + break; + + case DW_AT_upper_bound: + upper_bound_valid = true; + upper_bound = form_value.Unsigned(); + break; + + default: + break; + } } + } - array_info.element_orders.push_back(num_elements); + if (num_elements == 0) { + if (upper_bound_valid && upper_bound >= lower_bound) + num_elements = upper_bound - lower_bound + 1; } + + array_info.element_orders.push_back(num_elements); } return array_info; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index b8a517100524..1090e15370dd 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -266,9 +266,8 @@ static void PrepareContextToReceiveMembers(TypeSystemClang &ast, } ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes(const DWARFDIE &die) { - DWARFAttributes attributes; - size_t num_attributes = die.GetAttributes(attributes); - for (size_t i = 0; i < num_attributes; ++i) { + DWARFAttributes attributes = die.GetAttributes(); + for (size_t i = 0; i < attributes.Size(); ++i) { dw_attr_t attr = attributes.AttributeAtIndex(i); DWARFFormValue form_value; if (!attributes.ExtractFormValueAtIndex(i, form_value)) @@ -281,7 +280,8 @@ ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes(const DWARFDIE &die) { break; case DW_AT_accessibility: - accessibility = DWARFASTParser::GetAccessTypeFromDWARF(form_value.Unsigned()); + accessibility = + DWARFASTParser::GetAccessTypeFromDWARF(form_value.Unsigned()); break; case DW_AT_artificial: @@ -1385,9 +1385,8 @@ void DWARFASTParserClang::ParseInheritance( return; // TODO: implement DW_TAG_inheritance type parsing. - DWARFAttributes attributes; - const size_t num_attributes = die.GetAttributes(attributes); - if (num_attributes == 0) + DWARFAttributes attributes = die.GetAttributes(); + if (attributes.Size() == 0) return; DWARFFormValue encoding_form; @@ -1396,7 +1395,7 @@ void DWARFASTParserClang::ParseInheritance( bool is_base_of_class = true; off_t member_byte_offset = 0; - for (uint32_t i = 0; i < num_attributes; ++i) { + for (uint32_t i = 0; i < attributes.Size(); ++i) { const dw_attr_t attr = attributes.AttributeAtIndex(i); DWARFFormValue form_value; if (attributes.ExtractFormValueAtIndex(i, form_value)) { @@ -1428,7 +1427,8 @@ void DWARFASTParserClang::ParseInheritance( break; case DW_AT_accessibility: - accessibility = DWARFASTParser::GetAccessTypeFromDWARF(form_value.Unsigned()); + accessibility = + DWARFASTParser::GetAccessTypeFromDWARF(form_value.Unsigned()); break; case DW_AT_virtuality: @@ -2003,87 +2003,86 @@ bool DWARFASTParserClang::ParseTemplateDIE( [[fallthrough]]; case DW_TAG_template_type_parameter: case DW_TAG_template_value_parameter: { - DWARFAttributes attributes; - const size_t num_attributes = die.GetAttributes(attributes); + DWARFAttributes attributes = die.GetAttributes(); + if (attributes.Size() == 0) + return true; + const char *name = nullptr; const char *template_name = nullptr; CompilerType clang_type; uint64_t uval64 = 0; bool uval64_valid = false; bool is_default_template_arg = false; - if (num_attributes > 0) { - DWARFFormValue form_value; - for (size_t i = 0; i < num_attributes; ++i) { - const dw_attr_t attr = attributes.AttributeAtIndex(i); + DWARFFormValue form_value; + for (size_t i = 0; i < attributes.Size(); ++i) { + const dw_attr_t attr = attributes.AttributeAtIndex(i); - switch (attr) { - case DW_AT_name: - if (attributes.ExtractFormValueAtIndex(i, form_value)) - name = form_value.AsCString(); - break; + switch (attr) { + case DW_AT_name: + if (attributes.ExtractFormValueAtIndex(i, form_value)) + name = form_value.AsCString(); + break; - case DW_AT_GNU_template_name: - if (attributes.ExtractFormValueAtIndex(i, form_value)) - template_name = form_value.AsCString(); - break; + case DW_AT_GNU_template_name: + if (attributes.ExtractFormValueAtIndex(i, form_value)) + template_name = form_value.AsCString(); + break; - case DW_AT_type: - if (attributes.ExtractFormValueAtIndex(i, form_value)) { - Type *lldb_type = die.ResolveTypeUID(form_value.Reference()); - if (lldb_type) - clang_type = lldb_type->GetForwardCompilerType(); - } - break; + case DW_AT_type: + if (attributes.ExtractFormValueAtIndex(i, form_value)) { + Type *lldb_type = die.ResolveTypeUID(form_value.Reference()); + if (lldb_type) + clang_type = lldb_type->GetForwardCompilerType(); + } + break; - case DW_AT_const_value: - if (attributes.ExtractFormValueAtIndex(i, form_value)) { - uval64_valid = true; - uval64 = form_value.Unsigned(); - } - break; - case DW_AT_default_value: - if (attributes.ExtractFormValueAtIndex(i, form_value)) - is_default_template_arg = form_value.Boolean(); - break; - default: - break; + case DW_AT_const_value: + if (attributes.ExtractFormValueAtIndex(i, form_value)) { + uval64_valid = true; + uval64 = form_value.Unsigned(); } + break; + case DW_AT_default_value: + if (attributes.ExtractFormValueAtIndex(i, form_value)) + is_default_template_arg = form_value.Boolean(); + break; + default: + break; } + } - clang::ASTContext &ast = m_ast.getASTContext(); - if (!clang_type) - clang_type = m_ast.GetBasicType(eBasicTypeVoid); - - if (!is_template_template_argument) { - bool is_signed = false; - // Get the signed value for any integer or enumeration if available - clang_type.IsIntegerOrEnumerationType(is_signed); - - if (name && !name[0]) - name = nullptr; - - if (tag == DW_TAG_template_value_parameter && uval64_valid) { - std::optional<uint64_t> size = clang_type.GetBitSize(nullptr); - if (!size) - return false; - llvm::APInt apint(*size, uval64, is_signed); - template_param_infos.InsertArg( - name, - clang::TemplateArgument(ast, llvm::APSInt(apint, !is_signed), - ClangUtil::GetQualType(clang_type), - is_default_template_arg)); - } else { - template_param_infos.InsertArg( - name, clang::TemplateArgument(ClangUtil::GetQualType(clang_type), - /*isNullPtr*/ false, - is_default_template_arg)); - } + clang::ASTContext &ast = m_ast.getASTContext(); + if (!clang_type) + clang_type = m_ast.GetBasicType(eBasicTypeVoid); + + if (!is_template_template_argument) { + bool is_signed = false; + // Get the signed value for any integer or enumeration if available + clang_type.IsIntegerOrEnumerationType(is_signed); + + if (name && !name[0]) + name = nullptr; + + if (tag == DW_TAG_template_value_parameter && uval64_valid) { + std::optional<uint64_t> size = clang_type.GetBitSize(nullptr); + if (!size) + return false; + llvm::APInt apint(*size, uval64, is_signed); + template_param_infos.InsertArg( + name, clang::TemplateArgument(ast, llvm::APSInt(apint, !is_signed), + ClangUtil::GetQualType(clang_type), + is_default_template_arg)); } else { - auto *tplt_type = m_ast.CreateTemplateTemplateParmDecl(template_name); template_param_infos.InsertArg( - name, clang::TemplateArgument(clang::TemplateName(tplt_type), + name, clang::TemplateArgument(ClangUtil::GetQualType(clang_type), + /*isNullPtr*/ false, is_default_template_arg)); } + } else { + auto *tplt_type = m_ast.CreateTemplateTemplateParmDecl(template_name); + template_param_infos.InsertArg( + name, clang::TemplateArgument(clang::TemplateName(tplt_type), + is_default_template_arg)); } } return true; @@ -2243,7 +2242,6 @@ bool DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die, const dw_tag_t tag = die.Tag(); assert(clang_type); - DWARFAttributes attributes; switch (tag) { case DW_TAG_structure_type: case DW_TAG_union_type: @@ -2304,58 +2302,58 @@ size_t DWARFASTParserClang::ParseChildEnumerators( for (DWARFDIE die : parent_die.children()) { const dw_tag_t tag = die.Tag(); - if (tag == DW_TAG_enumerator) { - DWARFAttributes attributes; - const size_t num_child_attributes = die.GetAttributes(attributes); - if (num_child_attributes > 0) { - const char *name = nullptr; - bool got_value = false; - int64_t enum_value = 0; - Declaration decl; - - uint32_t i; - for (i = 0; i < num_child_attributes; ++i) { - const dw_attr_t attr = attributes.AttributeAtIndex(i); - DWARFFormValue form_value; - if (attributes.ExtractFormValueAtIndex(i, form_value)) { - switch (attr) { - case DW_AT_const_value: - got_value = true; - if (is_signed) - enum_value = form_value.Signed(); - else - enum_value = form_value.Unsigned(); - break; - - case DW_AT_name: - name = form_value.AsCString(); - break; - - case DW_AT_description: - default: - case DW_AT_decl_file: - decl.SetFile(attributes.CompileUnitAtIndex(i)->GetFile( - form_value.Unsigned())); - break; - case DW_AT_decl_line: - decl.SetLine(form_value.Unsigned()); - break; - case DW_AT_decl_column: - decl.SetColumn(form_value.Unsigned()); - break; - case DW_AT_sibling: - break; - } - } - } + if (tag != DW_TAG_enumerator) + continue; + + DWARFAttributes attributes = die.GetAttributes(); + if (attributes.Size() == 0) + continue; + + const char *name = nullptr; + bool got_value = false; + int64_t enum_value = 0; + Declaration decl; + + for (size_t i = 0; i < attributes.Size(); ++i) { + const dw_attr_t attr = attributes.AttributeAtIndex(i); + DWARFFormValue form_value; + if (attributes.ExtractFormValueAtIndex(i, form_value)) { + switch (attr) { + case DW_AT_const_value: + got_value = true; + if (is_signed) + enum_value = form_value.Signed(); + else + enum_value = form_value.Unsigned(); + break; - if (name && name[0] && got_value) { - m_ast.AddEnumerationValueToEnumerationType( - clang_type, decl, name, enum_value, enumerator_byte_size * 8); - ++enumerators_added; + case DW_AT_name: + name = form_value.AsCString(); + break; + + case DW_AT_description: + default: + case DW_AT_decl_file: + decl.SetFile( + attributes.CompileUnitAtIndex(i)->GetFile(form_value.Unsigned())); + break; + case DW_AT_decl_line: + decl.SetLine(form_value.Unsigned()); + break; + case DW_AT_decl_column: + decl.SetColumn(form_value.Unsigned()); + break; + case DW_AT_sibling: + break; } } } + + if (name && name[0] && got_value) { + m_ast.AddEnumerationValueToEnumerationType( + clang_type, decl, name, enum_value, enumerator_byte_size * 8); + ++enumerators_added; + } } return enumerators_added; } @@ -2503,9 +2501,8 @@ MemberAttributes::MemberAttributes(const DWARFDIE &die, ModuleSP module_sp) { member_byte_offset = (parent_die.Tag() == DW_TAG_union_type) ? 0 : UINT32_MAX; - DWARFAttributes attributes; - const size_t num_attributes = die.GetAttributes(attributes); - for (std::size_t i = 0; i < num_attributes; ++i) { + DWARFAttributes attributes = die.GetAttributes(); + for (size_t i = 0; i < attributes.Size(); ++i) { const dw_attr_t attr = attributes.AttributeAtIndex(i); DWARFFormValue form_value; if (attributes.ExtractFormValueAtIndex(i, form_value)) { @@ -2557,7 +2554,8 @@ MemberAttributes::MemberAttributes(const DWARFDIE &die, break; case DW_AT_accessibility: - accessibility = DWARFASTParser::GetAccessTypeFromDWARF(form_value.Unsigned()); + accessibility = + DWARFASTParser::GetAccessTypeFromDWARF(form_value.Unsigned()); break; case DW_AT_artificial: is_artificial = form_value.Boolean(); @@ -2588,9 +2586,8 @@ MemberAttributes::MemberAttributes(const DWARFDIE &die, PropertyAttributes::PropertyAttributes(const DWARFDIE &die) { - DWARFAttributes attributes; - const size_t num_attributes = die.GetAttributes(attributes); - for (size_t i = 0; i < num_attributes; ++i) { + DWARFAttributes attributes = die.GetAttributes(); + for (size_t i = 0; i < attributes.Size(); ++i) { const dw_attr_t attr = attributes.AttributeAtIndex(i); DWARFFormValue form_value; if (attributes.ExtractFormValueAtIndex(i, form_value)) { @@ -3066,87 +3063,87 @@ size_t DWARFASTParserClang::ParseChildParameters( const dw_tag_t tag = die.Tag(); switch (tag) { case DW_TAG_formal_parameter: { - DWARFAttributes attributes; - const size_t num_attributes = die.GetAttributes(attributes); - if (num_attributes > 0) { - const char *name = nullptr; - DWARFFormValue param_type_die_form; - bool is_artificial = false; - // one of None, Auto, Register, Extern, Static, PrivateExtern - - clang::StorageClass storage = clang::SC_None; - uint32_t i; - for (i = 0; i < num_attributes; ++i) { - const dw_attr_t attr = attributes.AttributeAtIndex(i); - DWARFFormValue form_value; - if (attributes.ExtractFormValueAtIndex(i, form_value)) { - switch (attr) { - case DW_AT_name: - name = form_value.AsCString(); - break; - case DW_AT_type: - param_type_die_form = form_value; - break; - case DW_AT_artificial: - is_artificial = form_value.Boolean(); - break; - case DW_AT_location: - case DW_AT_const_value: - case DW_AT_default_value: - case DW_AT_description: - case DW_AT_endianity: - case DW_AT_is_optional: - case DW_AT_segment: - case DW_AT_variable_parameter: - default: - case DW_AT_abstract_origin: - case DW_AT_sibling: - break; - } + DWARFAttributes attributes = die.GetAttributes(); + if (attributes.Size() == 0) { + arg_idx++; + break; + } + + const char *name = nullptr; + DWARFFormValue param_type_die_form; + bool is_artificial = false; + // one of None, Auto, Register, Extern, Static, PrivateExtern + + clang::StorageClass storage = clang::SC_None; + uint32_t i; + for (i = 0; i < attributes.Size(); ++i) { + const dw_attr_t attr = attributes.AttributeAtIndex(i); + DWARFFormValue form_value; + if (attributes.ExtractFormValueAtIndex(i, form_value)) { + switch (attr) { + case DW_AT_name: + name = form_value.AsCString(); + break; + case DW_AT_type: + param_type_die_form = form_value; + break; + case DW_AT_artificial: + is_artificial = form_value.Boolean(); + break; + case DW_AT_location: + case DW_AT_const_value: + case DW_AT_default_value: + case DW_AT_description: + case DW_AT_endianity: + case DW_AT_is_optional: + case DW_AT_segment: + case DW_AT_variable_parameter: + default: + case DW_AT_abstract_origin: + case DW_AT_sibling: + break; } } + } - bool skip = false; - if (skip_artificial && is_artificial) { - // In order to determine if a C++ member function is "const" we - // have to look at the const-ness of "this"... - if (arg_idx == 0 && - DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()) && - // Often times compilers omit the "this" name for the - // specification DIEs, so we can't rely upon the name being in - // the formal parameter DIE... - (name == nullptr || ::strcmp(name, "this") == 0)) { - Type *this_type = - die.ResolveTypeUID(param_type_die_form.Reference()); - if (this_type) { - uint32_t encoding_mask = this_type->GetEncodingMask(); - if (encoding_mask & Type::eEncodingIsPointerUID) { - is_static = false; - - if (encoding_mask & (1u << Type::eEncodingIsConstUID)) - type_quals |= clang::Qualifiers::Const; - if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) - type_quals |= clang::Qualifiers::Volatile; - } + bool skip = false; + if (skip_artificial && is_artificial) { + // In order to determine if a C++ member function is "const" we + // have to look at the const-ness of "this"... + if (arg_idx == 0 && + DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()) && + // Often times compilers omit the "this" name for the + // specification DIEs, so we can't rely upon the name being in + // the formal parameter DIE... + (name == nullptr || ::strcmp(name, "this") == 0)) { + Type *this_type = die.ResolveTypeUID(param_type_die_form.Reference()); + if (this_type) { + uint32_t encoding_mask = this_type->GetEncodingMask(); + if (encoding_mask & Type::eEncodingIsPointerUID) { + is_static = false; + + if (encoding_mask & (1u << Type::eEncodingIsConstUID)) + type_quals |= clang::Qualifiers::Const; + if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) + type_quals |= clang::Qualifiers::Volatile; } } - skip = true; } + skip = true; + } - if (!skip) { - Type *type = die.ResolveTypeUID(param_type_die_form.Reference()); - if (type) { - function_param_types.push_back(type->GetForwardCompilerType()); + if (!skip) { + Type *type = die.ResolveTypeUID(param_type_die_form.Reference()); + if (type) { + function_param_types.push_back(type->GetForwardCompilerType()); - clang::ParmVarDecl *param_var_decl = - m_ast.CreateParameterDeclaration( - containing_decl_ctx, GetOwningClangModule(die), name, - type->GetForwardCompilerType(), storage); - assert(param_var_decl); - function_param_decls.push_back(param_var_decl); + clang::ParmVarDecl *param_var_decl = m_ast.CreateParameterDeclaration( + containing_decl_ctx, GetOwningClangModule(die), name, + type->GetForwardCompilerType(), storage); + assert(param_var_decl); + function_param_decls.push_back(param_var_decl); - m_ast.SetMetadataAsUserID(param_var_decl, die.GetID()); - } + m_ast.SetMetadataAsUserID(param_var_decl, die.GetID()); } } arg_idx++; @@ -3175,21 +3172,24 @@ size_t DWARFASTParserClang::ParseChildParameters( } Type *DWARFASTParserClang::GetTypeForDIE(const DWARFDIE &die) { - if (die) { - SymbolFileDWARF *dwarf = die.GetDWARF(); - DWARFAttributes attributes; - const size_t num_attributes = die.GetAttributes(attributes); - if (num_attributes > 0) { - DWARFFormValue type_die_form; - for (size_t i = 0; i < num_attributes; ++i) { - dw_attr_t attr = attributes.AttributeAtIndex(i); - DWARFFormValue form_value; + if (!die) + return nullptr; - if (attr == DW_AT_type && - attributes.ExtractFormValueAtIndex(i, form_value)) - return dwarf->ResolveTypeUID(form_value.Reference(), true); - } - } + SymbolFileDWARF *dwarf = die.GetDWARF(); + if (!dwarf) + return nullptr; + + DWARFAttributes attributes = die.GetAttributes(); + if (attributes.Size() == 0) + return nullptr; + + DWARFFormValue type_die_form; + for (size_t i = 0; i < attributes.Size(); ++i) { + dw_attr_t attr = attributes.AttributeAtIndex(i); + DWARFFormValue form_value; + + if (attr == DW_AT_type && attributes.ExtractFormValueAtIndex(i, form_value)) + return dwarf->ResolveTypeUID(form_value.Reference(), true); } return nullptr; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp index 1697bf651f1d..37a917c3a766 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.cpp @@ -114,12 +114,10 @@ bool DWARFBaseDIE::Supports_DW_AT_APPLE_objc_complete_type() const { return IsValid() && GetDWARF()->Supports_DW_AT_APPLE_objc_complete_type(m_cu); } -size_t DWARFBaseDIE::GetAttributes(DWARFAttributes &attributes, - Recurse recurse) const { +DWARFAttributes DWARFBaseDIE::GetAttributes(Recurse recurse) const { if (IsValid()) - return m_die->GetAttributes(m_cu, attributes, recurse); - attributes.Clear(); - return 0; + return m_die->GetAttributes(m_cu, recurse); + return DWARFAttributes(); } bool operator==(const DWARFBaseDIE &lhs, const DWARFBaseDIE &rhs) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h index 51145ab0c4dc..8bcf807ad163 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFBaseDIE.h @@ -115,8 +115,7 @@ class DWARFBaseDIE { uint64_t fail_value) const; enum class Recurse : bool { no, yes }; - size_t GetAttributes(DWARFAttributes &attributes, - Recurse recurse = Recurse::yes) const; + DWARFAttributes GetAttributes(Recurse recurse = Recurse::yes) const; protected: DWARFUnit *m_cu = nullptr; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp index 1db71c0eccdf..0d72485a4ed8 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -410,10 +410,10 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges( // specification or abstract origin attributes and including those in the // results. Any duplicate attributes will have the first instance take // precedence (this can happen for declaration attributes). -size_t DWARFDebugInfoEntry::GetAttributes(DWARFUnit *cu, - DWARFAttributes &attributes, - Recurse recurse, - uint32_t curr_depth) const { +void DWARFDebugInfoEntry::GetAttributes(DWARFUnit *cu, + DWARFAttributes &attributes, + Recurse recurse, + uint32_t curr_depth) const { const auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu); if (abbrevDecl) { const DWARFDataExtractor &data = cu->GetData(); @@ -464,7 +464,6 @@ size_t DWARFDebugInfoEntry::GetAttributes(DWARFUnit *cu, } else { attributes.Clear(); } - return attributes.Size(); } // GetAttributeValue @@ -756,8 +755,7 @@ DWARFDeclContext DWARFDebugInfoEntry::GetDWARFDeclContext(DWARFUnit *cu) const { DWARFDIE DWARFDebugInfoEntry::GetParentDeclContextDIE(DWARFUnit *cu) const { - DWARFAttributes attributes; - GetAttributes(cu, attributes, Recurse::yes); + DWARFAttributes attributes = GetAttributes(cu, Recurse::yes); return GetParentDeclContextDIE(cu, attributes); } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h index e1378952efbc..5baea1f6d60a 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h @@ -50,9 +50,11 @@ class DWARFDebugInfoEntry { const DWARFUnit *cu, lldb::offset_t *offset_ptr); using Recurse = DWARFBaseDIE::Recurse; - size_t GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, - Recurse recurse = Recurse::yes) const { - return GetAttributes(cu, attrs, recurse, 0 /* curr_depth */); + DWARFAttributes GetAttributes(DWARFUnit *cu, + Recurse recurse = Recurse::yes) const { + DWARFAttributes attrs; + GetAttributes(cu, attrs, recurse, 0 /* curr_depth */); + return attrs; } dw_offset_t @@ -184,8 +186,8 @@ class DWARFDebugInfoEntry { dw_tag_t m_tag = llvm::dwarf::DW_TAG_null; private: - size_t GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse, - uint32_t curr_depth) const; + void GetAttributes(DWARFUnit *cu, DWARFAttributes &attrs, Recurse recurse, + uint32_t curr_depth) const; }; #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGINFOENTRY_H diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp index 8e2e04d4176a..2fca6c0f661a 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -371,11 +371,10 @@ std::optional<uint64_t> DWARFUnit::GetDWOId() { // m_die_array_mutex must be already held as read/write. void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) { - DWARFAttributes attributes; - size_t num_attributes = cu_die.GetAttributes(this, attributes); + DWARFAttributes attributes = cu_die.GetAttributes(this); // Extract DW_AT_addr_base first, as other attributes may need it. - for (size_t i = 0; i < num_attributes; ++i) { + for (size_t i = 0; i < attributes.Size(); ++i) { if (attributes.AttributeAtIndex(i) != DW_AT_addr_base) continue; DWARFFormValue form_value; @@ -385,7 +384,7 @@ void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) { } } - for (size_t i = 0; i < num_attributes; ++i) { + for (size_t i = 0; i < attributes.Size(); ++i) { dw_attr_t attr = attributes.AttributeAtIndex(i); DWARFFormValue form_value; if (!attributes.ExtractFormValueAtIndex(i, form_value)) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp index 9be005ea06d5..1aa83a42b671 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -223,62 +223,58 @@ void ManualDWARFIndex::IndexUnitImpl(DWARFUnit &unit, continue; } - DWARFAttributes attributes; const char *name = nullptr; const char *mangled_cstr = nullptr; bool is_declaration = false; - // bool is_artificial = false; bool has_address = false; bool has_location_or_const_value = false; bool is_global_or_static_variable = false; DWARFFormValue specification_die_form; - const size_t num_attributes = die.GetAttributes(&unit, attributes); - if (num_attributes > 0) { - for (uint32_t i = 0; i < num_attributes; ++i) { - dw_attr_t attr = attributes.AttributeAtIndex(i); - DWARFFormValue form_value; - switch (attr) { - default: - break; - case DW_AT_name: - if (attributes.ExtractFormValueAtIndex(i, form_value)) - name = form_value.AsCString(); - break; - - case DW_AT_declaration: - if (attributes.ExtractFormValueAtIndex(i, form_value)) - is_declaration = form_value.Unsigned() != 0; - break; - - case DW_AT_MIPS_linkage_name: - case DW_AT_linkage_name: - if (attributes.ExtractFormValueAtIndex(i, form_value)) - mangled_cstr = form_value.AsCString(); - break; - - case DW_AT_low_pc: - case DW_AT_high_pc: - case DW_AT_ranges: - has_address = true; - break; - - case DW_AT_entry_pc: - has_address = true; - break; - - case DW_AT_location: - case DW_AT_const_value: - has_location_or_const_value = true; - is_global_or_static_variable = die.IsGlobalOrStaticScopeVariable(); - - break; - - case DW_AT_specification: - if (attributes.ExtractFormValueAtIndex(i, form_value)) - specification_die_form = form_value; - break; - } + DWARFAttributes attributes = die.GetAttributes(&unit); + for (size_t i = 0; i < attributes.Size(); ++i) { + dw_attr_t attr = attributes.AttributeAtIndex(i); + DWARFFormValue form_value; + switch (attr) { + default: + break; + case DW_AT_name: + if (attributes.ExtractFormValueAtIndex(i, form_value)) + name = form_value.AsCString(); + break; + + case DW_AT_declaration: + if (attributes.ExtractFormValueAtIndex(i, form_value)) + is_declaration = form_value.Unsigned() != 0; + break; + + case DW_AT_MIPS_linkage_name: + case DW_AT_linkage_name: + if (attributes.ExtractFormValueAtIndex(i, form_value)) + mangled_cstr = form_value.AsCString(); + break; + + case DW_AT_low_pc: + case DW_AT_high_pc: + case DW_AT_ranges: + has_address = true; + break; + + case DW_AT_entry_pc: + has_address = true; + break; + + case DW_AT_location: + case DW_AT_const_value: + has_location_or_const_value = true; + is_global_or_static_variable = die.IsGlobalOrStaticScopeVariable(); + + break; + + case DW_AT_specification: + if (attributes.ExtractFormValueAtIndex(i, form_value)) + specification_die_form = form_value; + break; } } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index e40752b9ff21..5780dbea2ddb 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -3285,8 +3285,7 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc, (tag != DW_TAG_formal_parameter || !sc.function)) return nullptr; - DWARFAttributes attributes; - const size_t num_attributes = die.GetAttributes(attributes); + DWARFAttributes attributes = die.GetAttributes(); const char *name = nullptr; const char *mangled = nullptr; Declaration decl; @@ -3297,7 +3296,7 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc, DWARFFormValue const_value_form, location_form; Variable::RangeList scope_ranges; - for (size_t i = 0; i < num_attributes; ++i) { + for (size_t i = 0; i < attributes.Size(); ++i) { dw_attr_t attr = attributes.AttributeAtIndex(i); DWARFFormValue form_value; @@ -3895,8 +3894,7 @@ CollectCallSiteParameters(ModuleSP module, DWARFDIE call_site_die) { std::optional<DWARFExpressionList> LocationInCallee; std::optional<DWARFExpressionList> LocationInCaller; - DWARFAttributes attributes; - const size_t num_attributes = child.GetAttributes(attributes); + DWARFAttributes attributes = child.GetAttributes(); // Parse the location at index \p attr_index within this call site parameter // DIE, or return std::nullopt on failure. @@ -3915,7 +3913,7 @@ CollectCallSiteParameters(ModuleSP module, DWARFDIE call_site_die) { child.GetCU()); }; - for (size_t i = 0; i < num_attributes; ++i) { + for (size_t i = 0; i < attributes.Size(); ++i) { dw_attr_t attr = attributes.AttributeAtIndex(i); if (attr == DW_AT_location) LocationInCallee = parse_simple_location(i); @@ -3966,10 +3964,8 @@ SymbolFileDWARF::CollectCallEdges(ModuleSP module, DWARFDIE function_die) { // Second DW_AT_low_pc may come from DW_TAG_subprogram referenced by // DW_TAG_GNU_call_site's DW_AT_abstract_origin overwriting our 'low_pc'. // So do not inherit attributes from DW_AT_abstract_origin. - DWARFAttributes attributes; - const size_t num_attributes = - child.GetAttributes(attributes, DWARFDIE::Recurse::no); - for (size_t i = 0; i < num_attributes; ++i) { + DWARFAttributes attributes = child.GetAttributes(DWARFDIE::Recurse::no); + for (size_t i = 0; i < attributes.Size(); ++i) { DWARFFormValue form_value; if (!attributes.ExtractFormValueAtIndex(i, form_value)) { LLDB_LOG(log, "CollectCallEdges: Could not extract TAG_call_site form"); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits