Fix handling module paths with /proc/self prefix on Tizen
authorIgor Kulaychuk <i.kulaychuk@samsung.com>
Mon, 9 Apr 2018 11:48:54 +0000 (14:48 +0300)
committerIgor Kulaychuk <i.kulaychuk@samsung.com>
Mon, 9 Apr 2018 16:12:11 +0000 (19:12 +0300)
src/debug/netcoredbg/modules.cpp
src/debug/netcoredbg/symbolreader.cpp
src/debug/netcoredbg/symbolreader.h

index 4cb7e700a6935d40f1a70ba4ce3cfebef57aa19a..c8ab3b767b4789fa520c68af24a4dbdadd870a7b 100644 (file)
@@ -23,11 +23,31 @@ std::string Modules::GetModuleFileName(ICorDebugModule *pModule)
 {
     WCHAR name[mdNameLen];
     ULONG32 name_len = 0;
-    if (SUCCEEDED(pModule->GetName(_countof(name), &name_len, name)))
-    {
-        return to_utf8(name/*, name_len*/);
-    }
-    return std::string();
+
+    if (FAILED(pModule->GetName(_countof(name), &name_len, name)))
+        return std::string();
+
+    std::string moduleName = to_utf8(name/*, name_len*/);
+
+    // On Tizen platform module path may look like /proc/self/fd/8/bin/Xamarin.Forms.Platform.dll
+    // This path is invalid in debugger process, we shoud change `self` to `<debugee process id>`
+    static const std::string selfPrefix("/proc/self/");
+
+    if (moduleName.compare(0, selfPrefix.size(), selfPrefix) != 0)
+        return moduleName;
+
+    ToRelease<ICorDebugProcess> pProcess;
+    if (FAILED(pModule->GetProcess(&pProcess)))
+        return std::string();
+
+    DWORD pid = 0;
+
+    if (FAILED(pProcess->GetID(&pid)))
+        return std::string();
+
+    std::ostringstream ss;
+    ss << "/proc/" << pid << "/" << moduleName.substr(selfPrefix.size());
+    return ss.str();
 }
 
 HRESULT Modules::GetLocationInAny(
index 71c1c84a9947b6b99cae38c3e1460f1e0b030c90..29975ac2ea13f57830a89e38b91f241ae5ea8267 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <coreclrhost.h>
 
+#include "modules.h"
 #include "platform.h"
 #include "torelease.h"
 #include "cputil.h"
@@ -61,11 +62,15 @@ HRESULT SymbolReader::LoadSymbols(IMetaDataImport* pMD, ICorDebugModule* pModule
     IfFailRet(pModule->GetBaseAddress(&peAddress));
     IfFailRet(pModule->GetSize(&peSize));
 
-    ULONG32 len = 0;
-    WCHAR moduleName[MAX_LONGPATH];
-    IfFailRet(pModule->GetName(_countof(moduleName), &len, moduleName));
-
-    return LoadSymbolsForPortablePDB(moduleName, isInMemory, isInMemory, peAddress, peSize, 0, 0);
+    return LoadSymbolsForPortablePDB(
+        Modules::GetModuleFileName(pModule),
+        isInMemory,
+        isInMemory, // isFileLayout
+        peAddress,
+        peSize,
+        0,          // inMemoryPdbAddress
+        0           // inMemoryPdbSize
+    );
 }
 
 //
@@ -83,7 +88,7 @@ int ReadMemoryForSymbols(ULONG64 address, char *buffer, int cb)
 }
 
 HRESULT SymbolReader::LoadSymbolsForPortablePDB(
-    WCHAR* pModuleName,
+    const std::string &modulePath,
     BOOL isInMemory,
     BOOL isFileLayout,
     ULONG64 peAddress,
@@ -100,11 +105,9 @@ HRESULT SymbolReader::LoadSymbolsForPortablePDB(
 
     // The module name needs to be null for in-memory PE's.
     const char *szModuleName = nullptr;
-    std::string moduleName;
-    if (!isInMemory && pModuleName != nullptr)
+    if (!isInMemory && !modulePath.empty())
     {
-        moduleName = to_utf8(pModuleName);
-        szModuleName = moduleName.c_str();
+        szModuleName = modulePath.c_str();
     }
 
     m_symbolReaderHandle = loadSymbolsForModuleDelegate(szModuleName, isFileLayout, peAddress,
index bb76f3589bb1de50c41626ca040331a52580ac65..7de8114aee8ec1331da18d364555c4e4ba636f5b 100644 (file)
@@ -54,7 +54,7 @@ private:
     static HRESULT PrepareSymbolReader();
 
     HRESULT LoadSymbolsForPortablePDB(
-        WCHAR* pModuleName,
+        const std::string &modulePath,
         BOOL isInMemory,
         BOOL isFileLayout,
         ULONG64 peAddress,