diff --git a/src/ToolBox/SOS/Strike/CMakeLists.txt b/src/ToolBox/SOS/Strike/CMakeLists.txt index c474574a0885..c4e9b1029e92 100644 --- a/src/ToolBox/SOS/Strike/CMakeLists.txt +++ b/src/ToolBox/SOS/Strike/CMakeLists.txt @@ -138,6 +138,7 @@ else(WIN32) dbgutil # share the PAL in the dac module mscordaccore + palrt ) set(DEF_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/sos_unixexports.src) diff --git a/src/ToolBox/SOS/Strike/strike.cpp b/src/ToolBox/SOS/Strike/strike.cpp index ceffb8af5118..18230c945c42 100644 --- a/src/ToolBox/SOS/Strike/strike.cpp +++ b/src/ToolBox/SOS/Strike/strike.cpp @@ -11562,12 +11562,10 @@ class ClrStackImplWithICorDebug IfFailRet(pLocalsEnum->GetCount(&cLocals)); if (cLocals > 0 && bLocals) { -#ifndef FEATURE_PAL bool symbolsAvailable = false; SymbolReader symReader; if(SUCCEEDED(symReader.LoadSymbols(pMD, pModule))) symbolsAvailable = true; -#endif ExtOut("\nLOCALS:\n"); for (ULONG i=0; i < cLocals; i++) { @@ -11575,13 +11573,11 @@ class ClrStackImplWithICorDebug WCHAR paramName[mdNameLen] = W("\0"); ToRelease pValue; -#ifndef FEATURE_PAL if(symbolsAvailable) { Status = symReader.GetNamedLocalVariable(pILFrame, i, paramName, mdNameLen, &pValue); } else -#endif { ULONG cArgsFetched; Status = pLocalsEnum->Next(1, &pValue, &cArgsFetched); diff --git a/src/ToolBox/SOS/Strike/util.cpp b/src/ToolBox/SOS/Strike/util.cpp index 565b47d208d7..0fb114fd2f83 100644 --- a/src/ToolBox/SOS/Strike/util.cpp +++ b/src/ToolBox/SOS/Strike/util.cpp @@ -52,6 +52,7 @@ PIMAGEHLP_SYMBOL sym = (PIMAGEHLP_SYMBOL) symBuffer; void *SymbolReader::coreclrLib; ResolveSequencePointDelegate SymbolReader::resolveSequencePointDelegate; LoadSymbolsForModuleDelegate SymbolReader::loadSymbolsForModuleDelegate; +GetLocalVariableName SymbolReader::getLocalVariableNameDelegate; #endif // !FEATURE_PAL const char * const CorElementTypeName[ELEMENT_TYPE_MAX]= @@ -6208,16 +6209,19 @@ HRESULT SymbolReader::LoadSymbols(IMetaDataImport * pMD, ICorDebugModule * pModu } #ifdef FEATURE_PAL -bool SymbolReader::SymbolReaderDllExists() { +bool SymbolReader::SymbolReaderDllExists() +{ struct stat sb; std::string SymbolReaderDll(SymbolReaderDllName); SymbolReaderDll += ".dll"; - if (stat(SymbolReaderDll.c_str(), &sb) == -1) { + if (stat(SymbolReaderDll.c_str(), &sb) == -1) + { return false; } return true; } -HRESULT SymbolReader::LoadCoreCLR() { +HRESULT SymbolReader::LoadCoreCLR() +{ HRESULT Status = S_OK; std::string absolutePath, coreClrPath; @@ -6259,7 +6263,8 @@ HRESULT SymbolReader::LoadCoreCLR() { "UseLatestBehaviorWhenTFMNotSpecified"}; std::string entryPointExecutablePath; - if (!GetEntrypointExecutableAbsolutePath(entryPointExecutablePath)) { + if (!GetEntrypointExecutableAbsolutePath(entryPointExecutablePath)) + { perror("Could not get full path to current executable"); return E_FAIL; } @@ -6268,7 +6273,8 @@ HRESULT SymbolReader::LoadCoreCLR() { initializeCoreCLR(entryPointExecutablePath.c_str(), "soscorerun", sizeof(propertyKeys) / sizeof(propertyKeys[0]), propertyKeys, propertyValues, &hostHandle, &domainId); - if (Status != S_OK) { + if (Status != S_OK) + { fprintf(stderr, "Error: Fail to initialize CoreCLR\n"); return Status; } @@ -6276,14 +6282,15 @@ HRESULT SymbolReader::LoadCoreCLR() { coreclr_create_delegate_ptr CreateDelegate = (coreclr_create_delegate_ptr)dlsym(coreclrLib, "coreclr_create_delegate"); - Status = CreateDelegate(hostHandle, domainId, SymbolReaderDllName, + IfFailRet(CreateDelegate(hostHandle, domainId, SymbolReaderDllName, SymbolReaderClassName, "ResolveSequencePoint", - (void **)&resolveSequencePointDelegate); - IfFailRet(Status); - Status = CreateDelegate(hostHandle, domainId, SymbolReaderDllName, + (void **)&resolveSequencePointDelegate)); + IfFailRet(CreateDelegate(hostHandle, domainId, SymbolReaderDllName, SymbolReaderClassName, "LoadSymbolsForModule", - (void **)&loadSymbolsForModuleDelegate); - IfFailRet(Status); + (void **)&loadSymbolsForModuleDelegate)); + IfFailRet(CreateDelegate(hostHandle, domainId, SymbolReaderDllName, + SymbolReaderClassName, "GetLocalVariableName", + (void **)&getLocalVariableNameDelegate)); return Status; } #endif //FEATURE_PAL @@ -6357,26 +6364,62 @@ HRESULT SymbolReader::LoadSymbols(IMetaDataImport * pMD, ULONG64 baseAddress, __ } return Status; #else - if (loadSymbolsForModuleDelegate == nullptr) { + if (loadSymbolsForModuleDelegate == nullptr) + { Status = LoadCoreCLR(); } if (Status != S_OK) + { return Status; + } - char szName[mdNameLen]; WideCharToMultiByte(CP_ACP, 0, pModuleName, (int) (_wcslen(pModuleName) + 1), - szName, mdNameLen, NULL, NULL); - return !loadSymbolsForModuleDelegate(szName); + m_szModuleName, mdNameLen, NULL, NULL); + return !loadSymbolsForModuleDelegate(m_szModuleName); #endif // FEATURE_PAL } HRESULT SymbolReader::GetNamedLocalVariable(ISymUnmanagedScope * pScope, ICorDebugILFrame * pILFrame, mdMethodDef methodToken, ULONG localIndex, __inout_ecount(paramNameLen) WCHAR* paramName, ULONG paramNameLen, ICorDebugValue** ppValue) { HRESULT Status = S_OK; +#ifdef FEATURE_PAL + if (getLocalVariableNameDelegate == nullptr) + { + Status = LoadCoreCLR(); + } + if (Status != S_OK) + { + return Status; + } + BSTR wszParamName = SysAllocStringLen(0, mdNameLen); + if (wszParamName == NULL) + { + return E_OUTOFMEMORY; + } + int ret = getLocalVariableNameDelegate(m_szModuleName, methodToken, + localIndex, &wszParamName); + if (ret) + { + wcscpy_s(paramName, _wcslen(wszParamName) + 1, wszParamName); + paramNameLen = _wcslen(paramName); + SysFreeString(wszParamName); + + if (SUCCEEDED(pILFrame->GetLocalVariable(localIndex, ppValue)) && (*ppValue != NULL)) + { + return S_OK; + } + else + { + *ppValue = NULL; + return E_FAIL; + } + } + SysFreeString(wszParamName); + return E_FAIL; +#else if(pScope == NULL) { -#ifndef FEATURE_PAL ToRelease pSymMethod; IfFailRet(m_pSymReader->GetMethod(methodToken, &pSymMethod)); @@ -6384,9 +6427,6 @@ HRESULT SymbolReader::GetNamedLocalVariable(ISymUnmanagedScope * pScope, ICorDeb IfFailRet(pSymMethod->GetRootScope(&pScope)); return GetNamedLocalVariable(pScope, pILFrame, methodToken, localIndex, paramName, paramNameLen, ppValue); -#else - return E_FAIL; -#endif // FEATURE_PAL } else { @@ -6404,7 +6444,7 @@ HRESULT SymbolReader::GetNamedLocalVariable(ISymUnmanagedScope * pScope, ICorDeb if(varIndexInMethod != localIndex) continue; - ULONG32 nameLen = 0; + ULONG32 nameLen = 0; if(FAILED(pLocals[i]->GetName(paramNameLen, &nameLen, paramName))) swprintf_s(paramName, paramNameLen, W("local_%d\0"), localIndex); @@ -6440,7 +6480,9 @@ HRESULT SymbolReader::GetNamedLocalVariable(ISymUnmanagedScope * pScope, ICorDeb for(ULONG j = 0; j < numChildren; j++) pChildren[j]->Release(); } + return E_FAIL; +#endif // FEATURE_PAL } HRESULT SymbolReader::GetNamedLocalVariable(ICorDebugFrame * pFrame, ULONG localIndex, __inout_ecount(paramNameLen) WCHAR* paramName, ULONG paramNameLen, ICorDebugValue** ppValue) @@ -6529,11 +6571,14 @@ HRESULT SymbolReader::ResolveSequencePoint(__in_z WCHAR* pFilename, ULONG32 line } return E_FAIL; #else - if (loadSymbolsForModuleDelegate == nullptr) { + if (loadSymbolsForModuleDelegate == nullptr) + { Status = LoadCoreCLR(); } if (Status != S_OK) + { return Status; + } char szName[mdNameLen]; WideCharToMultiByte(CP_ACP, 0, pFilename, (int) (_wcslen(pFilename) + 1), diff --git a/src/ToolBox/SOS/Strike/util.h b/src/ToolBox/SOS/Strike/util.h index f1003bc6587c..1fe9f8ea3d07 100644 --- a/src/ToolBox/SOS/Strike/util.h +++ b/src/ToolBox/SOS/Strike/util.h @@ -2358,6 +2358,7 @@ class PERvaMemoryReader : IDiaReadExeAtRVACallback #ifdef FEATURE_PAL typedef int (*ResolveSequencePointDelegate)(const char*, const char*, unsigned int, unsigned int*, unsigned int*); typedef int (*LoadSymbolsForModuleDelegate)(const char*); +typedef int (*GetLocalVariableName)(const char*, int, int, BSTR*); static const char *SymbolReaderDllName = "System.Diagnostics.Debug.SymbolReader"; static const char *SymbolReaderClassName = "System.Diagnostics.Debug.SymbolReader.SymbolReader"; #endif //FEATURE_PAL @@ -2368,8 +2369,10 @@ class SymbolReader ISymUnmanagedReader* m_pSymReader; #ifdef FEATURE_PAL static void *coreclrLib; + char m_szModuleName[mdNameLen]; static ResolveSequencePointDelegate resolveSequencePointDelegate; static LoadSymbolsForModuleDelegate loadSymbolsForModuleDelegate; + static GetLocalVariableName getLocalVariableNameDelegate; #endif private: