Skip to content

gh-160107: Make AsyncioDebug reachable from _PyRuntime and add a header - #160108

Draft
taegyunkim wants to merge 1 commit into
python:mainfrom
taegyunkim:taegyun/asyncio-debug-offsets-runtime-pointer
Draft

taegyunkim wants to merge 1 commit into
python:mainfrom
taegyunkim:taegyun/asyncio-debug-offsets-runtime-pointer

Conversation

@taegyunkim

Copy link
Copy Markdown
Contributor

Implements the proposal in gh-160107.

  • _PyRuntimeState gets a new asyncio_debug_offsets pointer, and its offset is published as _Py_DebugOffsets.runtime_state.asyncio_debug_offsets. _asyncio's module init stores &_Py_AsyncioDebug there with a release store. It is NULL until _asyncio is initialized.
  • Py_AsyncioModuleDebugOffsets now starts with a cookie ("xasyncpy"), PY_VERSION_HEX and its size. The AsyncioDebug section is kept.
  • _remote_debugging follows the pointer instead of searching loaded binaries for the section, and rejects a table whose cookie doesn't match, whose version differs from _Py_DebugOffsets.version, or whose size is smaller than the local struct. The new runtime-state field is added to the validation list and the static_assert sizes are updated.
  • New test in test_external_inspection that follows the pointer from _PyRuntime with ctypes: NULL before import _asyncio, then a valid header after.

Tested on Linux arm64 (test_external_inspection, test_profiling, test_capi, with ptrace allowed so the remote asyncio tests run) and on a macOS arm64 debug build, where the remote-inspection tests skip without root. Not tested on Windows yet.

I used AI to help write this change. I have reviewed all of it.

…a header

Debuggers and profilers could only find the asyncio debug offsets by
searching loaded binaries for the AsyncioDebug section, and the table had
no cookie, version or size to check what they found.

_asyncio now stores the address of _Py_AsyncioDebug in
_PyRuntime.asyncio_debug_offsets, whose offset is published as
_Py_DebugOffsets.runtime_state.asyncio_debug_offsets. The pointer is NULL
until _asyncio is initialized. The table now starts with a cookie
("xasyncpy"), PY_VERSION_HEX and its size. The AsyncioDebug section is
kept for existing tools.

_remote_debugging follows the pointer instead of searching for the
section, and rejects a table whose cookie, version or size does not
match.
@taegyunkim

Copy link
Copy Markdown
Contributor Author

This is a reference implementation for gh-160107. I opened it earlier than I meant to, before the issue had any discussion, and I'm sorry for the CI it triggered. If a triager can cancel the queued run, please do. I won't push again until there's agreement on the direction in the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant