https://github.com/python/cpython/commit/624384d97405f071da94321505ef160c987cac50
commit: 624384d97405f071da94321505ef160c987cac50
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: hugovk <[email protected]>
date: 2026-06-04T11:31:47+03:00
summary:

[3.15] gh-149521: Do not update `last_profiled_frame` if it's not changed 
(GH-149522) (#149542)

Co-authored-by: Maurycy Pawłowski-Wieroński <[email protected]>

files:
M Modules/_remote_debugging/threads.c

diff --git a/Modules/_remote_debugging/threads.c 
b/Modules/_remote_debugging/threads.c
index 5176c4cf0671bb1..81735e85395ac9e 100644
--- a/Modules/_remote_debugging/threads.c
+++ b/Modules/_remote_debugging/threads.c
@@ -534,12 +534,14 @@ unwind_stack_for_thread(
             set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to 
collect frames");
             goto error;
         }
-        // Update last_profiled_frame for next sample
-        uintptr_t lpf_addr =
-            *current_tstate + 
(uintptr_t)unwinder->debug_offsets.thread_state.last_profiled_frame;
-        if (_Py_RemoteDebug_WriteRemoteMemory(&unwinder->handle, lpf_addr,
-                                              sizeof(uintptr_t), &frame_addr) 
< 0) {
-            PyErr_Clear();  // Non-fatal
+        // Update last_profiled_frame for next sample if it changed
+        if (frame_addr != ctx.last_profiled_frame) {
+            uintptr_t lpf_addr =
+                *current_tstate + 
(uintptr_t)unwinder->debug_offsets.thread_state.last_profiled_frame;
+            if (_Py_RemoteDebug_WriteRemoteMemory(&unwinder->handle, lpf_addr,
+                                                  sizeof(uintptr_t), 
&frame_addr) < 0) {
+                PyErr_Clear();  // Non-fatal
+            }
         }
     } else {
         // No caching - process entire frame chain with base_frame validation

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to