Turn GarbageCollection events off by default and allow VS turning them on
authorAndrew Au <andrewau@microsoft.com>
Tue, 7 Aug 2018 23:55:21 +0000 (16:55 -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/4143a9c607a387d16ffa724e37596501bb7e22f2

src/coreclr/src/debug/daccess/dacdbiimpl.cpp
src/coreclr/src/debug/daccess/dacdbiimpl.h
src/coreclr/src/debug/di/process.cpp
src/coreclr/src/debug/di/rspriv.h
src/coreclr/src/debug/ee/debugger.cpp
src/coreclr/src/debug/ee/debugger.h
src/coreclr/src/debug/inc/dacdbiinterface.h
src/coreclr/src/inc/cordebug.idl
src/coreclr/src/pal/prebuilt/inc/cordebug.h

index b00917c..988f673 100644 (file)
@@ -7259,6 +7259,22 @@ HRESULT DacDbiInterfaceImpl::GetMDStructuresVersion(ULONG32* pMDStructuresVersio
     return S_OK;
 }
 
+HRESULT DacDbiInterfaceImpl::EnableGCNotificationEvents(BOOL fEnable)
+{
+    DD_ENTER_MAY_THROW
+
+    HRESULT hr = S_OK;
+    EX_TRY
+    {
+        if (g_pDebugger != NULL)
+        {
+            TADDR addr = PTR_HOST_MEMBER_TADDR(Debugger, g_pDebugger, m_isGarbageCollectionEventsEnabled);
+            SafeWriteStructOrThrow<BOOL>(addr, &fEnable);
+        }
+    }
+    EX_CATCH_HRESULT(hr);
+    return hr;
+}
 
 DacRefWalker::DacRefWalker(ClrDataAccess *dac, BOOL walkStacks, BOOL walkFQ, UINT32 handleMask)
     : mDac(dac), mWalkStacks(walkStacks), mWalkFQ(walkFQ), mHandleMask(handleMask), mStackWalker(NULL),
index 6655800..403fa7f 100644 (file)
@@ -156,6 +156,7 @@ public:
     HRESULT GetILCodeVersionNodeData(VMPTR_ILCodeVersionNode vmILCodeVersionNode, DacSharedReJitInfo* pData);
     HRESULT GetDefinesBitField(ULONG32 *pDefines);
     HRESULT GetMDStructuresVersion(ULONG32* pMDStructuresVersion);
+    HRESULT EnableGCNotificationEvents(BOOL fEnable);
 
 private:
     void TypeHandleToExpandedTypeInfoImpl(AreValueTypesBoxed              boxed,
index 99e5aa4..1411857 100644 (file)
@@ -2557,6 +2557,11 @@ COM_METHOD CordbProcess::GetContainingObject(CORDB_ADDRESS interiorPointer, ICor
     return hr;
 }
 
+COM_METHOD CordbProcess::EnableGCNotificationEvents(BOOL fEnable)
+{
+    return this->m_pDacPrimitives->EnableGCNotificationEvents(fEnable);
+}
+
 #ifdef FEATURE_LEGACYNETCF_DBG_HOST_CONTROL
 
 COM_METHOD CordbProcess::InvokePauseCallback()
index d0a10be..4cccb4c 100644 (file)
@@ -3139,6 +3139,7 @@ public:
     // ICorDebugProcess10
     //-----------------------------------------------------------
     COM_METHOD GetContainingObject(CORDB_ADDRESS interiorPointer, ICorDebugObjectValue** ppContainingObject);
+    COM_METHOD EnableGCNotificationEvents(BOOL fEnable);
 
 #ifdef FEATURE_LEGACYNETCF_DBG_HOST_CONTROL
     // ---------------------------------------------------------------
index e8134a4..a6ba5ce 100644 (file)
@@ -952,7 +952,8 @@ Debugger::Debugger()
     m_forceNonInterceptable(FALSE),
     m_pLazyData(NULL),
     m_defines(_defines),
-    m_isBlockedOnGarbageCollectionEvent(FALSE)
+    m_isBlockedOnGarbageCollectionEvent(FALSE),
+    m_isGarbageCollectionEventsEnabled(FALSE)
 {
     CONTRACTL
     {
@@ -6008,7 +6009,7 @@ void Debugger::BeforeGarbageCollection()
     }
     CONTRACTL_END;
 
-    if (!CORDebuggerAttached())
+    if (!CORDebuggerAttached() || !this->m_isGarbageCollectionEventsEnabled)
     {
         return;
     }
@@ -6046,7 +6047,7 @@ void Debugger::AfterGarbageCollection()
     }
     CONTRACTL_END;
 
-    if (!CORDebuggerAttached())
+    if (!CORDebuggerAttached() || !this->m_isGarbageCollectionEventsEnabled)
     {
         return;
     }
index a07531b..381cb57 100644 (file)
@@ -2958,6 +2958,7 @@ public:
     virtual void AfterGarbageCollection();
 #endif
     BOOL m_isBlockedOnGarbageCollectionEvent;
+    BOOL m_isGarbageCollectionEventsEnabled;
 private:
     HANDLE GetGarbageCollectionBlockerEvent() { return  GetLazyData()->m_garbageCollectionBlockerEvent; }
 
index 7295884..abbe7d9 100644 (file)
@@ -2696,6 +2696,10 @@ public:
     virtual
         HRESULT GetILCodeVersionNodeData(VMPTR_ILCodeVersionNode ilCodeVersionNode, DacSharedReJitInfo* pData) = 0;
 
+    // TODO, andrewau, documentation
+    virtual
+        HRESULT EnableGCNotificationEvents(BOOL fEnable) = 0;
+
     // The following tag tells the DD-marshalling tool to stop scanning.
     // END_MARSHAL
     
index 63adbb7..32ec503 100644 (file)
@@ -3271,6 +3271,7 @@ interface ICorDebugProcess8 : IUnknown
 interface ICorDebugProcess10 : IUnknown
 {
     HRESULT GetContainingObject([in] CORDB_ADDRESS interiorPointer, [out] ICorDebugObjectValue** ppContainingObject);
+    HRESULT EnableGCNotificationEvents(BOOL fEnable);
 }
 
 // Event types MODULE_LOADED and MODULE_UNLOADED implement this interface
index 9eccc51..59375ba 100644 (file)
@@ -6,7 +6,7 @@
  /* File created by MIDL compiler version 8.01.0622 */
 /* at Mon Jan 18 19:14:07 2038
  */
-/* Compiler settings for C:/Dev/CoreCLR/src/inc/cordebug.idl:
+/* Compiler settings for F:/Dev/coreclr/src/inc/cordebug.idl:
     Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 8.01.0622 
     protocol : dce , ms_ext, c_ext, robust
     error checks: allocation ref bounds_check enum stub_data 
@@ -7842,6 +7842,9 @@ EXTERN_C const IID IID_ICorDebugProcess10;
             /* [in] */ CORDB_ADDRESS interiorPointer,
             /* [out] */ ICorDebugObjectValue **ppContainingObject) = 0;
         
+        virtual HRESULT STDMETHODCALLTYPE EnableGCNotificationEvents( 
+            BOOL fEnable) = 0;
+        
     };
     
     
@@ -7868,6 +7871,10 @@ EXTERN_C const IID IID_ICorDebugProcess10;
             /* [in] */ CORDB_ADDRESS interiorPointer,
             /* [out] */ ICorDebugObjectValue **ppContainingObject);
         
+        HRESULT ( STDMETHODCALLTYPE *EnableGCNotificationEvents )( 
+            ICorDebugProcess10 * This,
+            BOOL fEnable);
+        
         END_INTERFACE
     } ICorDebugProcess10Vtbl;
 
@@ -7894,6 +7901,9 @@ EXTERN_C const IID IID_ICorDebugProcess10;
 #define ICorDebugProcess10_GetContainingObject(This,interiorPointer,ppContainingObject)        \
     ( (This)->lpVtbl -> GetContainingObject(This,interiorPointer,ppContainingObject) ) 
 
+#define ICorDebugProcess10_EnableGCNotificationEvents(This,fEnable)    \
+    ( (This)->lpVtbl -> EnableGCNotificationEvents(This,fEnable) ) 
+
 #endif /* COBJMACROS */