From 308b4b60809fbc2e47c2ad308ac81776a764b946 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 4 Dec 2024 10:48:34 -0600 Subject: [PATCH] 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. --- scripts/ctx.py | 32 ++++++++++++++++++++++++++------ scripts/structs.py | 26 +++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/scripts/ctx.py b/scripts/ctx.py index 8a644b3d..317ca3b2 100755 --- a/scripts/ctx.py +++ b/scripts/ctx.py @@ -552,12 +552,22 @@ def collect(obj_paths, *, # function pointer? elif entry.tag == 'DW_TAG_subroutine_type': size = 0 - # probably a modifier - elif 'DW_AT_type' in entry: + # a modifier? + 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)] size = sizeof(type, seen | {entry.off}) # 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 else: assert False, "Unknown dwarf entry? %r" % entry.tag @@ -616,13 +626,23 @@ def collect(obj_paths, *, 'DW_TAG_base_type', 'DW_TAG_subroutine_type'}: children, notes = [], [] - # probably a modifier - elif 'DW_AT_type' in entry: + # a modifier? + 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) children, notes = childrenof( info[type], seen | {entry.off}) # 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 = [], [] else: assert False, "Unknown dwarf entry? %r" % entry.tag diff --git a/scripts/structs.py b/scripts/structs.py index 3f9ddba4..d03299f0 100755 --- a/scripts/structs.py +++ b/scripts/structs.py @@ -397,7 +397,13 @@ def collect(obj_paths, *, if child.tag == 'DW_TAG_subrange_type': size *= int(child['DW_AT_upper_bound']) + 1 # 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)] size = sizeof(type) else: @@ -429,7 +435,14 @@ def collect(obj_paths, *, 'DW_TAG_union_type'}: align = max(alignof(child) for child in entry.children) # 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) align = alignof(info[type]) else: @@ -466,7 +479,14 @@ def collect(obj_paths, *, i=child.off, children=children_)) # 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) children = childrenof(info[type]) else: