From: Konstantin Baladurin Date: Thu, 9 Aug 2018 16:25:30 +0000 (+0300) Subject: Suppress calling finalizer for incomplete object X-Git-Tag: submit/trunk/20180813.025323~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=44ca457161945982c2a9d9bd5ec945cdccc2e09f;p=sdk%2Ftools%2Fnetcoredbg.git Suppress calling finalizer for incomplete object Finalize shouldn't be called for objects that aren't initialized by ctor. --- diff --git a/src/debug/netcoredbg/expr.cpp b/src/debug/netcoredbg/expr.cpp index 52c0422..4788544 100644 --- a/src/debug/netcoredbg/expr.cpp +++ b/src/debug/netcoredbg/expr.cpp @@ -144,7 +144,7 @@ static HRESULT GetMethodToken(IMetaDataImport *pMD, mdTypeDef cl, const WCHAR *m return methodDef; } -static HRESULT FindFunction(ICorDebugModule *pModule, +HRESULT Evaluator::FindFunction(ICorDebugModule *pModule, const WCHAR *typeName, const WCHAR *methodName, ICorDebugFunction **ppFunction) diff --git a/src/debug/netcoredbg/manageddebugger.h b/src/debug/netcoredbg/manageddebugger.h index 68895e6..e1b0610 100644 --- a/src/debug/netcoredbg/manageddebugger.h +++ b/src/debug/netcoredbg/manageddebugger.h @@ -34,6 +34,7 @@ private: ToRelease m_pRunClassConstructor; ToRelease m_pGetTypeHandle; + ToRelease m_pSuppressFinalize; std::mutex m_evalMutex; std::unordered_map< DWORD, std::promise< std::unique_ptr> > > m_evalResults; @@ -64,7 +65,8 @@ private: HRESULT EvalObjectNoConstructor( ICorDebugThread *pThread, ICorDebugType *pType, - ICorDebugValue **ppEvalResult); + ICorDebugValue **ppEvalResult, + bool suppressFinalize = true); std::future< std::unique_ptr> > RunEval( ICorDebugThread *pThread, @@ -113,6 +115,13 @@ private: ICorDebugThread *pThread, std::vector< ToRelease > &types); + + static HRESULT FindFunction( + ICorDebugModule *pModule, + const WCHAR *typeName, + const WCHAR *methodName, + ICorDebugFunction **ppFunction); + public: Evaluator(Modules &modules) : m_modules(modules) {} diff --git a/src/debug/netcoredbg/valuewalk.cpp b/src/debug/netcoredbg/valuewalk.cpp index f88ccf6..cd96322 100644 --- a/src/debug/netcoredbg/valuewalk.cpp +++ b/src/debug/netcoredbg/valuewalk.cpp @@ -82,6 +82,9 @@ HRESULT Evaluator::WaitEvalResult(ICorDebugThread *pThread, try { auto evalResult = RunEval(pThread, pEval).get(); + if (!ppEvalResult) + return S_OK; + if (!evalResult->GetPtr()) return E_FAIL; *ppEvalResult = evalResult->Detach(); @@ -139,7 +142,8 @@ HRESULT Evaluator::EvalFunction( HRESULT Evaluator::EvalObjectNoConstructor( ICorDebugThread *pThread, ICorDebugType *pType, - ICorDebugValue **ppEvalResult) + ICorDebugValue **ppEvalResult, + bool suppressFinalize) { HRESULT Status = S_OK; @@ -172,7 +176,27 @@ HRESULT Evaluator::EvalObjectNoConstructor( (ICorDebugType **)typeParams.data() )); - return WaitEvalResult(pThread, pEval, ppEvalResult); + IfFailRet(WaitEvalResult(pThread, pEval, ppEvalResult)); + + if (suppressFinalize) + { + if (!m_pSuppressFinalize) + { + ToRelease pModule; + IfFailRet(m_modules.GetModuleWithName("System.Private.CoreLib.dll", &pModule)); + + static const WCHAR gcName[] = W("System.GC"); + static const WCHAR suppressFinalizeMethodName[] = W("SuppressFinalize"); + IfFailRet(FindFunction(pModule, gcName, suppressFinalizeMethodName, &m_pSuppressFinalize)); + } + + if (!m_pSuppressFinalize) + return E_FAIL; + + IfFailRet(EvalFunction(pThread, m_pSuppressFinalize, nullptr, *ppEvalResult, nullptr /* void method */)); + } + + return S_OK; } static HRESULT FindMethod(ICorDebugType *pType, WCHAR *methodName, ICorDebugFunction **ppFunc)