Make the write barrier unwinding fix works for coreclr release build
authorAndrew Au <andrewau@microsoft.com>
Wed, 10 Oct 2018 17:16:29 +0000 (10:16 -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/e6ab42f2d7183b2839e00917ca42227de281a9b2

src/coreclr/src/debug/ee/CMakeLists.txt
src/coreclr/src/debug/ee/controller.cpp
src/coreclr/src/debug/ee/controller.h

index 11a6702..91ecbee 100644 (file)
@@ -2,6 +2,16 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 add_definitions(-DFEATURE_NO_HOST)
 
+if(CMAKE_CONFIGURATION_TYPES) # multi-configuration generator?
+  foreach (Config DEBUG CHECKED)
+    set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:${Config}>:WRITE_BARRIER_CHECK=1>)
+  endforeach (Config)
+else()
+  if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED)
+    add_definitions(-DWRITE_BARRIER_CHECK=1)
+  endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED)
+endif(CMAKE_CONFIGURATION_TYPES)
+
 include_directories(BEFORE ${VM_DIR})
 include_directories(BEFORE ${VM_DIR}/${ARCH_SOURCES_DIR})
 include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR})
index 60d634a..ffb7729 100644 (file)
@@ -946,8 +946,10 @@ HRESULT DebuggerController::Initialize()
 
 bool DebuggerController::s_fUnwoundWriteBarrier = false;
 DWORD DebuggerController::s_eipBeforeUnwoundWriteBarrier = 0;
+#ifdef WRITE_BARRIER_CHECK
 DWORD DebuggerController::s_ecxBeforeUnwoundWriteBarrier = 0;
 DWORD DebuggerController::s_ebpBeforeUnwoundWriteBarrier = 0;
+#endif
 
 DebuggerController::DebuggerController(Thread * pThread, AppDomain * pAppDomain)
   : m_pAppDomain(pAppDomain), 
@@ -2735,15 +2737,18 @@ DPOSS_ACTION DebuggerController::ScanForTriggers(CORDB_ADDRESS_TYPE *address,
         tpr != TPR_TRIGGER_ONLY_THIS && 
         DebuggerDataBreakpoint::TriggerDataBreakpoint(thread, context))
     {
-        if (1) /* FIXME : IP range check is required */
+        PCODE ip = GetIP(context);
+        if (((ip >= (PCODE) JIT_WriteBarrierGroup) && (ip <= (PCODE) JIT_WriteBarrierGroup_End)) || ((ip >= (PCODE) JIT_PatchedWriteBarrierGroup) && (ip <= (PCODE) JIT_PatchedWriteBarrierGroup_End)))
         {
             // TODO: Comment on the JIT helper as well
             DWORD* esp = (DWORD*)context->Esp;
             DebuggerController::s_eipBeforeUnwoundWriteBarrier = context->Eip;
+#ifdef WRITE_BARRIER_CHECK
             DebuggerController::s_ebpBeforeUnwoundWriteBarrier = context->Ebp;
             DebuggerController::s_ecxBeforeUnwoundWriteBarrier = context->Ecx;
             context->Ebp = *esp; esp++;
             context->Ecx = *esp; esp++;
+#endif
             context->Eip = *esp; esp++;
             context->Esp = (DWORD)esp;
 
@@ -3041,8 +3046,10 @@ DPOSS_ACTION DebuggerController::DispatchPatchOrSingleStep(Thread *thread, CONTE
         {
             DWORD* esp = (DWORD*)context->Esp;
             context->Eip = DebuggerController::s_eipBeforeUnwoundWriteBarrier; esp--;
+#ifdef WRITE_BARRIER_CHECK
             context->Ecx = DebuggerController::s_ecxBeforeUnwoundWriteBarrier; esp--;
             context->Ebp = DebuggerController::s_ebpBeforeUnwoundWriteBarrier; esp--;
+#endif
             context->Esp = (DWORD)esp;
             DebuggerController::s_fUnwoundWriteBarrier = false;
         }
index 8cc242f..f58b2a3 100644 (file)
@@ -1416,8 +1416,10 @@ private:
 
     static bool         s_fUnwoundWriteBarrier;
     static DWORD        s_eipBeforeUnwoundWriteBarrier;
+#ifdef WRITE_BARRIER_CHECK
     static DWORD        s_ecxBeforeUnwoundWriteBarrier;
     static DWORD        s_ebpBeforeUnwoundWriteBarrier;
+#endif
 
 #endif // !DACCESS_COMPILE