]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.15] gh-151613: Fix remote debugging frame cache ABA (#152448)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Sat, 27 Jun 2026 17:42:31 +0000 (19:42 +0200)
committerGitHub <noreply@github.com>
Sat, 27 Jun 2026 17:42:31 +0000 (17:42 +0000)
commit65fbec64f6a4a6a8fb68f86e323efed54e5a083d
tree6c9042145dabd888911d000ebd9af6b3bf58189e
parent5d0fa7a5c47b99c84c9b7c24511f8fa9381fbb49
[3.15] gh-151613: Fix remote debugging frame cache ABA (#152448)

gh-151613: Fix remote debugging frame cache ABA (#151614)

The remote debugging frame cache previously used only the last_profiled_frame address as its cache anchor. If a frame returned and a later frame reused the same _PyInterpreterFrame address, the profiler could accept a stale cache entry and splice parent frames from a different call chain into the current stack.

This adds a last_profiled_frame_seq counter next to last_profiled_frame, increments it when the anchor advances, stores it in frame cache entries, and validates cache hits against both the frame address and the sequence. Cache miss walks now copy stack chunks before storing new cache entries so stored continuations come from a stable snapshot. The new regression test exercises alternating call chains and checks that cached stacks never contain frames from both branches.

(cherry picked from commit 8cda6ae2f1f86f2d26c29586ffc9687b410abfcf)
12 files changed:
Include/cpython/pystate.h
Include/internal/pycore_debug_offsets.h
Include/internal/pycore_interpframe.h
InternalDocs/frames.md
Misc/NEWS.d/next/Library/2026-06-17-22-31-57.gh-issue-151613.n0nua1.rst [new file with mode: 0644]
Modules/_remote_debugging/_remote_debugging.h
Modules/_remote_debugging/debug_offsets_validation.h
Modules/_remote_debugging/frame_cache.c
Modules/_remote_debugging/frames.c
Modules/_remote_debugging/module.c
Modules/_remote_debugging/threads.c
Python/pystate.c