dwarf_loader: Optimize a bit the reading of DW_AT_data_member_location

Using the newly added __attr_offset(), so that we try to read it, if it
isn't there, then we don't need to use dwarf_hasattr() for setting
member->is_static.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2021-01-27 11:29:38 -03:00
parent 65917b2494
commit c692e8ac5c
1 changed files with 9 additions and 2 deletions

View File

@ -771,10 +771,17 @@ static struct class_member *class_member__new(Dwarf_Die *die, struct cu *cu,
if (member != NULL) {
tag__init(&member->tag, cu, die);
member->name = strings__add(strings, attr_string(die, DW_AT_name));
member->is_static = !in_union && !dwarf_hasattr(die, DW_AT_data_member_location);
member->const_value = attr_numeric(die, DW_AT_const_value);
member->alignment = attr_numeric(die, DW_AT_alignment);
member->byte_offset = attr_offset(die, DW_AT_data_member_location);
Dwarf_Attribute attr;
if (dwarf_attr(die, DW_AT_data_member_location, &attr) != NULL) {
member->byte_offset = __attr_offset(&attr);
} else {
member->is_static = !in_union;
}
/*
* Bit offset calculated here is valid only for byte-aligned
* fields. For bitfields on little-endian archs we need to