From c8c524151cb3f3bed4175016db4ec2f3cd05b5f1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 24 Jan 2025 14:47:27 +0100 Subject: [PATCH 1/2] gh-129223: Raise KeyError in search_map_for_section() if not found --- Lib/test/test_external_inspection.py | 8 ++++++++ Modules/_testexternalinspection.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/Lib/test/test_external_inspection.py b/Lib/test/test_external_inspection.py index eceae532422f3c..d048aac25e5dab 100644 --- a/Lib/test/test_external_inspection.py +++ b/Lib/test/test_external_inspection.py @@ -63,6 +63,8 @@ def foo(): stack_trace = get_stack_trace(p.pid) except PermissionError: self.skipTest("Insufficient permissions to read the stack trace") + except KeyError as exc: + self.skipTest(str(exc)) finally: os.remove(fifo) p.kill() @@ -147,6 +149,8 @@ def new_eager_loop(): except PermissionError: self.skipTest( "Insufficient permissions to read the stack trace") + except KeyError as exc: + self.skipTest(str(exc)) finally: os.remove(fifo) p.kill() @@ -212,6 +216,8 @@ async def main(): stack_trace = get_async_stack_trace(p.pid) except PermissionError: self.skipTest("Insufficient permissions to read the stack trace") + except KeyError as exc: + self.skipTest(str(exc)) finally: os.remove(fifo) p.kill() @@ -272,6 +278,8 @@ async def main(): except PermissionError: self.skipTest( "Insufficient permissions to read the stack trace") + except KeyError as exc: + self.skipTest(str(exc)) finally: os.remove(fifo) p.kill() diff --git a/Modules/_testexternalinspection.c b/Modules/_testexternalinspection.c index 25e0e9c64ec27d..0959b82f65ce3c 100644 --- a/Modules/_testexternalinspection.c +++ b/Modules/_testexternalinspection.c @@ -383,6 +383,10 @@ search_map_for_section(pid_t pid, const char* secname, const char* map) ); result = start_address + (uintptr_t)section->sh_addr - elf_load_addr; } + else { + PyErr_Format(PyExc_KeyError, + "cannot find map for section %s", secname); + } exit: if (close(fd) != 0) { From 66f2f40ca73a3f2bbe1dea125ad49db9764a3923 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 25 Jan 2025 17:24:54 +0100 Subject: [PATCH 2/2] Don't skip the tests --- Lib/test/test_external_inspection.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Lib/test/test_external_inspection.py b/Lib/test/test_external_inspection.py index d048aac25e5dab..eceae532422f3c 100644 --- a/Lib/test/test_external_inspection.py +++ b/Lib/test/test_external_inspection.py @@ -63,8 +63,6 @@ def foo(): stack_trace = get_stack_trace(p.pid) except PermissionError: self.skipTest("Insufficient permissions to read the stack trace") - except KeyError as exc: - self.skipTest(str(exc)) finally: os.remove(fifo) p.kill() @@ -149,8 +147,6 @@ def new_eager_loop(): except PermissionError: self.skipTest( "Insufficient permissions to read the stack trace") - except KeyError as exc: - self.skipTest(str(exc)) finally: os.remove(fifo) p.kill() @@ -216,8 +212,6 @@ async def main(): stack_trace = get_async_stack_trace(p.pid) except PermissionError: self.skipTest("Insufficient permissions to read the stack trace") - except KeyError as exc: - self.skipTest(str(exc)) finally: os.remove(fifo) p.kill() @@ -278,8 +272,6 @@ async def main(): except PermissionError: self.skipTest( "Insufficient permissions to read the stack trace") - except KeyError as exc: - self.skipTest(str(exc)) finally: os.remove(fifo) p.kill()