Simple fixes
authorAndrew Au <andrewau@microsoft.com>
Sat, 7 Jul 2018 16:33:14 +0000 (09:33 -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/eba995ab407dea951c933e8804b4982215575c1b

src/coreclr/src/debug/ee/controller.cpp
src/coreclr/src/debug/ee/debugger.h
src/coreclr/src/debug/ee/rcthread.cpp
src/coreclr/src/vm/threadsuspend.h

index c4b2927..8018d76 100644 (file)
@@ -3017,16 +3017,6 @@ DPOSS_ACTION DebuggerController::DispatchPatchOrSingleStep(Thread *thread, CONTE
         reabort = thread->m_StateNC & Thread::TSNC_DebuggerReAbort;
         SENDIPCEVENT_END;
 
-        // CONTEXT c;
-        // c.ContextFlags = CONTEXT_DEBUG_REGISTERS;
-        // thread->GetThreadContext(&c);
-
-        // context->Dr7 = c.Dr7;
-        // context->Dr0 = c.Dr0;
-        // context->Dr1 = c.Dr1;
-        // context->Dr2 = c.Dr2;
-        // context->Dr3 = c.Dr3;
-
         if (!atSafePlace)
             g_pDebugger->DecThreadsAtUnsafePlaces();
 
index a342c7a..098ac0b 100644 (file)
@@ -2956,8 +2956,8 @@ public:
 #ifndef DACCESS_COMPILE
     virtual void BeforeGarbageCollection();
     virtual void AfterGarbageCollection();
-    BOOL m_isBlockedOnGarbageCollectionEvent;
 #endif
+    BOOL m_isBlockedOnGarbageCollectionEvent;
 private:
     HANDLE GetGarbageCollectionBlockerEvent() { return  GetLazyData()->m_garbageCollectionBlockerEvent; }
 
@@ -3795,16 +3795,15 @@ HANDLE OpenWin32EventOrThrow(
     LPCWSTR lpName
 );
 
-#define SENDIPCEVENT_RAW_BEGIN_EX(pDbgLockHolder, gcxStmt)               \
-  {                                                                      \
-    ThreadSuspend::LockThreadStore(ThreadSuspend::SUSPEND_FOR_DEBUGGER); \
-    Debugger::DebuggerLockHolder *__pDbgLockHolder = pDbgLockHolder;     \
-    gcxStmt;                                                             \
+#define SENDIPCEVENT_RAW_BEGIN_EX(pDbgLockHolder, gcxStmt)                            \
+  {                                                                                   \
+    ThreadStoreLockHolderWithSuspendReason tsld(ThreadSuspend::SUSPEND_FOR_DEBUGGER); \
+    Debugger::DebuggerLockHolder *__pDbgLockHolder = pDbgLockHolder;                  \
+    gcxStmt;                                                                          \
     g_pDebugger->LockForEventSending(__pDbgLockHolder);
 
-#define SENDIPCEVENT_RAW_END_EX                                          \
-    g_pDebugger->UnlockFromEventSending(__pDbgLockHolder);               \
-    ThreadStore::UnlockThreadStore();                                    \
+#define SENDIPCEVENT_RAW_END_EX                                                       \
+    g_pDebugger->UnlockFromEventSending(__pDbgLockHolder);                            \
   }
 
 #define SENDIPCEVENT_RAW_BEGIN(pDbgLockHolder)                  \
@@ -3829,7 +3828,7 @@ HANDLE OpenWin32EventOrThrow(
         Debugger::DebuggerLockHolder __dbgLockHolder(pDebugger, FALSE);                   \
         Debugger::DebuggerLockHolder *__pDbgLockHolder = &__dbgLockHolder;                \
         gcxStmt;                                                                          \
-        ThreadSuspend::LockThreadStore(ThreadSuspend::SUSPEND_FOR_DEBUGGER);              \
+        ThreadStoreLockHolderWithSuspendReason tsld(ThreadSuspend::SUSPEND_FOR_DEBUGGER); \
         g_pDebugger->LockForEventSending(__pDbgLockHolder);                               \
         /* Check if the thread has been suspended by the debugger via SetDebugState(). */ \
         if (thread != NULL && thread->HasThreadStateNC(Thread::TSNC_DebuggerUserSuspend)) \
@@ -3844,8 +3843,7 @@ HANDLE OpenWin32EventOrThrow(
             ;                                                   \
         }                                                       \
         g_pDebugger->UnlockFromEventSending(__pDbgLockHolder);  \
-        ThreadStore::UnlockThreadStore();                       \
-      } /* ~gcxStmt & ~DebuggerLockHolder */                    \
+      } /* ~gcxStmt & ~DebuggerLockHolder & ~tsld */            \
     } while (__fRetry);                                         \
     FireEtwDebugIPCEventEnd();                                  \
   }
index 00a2fdc..95d00f7 100644 (file)
@@ -1249,7 +1249,7 @@ void DebuggerRCThread::MainLoop()
         {
             LOG((LF_CORDB, LL_INFO1000, "DRCT::ML:: straggler event set.\n"));
             
-            ThreadStore::LockThreadStore();
+            ThreadStoreLockHolder tsl;
             Debugger::DebuggerLockHolder debugLockHolder(m_debugger);
             // Make sure that we're still synchronizing...
             if (m_debugger->IsSynchronizing())
@@ -1260,17 +1260,16 @@ void DebuggerRCThread::MainLoop()
 
                 //
                 // Skip waiting the first time and just give it a go.  Note: Implicit
-                // release of the lock, because we are leaving its scope.
+                // release of the debugger and thread store lock, because we are leaving its scope.
                 //
-                ThreadStore::UnlockThreadStore();
                 goto LWaitTimedOut;
             }
 #ifdef LOGGING
             else
                 LOG((LF_CORDB, LL_INFO1000, "DRCT::ML:: told to wait, but not syncing anymore.\n"));
 #endif
-            ThreadStore::UnlockThreadStore();
             // dbgLockHolder goes out of scope - implicit Release
+            // tsl goes out of scope - implicit Release
          }
         else if (dwWaitResult == WAIT_TIMEOUT)
         {
index 022e46a..bd322fc 100644 (file)
@@ -263,4 +263,21 @@ private:
     static LONG m_DebugWillSyncCount;
 };
 
+// void(*)(BOOL,ThreadSuspend::SUSPEND_REASON)
+
+class ThreadStoreLockHolderWithSuspendReason
+{
+public:
+    ThreadStoreLockHolderWithSuspendReason(ThreadSuspend::SUSPEND_REASON reason)
+    {
+        ThreadSuspend::LockThreadStore(reason);
+    }
+    ~ThreadStoreLockHolderWithSuspendReason()
+    {
+        ThreadSuspend::UnlockThreadStore();
+    }
+private:
+    ThreadSuspend::SUSPEND_REASON m_reason;
+};
+
 #endif // _THREAD_SUSPEND_H_