#include <unordered_set>
#include "debugger.h"
-#include "modules.h"
Debugger::ManagedBreakpoint::ManagedBreakpoint() :
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);
ULONG32 ilOffset;
std::string fullname;
- IfFailRet(Modules::GetLocationInModule(
+ IfFailRet(m_modules.GetLocationInModule(
pModule,
bp.fullname,
bp.linenum,
ToRelease<ICorDebugModule> pModule;
- IfFailRet(Modules::GetLocationInAny(
+ IfFailRet(m_modules.GetLocationInAny(
bp.fullname,
bp.linenum,
ilOffset,
#include "platform.h"
#include "debugger.h"
-#include "modules.h"
#include "frames.h"
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 {
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,
// 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>
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;
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> ¶ms,
+ ICorDebugThread *pThread,
+ std::vector< ToRelease<ICorDebugType> > &types);
+
public:
+ Evaluator(Modules &modules) : m_modules(modules) {}
+
HRESULT RunClassConstructor(ICorDebugThread *pThread, ICorDebugValue *pValue);
HRESULT EvalFunction(
std::function<void(const std::string&)> cb
);
+ HRESULT GetType(
+ const std::string &typeName,
+ ICorDebugThread *pThread,
+ ICorDebugType **ppType);
+
HRESULT WalkMembers(
ICorDebugValue *pValue,
ICorDebugThread *pThread,
void SetLastStoppedThread(ICorDebugThread *pThread);
+ Modules m_modules;
Evaluator m_evaluator;
Protocol *m_protocol;
ManagedCallback *m_managedCallback;
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();
#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)
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");
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;
return S_OK;
}
-HRESULT ResolveParameters(const std::vector<std::string> ¶ms,
- ICorDebugThread *pThread,
- std::vector< ToRelease<ICorDebugType> > &types)
+HRESULT Evaluator::ResolveParameters(
+ const std::vector<std::string> ¶ms,
+ ICorDebugThread *pThread,
+ std::vector< ToRelease<ICorDebugType> > &types)
{
HRESULT Status;
for (auto &p : 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;
if (!pTypeModule)
{
- Modules::ForEachModule([&](ICorDebugModule *pModule)->HRESULT {
+ m_modules.ForEachModule([&](ICorDebugModule *pModule)->HRESULT {
if (typeToken != mdTypeDefNil) // already found
return S_OK;
+++ /dev/null
-// 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);
#include "typeprinter.h"
#include "platform.h"
#include "debugger.h"
-#include "modules.h"
#include "frames.h"
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;
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;
}
}
-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;
// 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);
#include "platform.h"
#include "typeprinter.h"
#include "debugger.h"
-#include "modules.h"
#include "frames.h"
#define __in
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);
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;
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);
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 << "}\","
Debugger::Debugger() :
m_processAttachedState(ProcessUnattached),
+ m_evaluator(m_modules),
m_managedCallback(new ManagedCallback()),
m_pDebug(nullptr),
m_pProcess(nullptr),
void Debugger::Cleanup()
{
- Modules::CleanupAllModules();
+ m_modules.CleanupAllModules();
m_evaluator.Cleanup();
m_protocol->Cleanup();
// TODO: Cleanup libcoreclr.so instance
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;
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;
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;
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;
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;
}
return S_OK;
}
-HRESULT GetFrameLocation(ICorDebugFrame *pFrame,
- ULONG32 &ilOffset,
- Modules::SequencePoint &sequencePoint)
+HRESULT Modules::GetFrameILAndSequencePoint(
+ ICorDebugFrame *pFrame,
+ ULONG32 &ilOffset,
+ Modules::SequencePoint &sequencePoint)
{
HRESULT Status;
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;
}
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;
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;
}
return S_OK;
}
-HRESULT GetModuleId(ICorDebugModule *pModule, std::string &id)
+HRESULT Modules::GetModuleId(ICorDebugModule *pModule, std::string &id)
{
HRESULT Status;
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;
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,
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;
}
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;
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
// 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 ¶mName,
- 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 ¶mName,
+ ICorDebugValue** ppValue,
+ ULONG32 *pIlStart,
+ ULONG32 *pIlEnd);
+
+ HRESULT ForEachModule(std::function<HRESULT(ICorDebugModule *pModule)> cb);
+};
#include <utility>
#include "cputil.h"
-#include "modules.h"
#include "typeprinter.h"
#include "valueprint.h"
-#include "expr.h"
#include "debugger.h"
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;
#include "debugger.h"
#include "typeprinter.h"
-#include "modules.h"
#include "valueprint.h"
-#include "expr.h"
#include "frames.h"