From 0385fb46c90ed61d7f075290ecbc56576cfa81b5 Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Sat, 7 Jul 2018 09:33:14 -0700 Subject: [PATCH] Simple fixes Commit migrated from https://github.com/dotnet/coreclr/commit/eba995ab407dea951c933e8804b4982215575c1b --- src/coreclr/src/debug/ee/controller.cpp | 10 ---------- src/coreclr/src/debug/ee/debugger.h | 22 ++++++++++------------ src/coreclr/src/debug/ee/rcthread.cpp | 7 +++---- src/coreclr/src/vm/threadsuspend.h | 17 +++++++++++++++++ 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/coreclr/src/debug/ee/controller.cpp b/src/coreclr/src/debug/ee/controller.cpp index c4b2927..8018d76 100644 --- a/src/coreclr/src/debug/ee/controller.cpp +++ b/src/coreclr/src/debug/ee/controller.cpp @@ -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(); diff --git a/src/coreclr/src/debug/ee/debugger.h b/src/coreclr/src/debug/ee/debugger.h index a342c7a..098ac0b 100644 --- a/src/coreclr/src/debug/ee/debugger.h +++ b/src/coreclr/src/debug/ee/debugger.h @@ -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(); \ } diff --git a/src/coreclr/src/debug/ee/rcthread.cpp b/src/coreclr/src/debug/ee/rcthread.cpp index 00a2fdc..95d00f7 100644 --- a/src/coreclr/src/debug/ee/rcthread.cpp +++ b/src/coreclr/src/debug/ee/rcthread.cpp @@ -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) { diff --git a/src/coreclr/src/vm/threadsuspend.h b/src/coreclr/src/vm/threadsuspend.h index 022e46a..bd322fc6 100644 --- a/src/coreclr/src/vm/threadsuspend.h +++ b/src/coreclr/src/vm/threadsuspend.h @@ -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_ -- 2.7.4