Skip to content

Commit c8c5241

Browse files
committed
gh-129223: Raise KeyError in search_map_for_section() if not found
1 parent fc6bc1e commit c8c5241

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Lib/test/test_external_inspection.py

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def foo():
6363
stack_trace = get_stack_trace(p.pid)
6464
except PermissionError:
6565
self.skipTest("Insufficient permissions to read the stack trace")
66+
except KeyError as exc:
67+
self.skipTest(str(exc))
6668
finally:
6769
os.remove(fifo)
6870
p.kill()
@@ -147,6 +149,8 @@ def new_eager_loop():
147149
except PermissionError:
148150
self.skipTest(
149151
"Insufficient permissions to read the stack trace")
152+
except KeyError as exc:
153+
self.skipTest(str(exc))
150154
finally:
151155
os.remove(fifo)
152156
p.kill()
@@ -212,6 +216,8 @@ async def main():
212216
stack_trace = get_async_stack_trace(p.pid)
213217
except PermissionError:
214218
self.skipTest("Insufficient permissions to read the stack trace")
219+
except KeyError as exc:
220+
self.skipTest(str(exc))
215221
finally:
216222
os.remove(fifo)
217223
p.kill()
@@ -272,6 +278,8 @@ async def main():
272278
except PermissionError:
273279
self.skipTest(
274280
"Insufficient permissions to read the stack trace")
281+
except KeyError as exc:
282+
self.skipTest(str(exc))
275283
finally:
276284
os.remove(fifo)
277285
p.kill()

Modules/_testexternalinspection.c

+4
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ search_map_for_section(pid_t pid, const char* secname, const char* map)
383383
);
384384
result = start_address + (uintptr_t)section->sh_addr - elf_load_addr;
385385
}
386+
else {
387+
PyErr_Format(PyExc_KeyError,
388+
"cannot find map for section %s", secname);
389+
}
386390

387391
exit:
388392
if (close(fd) != 0) {

0 commit comments

Comments
 (0)