From 857f3bd91bb1ecfe2fd1cec015116408b3da4d20 Mon Sep 17 00:00:00 2001 From: Igor Kulaychuk Date: Wed, 12 Jul 2017 03:53:56 +0300 Subject: [PATCH] Display more info on module loading --- src/debug/debugger/main.cpp | 28 +++++++++++++++----- src/debug/debugger/modules.cpp | 54 ++++++++++++++++++++++++++++++++------- src/debug/debugger/symbolreader.h | 2 ++ 3 files changed, 69 insertions(+), 15 deletions(-) diff --git a/src/debug/debugger/main.cpp b/src/debug/debugger/main.cpp index 974a9d6..046c23f 100644 --- a/src/debug/debugger/main.cpp +++ b/src/debug/debugger/main.cpp @@ -117,7 +117,12 @@ HRESULT PrintBreakpoint(ULONG32 id, std::string &output); void SetCoreCLRPath(const std::string &coreclrPath); std::string GetModuleName(ICorDebugModule *pModule); HRESULT GetStepRangeFromCurrentIP(ICorDebugThread *pThread, COR_DEBUG_STEP_RANGE *range); -HRESULT TryLoadModuleSymbols(ICorDebugModule *pModule); +HRESULT TryLoadModuleSymbols(ICorDebugModule *pModule, + std::string &id, + std::string &name, + bool &symbolsLoaded, + CORDB_ADDRESS &baseAddress, + ULONG32 &size); HRESULT GetFrameLocation(ICorDebugFrame *pFrame, ULONG32 &ilOffset, mdMethodDef &methodToken, @@ -627,13 +632,24 @@ public: /* [in] */ ICorDebugAppDomain *pAppDomain, /* [in] */ ICorDebugModule *pModule) { - std::string name = GetModuleName(pModule); - if (!name.empty()) + std::string id; + std::string name; + bool symbolsLoaded = false; + CORDB_ADDRESS baseAddress = 0; + ULONG32 size = 0; + + TryLoadModuleSymbols(pModule, id, name, symbolsLoaded, baseAddress, size); { - out_printf("=library-loaded,target-name=\"%s\"\n", name.c_str()); + std::stringstream ss; + ss << "id=\"{" << id << "}\",target-name=\"" << name << "\"," + << "symbols-loaded=\"" << symbolsLoaded << "\"," + << "base-address=\"0x" << std::hex << baseAddress << "\"," + << "size=\"" << std::dec << size << "\""; + out_printf("=library-loaded,%s\n", ss.str().c_str()); } - TryLoadModuleSymbols(pModule); - TryResolveBreakpointsForModule(pModule); + if (symbolsLoaded) + TryResolveBreakpointsForModule(pModule); + pAppDomain->Continue(0); return S_OK; } diff --git a/src/debug/debugger/modules.cpp b/src/debug/debugger/modules.cpp index 56d23cc..418a643 100644 --- a/src/debug/debugger/modules.cpp +++ b/src/debug/debugger/modules.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "torelease.h" #include "symbolreader.h" @@ -170,30 +171,65 @@ HRESULT GetStepRangeFromCurrentIP(ICorDebugThread *pThread, COR_DEBUG_STEP_RANGE return S_OK; } -HRESULT TryLoadModuleSymbols(ICorDebugModule *pModule) +HRESULT GetModuleId(ICorDebugModule *pModule, std::string &id) { HRESULT Status; - std::string name = GetModuleName(pModule); - - if (name.empty()) - return E_FAIL; ToRelease pMDUnknown; ToRelease pMDImport; IfFailRet(pModule->GetMetaDataInterface(IID_IMetaDataImport, &pMDUnknown)); + IfFailRet(pMDUnknown->QueryInterface(IID_IMetaDataImport, (LPVOID*) &pMDImport)); + + GUID mvid; + + IfFailRet(pMDImport->GetScopeProps(nullptr, 0, nullptr, &mvid)); + + std::stringstream ss; + ss << std::hex + << std::setfill('0') << std::setw(8) << mvid.Data1 << "-" + << std::setfill('0') << std::setw(4) << mvid.Data2 << "-" + << std::setfill('0') << std::setw(4) << mvid.Data3 << "-" + << std::setfill('0') << std::setw(2) << (static_cast(mvid.Data4[0]) & 0xFF) + << std::setfill('0') << std::setw(2) << (static_cast(mvid.Data4[1]) & 0xFF) + << "-"; + for (int i = 2; i < 8; i++) + ss << std::setfill('0') << std::setw(2) << (static_cast(mvid.Data4[i]) & 0xFF); + + id = ss.str(); + + return S_OK; +} +HRESULT TryLoadModuleSymbols(ICorDebugModule *pModule, + std::string &id, + std::string &name, + bool &symbolsLoaded, + CORDB_ADDRESS &baseAddress, + ULONG32 &size) +{ + HRESULT Status; + + ToRelease pMDUnknown; + ToRelease pMDImport; + IfFailRet(pModule->GetMetaDataInterface(IID_IMetaDataImport, &pMDUnknown)); IfFailRet(pMDUnknown->QueryInterface(IID_IMetaDataImport, (LPVOID*) &pMDImport)); auto symbolReader = std::make_shared(); - IfFailRet(symbolReader->LoadSymbols(pMDImport, pModule)); + symbolReader->LoadSymbols(pMDImport, pModule); + symbolsLoaded = symbolReader->SymbolsLoaded(); - CORDB_ADDRESS modAddress; - pModule->GetBaseAddress(&modAddress); + name = GetModuleName(pModule); + + IfFailRet(GetModuleId(pModule, id)); + + IfFailRet(pModule->GetBaseAddress(&baseAddress)); + IfFailRet(pModule->GetSize(&size)); { std::lock_guard lock(g_modulesInfoMutex); - g_modulesInfo.insert({name, {modAddress, symbolReader}}); + g_modulesInfo.insert({name, {baseAddress, symbolReader}}); } + return S_OK; } diff --git a/src/debug/debugger/symbolreader.h b/src/debug/debugger/symbolreader.h index 10d7fc4..9b9d8f9 100644 --- a/src/debug/debugger/symbolreader.h +++ b/src/debug/debugger/symbolreader.h @@ -51,6 +51,8 @@ public: } } + bool SymbolsLoaded() const { return m_symbolReaderHandle != 0; } + static void SetCoreCLRPath(const std::string &path) { coreClrPath = path; } HRESULT LoadSymbols(IMetaDataImport* pMD, ICorDebugModule* pModule); -- 2.7.4