Fixing the deadlocks
authorAndrew Au <andrewau@microsoft.com>
Mon, 6 Aug 2018 22:04:37 +0000 (15:04 -0700)
committerAndrew Au <cshung@gmail.com>
Wed, 7 Nov 2018 02:34:47 +0000 (18:34 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/e467645dbefa58e144a42c3b742cee859b68d55d

src/coreclr/src/debug/ee/debugger.cpp
src/coreclr/src/debug/ee/debugger.h
src/coreclr/src/vm/dbginterface.h
src/coreclr/src/vm/threadsuspend.cpp

index b9decbc..e8134a4 100644 (file)
@@ -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());
             }
index 7e0134d..a07531b 100644 (file)
@@ -2218,7 +2218,7 @@ public:
                             unsigned int errorLine,
                             bool exitThread);
 
-    BOOL IsSynchronizing(void)
+    virtual BOOL IsSynchronizing(void)
     {
         LIMITED_METHOD_CONTRACT;
 
index a855a10..d0be137 100644 (file)
@@ -412,6 +412,7 @@ public:
     virtual void BeforeGarbageCollection() = 0;
     virtual void AfterGarbageCollection() = 0;
 #endif
+    virtual BOOL IsSynchronizing() = 0;
 };
 
 #ifndef DACCESS_COMPILE
index 822c396..1902d82 100644 (file)
@@ -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
             )
         {