From 2a903e61ff509391506ca09a20abac86f496e470 Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Mon, 6 Aug 2018 15:04:37 -0700 Subject: [PATCH] Fixing the deadlocks Commit migrated from https://github.com/dotnet/coreclr/commit/e467645dbefa58e144a42c3b742cee859b68d55d --- src/coreclr/src/debug/ee/debugger.cpp | 8 +++----- src/coreclr/src/debug/ee/debugger.h | 2 +- src/coreclr/src/vm/dbginterface.h | 1 + src/coreclr/src/vm/threadsuspend.cpp | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/coreclr/src/debug/ee/debugger.cpp b/src/coreclr/src/debug/ee/debugger.cpp index b9decbc..e8134a4 100644 --- a/src/coreclr/src/debug/ee/debugger.cpp +++ b/src/coreclr/src/debug/ee/debugger.cpp @@ -6057,9 +6057,7 @@ void Debugger::AfterGarbageCollection() return; { - Debugger::DebuggerLockHolder dbgLockHolder(this); - - this->m_isBlockedOnGarbageCollectionEvent = true; + Debugger::DebuggerLockHolder dbgLockHolder(this); DebuggerIPCEvent* ipce1 = m_pRCThread->GetIPCEventSendBuffer(); InitIPCEvent(ipce1, @@ -6073,6 +6071,7 @@ void Debugger::AfterGarbageCollection() WaitForSingleObject(this->GetGarbageCollectionBlockerEvent(), INFINITE); ResetEvent(this->GetGarbageCollectionBlockerEvent()); + this->m_isBlockedOnGarbageCollectionEvent = false; } void Debugger::SendDataBreakpoint(Thread *thread, CONTEXT *context, @@ -10817,7 +10816,7 @@ bool Debugger::HandleIPCEvent(DebuggerIPCEvent * pEvent) _ASSERTE(ThreadHoldsLock()); // Simply trap all Runtime threads if we're not already trying to. - if (!m_trappingRuntimeThreads) + if (!m_isBlockedOnGarbageCollectionEvent && !m_trappingRuntimeThreads) { // If the RS sent an Async-break, then that's an explicit request. m_RSRequestedSync = TRUE; @@ -10831,7 +10830,6 @@ bool Debugger::HandleIPCEvent(DebuggerIPCEvent * pEvent) { if (this->m_isBlockedOnGarbageCollectionEvent) { - this->m_isBlockedOnGarbageCollectionEvent = false; this->m_stopped = false; SetEvent(this->GetGarbageCollectionBlockerEvent()); } diff --git a/src/coreclr/src/debug/ee/debugger.h b/src/coreclr/src/debug/ee/debugger.h index 7e0134d..a07531b 100644 --- a/src/coreclr/src/debug/ee/debugger.h +++ b/src/coreclr/src/debug/ee/debugger.h @@ -2218,7 +2218,7 @@ public: unsigned int errorLine, bool exitThread); - BOOL IsSynchronizing(void) + virtual BOOL IsSynchronizing(void) { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/src/vm/dbginterface.h b/src/coreclr/src/vm/dbginterface.h index a855a10..d0be137 100644 --- a/src/coreclr/src/vm/dbginterface.h +++ b/src/coreclr/src/vm/dbginterface.h @@ -412,6 +412,7 @@ public: virtual void BeforeGarbageCollection() = 0; virtual void AfterGarbageCollection() = 0; #endif + virtual BOOL IsSynchronizing() = 0; }; #ifndef DACCESS_COMPILE diff --git a/src/coreclr/src/vm/threadsuspend.cpp b/src/coreclr/src/vm/threadsuspend.cpp index 822c396..1902d82 100644 --- a/src/coreclr/src/vm/threadsuspend.cpp +++ b/src/coreclr/src/vm/threadsuspend.cpp @@ -7108,7 +7108,7 @@ retry_for_debugger: || Thread::ThreadsAtUnsafePlaces() #ifdef DEBUGGING_SUPPORTED // seriously? When would we want to disable debugging support? :) || (CORDebuggerAttached() && - g_pDebugInterface->ThreadsAtUnsafePlaces()) + (g_pDebugInterface->ThreadsAtUnsafePlaces() || g_pDebugInterface->IsSynchronizing())) #endif // DEBUGGING_SUPPORTED ) { -- 2.7.4