Display more info on module loading
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Wed, 12 Jul 2017 00:53:56 +0000 (03:53 +0300)
committerIgor Kulaychuk <i.kulaychuk@samsung.com>
Mon, 13 Nov 2017 19:22:40 +0000 (22:22 +0300)
src/debug/debugger/main.cpp
src/debug/debugger/modules.cpp
src/debug/debugger/symbolreader.h

index 974a9d6..046c23f 100644 (file)
@@ -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;
         }
index 56d23cc..418a643 100644 (file)
@@ -10,6 +10,7 @@
 #include <memory>
 #include <unordered_map>
 #include <vector>
+#include <iomanip>
 
 #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<IUnknown> pMDUnknown;
     ToRelease<IMetaDataImport> 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<int>(mvid.Data4[0]) & 0xFF)
+    << std::setfill('0') << std::setw(2) << (static_cast<int>(mvid.Data4[1]) & 0xFF)
+    << "-";
+    for (int i = 2; i < 8; i++)
+        ss << std::setfill('0') << std::setw(2) << (static_cast<int>(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<IUnknown> pMDUnknown;
+    ToRelease<IMetaDataImport> pMDImport;
+    IfFailRet(pModule->GetMetaDataInterface(IID_IMetaDataImport, &pMDUnknown));
     IfFailRet(pMDUnknown->QueryInterface(IID_IMetaDataImport, (LPVOID*) &pMDImport));
 
     auto symbolReader = std::make_shared<SymbolReader>();
-    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<std::mutex> lock(g_modulesInfoMutex);
-        g_modulesInfo.insert({name, {modAddress, symbolReader}});
+        g_modulesInfo.insert({name, {baseAddress, symbolReader}});
     }
+
     return S_OK;
 }
 
index 10d7fc4..9b9d8f9 100644 (file)
@@ -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);