Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion elftools/dwarf/dwarfinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def __init__(self,
debug_rnglists_sec,
debug_sup_sec,
gnu_debugaltlink_sec,
debug_types_sec
debug_types_sec,
max_cu_cache_size = -1
):
""" config:
A DwarfConfig object
Expand All @@ -91,6 +92,9 @@ def __init__(self,
DebugSectionDescriptor for a section. Pass None for sections
that don't exist. These arguments are best given with
keyword syntax.

max_cu_cache_size:
Enforces a limit on CU cache size, For unlimitted cache size set to -1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size limit is on the number of entries/CUs? The comment should say this in more detail.

"""
self.config = config
self.debug_info_sec = debug_info_sec
Expand All @@ -113,6 +117,8 @@ def __init__(self,
self.gnu_debugaltlink_sec = gnu_debugaltlink_sec
self.debug_types_sec = debug_types_sec

self.max_cu_cache_size = max_cu_cache_size

# Sets the supplementary_dwarfinfo to None. Client code can set this
# to something else, typically a DWARFInfo file read from an ELFFile
# which path is stored in the debug_sup_sec or gnu_debugaltlink_sec.
Expand Down Expand Up @@ -547,6 +553,12 @@ def _cached_CU_at_offset(self, offset):
# bisect_right search while the parallel indexed ._cu_cache[] holds
# the object references.
cu = self._parse_CU_at_offset(offset)

# max_cu_cache_size of -1 makes cache size unlimited
if self.max_cu_cache_size != -1 and len(self._cu_cache) > self.max_cu_cache_size:
self._cu_offsets_map.pop(0)
self._cu_cache.pop(0)

self._cu_offsets_map.insert(i, offset)
self._cu_cache.insert(i, cu)
return cu
Expand Down
5 changes: 3 additions & 2 deletions elftools/elf/elffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def has_dwarf_info(self, strict=False):
self.has_section('.zdebug_info') or
(not strict and self.has_section('.eh_frame')))

def get_dwarf_info(self, relocate_dwarf_sections=True, follow_links=True):
def get_dwarf_info(self, relocate_dwarf_sections=True, follow_links=True, max_cu_cache_size = -1):
""" Return a DWARFInfo object representing the debugging information in
this file.

Expand Down Expand Up @@ -355,7 +355,8 @@ def get_dwarf_info(self, relocate_dwarf_sections=True, follow_links=True):
debug_rnglists_sec=debug_sections[debug_rnglists_sec_name],
debug_sup_sec=debug_sections[debug_sup_name],
gnu_debugaltlink_sec=debug_sections[gnu_debugaltlink_name],
debug_types_sec=debug_sections[debug_types_sec_name]
debug_types_sec=debug_sections[debug_types_sec_name],
max_cu_cache_size = max_cu_cache_size
)
if follow_links:
dwarfinfo.supplementary_dwarfinfo = self.get_supplementary_dwarfinfo(dwarfinfo)
Expand Down