diff --git a/elftools/dwarf/compileunit.py b/elftools/dwarf/compileunit.py index 704dec37..a6b2c1fe 100644 --- a/elftools/dwarf/compileunit.py +++ b/elftools/dwarf/compileunit.py @@ -226,6 +226,9 @@ def _get_cached_DIE(self, offset): # the top DIE and obtain a reference to its stream. top_die_stream = self.get_top_DIE().stream + if self.dwarfinfo._skip_cache: + return DIE(cu=self, stream=top_die_stream, offset=offset) + # `offset` is the offset in the stream of the DIE we want to return. # The map is maintined as a parallel array to the list. We call # bisect each time to ensure new DIEs are inserted in the correct diff --git a/elftools/dwarf/dwarfinfo.py b/elftools/dwarf/dwarfinfo.py index 40614628..a34ba2cf 100644 --- a/elftools/dwarf/dwarfinfo.py +++ b/elftools/dwarf/dwarfinfo.py @@ -134,6 +134,8 @@ def __init__(self, self._cu_cache = [] self._cu_offsets_map = [] + self._skip_cache = False + @property def has_debug_info(self): """ Return whether this contains debug information. @@ -430,6 +432,10 @@ def _cached_CU_at_offset(self, offset): See get_CU_at(). """ + if self._skip_cache: + cu = self._parse_CU_at_offset(offset) + return cu + # Find the insert point for the requested offset. With bisect_right, # if this entry is present in the cache it will be the prior entry. i = bisect_right(self._cu_offsets_map, offset) @@ -575,3 +581,10 @@ def parse_debugsupinfo(self): return suplink.sup_filename return None + def skip_cache(self): + self._skip_cache = True + pass + + def enable_cache(self): + self._skip_cache = False + pass