Refactor Modules namespace into Modules class
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Thu, 18 Jan 2018 17:56:19 +0000 (20:56 +0300)
committerIgor Kulaychuk <i.kulaychuk@samsung.com>
Thu, 18 Jan 2018 17:56:19 +0000 (20:56 +0300)
12 files changed:
src/debug/netcoredbg/breakpoints.cpp
src/debug/netcoredbg/commands.cpp
src/debug/netcoredbg/debugger.h
src/debug/netcoredbg/expr.cpp
src/debug/netcoredbg/expr.h [deleted file]
src/debug/netcoredbg/frames.cpp
src/debug/netcoredbg/frames.h
src/debug/netcoredbg/main.cpp
src/debug/netcoredbg/modules.cpp
src/debug/netcoredbg/modules.h
src/debug/netcoredbg/valuewalk.cpp
src/debug/netcoredbg/variables.cpp

index 6ce65f8b41a8cc5cc1badb3de18eacdfa5335691..aa7860c795ee0acf6cdef2551d67f3858c63ec79 100644 (file)
@@ -9,7 +9,6 @@
 #include <unordered_set>
 
 #include "debugger.h"
-#include "modules.h"
 
 
 Debugger::ManagedBreakpoint::ManagedBreakpoint() :
@@ -45,7 +44,7 @@ HRESULT Debugger::HitBreakpoint(ICorDebugThread *pThread, Breakpoint &breakpoint
         return E_FAIL;
     IfFailRet(pFrame->GetFunctionToken(&methodToken));
 
-    IfFailRet(Modules::GetFrameLocation(pFrame, ilOffset, sp));
+    IfFailRet(m_modules.GetFrameILAndSequencePoint(pFrame, ilOffset, sp));
 
     std::lock_guard<std::mutex> lock(m_breakpointsMutex);
 
@@ -93,7 +92,7 @@ HRESULT Debugger::ResolveBreakpointInModule(ICorDebugModule *pModule, ManagedBre
     ULONG32 ilOffset;
     std::string fullname;
 
-    IfFailRet(Modules::GetLocationInModule(
+    IfFailRet(m_modules.GetLocationInModule(
         pModule,
         bp.fullname,
         bp.linenum,
@@ -155,7 +154,7 @@ HRESULT Debugger::ResolveBreakpoint(ManagedBreakpoint &bp)
 
     ToRelease<ICorDebugModule> pModule;
 
-    IfFailRet(Modules::GetLocationInAny(
+    IfFailRet(m_modules.GetLocationInAny(
         bp.fullname,
         bp.linenum,
         ilOffset,
index 11fbfd743b4e9701544f32303bd5121b85743266..8b388eaad6e7a94c3134843d9ca90d7bfdca8043 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "platform.h"
 #include "debugger.h"
-#include "modules.h"
 #include "frames.h"
 
 
@@ -189,7 +188,7 @@ HRESULT Debugger::SetupStep(ICorDebugThread *pThread, Debugger::StepType stepTyp
     BOOL bStepIn = stepType == STEP_IN;
 
     COR_DEBUG_STEP_RANGE range;
-    if (SUCCEEDED(Modules::GetStepRangeFromCurrentIP(pThread, &range)))
+    if (SUCCEEDED(m_modules.GetStepRangeFromCurrentIP(pThread, &range)))
     {
         IfFailRet(pStepper->StepRange(bStepIn, &range, 1));
     } else {
@@ -242,7 +241,7 @@ HRESULT Debugger::GetStackTrace(int threadId, int lowFrame, int highFrame, std::
         return E_FAIL;
     ToRelease<ICorDebugThread> pThread;
     IfFailRet(m_pProcess->GetThread(threadId, &pThread));
-    return ::GetStackTrace(pThread, lowFrame, highFrame, stackFrames);
+    return GetStackTrace(pThread, lowFrame, highFrame, stackFrames);
 }
 
 HRESULT MIProtocol::StepCommand(const std::vector<std::string> &args,
index 563c48f458d452453b9c0adc0a1a09eb1dca79b4..62dab3e4a9e51a5cbba57457c77c8c78a4a550c3 100644 (file)
@@ -3,6 +3,7 @@
 // See the LICENSE file in the project root for more information.
 
 #include "protocol.h"
+#include "modules.h"
 #include <unordered_map>
 #include <unordered_set>
 #include <vector>
@@ -28,6 +29,7 @@ public:
     typedef std::function<HRESULT(mdMethodDef,ICorDebugModule*,ICorDebugType*,ICorDebugValue*,bool,const std::string&)> WalkMembersCallback;
     typedef std::function<HRESULT(ICorDebugILFrame*,ICorDebugValue*,const std::string&)> WalkStackVarsCallback;
 
+    Modules &m_modules;
 private:
 
     ToRelease<ICorDebugFunction> m_pRunClassConstructor;
@@ -98,8 +100,23 @@ private:
         ULONG rawValueLength,
         ICorDebugValue **ppLiteralValue);
 
+    HRESULT FindType(
+        const std::vector<std::string> &parts,
+        int &nextPart,
+        ICorDebugThread *pThread,
+        ICorDebugModule *pModule,
+        ICorDebugType **ppType,
+        ICorDebugModule **ppModule = nullptr);
+
+    HRESULT ResolveParameters(
+        const std::vector<std::string> &params,
+        ICorDebugThread *pThread,
+        std::vector< ToRelease<ICorDebugType> > &types);
+
 public:
 
+    Evaluator(Modules &modules) : m_modules(modules) {}
+
     HRESULT RunClassConstructor(ICorDebugThread *pThread, ICorDebugValue *pValue);
 
     HRESULT EvalFunction(
@@ -125,6 +142,11 @@ public:
         std::function<void(const std::string&)> cb
     );
 
+    HRESULT GetType(
+        const std::string &typeName,
+        ICorDebugThread *pThread,
+        ICorDebugType **ppType);
+
     HRESULT WalkMembers(
         ICorDebugValue *pValue,
         ICorDebugThread *pThread,
@@ -166,6 +188,7 @@ private:
 
     void SetLastStoppedThread(ICorDebugThread *pThread);
 
+    Modules m_modules;
     Evaluator m_evaluator;
     Protocol *m_protocol;
     ManagedCallback *m_managedCallback;
@@ -283,6 +306,9 @@ private:
         ICorDebugValue *pValue,
         unsigned int &numchild,
         bool static_members = false);
+
+    HRESULT GetStackTrace(ICorDebugThread *pThread, int lowFrame, int highFrame, std::vector<StackFrame> &stackFrames);
+    HRESULT GetFrameLocation(ICorDebugFrame *pFrame, int threadId, uint32_t level, StackFrame &stackFrame);
 public:
     Debugger();
     ~Debugger();
index f3b3a168ab9418a129f9ae022767b8e4d7426443..b58da3da7ea6fcabdc5004c630a00d50c104c193 100644 (file)
@@ -16,9 +16,7 @@
 
 #include "debugger.h"
 #include "typeprinter.h"
-#include "modules.h"
 #include "valueprint.h"
-#include "expr.h"
 
 
 static HRESULT ParseIndices(const std::string &s, std::vector<ULONG32> &indices)
@@ -190,7 +188,7 @@ HRESULT Evaluator::RunClassConstructor(ICorDebugThread *pThread, ICorDebugValue
     if (!m_pRunClassConstructor && !m_pGetTypeHandle)
     {
         ToRelease<ICorDebugModule> pModule;
-        IfFailRet(Modules::GetModuleWithName("System.Private.CoreLib.dll", &pModule));
+        IfFailRet(m_modules.GetModuleWithName("System.Private.CoreLib.dll", &pModule));
 
         static const WCHAR helpersName[] = W("System.Runtime.CompilerServices.RuntimeHelpers");
         static const WCHAR runCCTorMethodName[] = W("RunClassConstructor");
@@ -463,16 +461,10 @@ HRESULT FindTypeInModule(ICorDebugModule *pModule, const std::vector<std::string
     return S_OK;
 }
 
-HRESULT FindType(
-    const std::vector<std::string> &parts,
-    int &nextPart, ICorDebugThread *pThread,
-    ICorDebugModule *pModule,
-    ICorDebugType **ppType,
-    ICorDebugModule **ppModule = nullptr);
-
-HRESULT GetType(const std::string &typeName,
-                ICorDebugThread *pThread,
-                ICorDebugType **ppType)
+HRESULT Evaluator::GetType(
+    const std::string &typeName,
+    ICorDebugThread *pThread,
+    ICorDebugType **ppType)
 {
     HRESULT Status;
     std::vector<int> ranks;
@@ -506,9 +498,10 @@ HRESULT GetType(const std::string &typeName,
     return S_OK;
 }
 
-HRESULT ResolveParameters(const std::vector<std::string> &params,
-                          ICorDebugThread *pThread,
-                          std::vector< ToRelease<ICorDebugType> > &types)
+HRESULT Evaluator::ResolveParameters(
+    const std::vector<std::string> &params,
+    ICorDebugThread *pThread,
+    std::vector< ToRelease<ICorDebugType> > &types)
 {
     HRESULT Status;
     for (auto &p : params)
@@ -520,12 +513,13 @@ HRESULT ResolveParameters(const std::vector<std::string> &params,
     return S_OK;
 }
 
-HRESULT FindType(const std::vector<std::string> &parts,
-                 int &nextPart,
-                 ICorDebugThread *pThread,
-                 ICorDebugModule *pModule,
-                 ICorDebugType **ppType,
-                 ICorDebugModule **ppModule)
+HRESULT Evaluator::FindType(
+    const std::vector<std::string> &parts,
+    int &nextPart,
+    ICorDebugThread *pThread,
+    ICorDebugModule *pModule,
+    ICorDebugType **ppType,
+    ICorDebugModule **ppModule)
 {
     HRESULT Status;
 
@@ -537,7 +531,7 @@ HRESULT FindType(const std::vector<std::string> &parts,
 
     if (!pTypeModule)
     {
-        Modules::ForEachModule([&](ICorDebugModule *pModule)->HRESULT {
+        m_modules.ForEachModule([&](ICorDebugModule *pModule)->HRESULT {
             if (typeToken != mdTypeDefNil) // already found
                 return S_OK;
 
diff --git a/src/debug/netcoredbg/expr.h b/src/debug/netcoredbg/expr.h
deleted file mode 100644 (file)
index 619f520..0000000
+++ /dev/null
@@ -1,5 +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.
-
-HRESULT GetType(const std::string &typeName, ICorDebugThread *pThread, ICorDebugType **ppType);
index 708894f9d99964ea906d006cc52a9ea7c80f1365..64e2b1d385244e3407254caa2c622c5d76800c21 100644 (file)
@@ -15,7 +15,6 @@
 #include "typeprinter.h"
 #include "platform.h"
 #include "debugger.h"
-#include "modules.h"
 #include "frames.h"
 
 
@@ -56,7 +55,7 @@ static uint64_t FrameAddr(ICorDebugFrame *pFrame)
     return startAddr;
 }
 
-HRESULT GetFrameLocation(ICorDebugFrame *pFrame, int threadId, uint32_t level, StackFrame &stackFrame)
+HRESULT Debugger::GetFrameLocation(ICorDebugFrame *pFrame, int threadId, uint32_t level, StackFrame &stackFrame)
 {
     HRESULT Status;
 
@@ -65,7 +64,7 @@ HRESULT GetFrameLocation(ICorDebugFrame *pFrame, int threadId, uint32_t level, S
     ULONG32 ilOffset;
     Modules::SequencePoint sp;
 
-    if (SUCCEEDED(Modules::GetFrameLocation(pFrame, ilOffset, sp)))
+    if (SUCCEEDED(m_modules.GetFrameILAndSequencePoint(pFrame, ilOffset, sp)))
     {
         stackFrame.source = Source(sp.document);
         stackFrame.line = sp.startLine;
@@ -388,7 +387,7 @@ static const char *GetInternalTypeName(CorDebugInternalFrameType frameType)
     }
 }
 
-HRESULT GetStackTrace(ICorDebugThread *pThread, int lowFrame, int highFrame, std::vector<StackFrame> &stackFrames)
+HRESULT Debugger::GetStackTrace(ICorDebugThread *pThread, int lowFrame, int highFrame, std::vector<StackFrame> &stackFrames)
 {
     HRESULT Status;
     std::stringstream ss;
index 70f9a4bffa0b7b84966a4e12f08f1d1fac4fb40f..62c3670f4a0968e9dba65a0f23c4ec27a7e39cae 100644 (file)
@@ -2,7 +2,6 @@
 // Distributed under the MIT License.
 // See the LICENSE file in the project root for more information.
 
-HRESULT GetFrameLocation(ICorDebugFrame *pFrame, int threadId, uint32_t level, StackFrame &stackFrame);
+
 HRESULT GetFrameAt(ICorDebugThread *pThread, int level, ICorDebugFrame **ppFrame);
 HRESULT GetThreadsState(ICorDebugController *controller, std::vector<Thread> &threads);
-HRESULT GetStackTrace(ICorDebugThread *pThread, int lowFrame, int highFrame, std::vector<StackFrame> &stackFrames);
index a6f1c52a9d9f4af0c7dcaade5d11fc679f0963b6..1faf90c0bdbbb7d49c0921f31b5a4b75b32e4c31 100644 (file)
@@ -18,7 +18,6 @@
 #include "platform.h"
 #include "typeprinter.h"
 #include "debugger.h"
-#include "modules.h"
 #include "frames.h"
 
 #define __in
@@ -333,7 +332,7 @@ public:
 
             ToRelease<ICorDebugFrame> pFrame;
             if (SUCCEEDED(pThread->GetActiveFrame(&pFrame)) && pFrame != nullptr)
-                GetFrameLocation(pFrame, threadId, 0, event.frame);
+                m_debugger->GetFrameLocation(pFrame, threadId, 0, event.frame);
 
             m_debugger->SetLastStoppedThread(pThread);
             m_debugger->m_protocol->EmitStoppedEvent(event);
@@ -354,7 +353,7 @@ public:
             ToRelease<ICorDebugFrame> pFrame;
             HRESULT Status = S_FALSE;
             if (SUCCEEDED(pThread->GetActiveFrame(&pFrame)) && pFrame != nullptr)
-                Status = GetFrameLocation(pFrame, threadId, 0, stackFrame);
+                Status = m_debugger->GetFrameLocation(pFrame, threadId, 0, stackFrame);
 
             const bool no_source = Status == S_FALSE;
 
@@ -395,7 +394,7 @@ public:
                 StackFrame stackFrame;
                 ToRelease<ICorDebugFrame> pFrame;
                 if (SUCCEEDED(pThread->GetActiveFrame(&pFrame)) && pFrame != nullptr)
-                    GetFrameLocation(pFrame, threadId, 0, stackFrame);
+                    m_debugger->GetFrameLocation(pFrame, threadId, 0, stackFrame);
 
                 m_debugger->SetLastStoppedThread(pThread);
 
@@ -498,7 +497,7 @@ public:
             CORDB_ADDRESS baseAddress = 0;
             ULONG32 size = 0;
 
-            Modules::TryLoadModuleSymbols(pModule, id, name, symbolsLoaded, baseAddress, size);
+            m_debugger->m_modules.TryLoadModuleSymbols(pModule, id, name, symbolsLoaded, baseAddress, size);
 
             std::stringstream ss;
             ss << "id=\"{" << id << "}\","
@@ -667,6 +666,7 @@ public:
 
 Debugger::Debugger() :
     m_processAttachedState(ProcessUnattached),
+    m_evaluator(m_modules),
     m_managedCallback(new ManagedCallback()),
     m_pDebug(nullptr),
     m_pProcess(nullptr),
@@ -939,7 +939,7 @@ HRESULT Debugger::TerminateProcess()
 
 void Debugger::Cleanup()
 {
-    Modules::CleanupAllModules();
+    m_modules.CleanupAllModules();
     m_evaluator.Cleanup();
     m_protocol->Cleanup();
     // TODO: Cleanup libcoreclr.so instance
index 98752e2690cdedb47863b649f9c71cb17bb06a07..e1c9abaf6eebf4739882857bf9e6eb80beb68bbf 100644 (file)
 bool ShouldLoadSymbolsForModule(const std::string &moduleName);
 HRESULT SetJMCFromAttributes(ICorDebugModule *pModule, SymbolReader *symbolReader);
 
-namespace Modules {
-struct ModuleInfo
+void Modules::CleanupAllModules()
 {
-    std::unique_ptr<SymbolReader> symbols;
-    ToRelease<ICorDebugModule> module;
-
-    ModuleInfo(ModuleInfo &&) = default;
-    ModuleInfo(const ModuleInfo &) = delete;
-};
-
-std::mutex g_modulesInfoMutex;
-std::unordered_map<CORDB_ADDRESS, ModuleInfo> g_modulesInfo;
-
-void CleanupAllModules()
-{
-    std::lock_guard<std::mutex> lock(g_modulesInfoMutex);
-    g_modulesInfo.clear();
+    std::lock_guard<std::mutex> lock(m_modulesInfoMutex);
+    m_modulesInfo.clear();
 }
 
-std::string GetModuleFileName(ICorDebugModule *pModule)
+std::string Modules::GetModuleFileName(ICorDebugModule *pModule)
 {
     WCHAR name[mdNameLen];
     ULONG32 name_len = 0;
@@ -50,12 +37,13 @@ std::string GetModuleFileName(ICorDebugModule *pModule)
     return std::string();
 }
 
-HRESULT GetLocationInAny(std::string filename,
-                         ULONG linenum,
-                         ULONG32 &ilOffset,
-                         mdMethodDef &methodToken,
-                         std::string &fullname,
-                         ICorDebugModule **ppModule)
+HRESULT Modules::GetLocationInAny(
+    std::string filename,
+    ULONG linenum,
+    ULONG32 &ilOffset,
+    mdMethodDef &methodToken,
+    std::string &fullname,
+    ICorDebugModule **ppModule)
 {
     HRESULT Status;
 
@@ -63,9 +51,9 @@ HRESULT GetLocationInAny(std::string filename,
 
     Status = MultiByteToWideChar(CP_UTF8, 0, filename.c_str(), filename.size() + 1, nameBuffer, MAX_LONGPATH);
 
-    std::lock_guard<std::mutex> lock(g_modulesInfoMutex);
+    std::lock_guard<std::mutex> lock(m_modulesInfoMutex);
 
-    for (auto &info_pair : g_modulesInfo)
+    for (auto &info_pair : m_modulesInfo)
     {
         ModuleInfo &mdInfo = info_pair.second;
 
@@ -88,12 +76,13 @@ HRESULT GetLocationInAny(std::string filename,
     return E_FAIL;
 }
 
-HRESULT GetLocationInModule(ICorDebugModule *pModule,
-                            std::string filename,
-                            ULONG linenum,
-                            ULONG32 &ilOffset,
-                            mdMethodDef &methodToken,
-                            std::string &fullname)
+HRESULT Modules::GetLocationInModule(
+    ICorDebugModule *pModule,
+    std::string filename,
+    ULONG linenum,
+    ULONG32 &ilOffset,
+    mdMethodDef &methodToken,
+    std::string &fullname)
 {
     HRESULT Status;
 
@@ -104,9 +93,9 @@ HRESULT GetLocationInModule(ICorDebugModule *pModule,
     CORDB_ADDRESS modAddress;
     IfFailRet(pModule->GetBaseAddress(&modAddress));
 
-    std::lock_guard<std::mutex> lock(g_modulesInfoMutex);
-    auto info_pair = g_modulesInfo.find(modAddress);
-    if (info_pair == g_modulesInfo.end())
+    std::lock_guard<std::mutex> lock(m_modulesInfoMutex);
+    auto info_pair = m_modulesInfo.find(modAddress);
+    if (info_pair == m_modulesInfo.end())
     {
         return E_FAIL;
     }
@@ -122,9 +111,10 @@ HRESULT GetLocationInModule(ICorDebugModule *pModule,
     return S_OK;
 }
 
-HRESULT GetFrameLocation(ICorDebugFrame *pFrame,
-                         ULONG32 &ilOffset,
-                         Modules::SequencePoint &sequencePoint)
+HRESULT Modules::GetFrameILAndSequencePoint(
+    ICorDebugFrame *pFrame,
+    ULONG32 &ilOffset,
+    Modules::SequencePoint &sequencePoint)
 {
     HRESULT Status;
 
@@ -156,9 +146,9 @@ HRESULT GetFrameLocation(ICorDebugFrame *pFrame,
     ULONG linenum;
 
     {
-        std::lock_guard<std::mutex> lock(g_modulesInfoMutex);
-        auto info_pair = g_modulesInfo.find(modAddress);
-        if (info_pair == g_modulesInfo.end())
+        std::lock_guard<std::mutex> lock(m_modulesInfoMutex);
+        auto info_pair = m_modulesInfo.find(modAddress);
+        if (info_pair == m_modulesInfo.end())
         {
             return E_FAIL;
         }
@@ -196,7 +186,7 @@ HRESULT GetFrameLocation(ICorDebugFrame *pFrame,
     return E_FAIL;
 }
 
-HRESULT GetStepRangeFromCurrentIP(ICorDebugThread *pThread, COR_DEBUG_STEP_RANGE *range)
+HRESULT Modules::GetStepRangeFromCurrentIP(ICorDebugThread *pThread, COR_DEBUG_STEP_RANGE *range)
 {
     HRESULT Status;
     ToRelease<ICorDebugFrame> pFrame;
@@ -227,9 +217,9 @@ HRESULT GetStepRangeFromCurrentIP(ICorDebugThread *pThread, COR_DEBUG_STEP_RANGE
     ULONG32 ilEndOffset;
 
     {
-        std::lock_guard<std::mutex> lock(g_modulesInfoMutex);
-        auto info_pair = g_modulesInfo.find(modAddress);
-        if (info_pair == g_modulesInfo.end())
+        std::lock_guard<std::mutex> lock(m_modulesInfoMutex);
+        auto info_pair = m_modulesInfo.find(modAddress);
+        if (info_pair == m_modulesInfo.end())
         {
             return E_FAIL;
         }
@@ -250,7 +240,7 @@ HRESULT GetStepRangeFromCurrentIP(ICorDebugThread *pThread, COR_DEBUG_STEP_RANGE
     return S_OK;
 }
 
-HRESULT GetModuleId(ICorDebugModule *pModule, std::string &id)
+HRESULT Modules::GetModuleId(ICorDebugModule *pModule, std::string &id)
 {
     HRESULT Status;
 
@@ -279,12 +269,13 @@ HRESULT GetModuleId(ICorDebugModule *pModule, std::string &id)
     return S_OK;
 }
 
-HRESULT TryLoadModuleSymbols(ICorDebugModule *pModule,
-                             std::string &id,
-                             std::string &name,
-                             bool &symbolsLoaded,
-                             CORDB_ADDRESS &baseAddress,
-                             ULONG32 &size)
+HRESULT Modules::TryLoadModuleSymbols(
+    ICorDebugModule *pModule,
+    std::string &id,
+    std::string &name,
+    bool &symbolsLoaded,
+    CORDB_ADDRESS &baseAddress,
+    ULONG32 &size)
 {
     HRESULT Status;
 
@@ -318,16 +309,16 @@ HRESULT TryLoadModuleSymbols(ICorDebugModule *pModule,
     IfFailRet(pModule->GetSize(&size));
 
     {
-        std::lock_guard<std::mutex> lock(g_modulesInfoMutex);
+        std::lock_guard<std::mutex> lock(m_modulesInfoMutex);
         pModule->AddRef();
         ModuleInfo mdInfo { std::move(symbolReader), pModule };
-        g_modulesInfo.insert(std::make_pair(baseAddress, std::move(mdInfo)));
+        m_modulesInfo.insert(std::make_pair(baseAddress, std::move(mdInfo)));
     }
 
     return S_OK;
 }
 
-HRESULT GetFrameNamedLocalVariable(
+HRESULT Modules::GetFrameNamedLocalVariable(
     ICorDebugModule *pModule,
     ICorDebugILFrame *pILFrame,
     mdMethodDef methodToken,
@@ -345,9 +336,9 @@ HRESULT GetFrameNamedLocalVariable(
     WCHAR wParamName[mdNameLen] = W("\0");
 
     {
-        std::lock_guard<std::mutex> lock(g_modulesInfoMutex);
-        auto info_pair = g_modulesInfo.find(modAddress);
-        if (info_pair == g_modulesInfo.end())
+        std::lock_guard<std::mutex> lock(m_modulesInfoMutex);
+        auto info_pair = m_modulesInfo.find(modAddress);
+        if (info_pair == m_modulesInfo.end())
         {
             return E_FAIL;
         }
@@ -360,11 +351,11 @@ HRESULT GetFrameNamedLocalVariable(
     return S_OK;
 }
 
-HRESULT GetModuleWithName(const std::string &name, ICorDebugModule **ppModule)
+HRESULT Modules::GetModuleWithName(const std::string &name, ICorDebugModule **ppModule)
 {
-    std::lock_guard<std::mutex> lock(g_modulesInfoMutex);
+    std::lock_guard<std::mutex> lock(m_modulesInfoMutex);
 
-    for (auto &info_pair : g_modulesInfo)
+    for (auto &info_pair : m_modulesInfo)
     {
         ModuleInfo &mdInfo = info_pair.second;
 
@@ -380,17 +371,15 @@ HRESULT GetModuleWithName(const std::string &name, ICorDebugModule **ppModule)
     return E_FAIL;
 }
 
-HRESULT ForEachModule(std::function<HRESULT(ICorDebugModule *pModule)> cb)
+HRESULT Modules::ForEachModule(std::function<HRESULT(ICorDebugModule *pModule)> cb)
 {
     HRESULT Status;
-    std::lock_guard<std::mutex> lock(g_modulesInfoMutex);
+    std::lock_guard<std::mutex> lock(m_modulesInfoMutex);
 
-    for (auto &info_pair : g_modulesInfo)
+    for (auto &info_pair : m_modulesInfo)
     {
         ModuleInfo &mdInfo = info_pair.second;
         IfFailRet(cb(mdInfo.module));
     }
     return S_OK;
 }
-
-} // Modules namespace
\ No newline at end of file
index 540fd7606e8393eecf26fb5724b088c9ebf4934c..954c18fdca6c517b7f852ef9ab6bf56d7e1148ed 100644 (file)
@@ -2,63 +2,87 @@
 // Distributed under the MIT License.
 // See the LICENSE file in the project root for more information.
 
-namespace Modules
+#include <unordered_map>
+#include <mutex>
+
+
+class SymbolReader;
+
+class Modules
 {
+    struct ModuleInfo
+    {
+        std::unique_ptr<SymbolReader> symbols;
+        ToRelease<ICorDebugModule> module;
 
-struct SequencePoint {
-    int32_t startLine;
-    int32_t startColumn;
-    int32_t endLine;
-    int32_t endColumn;
-    int32_t offset;
-    std::string document;
-};
+        ModuleInfo(ModuleInfo &&) = default;
+        ModuleInfo(const ModuleInfo &) = delete;
+    };
+
+    std::mutex m_modulesInfoMutex;
+    std::unordered_map<CORDB_ADDRESS, ModuleInfo> m_modulesInfo;
+
+    std::string GetModuleFileName(ICorDebugModule *pModule);
+
+public:
+
+    struct SequencePoint {
+        int32_t startLine;
+        int32_t startColumn;
+        int32_t endLine;
+        int32_t endColumn;
+        int32_t offset;
+        std::string document;
+    };
+
+    static HRESULT GetModuleId(ICorDebugModule *pModule, std::string &id);
 
-HRESULT GetModuleId(ICorDebugModule *pModule, std::string &id);
-
-HRESULT GetModuleWithName(const std::string &name, ICorDebugModule **ppModule);
-
-std::string GetModuleFileName(ICorDebugModule *pModule);
-
-HRESULT GetFrameLocation(ICorDebugFrame *pFrame,
-                         ULONG32 &ilOffset,
-                         Modules::SequencePoint &sequencePoint);
-
-HRESULT GetLocationInModule(ICorDebugModule *pModule,
-                            std::string filename,
-                            ULONG linenum,
-                            ULONG32 &ilOffset,
-                            mdMethodDef &methodToken,
-                            std::string &fullname);
-
-HRESULT GetLocationInAny(std::string filename,
-                         ULONG linenum,
-                         ULONG32 &ilOffset,
-                         mdMethodDef &methodToken,
-                         std::string &fullname,
-                         ICorDebugModule **ppModule);
-
-HRESULT GetStepRangeFromCurrentIP(ICorDebugThread *pThread,
-                                  COR_DEBUG_STEP_RANGE *range);
-
-HRESULT TryLoadModuleSymbols(ICorDebugModule *pModule,
-                             std::string &id,
-                             std::string &name,
-                             bool &symbolsLoaded,
-                             CORDB_ADDRESS &baseAddress,
-                             ULONG32 &size);
-
-void CleanupAllModules();
-
-HRESULT GetFrameNamedLocalVariable(
-    ICorDebugModule *pModule,
-    ICorDebugILFrame *pILFrame,
-    mdMethodDef methodToken,
-    ULONG localIndex,
-    std::string &paramName,
-    ICorDebugValue** ppValue,
-    ULONG32 *pIlStart,
-    ULONG32 *pIlEnd);
-
-HRESULT ForEachModule(std::function<HRESULT(ICorDebugModule *pModule)> cb);
-}
+    HRESULT GetModuleWithName(const std::string &name, ICorDebugModule **ppModule);
+
+    HRESULT GetFrameILAndSequencePoint(
+        ICorDebugFrame *pFrame,
+        ULONG32 &ilOffset,
+        SequencePoint &sequencePoint);
+
+    HRESULT GetLocationInModule(
+        ICorDebugModule *pModule,
+        std::string filename,
+        ULONG linenum,
+        ULONG32 &ilOffset,
+        mdMethodDef &methodToken,
+        std::string &fullname);
+
+    HRESULT GetLocationInAny(
+        std::string filename,
+        ULONG linenum,
+        ULONG32 &ilOffset,
+        mdMethodDef &methodToken,
+        std::string &fullname,
+        ICorDebugModule **ppModule);
+
+    HRESULT GetStepRangeFromCurrentIP(
+        ICorDebugThread *pThread,
+        COR_DEBUG_STEP_RANGE *range);
+
+    HRESULT TryLoadModuleSymbols(
+        ICorDebugModule *pModule,
+        std::string &id,
+        std::string &name,
+        bool &symbolsLoaded,
+        CORDB_ADDRESS &baseAddress,
+        ULONG32 &size);
+
+    void CleanupAllModules();
+
+    HRESULT GetFrameNamedLocalVariable(
+        ICorDebugModule *pModule,
+        ICorDebugILFrame *pILFrame,
+        mdMethodDef methodToken,
+        ULONG localIndex,
+        std::string &paramName,
+        ICorDebugValue** ppValue,
+        ULONG32 *pIlStart,
+        ULONG32 *pIlEnd);
+
+    HRESULT ForEachModule(std::function<HRESULT(ICorDebugModule *pModule)> cb);
+};
index fbca7f22d609cde2ca74eb70a93ab6d0132b086e..d7e84e2130f1d12e0cae3a10bb71918df4163ef9 100644 (file)
 #include <utility>
 
 #include "cputil.h"
-#include "modules.h"
 #include "typeprinter.h"
 #include "valueprint.h"
-#include "expr.h"
 #include "debugger.h"
 
 
@@ -899,7 +897,7 @@ HRESULT Evaluator::WalkStackVars(ICorDebugFrame *pFrame, WalkStackVarsCallback c
             ToRelease<ICorDebugValue> pValue;
             ULONG32 ilStart;
             ULONG32 ilEnd;
-            Status = Modules::GetFrameNamedLocalVariable(pModule, pILFrame, methodDef, i, paramName, &pValue, &ilStart, &ilEnd);
+            Status = m_modules.GetFrameNamedLocalVariable(pModule, pILFrame, methodDef, i, paramName, &pValue, &ilStart, &ilEnd);
 
             if (FAILED(Status))
                 continue;
index 61396c6f4795ee559acad7389e274e8775fa391e..ec3600fe045c22b9c30e33becfd40f487e033e9c 100644 (file)
@@ -16,9 +16,7 @@
 
 #include "debugger.h"
 #include "typeprinter.h"
-#include "modules.h"
 #include "valueprint.h"
-#include "expr.h"
 #include "frames.h"