Refactor all evaluation related functions into separate Evaluator class
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Wed, 17 Jan 2018 21:58:14 +0000 (00:58 +0300)
committerIgor Kulaychuk <i.kulaychuk@samsung.com>
Wed, 17 Jan 2018 21:58:14 +0000 (00:58 +0300)
src/debug/netcoredbg/debugger.h
src/debug/netcoredbg/expr.cpp
src/debug/netcoredbg/expr.h
src/debug/netcoredbg/main.cpp
src/debug/netcoredbg/valuewalk.cpp
src/debug/netcoredbg/valuewalk.h [deleted file]
src/debug/netcoredbg/variables.cpp

index a0d031d917771822c7156b833ea1eb9816d7b7ec..4f7d4bf19a78796c238ee9d9dcd67f5ff67d2af4 100644 (file)
 #include <unordered_set>
 #include <vector>
 #include <condition_variable>
+#include <future>
 
 class ManagedCallback;
 class Protocol;
 
+struct Member;
+
+enum ValueKind
+{
+    ValueIsScope,
+    ValueIsClass,
+    ValueIsVariable
+};
+
+class Evaluator
+{
+public:
+
+    typedef std::function<HRESULT(mdMethodDef,ICorDebugModule*,ICorDebugType*,ICorDebugValue*,bool,const std::string&)> WalkMembersCallback;
+    typedef std::function<HRESULT(ICorDebugILFrame*,ICorDebugValue*,const std::string&)> WalkStackVarsCallback;
+
+private:
+
+    ToRelease<ICorDebugFunction> m_pRunClassConstructor;
+    ToRelease<ICorDebugFunction> m_pGetTypeHandle;
+
+    std::mutex m_evalMutex;
+    std::unordered_map< DWORD, std::promise< std::unique_ptr<ToRelease<ICorDebugValue>> > > m_evalResults;
+
+    HRESULT FollowNested(ICorDebugThread *pThread,
+                         ICorDebugILFrame *pILFrame,
+                         const std::string &methodClass,
+                         const std::vector<std::string> &parts,
+                         ICorDebugValue **ppResult);
+    HRESULT FollowFields(ICorDebugThread *pThread,
+                         ICorDebugILFrame *pILFrame,
+                         ICorDebugValue *pValue,
+                         ValueKind valueKind,
+                         const std::vector<std::string> &parts,
+                         int nextPart,
+                         ICorDebugValue **ppResult);
+    HRESULT GetFieldOrPropertyWithName(ICorDebugThread *pThread,
+                                       ICorDebugILFrame *pILFrame,
+                                       ICorDebugValue *pInputValue,
+                                       ValueKind valueKind,
+                                       const std::string &name,
+                                       ICorDebugValue **ppResultValue);
+
+    HRESULT WaitEvalResult(ICorDebugThread *pThread,
+                           ICorDebugEval *pEval,
+                           ICorDebugValue **ppEvalResult);
+
+    HRESULT EvalObjectNoConstructor(
+        ICorDebugThread *pThread,
+        ICorDebugType *pType,
+        ICorDebugValue **ppEvalResult);
+
+    std::future< std::unique_ptr<ToRelease<ICorDebugValue>> > RunEval(
+        ICorDebugThread *pThread,
+        ICorDebugEval *pEval);
+
+    HRESULT WalkMembers(
+        ICorDebugValue *pInputValue,
+        ICorDebugThread *pThread,
+        ICorDebugILFrame *pILFrame,
+        ICorDebugType *pTypeCast,
+        WalkMembersCallback cb);
+
+    HRESULT HandleSpecialLocalVar(
+        const std::string &localName,
+        ICorDebugValue *pLocalValue,
+        ICorDebugILFrame *pILFrame,
+        std::unordered_set<std::string> &locals,
+        WalkStackVarsCallback cb);
+
+    HRESULT HandleSpecialThisParam(
+        ICorDebugValue *pThisValue,
+        ICorDebugILFrame *pILFrame,
+        std::unordered_set<std::string> &locals,
+        WalkStackVarsCallback cb);
+
+    HRESULT GetLiteralValue(
+        ICorDebugThread *pThread,
+        ICorDebugType *pType,
+        ICorDebugModule *pModule,
+        PCCOR_SIGNATURE pSignatureBlob,
+        ULONG sigBlobLength,
+        UVCP_CONSTANT pRawValue,
+        ULONG rawValueLength,
+        ICorDebugValue **ppLiteralValue);
+
+public:
+
+    HRESULT RunClassConstructor(ICorDebugThread *pThread, ICorDebugValue *pValue);
+
+    HRESULT EvalFunction(
+        ICorDebugThread *pThread,
+        ICorDebugFunction *pFunc,
+        ICorDebugType *pType, // may be nullptr
+        ICorDebugValue *pArgValue, // may be nullptr
+        ICorDebugValue **ppEvalResult);
+
+    HRESULT EvalExpr(ICorDebugThread *pThread,
+                     ICorDebugFrame *pFrame,
+                     const std::string &expression,
+                     ICorDebugValue **ppResult);
+
+    bool IsEvalRunning();
+
+    // Should be called by ICorDebugManagedCallback
+    void NotifyEvalComplete(ICorDebugThread *pThread, ICorDebugEval *pEval);
+
+    HRESULT ObjectToString(
+        ICorDebugThread *pThread,
+        ICorDebugValue *pValue,
+        std::function<void(const std::string&)> cb
+    );
+
+    HRESULT WalkMembers(
+        ICorDebugValue *pValue,
+        ICorDebugThread *pThread,
+        ICorDebugILFrame *pILFrame,
+        WalkMembersCallback cb);
+
+    HRESULT WalkStackVars(ICorDebugFrame *pFrame, WalkStackVarsCallback cb);
+
+    void Cleanup();
+};
+
 class Debugger
 {
 public:
@@ -22,6 +147,7 @@ public:
 
 private:
     friend class ManagedCallback;
+    Evaluator m_evaluator;
     Protocol *m_protocol;
     ManagedCallback *m_managedCallback;
     ICorDebug *m_pDebug;
@@ -38,13 +164,6 @@ private:
     DWORD m_processId;
     std::string m_clrPath;
 
-    enum ValueKind
-    {
-        ValueIsScope,
-        ValueIsClass,
-        ValueIsVariable
-    };
-
     struct VariableReference
     {
         uint32_t variablesReference; // key
@@ -117,7 +236,7 @@ private:
     void DeleteAllBreakpoints();
 
     HRESULT ResolveBreakpointInModule(ICorDebugModule *pModule, ManagedBreakpoint &bp);
-    HRESULT Debugger::ResolveBreakpoint(ManagedBreakpoint &bp);
+    HRESULT ResolveBreakpoint(ManagedBreakpoint &bp);
 
     HRESULT CheckNoProcess();
 
@@ -131,33 +250,20 @@ private:
     HRESULT GetStackVariables(uint64_t frameId, ICorDebugThread *pThread, ICorDebugFrame *pFrame, int start, int count, std::vector<Variable> &variables);
     HRESULT GetChildren(VariableReference &ref, ICorDebugThread *pThread, ICorDebugFrame *pFrame, int start, int count, std::vector<Variable> &variables);
 
-    HRESULT EvalExpr(ICorDebugThread *pThread,
-                     ICorDebugFrame *pFrame,
-                     const std::string &expression,
-                     ICorDebugValue **ppResult);
-    HRESULT FollowNested(ICorDebugThread *pThread,
-                         ICorDebugILFrame *pILFrame,
-                         const std::string &methodClass,
-                         const std::vector<std::string> &parts,
-                         ICorDebugValue **ppResult);
-    HRESULT FollowFields(ICorDebugThread *pThread,
-                         ICorDebugILFrame *pILFrame,
-                         ICorDebugValue *pValue,
-                         ValueKind valueKind,
-                         const std::vector<std::string> &parts,
-                         int nextPart,
-                         ICorDebugValue **ppResult);
-    HRESULT GetFieldOrPropertyWithName(ICorDebugThread *pThread,
-                                       ICorDebugILFrame *pILFrame,
-                                       ICorDebugValue *pInputValue,
-                                       ValueKind valueKind,
-                                       const std::string &name,
-                                       ICorDebugValue **ppResultValue);
-
-    ToRelease<ICorDebugFunction> m_pRunClassConstructor;
-    ToRelease<ICorDebugFunction> m_pGetTypeHandle;
-    HRESULT RunClassConstructor(ICorDebugThread *pThread, ICorDebugValue *pValue);
-
+    HRESULT FetchFieldsAndProperties(
+        ICorDebugValue *pInputValue,
+        ICorDebugThread *pThread,
+        ICorDebugILFrame *pILFrame,
+        std::vector<Member> &members,
+        bool fetchOnlyStatic,
+        bool &hasStaticMembers,
+        int childStart,
+        int childEnd);
+
+    HRESULT GetNumChild(
+        ICorDebugValue *pValue,
+        unsigned int &numchild,
+        bool static_members = false);
 public:
     Debugger();
     ~Debugger();
index 88e0b805f17bac935ca83e92012d333c1a530e8f..59765df7ff5a05b2b532071e0578fcbbbdad1727 100644 (file)
@@ -17,7 +17,6 @@
 #include "debugger.h"
 #include "typeprinter.h"
 #include "modules.h"
-#include "valuewalk.h"
 #include "valueprint.h"
 #include "expr.h"
 
@@ -52,12 +51,12 @@ static HRESULT ParseIndices(const std::string &s, std::vector<ULONG32> &indices)
     return S_OK;
 }
 
-HRESULT Debugger::GetFieldOrPropertyWithName(ICorDebugThread *pThread,
-                                             ICorDebugILFrame *pILFrame,
-                                             ICorDebugValue *pInputValue,
-                                             ValueKind valueKind,
-                                             const std::string &name,
-                                             ICorDebugValue **ppResultValue)
+HRESULT Evaluator::GetFieldOrPropertyWithName(ICorDebugThread *pThread,
+                                              ICorDebugILFrame *pILFrame,
+                                              ICorDebugValue *pInputValue,
+                                              ValueKind valueKind,
+                                              const std::string &name,
+                                              ICorDebugValue **ppResultValue)
 {
     HRESULT Status;
 
@@ -150,13 +149,13 @@ static mdTypeDef GetTypeTokenForName(IMetaDataImport *pMD, mdTypeDef tkEnclosing
     return typeToken;
 }
 
-HRESULT Debugger::FollowFields(ICorDebugThread *pThread,
-                              ICorDebugILFrame *pILFrame,
-                              ICorDebugValue *pValue,
-                              ValueKind valueKind,
-                              const std::vector<std::string> &parts,
-                              int nextPart,
-                              ICorDebugValue **ppResult)
+HRESULT Evaluator::FollowFields(ICorDebugThread *pThread,
+                                ICorDebugILFrame *pILFrame,
+                                ICorDebugValue *pValue,
+                                ValueKind valueKind,
+                                const std::vector<std::string> &parts,
+                                int nextPart,
+                                ICorDebugValue **ppResult)
 {
     HRESULT Status;
 
@@ -504,11 +503,11 @@ HRESULT FindType(const std::vector<std::string> &parts,
     return S_OK;
 }
 
-HRESULT Debugger::FollowNested(ICorDebugThread *pThread,
-                               ICorDebugILFrame *pILFrame,
-                               const std::string &methodClass,
-                               const std::vector<std::string> &parts,
-                               ICorDebugValue **ppResult)
+HRESULT Evaluator::FollowNested(ICorDebugThread *pThread,
+                                ICorDebugILFrame *pILFrame,
+                                const std::string &methodClass,
+                                const std::vector<std::string> &parts,
+                                ICorDebugValue **ppResult)
 {
     HRESULT Status;
 
@@ -539,10 +538,10 @@ HRESULT Debugger::FollowNested(ICorDebugThread *pThread,
     return E_FAIL;
 }
 
-HRESULT Debugger::EvalExpr(ICorDebugThread *pThread,
-                           ICorDebugFrame *pFrame,
-                           const std::string &expression,
-                           ICorDebugValue **ppResult)
+HRESULT Evaluator::EvalExpr(ICorDebugThread *pThread,
+                            ICorDebugFrame *pFrame,
+                            const std::string &expression,
+                            ICorDebugValue **ppResult)
 {
     HRESULT Status;
 
index 184d1f3c87904184f44e3d1498f3003cac35f819..619f520bad8a899fd8279fb76104cafd8c344efd 100644 (file)
@@ -3,4 +3,3 @@
 // See the LICENSE file in the project root for more information.
 
 HRESULT GetType(const std::string &typeName, ICorDebugThread *pThread, ICorDebugType **ppType);
-HRESULT EvalExpr(ICorDebugThread *pThread, ICorDebugFrame *pFrame, const std::string &expression, ICorDebugValue **ppResult);
index 676ba38ca5b6f5f64a107c5cabbb94dcb4cf321c..29a1f906fcd82f9476d5fff989f9f14d98a5c6b7 100644 (file)
@@ -19,7 +19,6 @@
 #include "typeprinter.h"
 #include "debugger.h"
 #include "modules.h"
-#include "valuewalk.h"
 #include "frames.h"
 
 #define __in
@@ -326,7 +325,7 @@ public:
             /* [in] */ ICorDebugThread *pThread,
             /* [in] */ ICorDebugBreakpoint *pBreakpoint)
         {
-            if (IsEvalRunning())
+            if (m_debugger->m_evaluator.IsEvalRunning())
             {
                 pAppDomain->Continue(0);
                 return S_OK;
@@ -418,7 +417,8 @@ public:
                     m_debugger->m_protocol->EmitStoppedEvent(event);
                 };
 
-                if (FAILED(pThread->GetCurrentException(&pExceptionValue)) || FAILED(ObjectToString(pThread, pExceptionValue, emitFunc)))
+                if (FAILED(pThread->GetCurrentException(&pExceptionValue)) ||
+                    FAILED(m_debugger->m_evaluator.ObjectToString(pThread, pExceptionValue, emitFunc)))
                 {
                     emitFunc(details);
                 }
@@ -440,7 +440,7 @@ public:
             /* [in] */ ICorDebugThread *pThread,
             /* [in] */ ICorDebugEval *pEval)
         {
-            NotifyEvalComplete(pThread, pEval);
+            m_debugger->m_evaluator.NotifyEvalComplete(pThread, pEval);
             return S_OK;
         }
 
@@ -449,7 +449,7 @@ public:
             /* [in] */ ICorDebugThread *pThread,
             /* [in] */ ICorDebugEval *pEval)
         {
-            NotifyEvalComplete(pThread, pEval);
+            m_debugger->m_evaluator.NotifyEvalComplete(pThread, pEval);
             return S_OK;
         }
 
@@ -465,7 +465,7 @@ public:
         virtual HRESULT STDMETHODCALLTYPE ExitProcess(
             /* [in] */ ICorDebugProcess *pProcess)
         {
-            NotifyEvalComplete(nullptr, nullptr);
+            m_debugger->m_evaluator.NotifyEvalComplete(nullptr, nullptr);
             m_debugger->m_protocol->EmitExitedEvent(ExitedEvent(0));
             NotifyProcessExited();
             return S_OK;
@@ -486,7 +486,7 @@ public:
             /* [in] */ ICorDebugAppDomain *pAppDomain,
             /* [in] */ ICorDebugThread *thread)
         {
-            NotifyEvalComplete(thread, nullptr);
+            m_debugger->m_evaluator.NotifyEvalComplete(thread, nullptr);
             DWORD threadId = 0;
             thread->GetID(&threadId);
             m_debugger->m_protocol->EmitThreadEvent(ThreadEvent(ThreadExited, threadId));
@@ -942,13 +942,18 @@ HRESULT Debugger::TerminateProcess()
     return S_OK;
 }
 
-void Debugger::Cleanup()
+void Evaluator::Cleanup()
 {
-    Modules::CleanupAllModules();
     if (m_pRunClassConstructor)
         m_pRunClassConstructor->Release();
     if (m_pGetTypeHandle)
         m_pGetTypeHandle->Release();
+}
+
+void Debugger::Cleanup()
+{
+    Modules::CleanupAllModules();
+    m_evaluator.Cleanup();
     m_protocol->Cleanup();
     // TODO: Cleanup libcoreclr.so instance
 }
index e87e42e918ffc7afd40a33106f00ac8c3d759b38..fbca7f22d609cde2ca74eb70a93ab6d0132b086e 100644 (file)
 #include <vector>
 #include <list>
 #include <iomanip>
-#include <future>
 #include <utility>
 
 #include "cputil.h"
 #include "modules.h"
 #include "typeprinter.h"
-#include "valuewalk.h"
 #include "valueprint.h"
 #include "expr.h"
+#include "debugger.h"
 
 
-static std::mutex g_evalMutex;
-static std::unordered_map< DWORD, std::promise< std::unique_ptr<ToRelease<ICorDebugValue>> > > g_evalResults;
-
-void NotifyEvalComplete(ICorDebugThread *pThread, ICorDebugEval *pEval)
+void Evaluator::NotifyEvalComplete(ICorDebugThread *pThread, ICorDebugEval *pEval)
 {
-    std::lock_guard<std::mutex> lock(g_evalMutex);
+    std::lock_guard<std::mutex> lock(m_evalMutex);
     if (!pThread)
     {
-        g_evalResults.clear();
+        m_evalResults.clear();
         return;
     }
 
@@ -45,23 +41,23 @@ void NotifyEvalComplete(ICorDebugThread *pThread, ICorDebugEval *pEval)
         pEval->GetResult(&(*ppEvalResult));
     }
 
-    auto it = g_evalResults.find(threadId);
+    auto it = m_evalResults.find(threadId);
 
-    if (it == g_evalResults.end())
+    if (it == m_evalResults.end())
         return;
 
     it->second.set_value(std::move(ppEvalResult));
 
-    g_evalResults.erase(it);
+    m_evalResults.erase(it);
 }
 
-bool IsEvalRunning()
+bool Evaluator::IsEvalRunning()
 {
-    std::lock_guard<std::mutex> lock(g_evalMutex);
-    return !g_evalResults.empty();
+    std::lock_guard<std::mutex> lock(m_evalMutex);
+    return !m_evalResults.empty();
 }
 
-std::future< std::unique_ptr<ToRelease<ICorDebugValue>> > RunEval(
+std::future< std::unique_ptr<ToRelease<ICorDebugValue>> > Evaluator::RunEval(
     ICorDebugThread *pThread,
     ICorDebugEval *pEval)
 {
@@ -75,20 +71,20 @@ std::future< std::unique_ptr<ToRelease<ICorDebugValue>> > RunEval(
     if (FAILED(pThread->GetProcess(&pProcess)))
         return f;
 
-    std::lock_guard<std::mutex> lock(g_evalMutex);
+    std::lock_guard<std::mutex> lock(m_evalMutex);
 
-    if (!g_evalResults.insert(std::make_pair(threadId, std::move(p))).second)
+    if (!m_evalResults.insert(std::make_pair(threadId, std::move(p))).second)
         return f; // Already running eval? The future will throw broken promise
 
     if (FAILED(pProcess->Continue(0)))
-        g_evalResults.erase(threadId);
+        m_evalResults.erase(threadId);
 
     return f;
 }
 
-static HRESULT WaitEvalResult(ICorDebugThread *pThread,
-                              ICorDebugEval *pEval,
-                              ICorDebugValue **ppEvalResult)
+HRESULT Evaluator::WaitEvalResult(ICorDebugThread *pThread,
+                                  ICorDebugEval *pEval,
+                                  ICorDebugValue **ppEvalResult)
 {
     try
     {
@@ -105,7 +101,7 @@ static HRESULT WaitEvalResult(ICorDebugThread *pThread,
     return S_OK;
 }
 
-HRESULT EvalFunction(
+HRESULT Evaluator::EvalFunction(
     ICorDebugThread *pThread,
     ICorDebugFunction *pFunc,
     ICorDebugType *pType, // may be nullptr
@@ -147,7 +143,7 @@ HRESULT EvalFunction(
     return WaitEvalResult(pThread, pEval, ppEvalResult);
 }
 
-HRESULT EvalObjectNoConstructor(
+HRESULT Evaluator::EvalObjectNoConstructor(
     ICorDebugThread *pThread,
     ICorDebugType *pType,
     ICorDebugValue **ppEvalResult)
@@ -230,7 +226,7 @@ static HRESULT FindMethod(ICorDebugType *pType, WCHAR *methodName, ICorDebugFunc
     return E_FAIL;
 }
 
-HRESULT ObjectToString(
+HRESULT Evaluator::ObjectToString(
     ICorDebugThread *pThread,
     ICorDebugValue *pValue,
     std::function<void(const std::string&)> cb
@@ -337,14 +333,15 @@ static std::string IndiciesToStr(const std::vector<ULONG32> &ind, const std::vec
     return ss.str();
 }
 
-static HRESULT GetLiteralValue(ICorDebugThread *pThread,
-                               ICorDebugType *pType,
-                               ICorDebugModule *pModule,
-                               PCCOR_SIGNATURE pSignatureBlob,
-                               ULONG sigBlobLength,
-                               UVCP_CONSTANT pRawValue,
-                               ULONG rawValueLength,
-                               ICorDebugValue **ppLiteralValue)
+HRESULT Evaluator::GetLiteralValue(
+    ICorDebugThread *pThread,
+    ICorDebugType *pType,
+    ICorDebugModule *pModule,
+    PCCOR_SIGNATURE pSignatureBlob,
+    ULONG sigBlobLength,
+    UVCP_CONSTANT pRawValue,
+    ULONG rawValueLength,
+    ICorDebugValue **ppLiteralValue)
 {
     HRESULT Status = S_OK;
 
@@ -495,11 +492,12 @@ static HRESULT GetLiteralValue(ICorDebugThread *pThread,
     return S_OK;
 }
 
-static HRESULT WalkMembers(ICorDebugValue *pInputValue,
-                           ICorDebugThread *pThread,
-                           ICorDebugILFrame *pILFrame,
-                           ICorDebugType *pTypeCast,
-                           WalkMembersCallback cb)
+HRESULT Evaluator::WalkMembers(
+    ICorDebugValue *pInputValue,
+    ICorDebugThread *pThread,
+    ICorDebugILFrame *pILFrame,
+    ICorDebugType *pTypeCast,
+    WalkMembersCallback cb)
 {
     HRESULT Status = S_OK;
 
@@ -715,19 +713,21 @@ static HRESULT WalkMembers(ICorDebugValue *pInputValue,
     return S_OK;
 }
 
-HRESULT WalkMembers(ICorDebugValue *pValue,
-                    ICorDebugThread *pThread,
-                    ICorDebugILFrame *pILFrame,
-                    WalkMembersCallback cb)
+HRESULT Evaluator::WalkMembers(
+    ICorDebugValue *pValue,
+    ICorDebugThread *pThread,
+    ICorDebugILFrame *pILFrame,
+    WalkMembersCallback cb)
 {
     return WalkMembers(pValue, pThread, pILFrame, nullptr, cb);
 }
 
-static HRESULT HandleSpecialLocalVar(const std::string &localName,
-                                     ICorDebugValue *pLocalValue,
-                                     ICorDebugILFrame *pILFrame,
-                                     std::unordered_set<std::string> &locals,
-                                     WalkStackVarsCallback cb)
+HRESULT Evaluator::HandleSpecialLocalVar(
+    const std::string &localName,
+    ICorDebugValue *pLocalValue,
+    ICorDebugILFrame *pILFrame,
+    std::unordered_set<std::string> &locals,
+    WalkStackVarsCallback cb)
 {
     static const std::string captureName = "CS$<>";
 
@@ -758,10 +758,11 @@ static HRESULT HandleSpecialLocalVar(const std::string &localName,
     return S_OK;
 }
 
-static HRESULT HandleSpecialThisParam(ICorDebugValue *pThisValue,
-                                      ICorDebugILFrame *pILFrame,
-                                      std::unordered_set<std::string> &locals,
-                                      WalkStackVarsCallback cb)
+HRESULT Evaluator::HandleSpecialThisParam(
+    ICorDebugValue *pThisValue,
+    ICorDebugILFrame *pILFrame,
+    std::unordered_set<std::string> &locals,
+    WalkStackVarsCallback cb)
 {
     static const std::string displayClass = "<>c__DisplayClass";
     static const std::string hideClass = "<>c";
@@ -804,7 +805,7 @@ static HRESULT HandleSpecialThisParam(ICorDebugValue *pThisValue,
     return S_OK;
 }
 
-HRESULT WalkStackVars(ICorDebugFrame *pFrame, WalkStackVarsCallback cb)
+HRESULT Evaluator::WalkStackVars(ICorDebugFrame *pFrame, WalkStackVarsCallback cb)
 {
     HRESULT Status;
 
@@ -919,4 +920,4 @@ HRESULT WalkStackVars(ICorDebugFrame *pFrame, WalkStackVarsCallback cb)
     }
 
     return S_OK;
-}
\ No newline at end of file
+}
diff --git a/src/debug/netcoredbg/valuewalk.h b/src/debug/netcoredbg/valuewalk.h
deleted file mode 100644 (file)
index 766497b..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) 2017 Samsung Electronics Co., LTD
-// Distributed under the MIT License.
-// See the LICENSE file in the project root for more information.
-
-typedef std::function<HRESULT(mdMethodDef,ICorDebugModule*,ICorDebugType*,ICorDebugValue*,bool,const std::string&)> WalkMembersCallback;
-typedef std::function<HRESULT(ICorDebugILFrame*,ICorDebugValue*,const std::string&)> WalkStackVarsCallback;
-HRESULT WalkMembers(ICorDebugValue *pValue, ICorDebugThread *pThread, ICorDebugILFrame *pILFrame, WalkMembersCallback cb);
-HRESULT WalkStackVars(ICorDebugFrame *pFrame, WalkStackVarsCallback cb);
-HRESULT EvalFunction(
-    ICorDebugThread *pThread,
-    ICorDebugFunction *pFunc,
-    ICorDebugType *pType, // may be nullptr
-    ICorDebugValue *pArgValue, // may be nullptr
-    ICorDebugValue **ppEvalResult);
-
-HRESULT EvalObjectNoConstructor(
-    ICorDebugThread *pThread,
-    ICorDebugType *pType,
-    ICorDebugValue **ppEvalResult);
-
-bool IsEvalRunning();
-void NotifyEvalComplete(ICorDebugThread *pThread, ICorDebugEval *pEval);
-HRESULT ObjectToString(
-    ICorDebugThread *pThread,
-    ICorDebugValue *pValue,
-    std::function<void(const std::string&)> cb
-);
index e245efb999e7b542f8bcca66b3fd66d485c7498b..841998fd117b7526b4da406adc4089f03bb99a13 100644 (file)
 #include "debugger.h"
 #include "typeprinter.h"
 #include "modules.h"
-#include "valuewalk.h"
 #include "valueprint.h"
 #include "expr.h"
 #include "frames.h"
 
 
-HRESULT GetNumChild(ICorDebugValue *pValue,
-                    unsigned int &numchild,
-                    bool static_members = false)
+HRESULT Debugger::GetNumChild(
+    ICorDebugValue *pValue,
+    unsigned int &numchild,
+    bool static_members)
 {
     HRESULT Status = S_OK;
     numchild = 0;
@@ -33,7 +33,7 @@ HRESULT GetNumChild(ICorDebugValue *pValue,
     ULONG numstatic = 0;
     ULONG numinstance = 0;
 
-    IfFailRet(WalkMembers(pValue, nullptr, nullptr, [&numstatic, &numinstance](
+    IfFailRet(m_evaluator.WalkMembers(pValue, nullptr, nullptr, [&numstatic, &numinstance](
         mdMethodDef,
         ICorDebugModule *,
         ICorDebugType *,
@@ -93,7 +93,7 @@ static HRESULT FindFunction(ICorDebugModule *pModule,
     return pModule->GetFunctionFromToken(methodDef, ppFunction);
 }
 
-HRESULT Debugger::RunClassConstructor(ICorDebugThread *pThread, ICorDebugValue *pValue)
+HRESULT Evaluator::RunClassConstructor(ICorDebugThread *pThread, ICorDebugValue *pValue)
 {
     HRESULT Status;
 
@@ -157,14 +157,15 @@ private:
     Member(const Member &that) = delete;
 };
 
-static HRESULT FetchFieldsAndProperties(ICorDebugValue *pInputValue,
-                                        ICorDebugThread *pThread,
-                                        ICorDebugILFrame *pILFrame,
-                                        std::vector<Member> &members,
-                                        bool fetchOnlyStatic,
-                                        bool &hasStaticMembers,
-                                        int childStart,
-                                        int childEnd)
+HRESULT Debugger::FetchFieldsAndProperties(
+    ICorDebugValue *pInputValue,
+    ICorDebugThread *pThread,
+    ICorDebugILFrame *pILFrame,
+    std::vector<Member> &members,
+    bool fetchOnlyStatic,
+    bool &hasStaticMembers,
+    int childStart,
+    int childEnd)
 {
     hasStaticMembers = false;
     HRESULT Status;
@@ -174,7 +175,7 @@ static HRESULT FetchFieldsAndProperties(ICorDebugValue *pInputValue,
 
     int currentIndex = -1;
 
-    IfFailRet(WalkMembers(pInputValue, pThread, pILFrame, [&](
+    IfFailRet(m_evaluator.WalkMembers(pInputValue, pThread, pILFrame, [&](
         mdMethodDef mdGetter,
         ICorDebugModule *pModule,
         ICorDebugType *pType,
@@ -205,7 +206,7 @@ static HRESULT FetchFieldsAndProperties(ICorDebugValue *pInputValue,
         {
             ToRelease<ICorDebugFunction> pFunc;
             if (SUCCEEDED(pModule->GetFunctionFromToken(mdGetter, &pFunc)))
-                EvalFunction(pThread, pFunc, pType, is_static ? nullptr : pInputValue, &pResultValue);
+                m_evaluator.EvalFunction(pThread, pFunc, pType, is_static ? nullptr : pInputValue, &pResultValue);
         }
         else
         {
@@ -299,7 +300,10 @@ HRESULT Debugger::GetStackVariables(uint64_t frameId, ICorDebugThread *pThread,
         }
     }
 
-    IfFailRet(WalkStackVars(pFrame, [&](ICorDebugILFrame *pILFrame, ICorDebugValue *pValue, const std::string &name) -> HRESULT
+    IfFailRet(m_evaluator.WalkStackVars(pFrame, [&](
+        ICorDebugILFrame *pILFrame,
+        ICorDebugValue *pValue,
+        const std::string &name) -> HRESULT
     {
         ++currentIndex;
         if (currentIndex < start || (count != 0 && currentIndex >= start + count))
@@ -335,7 +339,10 @@ HRESULT Debugger::GetScopes(uint64_t frameId, std::vector<Scope> &scopes)
     if (SUCCEEDED(pThread->GetCurrentException(&pExceptionValue)) && pExceptionValue != nullptr)
         namedVariables++;
 
-    IfFailRet(WalkStackVars(pFrame, [&](ICorDebugILFrame *pILFrame, ICorDebugValue *pValue, const std::string &name) -> HRESULT
+    IfFailRet(m_evaluator.WalkStackVars(pFrame, [&](
+        ICorDebugILFrame *pILFrame,
+        ICorDebugValue *pValue,
+        const std::string &name) -> HRESULT
     {
         namedVariables++;
         return S_OK;
@@ -419,7 +426,7 @@ HRESULT Debugger::GetChildren(VariableReference &ref,
         bool staticsInRange = start < ref.namedVariables && (count == 0 || start + count >= ref.namedVariables);
         if (staticsInRange)
         {
-            RunClassConstructor(pThread, ref.value);
+            m_evaluator.RunClassConstructor(pThread, ref.value);
 
             Variable var;
             var.name = "Static members";
@@ -443,7 +450,7 @@ HRESULT Debugger::Evaluate(uint64_t frameId, const std::string &expression, Vari
     IfFailRet(GetFrameAt(pThread, stackFrame.GetLevel(), &pFrame));
 
     ToRelease<ICorDebugValue> pResultValue;
-    IfFailRet(EvalExpr(pThread, pFrame, expression, &pResultValue));
+    IfFailRet(m_evaluator.EvalExpr(pThread, pFrame, expression, &pResultValue));
 
     variable.evaluateName = expression;