Skip to content

Commit

Permalink
pythongh-129223: Raise KeyError in search_map_for_section() if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Jan 24, 2025
1 parent fc6bc1e commit c8c5241
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Lib/test/test_external_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions Modules/_testexternalinspection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c8c5241

Please sign in to comment.