Added symbols loading when loading in-memory modules
authorThanik Kanagaratnam <thanik1234@gmail.com>
Sat, 17 Feb 2024 19:36:15 +0000 (14:36 -0500)
committerGleb Balykov/Advanced System SW Lab /SRR/Staff Engineer/Samsung Electronics <g.balykov@samsung.com>
Mon, 18 Mar 2024 12:14:37 +0000 (15:14 +0300)
src/managed/interop.cpp
src/metadata/modules.cpp

index 7c4664962552f042cd808f564411942c857aa210..7396dbf6dfc9017601a0fabad8e00c89c2182252 100644 (file)
@@ -111,9 +111,11 @@ constexpr char UtilsClassName[] = "NetCoreDbg.Utils";
 // Returns the number of bytes read.
 int ReadMemoryForSymbols(uint64_t address, char *buffer, int cb)
 {
-    // TODO: In-memory PDB?
-    // OSPageSize() for Linux/Windows already implemented in code.
-    return 0;
+    if (address == 0 || buffer == 0 || cb == 0)
+        return 0;
+
+    std::memcpy(buffer, (const void*) address, cb);
+    return cb;
 }
 
 } // unnamed namespace
index 7ec0e2ea1e5bfce4c763422d764e42302c4d8d8a..26cc23a481294d05802b0907ae0c85ed54311195 100644 (file)
@@ -493,11 +493,29 @@ static HRESULT LoadSymbols(IMetaDataImport *pMD, ICorDebugModule *pModule, VOID
     IfFailRet(pModule->GetBaseAddress(&peAddress));
     IfFailRet(pModule->GetSize(&peSize));
 
+    std::vector<unsigned char> peBuf;
+    ULONG64 peBufAddress = 0;
+    if (isInMemory)
+    {
+        ICorDebugProcess* process = 0;
+        IfFailRet(pModule->GetProcess(&process));
+
+        if (peAddress != 0 && peSize != 0)
+        {
+            peBuf.resize(peSize);
+            peBufAddress = (ULONG64)&peBuf[0];
+            SIZE_T read = 0;
+            IfFailRet(process->ReadMemory(peAddress, peSize, &peBuf[0], &read));
+            if (read != peSize)
+                return E_FAIL;
+        }
+    }
+
     return Interop::LoadSymbolsForPortablePDB(
         GetModuleFileName(pModule),
         isInMemory,
         isInMemory, // isFileLayout
-        peAddress,
+        peBufAddress,
         peSize,
         0,          // inMemoryPdbAddress
         0,          // inMemoryPdbSize