From: Igor Kulaychuk Date: Mon, 9 Apr 2018 11:48:54 +0000 (+0300) Subject: Fix handling module paths with /proc/self prefix on Tizen X-Git-Tag: submit/tizen/20180620.071641~12^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=45ee6fe704ef86df02edbf5ff42279e7c54ef703;p=sdk%2Ftools%2Fnetcoredbg.git Fix handling module paths with /proc/self prefix on Tizen --- diff --git a/src/debug/netcoredbg/modules.cpp b/src/debug/netcoredbg/modules.cpp index 4cb7e70..c8ab3b7 100644 --- a/src/debug/netcoredbg/modules.cpp +++ b/src/debug/netcoredbg/modules.cpp @@ -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 `` + static const std::string selfPrefix("/proc/self/"); + + if (moduleName.compare(0, selfPrefix.size(), selfPrefix) != 0) + return moduleName; + + ToRelease 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( diff --git a/src/debug/netcoredbg/symbolreader.cpp b/src/debug/netcoredbg/symbolreader.cpp index 71c1c84..29975ac 100644 --- a/src/debug/netcoredbg/symbolreader.cpp +++ b/src/debug/netcoredbg/symbolreader.cpp @@ -8,6 +8,7 @@ #include +#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, diff --git a/src/debug/netcoredbg/symbolreader.h b/src/debug/netcoredbg/symbolreader.h index bb76f35..7de8114 100644 --- a/src/debug/netcoredbg/symbolreader.h +++ b/src/debug/netcoredbg/symbolreader.h @@ -54,7 +54,7 @@ private: static HRESULT PrepareSymbolReader(); HRESULT LoadSymbolsForPortablePDB( - WCHAR* pModuleName, + const std::string &modulePath, BOOL isInMemory, BOOL isFileLayout, ULONG64 peAddress,