mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-25 02:13:06 +00:00
dwarftypeindex: isolate pre-GCC 5.1 enum special case code
And change the signed heuristic.
This commit is contained in:
parent
e3fa0bca93
commit
959968b4e4
@ -217,26 +217,26 @@ class DwarfTypeIndex(TypeIndex):
|
||||
if dwarf_type.find_flag(DW_AT.declaration):
|
||||
return EnumType(name, None, None, qualifiers)
|
||||
else:
|
||||
size = dwarf_type.size()
|
||||
signed_max = 2**(size - 1) - 1
|
||||
signed = True
|
||||
enumerators = []
|
||||
for child in dwarf_type.children():
|
||||
if child.tag != DW_TAG.enumerator:
|
||||
continue
|
||||
enumerator_name = child.name()
|
||||
enumerator_value = child.find_constant(DW_AT.const_value)
|
||||
if enumerator_value > signed_max:
|
||||
signed = False
|
||||
enumerators.append((enumerator_name, enumerator_value))
|
||||
int_type: Type
|
||||
try:
|
||||
type_die = dwarf_type.type()
|
||||
except DwarfAttribNotFoundError:
|
||||
# GCC before 5.1 did not include DW_AT_type for
|
||||
# DW_TAG_enumeration_type DIEs, so we have to fabricate
|
||||
# one.
|
||||
int_type = IntType('', size, signed)
|
||||
# DW_TAG_enumeration_type DIEs, so we have to fabricate the
|
||||
# compatible type.
|
||||
size = dwarf_type.size()
|
||||
# GCC before 7.1 didn't include DW_AT_encoding for
|
||||
# DW_TAG_enumeration_type DIEs, either, so we also have to
|
||||
# guess at the sign.
|
||||
signed = any(enumerator[1] < 0 for enumerator in enumerators)
|
||||
int_type = IntType('', dwarf_type.size(), signed)
|
||||
else:
|
||||
int_type = self._from_dwarf_type(type_die)
|
||||
if not isinstance(int_type, IntType):
|
||||
|
Loading…
Reference in New Issue
Block a user