From a054811c7e9844c9fffa73d78bda297b99633073 Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Tue, 22 Apr 2025 18:59:05 +0800 Subject: [PATCH 1/4] gh-131591: Reset RemoteDebuggerSuupport state after fork Signed-off-by: Manjusaka --- .../2025-04-22-19-00-03.gh-issue-131591.CdEqBr.rst | 1 + Modules/posixmodule.c | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-04-22-19-00-03.gh-issue-131591.CdEqBr.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-04-22-19-00-03.gh-issue-131591.CdEqBr.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-04-22-19-00-03.gh-issue-131591.CdEqBr.rst new file mode 100644 index 00000000000000..041676170cd362 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-04-22-19-00-03.gh-issue-131591.CdEqBr.rst @@ -0,0 +1 @@ +Reset ``_PyRemoteDebuggerSupport`` after os.fork diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b7300def8dc75f..c2d5098d72ec93 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -677,6 +677,14 @@ PyOS_AfterFork_Parent(void) run_at_forkers(interp->after_forkers_parent, 0); } +void +PyRemoteDebugCall_Reset(PyThreadState *tstate) +{ + tstate->remote_debugger_support.debugger_pending_call = 0; + memset(tstate->remote_debugger_support.debugger_script_path, 0, MAX_SCRIPT_PATH_SIZE); +} + + void PyOS_AfterFork_Child(void) { @@ -710,6 +718,8 @@ PyOS_AfterFork_Child(void) goto fatal_error; } + PyRemoteDebugCall_Reset(tstate); + // Remove the dead thread states. We "start the world" once we are the only // thread state left to undo the stop the world call in `PyOS_BeforeFork`. // That needs to happen before `_PyThreadState_DeleteList`, because that From 4b7b1d360bbde6a57ff9ba9344f9f672913f80f2 Mon Sep 17 00:00:00 2001 From: Nadeshiko Manju Date: Thu, 24 Apr 2025 20:27:38 +0800 Subject: [PATCH 2/4] Update Misc/NEWS.d/next/Core_and_Builtins/2025-04-22-19-00-03.gh-issue-131591.CdEqBr.rst Co-authored-by: Pablo Galindo Salgado --- .../2025-04-22-19-00-03.gh-issue-131591.CdEqBr.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-04-22-19-00-03.gh-issue-131591.CdEqBr.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-04-22-19-00-03.gh-issue-131591.CdEqBr.rst index 041676170cd362..e237649e59207e 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2025-04-22-19-00-03.gh-issue-131591.CdEqBr.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-04-22-19-00-03.gh-issue-131591.CdEqBr.rst @@ -1 +1 @@ -Reset ``_PyRemoteDebuggerSupport`` after os.fork +Reset any :pep:`768` remote debugging pending call in children after :func:`os.fork` calls. From ba098017382496d7f6575eb739ddf842d2e6f89d Mon Sep 17 00:00:00 2001 From: Nadeshiko Manju Date: Thu, 24 Apr 2025 20:27:45 +0800 Subject: [PATCH 3/4] Update Modules/posixmodule.c Co-authored-by: Pablo Galindo Salgado --- Modules/posixmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index c2d5098d72ec93..6ff01634a1b0bc 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -677,7 +677,7 @@ PyOS_AfterFork_Parent(void) run_at_forkers(interp->after_forkers_parent, 0); } -void +static void PyRemoteDebugCall_Reset(PyThreadState *tstate) { tstate->remote_debugger_support.debugger_pending_call = 0; From 16f3f248f4aa50402521e275b3857efc8fe53708 Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Thu, 24 Apr 2025 20:30:59 +0800 Subject: [PATCH 4/4] fix review idea Signed-off-by: Manjusaka --- Modules/posixmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 6ff01634a1b0bc..8d7131b2eacf95 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -678,7 +678,7 @@ PyOS_AfterFork_Parent(void) } static void -PyRemoteDebugCall_Reset(PyThreadState *tstate) +reset_remotedebug_data(PyThreadState *tstate) { tstate->remote_debugger_support.debugger_pending_call = 0; memset(tstate->remote_debugger_support.debugger_script_path, 0, MAX_SCRIPT_PATH_SIZE); @@ -718,7 +718,7 @@ PyOS_AfterFork_Child(void) goto fatal_error; } - PyRemoteDebugCall_Reset(tstate); + reset_remotedebug_data(tstate); // Remove the dead thread states. We "start the world" once we are the only // thread state left to undo the stop the world call in `PyOS_BeforeFork`.