From 23d6092e6da96048b5b7aed616369032354a3b78 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:32:26 -0300 Subject: [PATCH] [release/9.0-staging] [debugger] Fix a step that becomes a go (#110533) * Fixing step becomes a go * Trying to avoid step that becomes a go * Adding comments and more protections. * fixing comment * Checking if removing this comments, CI failures are gone. * Adding part of the changes to understand the failures on CI * Update src/coreclr/debug/ee/controller.cpp Co-authored-by: mikelle-rogers <45022607+mikelle-rogers@users.noreply.github.com> * Fixing wrong fix. --------- Co-authored-by: Thays Grazia Co-authored-by: Thays Grazia Co-authored-by: mikelle-rogers <45022607+mikelle-rogers@users.noreply.github.com> --- src/coreclr/debug/ee/controller.cpp | 10 +++++++++- src/coreclr/vm/threadsuspend.cpp | 12 +++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/coreclr/debug/ee/controller.cpp b/src/coreclr/debug/ee/controller.cpp index fd26e7fe3135d..4e1736c96583a 100644 --- a/src/coreclr/debug/ee/controller.cpp +++ b/src/coreclr/debug/ee/controller.cpp @@ -7410,7 +7410,15 @@ bool DebuggerStepper::TriggerSingleStep(Thread *thread, const BYTE *ip) if (!g_pEEInterface->IsManagedNativeCode(ip)) { LOG((LF_CORDB,LL_INFO10000, "DS::TSS: not in managed code, Returning false (case 0)!\n")); - DisableSingleStep(); + // Sometimes we can get here with a callstack that is coming from an APC + // this will disable the single stepping and incorrectly resume an app that the user + // is stepping through. +#ifdef FEATURE_THREAD_ACTIVATION + if ((thread->m_State & Thread::TS_DebugWillSync) == 0) +#endif + { + DisableSingleStep(); + } return false; } diff --git a/src/coreclr/vm/threadsuspend.cpp b/src/coreclr/vm/threadsuspend.cpp index 71f59672eba1c..2ddc2c3b120c9 100644 --- a/src/coreclr/vm/threadsuspend.cpp +++ b/src/coreclr/vm/threadsuspend.cpp @@ -5746,8 +5746,9 @@ BOOL CheckActivationSafePoint(SIZE_T ip) Thread *pThread = GetThreadNULLOk(); // The criteria for safe activation is to be running managed code. - // Also we are not interested in handling interruption if we are already in preemptive mode. - BOOL isActivationSafePoint = pThread != NULL && + // Also we are not interested in handling interruption if we are already in preemptive mode nor if we are single stepping + BOOL isActivationSafePoint = pThread != NULL && + (pThread->m_StateNC & Thread::TSNC_DebuggerIsStepping) == 0 && pThread->PreemptiveGCDisabled() && ExecutionManager::IsManagedCode(ip); @@ -5932,7 +5933,12 @@ bool Thread::InjectActivation(ActivationReason reason) { return true; } - + // Avoid APC calls when the thread is in single step state to avoid any + // wrong resume because it's running a native code. + if ((m_StateNC & Thread::TSNC_DebuggerIsStepping) != 0) + { + return false; + } #ifdef FEATURE_SPECIAL_USER_MODE_APC _ASSERTE(UseSpecialUserModeApc());