scripts: Added DwarfEntry.info to help find recursive tags
Long story short: DW_TAG_lexical_blocks are annoying. In order to search the full tree of children of a given dwarf entry, we need a recursive function somewhere. We might as well make this function a part of the DwarfEntry class so we can share it with other scripts. Note this is roughly the same as collect_dwarf_info, but limited to the children of a given dwarf entry. This is useful for ongoing stack.py rework.
This commit is contained in:
+14
-1
@@ -393,6 +393,19 @@ class DwarfEntry:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def info(self, tags=None):
|
||||||
|
# recursively flatten children
|
||||||
|
def flatten(entry):
|
||||||
|
for child in entry.children:
|
||||||
|
# filter if requested
|
||||||
|
if tags is None or child.tag in tags:
|
||||||
|
yield child
|
||||||
|
|
||||||
|
yield from flatten(child)
|
||||||
|
|
||||||
|
return DwarfInfo(co.OrderedDict(
|
||||||
|
(child.off, child) for child in flatten(self)))
|
||||||
|
|
||||||
# a collection of dwarf entries
|
# a collection of dwarf entries
|
||||||
class DwarfInfo:
|
class DwarfInfo:
|
||||||
def __init__(self, entries):
|
def __init__(self, entries):
|
||||||
@@ -443,7 +456,7 @@ class DwarfInfo:
|
|||||||
return len(self.entries)
|
return len(self.entries)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return (v for k, v in self.entries.items())
|
return iter(self.entries.values())
|
||||||
|
|
||||||
def collect_dwarf_info(obj_path, tags=None, *,
|
def collect_dwarf_info(obj_path, tags=None, *,
|
||||||
objdump_path=OBJDUMP_PATH,
|
objdump_path=OBJDUMP_PATH,
|
||||||
|
|||||||
+14
-1
@@ -402,6 +402,19 @@ class DwarfEntry:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def info(self, tags=None):
|
||||||
|
# recursively flatten children
|
||||||
|
def flatten(entry):
|
||||||
|
for child in entry.children:
|
||||||
|
# filter if requested
|
||||||
|
if tags is None or child.tag in tags:
|
||||||
|
yield child
|
||||||
|
|
||||||
|
yield from flatten(child)
|
||||||
|
|
||||||
|
return DwarfInfo(co.OrderedDict(
|
||||||
|
(child.off, child) for child in flatten(self)))
|
||||||
|
|
||||||
# a collection of dwarf entries
|
# a collection of dwarf entries
|
||||||
class DwarfInfo:
|
class DwarfInfo:
|
||||||
def __init__(self, entries):
|
def __init__(self, entries):
|
||||||
@@ -452,7 +465,7 @@ class DwarfInfo:
|
|||||||
return len(self.entries)
|
return len(self.entries)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return (v for k, v in self.entries.items())
|
return iter(self.entries.values())
|
||||||
|
|
||||||
def collect_dwarf_info(obj_path, tags=None, *,
|
def collect_dwarf_info(obj_path, tags=None, *,
|
||||||
objdump_path=OBJDUMP_PATH,
|
objdump_path=OBJDUMP_PATH,
|
||||||
|
|||||||
+14
-1
@@ -393,6 +393,19 @@ class DwarfEntry:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def info(self, tags=None):
|
||||||
|
# recursively flatten children
|
||||||
|
def flatten(entry):
|
||||||
|
for child in entry.children:
|
||||||
|
# filter if requested
|
||||||
|
if tags is None or child.tag in tags:
|
||||||
|
yield child
|
||||||
|
|
||||||
|
yield from flatten(child)
|
||||||
|
|
||||||
|
return DwarfInfo(co.OrderedDict(
|
||||||
|
(child.off, child) for child in flatten(self)))
|
||||||
|
|
||||||
# a collection of dwarf entries
|
# a collection of dwarf entries
|
||||||
class DwarfInfo:
|
class DwarfInfo:
|
||||||
def __init__(self, entries):
|
def __init__(self, entries):
|
||||||
@@ -443,7 +456,7 @@ class DwarfInfo:
|
|||||||
return len(self.entries)
|
return len(self.entries)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return (v for k, v in self.entries.items())
|
return iter(self.entries.values())
|
||||||
|
|
||||||
def collect_dwarf_info(obj_path, tags=None, *,
|
def collect_dwarf_info(obj_path, tags=None, *,
|
||||||
objdump_path=OBJDUMP_PATH,
|
objdump_path=OBJDUMP_PATH,
|
||||||
|
|||||||
+15
-2
@@ -253,7 +253,7 @@ class DwarfEntry:
|
|||||||
def name(self):
|
def name(self):
|
||||||
if 'DW_AT_name' in self:
|
if 'DW_AT_name' in self:
|
||||||
name = self['DW_AT_name'].split(':')[-1].strip()
|
name = self['DW_AT_name'].split(':')[-1].strip()
|
||||||
# prefix with struct/union
|
# prefix with struct/union/enum
|
||||||
if self.tag == 'DW_TAG_structure_type':
|
if self.tag == 'DW_TAG_structure_type':
|
||||||
name = 'struct ' + name
|
name = 'struct ' + name
|
||||||
elif self.tag == 'DW_TAG_union_type':
|
elif self.tag == 'DW_TAG_union_type':
|
||||||
@@ -264,6 +264,19 @@ class DwarfEntry:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def info(self, tags=None):
|
||||||
|
# recursively flatten children
|
||||||
|
def flatten(entry):
|
||||||
|
for child in entry.children:
|
||||||
|
# filter if requested
|
||||||
|
if tags is None or child.tag in tags:
|
||||||
|
yield child
|
||||||
|
|
||||||
|
yield from flatten(child)
|
||||||
|
|
||||||
|
return DwarfInfo(co.OrderedDict(
|
||||||
|
(child.off, child) for child in flatten(self)))
|
||||||
|
|
||||||
# a collection of dwarf entries
|
# a collection of dwarf entries
|
||||||
class DwarfInfo:
|
class DwarfInfo:
|
||||||
def __init__(self, entries):
|
def __init__(self, entries):
|
||||||
@@ -314,7 +327,7 @@ class DwarfInfo:
|
|||||||
return len(self.entries)
|
return len(self.entries)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return (v for k, v in self.entries.items())
|
return iter(self.entries.values())
|
||||||
|
|
||||||
def collect_dwarf_info(obj_path, tags=None, *,
|
def collect_dwarf_info(obj_path, tags=None, *,
|
||||||
objdump_path=OBJDUMP_PATH,
|
objdump_path=OBJDUMP_PATH,
|
||||||
|
|||||||
Reference in New Issue
Block a user