Refactor EvalProperty() -> EvalFunction()
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Thu, 20 Jul 2017 01:08:40 +0000 (04:08 +0300)
committerIgor Kulaychuk <i.kulaychuk@samsung.com>
Mon, 13 Nov 2017 19:22:40 +0000 (22:22 +0300)
src/debug/netcoredbg/valuewalk.cpp
src/debug/netcoredbg/varobj.cpp

index da9b817..0d66f2f 100644 (file)
@@ -43,13 +43,24 @@ void NotifyEvalComplete()
     g_evalCV.notify_one();
 }
 
-HRESULT EvalProperty(
+static HRESULT WaitEvalResult(ICorDebugProcess *pProcess,
+                              ICorDebugEval *pEval,
+                              ICorDebugValue **ppEvalResult)
+{
+    HRESULT Status;
+    std::unique_lock<std::mutex> lock(g_evalMutex);
+    g_evalComplete = false;
+    IfFailRet(pProcess->Continue(0));
+    g_evalCV.wait(lock, []{return g_evalComplete;});
+
+    return pEval->GetResult(ppEvalResult);
+}
+
+HRESULT EvalFunction(
     ICorDebugThread *pThread,
-    mdMethodDef methodDef,
-    ICorDebugModule *pModule,
-    ICorDebugType *pType,
-    ICorDebugValue *pInputValue,
-    bool is_static,
+    ICorDebugFunction *pFunc,
+    ICorDebugType *pType, // may be nullptr
+    ICorDebugValue *pArgValue, // may be nullptr
     ICorDebugValue **ppEvalResult)
 {
     HRESULT Status = S_OK;
@@ -60,22 +71,21 @@ HRESULT EvalProperty(
     IfFailRet(pThread->GetProcess(&pProcess));
     IfFailRet(pThread->CreateEval(&pEval));
 
-    ToRelease<ICorDebugFunction> pFunc;
-    IfFailRet(pModule->GetFunctionFromToken(methodDef, &pFunc));
-
-    ToRelease<ICorDebugTypeEnum> pTypeEnum;
-
     std::vector< ToRelease<ICorDebugType> > typeParams;
-    if(SUCCEEDED(pType->EnumerateTypeParameters(&pTypeEnum)))
+
+    if (pType)
     {
-        ICorDebugType *curType;
-        ULONG fetched = 0;
-        while(SUCCEEDED(pTypeEnum->Next(1, &curType, &fetched)) && fetched == 1)
+        ToRelease<ICorDebugTypeEnum> pTypeEnum;
+        if(SUCCEEDED(pType->EnumerateTypeParameters(&pTypeEnum)))
         {
-            typeParams.emplace_back(curType);
+            ICorDebugType *curType;
+            ULONG fetched = 0;
+            while(SUCCEEDED(pTypeEnum->Next(1, &curType, &fetched)) && fetched == 1)
+            {
+                typeParams.emplace_back(curType);
+            }
         }
     }
-
     ToRelease<ICorDebugEval2> pEval2;
     IfFailRet(pEval->QueryInterface(IID_ICorDebugEval2, (LPVOID*) &pEval2));
 
@@ -83,16 +93,11 @@ HRESULT EvalProperty(
         pFunc,
         typeParams.size(),
         (ICorDebugType **)typeParams.data(),
-        is_static ? 0 : 1,
-        is_static ? NULL : &pInputValue
+        pArgValue ? 1 : 0,
+        pArgValue ? &pArgValue : nullptr
     ));
 
-    std::unique_lock<std::mutex> lock(g_evalMutex);
-    g_evalComplete = false;
-    IfFailRet(pProcess->Continue(0));
-    g_evalCV.wait(lock, []{return g_evalComplete;});
-
-    return pEval->GetResult(ppEvalResult);
+    return WaitEvalResult(pProcess, pEval, ppEvalResult);
 }
 
 static void IncIndicies(std::vector<ULONG32> &ind, const std::vector<ULONG32> &dims)
index 7898a7e..ae5683e 100644 (file)
@@ -17,13 +17,11 @@ typedef std::function<HRESULT(mdMethodDef,ICorDebugModule*,ICorDebugType*,ICorDe
 typedef std::function<HRESULT(ICorDebugILFrame*,ICorDebugValue*,const std::string&)> WalkStackVarsCallback;
 HRESULT WalkMembers(ICorDebugValue *pValue, ICorDebugILFrame *pILFrame, WalkMembersCallback cb);
 HRESULT WalkStackVars(ICorDebugFrame *pFrame, WalkStackVarsCallback cb);
-HRESULT EvalProperty(
+HRESULT EvalFunction(
     ICorDebugThread *pThread,
-    mdMethodDef methodDef,
-    ICorDebugModule *pModule,
-    ICorDebugType *pType,
-    ICorDebugValue *pInputValue,
-    bool is_static,
+    ICorDebugFunction *pFunc,
+    ICorDebugType *pType, // may be nullptr
+    ICorDebugValue *pArgValue, // may be nullptr
     ICorDebugValue **ppEvalResult);
 
 // Valueprint
@@ -165,7 +163,9 @@ static HRESULT FetchFieldsAndProperties(ICorDebugValue *pInputValue,
 
         if (mdGetter != mdMethodDefNil)
         {
-            EvalProperty(pThread, mdGetter, pModule, pType, pInputValue, is_static, &pResultValue);
+            ToRelease<ICorDebugFunction> pFunc;
+            if (SUCCEEDED(pModule->GetFunctionFromToken(mdGetter, &pFunc)))
+                EvalFunction(pThread, pFunc, pType, is_static ? nullptr : pInputValue, &pResultValue);
         }
         else
         {