From 2efa9343fbd986bb9318813262e39cef226e8ba3 Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Thu, 8 Mar 2018 21:30:05 -0800 Subject: [PATCH] dwarf: add Die.size() Instead of having to do die.find_constant(DW_AT.byte_size). --- drgn/dwarf.pyx | 3 +++ drgn/type.py | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drgn/dwarf.pyx b/drgn/dwarf.pyx index cbc60f24..a9c60405 100644 --- a/drgn/dwarf.pyx +++ b/drgn/dwarf.pyx @@ -1434,6 +1434,9 @@ cdef class Die: cpdef str name(self): return self.find_string(DW_AT_name) + def size(self): + return self.find_constant(DW_AT_byte_size) + cpdef uint64_t address(self): cdef const DieAttrib *low_pc = self.find_attrib(DW_AT_low_pc) if low_pc.form != DW_FORM_addr: diff --git a/drgn/type.py b/drgn/type.py index 92848037..aa063e84 100644 --- a/drgn/type.py +++ b/drgn/type.py @@ -604,7 +604,7 @@ class TypeFactory: if dwarf_type.tag == DW_TAG.base_type: encoding = dwarf_type.find_constant(DW_AT.encoding) - size = dwarf_type.find_constant(DW_AT.byte_size) + size = dwarf_type.size() if encoding == DW_ATE.boolean: return BoolType(dwarf_type.name(), size, qualifiers) elif encoding == DW_ATE.float: @@ -623,7 +623,7 @@ class TypeFactory: size = None members = None else: - size = dwarf_type.find_constant(DW_AT.byte_size) + size = dwarf_type.size() members = [] for child in dwarf_type.children(): if child.tag != DW_TAG.member: @@ -657,7 +657,7 @@ class TypeFactory: signed = None enumerators = None else: - size = dwarf_type.find_constant(DW_AT.byte_size) + size = dwarf_type.size() encoding = dwarf_type.find_constant(DW_AT.encoding) if encoding == DW_ATE.signed: signed = True @@ -682,7 +682,7 @@ class TypeFactory: self.from_dwarf_type(dwarf_type.type()), qualifiers) elif dwarf_type.tag == DW_TAG.pointer_type: - size = dwarf_type.find_constant(DW_AT.byte_size) + size = dwarf_type.size() try: deref_type = dwarf_type.type() except DwarfAttribNotFoundError: