From 0c9fad26b99d303900f571a5fdc98954f249f975 Mon Sep 17 00:00:00 2001 From: disinvite Date: Wed, 31 Jan 2024 15:17:15 -0500 Subject: [PATCH] Bugfix for get_module --- tools/roadmap/roadmap.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/roadmap/roadmap.py b/tools/roadmap/roadmap.py index 5eaae874..97a4f894 100644 --- a/tools/roadmap/roadmap.py +++ b/tools/roadmap/roadmap.py @@ -56,10 +56,17 @@ def get_all_cmake_modules(self) -> List[str]: def get_module(self, addr: int) -> Optional[str]: i = bisect.bisect_left(self.contrib_starts, addr) + # If the addr matches the section contribution start, we are in the + # right spot. Otherwise, we need to subtract one here. + # We don't want the insertion point given by bisect, but the + # section contribution that contains the address. - # Clamp to final section contribution for a very high address - if i >= len(self.section_contrib): - i = len(self.section_contrib) - 1 + (potential_start, _, __) = self.section_contrib[i] + if potential_start != addr: + i -= 1 + + # Safety catch: clamp to range of indices from section_contrib. + i = max(0, min(i, len(self.section_contrib) - 1)) (start, size, module_id) = self.section_contrib[i] if start <= addr < start + size: