scripts: Made dwarf tags explicit in ctx.py/structs.py

This will make ctx.py/structs.py more likely to error on unknown tags,
which is preferable to silently reporting incorrect numbers.
This commit is contained in:
Christopher Haster
2024-12-04 10:48:34 -06:00
parent b90b2953ea
commit 308b4b6080
2 changed files with 49 additions and 9 deletions
+26 -6
View File
@@ -552,12 +552,22 @@ def collect(obj_paths, *,
# function pointer? # function pointer?
elif entry.tag == 'DW_TAG_subroutine_type': elif entry.tag == 'DW_TAG_subroutine_type':
size = 0 size = 0
# probably a modifier # a modifier?
elif 'DW_AT_type' in entry: elif (entry.tag in {
'DW_TAG_typedef',
'DW_TAG_array_type',
'DW_TAG_enumeration_type',
'DW_TAG_formal_parameter',
'DW_TAG_member',
'DW_TAG_const_type',
'DW_TAG_volatile_type',
'DW_TAG_restrict_type'}
and 'DW_AT_type' in entry):
type = info[int(entry['DW_AT_type'].strip('<>'), 0)] type = info[int(entry['DW_AT_type'].strip('<>'), 0)]
size = sizeof(type, seen | {entry.off}) size = sizeof(type, seen | {entry.off})
# void? # void?
elif 'DW_AT_byte_size' not in entry: elif ('DW_AT_type' not in entry
and 'DW_AT_byte_size' not in entry):
size = 0 size = 0
else: else:
assert False, "Unknown dwarf entry? %r" % entry.tag assert False, "Unknown dwarf entry? %r" % entry.tag
@@ -616,13 +626,23 @@ def collect(obj_paths, *,
'DW_TAG_base_type', 'DW_TAG_base_type',
'DW_TAG_subroutine_type'}: 'DW_TAG_subroutine_type'}:
children, notes = [], [] children, notes = [], []
# probably a modifier # a modifier?
elif 'DW_AT_type' in entry: elif (entry.tag in {
'DW_TAG_typedef',
'DW_TAG_array_type',
'DW_TAG_enumeration_type',
'DW_TAG_formal_parameter',
'DW_TAG_member',
'DW_TAG_const_type',
'DW_TAG_volatile_type',
'DW_TAG_restrict_type'}
and 'DW_AT_type' in entry):
type = int(entry['DW_AT_type'].strip('<>'), 0) type = int(entry['DW_AT_type'].strip('<>'), 0)
children, notes = childrenof( children, notes = childrenof(
info[type], seen | {entry.off}) info[type], seen | {entry.off})
# void? # void?
elif 'DW_AT_byte_size' not in entry: elif ('DW_AT_type' not in entry
and 'DW_AT_byte_size' not in entry):
children, notes = [], [] children, notes = [], []
else: else:
assert False, "Unknown dwarf entry? %r" % entry.tag assert False, "Unknown dwarf entry? %r" % entry.tag
+23 -3
View File
@@ -397,7 +397,13 @@ def collect(obj_paths, *,
if child.tag == 'DW_TAG_subrange_type': if child.tag == 'DW_TAG_subrange_type':
size *= int(child['DW_AT_upper_bound']) + 1 size *= int(child['DW_AT_upper_bound']) + 1
# indirect type? # indirect type?
elif 'DW_AT_type' in entry: elif entry.tag in {
'DW_TAG_typedef',
'DW_TAG_enumeration_type',
'DW_TAG_member',
'DW_TAG_const_type',
'DW_TAG_volatile_type',
'DW_TAG_restrict_type'}:
type = info[int(entry['DW_AT_type'].strip('<>'), 0)] type = info[int(entry['DW_AT_type'].strip('<>'), 0)]
size = sizeof(type) size = sizeof(type)
else: else:
@@ -429,7 +435,14 @@ def collect(obj_paths, *,
'DW_TAG_union_type'}: 'DW_TAG_union_type'}:
align = max(alignof(child) for child in entry.children) align = max(alignof(child) for child in entry.children)
# indirect type? # indirect type?
elif 'DW_AT_type' in entry: elif entry.tag in {
'DW_TAG_typedef',
'DW_TAG_array_type',
'DW_TAG_enumeration_type',
'DW_TAG_member',
'DW_TAG_const_type',
'DW_TAG_volatile_type',
'DW_TAG_restrict_type'}:
type = int(entry['DW_AT_type'].strip('<>'), 0) type = int(entry['DW_AT_type'].strip('<>'), 0)
align = alignof(info[type]) align = alignof(info[type])
else: else:
@@ -466,7 +479,14 @@ def collect(obj_paths, *,
i=child.off, i=child.off,
children=children_)) children=children_))
# indirect type? # indirect type?
elif 'DW_AT_type' in entry: elif entry.tag in {
'DW_TAG_typedef',
'DW_TAG_array_type',
'DW_TAG_enumeration_type',
'DW_TAG_member',
'DW_TAG_const_type',
'DW_TAG_volatile_type',
'DW_TAG_restrict_type'}:
type = int(entry['DW_AT_type'].strip('<>'), 0) type = int(entry['DW_AT_type'].strip('<>'), 0)
children = childrenof(info[type]) children = childrenof(info[type])
else: else: