From: Steve MacLean Date: Mon, 23 Mar 2020 19:04:17 +0000 (-0400) Subject: Fix Runtime::GetRuntime*Name() for cross-dac (#930) X-Git-Tag: submit/tizen_5.5/20200504.045052~11^2^2~45 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0669422a056b68e7517759ff61b8efb39de49219;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Fix Runtime::GetRuntime*Name() for cross-dac (#930) * Fix Runtime::GetRuntime*Name() for cross-dac * Refactor GetRuntime*Name() Add IRuntime::RuntimeConfiguration Add IRuntime::GetRuntimeConfiguration() Remove IRuntime::IsDesktop() Remove NETCORE_RUNTIME* Remove DESKTOP_RUNTIME* --- diff --git a/src/SOS/SOS.UnitTests/Scripts/DualRuntimes.script b/src/SOS/SOS.UnitTests/Scripts/DualRuntimes.script index 954d5fea3..32368122f 100644 --- a/src/SOS/SOS.UnitTests/Scripts/DualRuntimes.script +++ b/src/SOS/SOS.UnitTests/Scripts/DualRuntimes.script @@ -69,7 +69,7 @@ VERIFY:\s*Total\s+\s+objects\s+ # SOSCOMMAND:SOSStatus -VERIFY:.*\.NET Core runtime at.*\s+ +VERIFY:.*\.NET Core .*runtime at.*\s+ IFDEF:TRIAGE_DUMP SOSCOMMAND:setclrpath %DESKTOP_RUNTIME_PATH% diff --git a/src/SOS/Strike/EventCallbacks.cpp b/src/SOS/Strike/EventCallbacks.cpp index bdef2f9e6..2c5813af5 100644 --- a/src/SOS/Strike/EventCallbacks.cpp +++ b/src/SOS/Strike/EventCallbacks.cpp @@ -135,12 +135,19 @@ HRESULT __stdcall EventCallbacks::LoadModule(ULONG64 ImageFileHandle, { HRESULT handleEventStatus = DEBUG_STATUS_NO_CHANGE; - if (ModuleName != NULL) + if (ModuleName != NULL) { - bool isNetCore = _stricmp(ModuleName, NETCORE_RUNTIME_MODULE_NAME_A) == 0; - bool isDesktop = _stricmp(ModuleName, DESKTOP_RUNTIME_MODULE_NAME_A) == 0; + bool isRuntimeModule = false; + for (int runtime = 0; runtime < IRuntime::ConfigurationEnd; ++runtime) + { + if (_stricmp(ModuleName, GetRuntimeModuleName((IRuntime::RuntimeConfiguration)runtime)) == 0) + { + isRuntimeModule = true; + break; + } + } - if (isNetCore || isDesktop) + if (isRuntimeModule) { if (g_breakOnRuntimeModuleLoad) { diff --git a/src/SOS/Strike/exts.h b/src/SOS/Strike/exts.h index 2d630b87b..d109637a1 100644 --- a/src/SOS/Strike/exts.h +++ b/src/SOS/Strike/exts.h @@ -197,9 +197,9 @@ public: inline void EENotLoadedMessage(HRESULT Status) { #ifdef FEATURE_PAL - ExtOut("Failed to find runtime module (%s), 0x%08x\n", NETCORE_RUNTIME_DLL_NAME_A, Status); + ExtOut("Failed to find runtime module (%s), 0x%08x\n", GetRuntimeDllName(IRuntime::Core), Status); #else - ExtOut("Failed to find runtime module (%s or %s), 0x%08x\n", NETCORE_RUNTIME_DLL_NAME_A, DESKTOP_RUNTIME_DLL_NAME_A, Status); + ExtOut("Failed to find runtime module (%s or %s or %s), 0x%08x\n", GetRuntimeDllName(IRuntime::Core), GetRuntimeDllName(IRuntime::WindowsDesktop), GetRuntimeDllName(IRuntime::UnixCore), Status); #endif ExtOut("Extension commands need it in order to have something to do.\n"); } diff --git a/src/SOS/Strike/hostcoreclr.cpp b/src/SOS/Strike/hostcoreclr.cpp index 731401a48..1e791369c 100644 --- a/src/SOS/Strike/hostcoreclr.cpp +++ b/src/SOS/Strike/hostcoreclr.cpp @@ -368,7 +368,7 @@ static HRESULT GetHostRuntime(std::string& coreClrPath, std::string& hostRuntime return hr; } // Don't use the desktop runtime to host - if (g_pRuntime->IsDesktop()) + if (g_pRuntime->GetRuntimeConfiguration() == IRuntime::WindowsDesktop) { return E_FAIL; } @@ -391,7 +391,7 @@ static HRESULT GetHostRuntime(std::string& coreClrPath, std::string& hostRuntime hostRuntimeDirectory.assign(g_hostRuntimeDirectory); coreClrPath.assign(g_hostRuntimeDirectory); coreClrPath.append(DIRECTORY_SEPARATOR_STR_A); - coreClrPath.append(NETCORE_RUNTIME_DLL_NAME_A); + coreClrPath.append(GetRuntimeDllName(IRuntime::Core)); return S_OK; } @@ -732,7 +732,7 @@ void InitializeSymbolStoreFromSymPath() // static void SymbolFileCallback(void* param, const char* moduleFileName, const char* symbolFilePath) { - if (strcmp(moduleFileName, NETCORE_RUNTIME_DLL_NAME_A) == 0) { + if (strcmp(moduleFileName, GetRuntimeDllName(IRuntime::Core)) == 0) { return; } if (strcmp(moduleFileName, NETCORE_DAC_DLL_NAME_A) == 0) { diff --git a/src/SOS/Strike/runtime.cpp b/src/SOS/Strike/runtime.cpp index a84ea2fad..60004e8e1 100644 --- a/src/SOS/Strike/runtime.cpp +++ b/src/SOS/Strike/runtime.cpp @@ -33,7 +33,7 @@ Runtime* Runtime::s_desktop = nullptr; #endif // Used to initialize the runtime instance with values from the host when under dotnet-dump -bool Runtime::s_isDesktop = false; +IRuntime::RuntimeConfiguration Runtime::s_configuration = IRuntime::Core; LPCSTR Runtime::s_dacFilePath = nullptr; LPCSTR Runtime::s_dbiFilePath = nullptr; @@ -46,9 +46,9 @@ IRuntime* g_pRuntime = nullptr; /**********************************************************************\ * Creates a desktop or .NET Core instance of the runtime class \**********************************************************************/ -HRESULT Runtime::CreateInstance(bool isDesktop, Runtime **ppRuntime) +HRESULT Runtime::CreateInstance(RuntimeConfiguration configuration, Runtime **ppRuntime) { - PCSTR runtimeModuleName = isDesktop ? DESKTOP_RUNTIME_MODULE_NAME_A : NETCORE_RUNTIME_MODULE_NAME_A; + PCSTR runtimeModuleName = GetRuntimeModuleName(configuration); ULONG moduleIndex = 0; ULONG64 moduleAddress = 0; ULONG64 moduleSize = 0; @@ -57,15 +57,6 @@ HRESULT Runtime::CreateInstance(bool isDesktop, Runtime **ppRuntime) if (*ppRuntime == nullptr) { hr = g_ExtSymbols->GetModuleByModuleName(runtimeModuleName, 0, &moduleIndex, &moduleAddress); -#ifndef FEATURE_PAL - // On Windows, support loading a Linux core dump by checking for NETCORE_RUNTIME_MODULE_NAME_UNIX_A too - if (!SUCCEEDED(hr) && !isDesktop) - { - runtimeModuleName = NETCORE_RUNTIME_MODULE_NAME_UNIX_A; - - hr = g_ExtSymbols->GetModuleByModuleName(runtimeModuleName, 0, &moduleIndex, &moduleAddress); - } -#endif // !FEATURE_PAL if (SUCCEEDED(hr)) { #ifdef FEATURE_PAL @@ -99,7 +90,7 @@ HRESULT Runtime::CreateInstance(bool isDesktop, Runtime **ppRuntime) { if (moduleSize > 0) { - *ppRuntime = new Runtime(isDesktop, moduleIndex, moduleAddress, moduleSize); + *ppRuntime = new Runtime(configuration, moduleIndex, moduleAddress, moduleSize); OnUnloadTask::Register(CleanupRuntimes); } else @@ -124,13 +115,17 @@ HRESULT Runtime::CreateInstance() HRESULT hr = S_OK; if (g_pRuntime == nullptr) { - hr = CreateInstance(false, &s_netcore); + hr = CreateInstance(IRuntime::Core, &s_netcore); #ifdef FEATURE_PAL g_pRuntime = s_netcore; #else if (FAILED(hr)) { - hr = CreateInstance(true, &s_desktop); + hr = CreateInstance(IRuntime::UnixCore, &s_netcore); + } + if (FAILED(hr)) + { + hr = CreateInstance(IRuntime::WindowsDesktop, &s_desktop); } g_pRuntime = s_netcore != nullptr ? s_netcore : s_desktop; #endif @@ -146,7 +141,7 @@ HRESULT Runtime::CreateInstance() bool Runtime::SwitchRuntime(bool desktop) { if (desktop) { - CreateInstance(true, &s_desktop); + CreateInstance(IRuntime::WindowsDesktop, &s_desktop); } IRuntime* runtime = desktop ? s_desktop : s_netcore; if (runtime == nullptr) { @@ -477,7 +472,7 @@ HRESULT Runtime::GetCorDebugInterface(ICorDebugProcess** ppCorDebugProcess) GUID skuId = CLR_ID_CORECLR; #endif #ifndef FEATURE_PAL - if (IsDesktop()) + if (GetRuntimeConfiguration() == IRuntime::WindowsDesktop) { skuId = CLR_ID_V4_DESKTOP; } @@ -530,7 +525,7 @@ HRESULT Runtime::GetCorDebugInterface(ICorDebugProcess** ppCorDebugProcess) \**********************************************************************/ void Runtime::DisplayStatus() { - ExtOut("%s runtime at %p (%08x)\n", m_isDesktop ? "Desktop" : ".NET Core", m_address, m_size); + ExtOut("%s runtime at %p (%08x)\n", GetRuntimeConfigurationName(GetRuntimeConfiguration()), m_address, m_size); if (m_runtimeDirectory != nullptr) { ExtOut("Runtime directory: %s\n", m_runtimeDirectory); } diff --git a/src/SOS/Strike/runtime.h b/src/SOS/Strike/runtime.h index fdae98432..561b9416d 100644 --- a/src/SOS/Strike/runtime.h +++ b/src/SOS/Strike/runtime.h @@ -7,11 +7,6 @@ #ifdef FEATURE_PAL -#define NETCORE_RUNTIME_MODULE_NAME_W MAKEDLLNAME_W(W("coreclr")) -#define NETCORE_RUNTIME_MODULE_NAME_A MAKEDLLNAME_A("coreclr") -#define NETCORE_RUNTIME_DLL_NAME_W NETCORE_RUNTIME_MODULE_NAME_W -#define NETCORE_RUNTIME_DLL_NAME_A NETCORE_RUNTIME_MODULE_NAME_A - #define NETCORE_DAC_MODULE_NAME_W MAKEDLLNAME_W(W("mscordaccore")) #define NETCORE_DAC_MODULE_NAME_A MAKEDLLNAME_A("mscordaccore") #define NETCORE_DAC_DLL_NAME_W NETCORE_DAC_MODULE_NAME_W @@ -24,13 +19,6 @@ #else -#define NETCORE_RUNTIME_MODULE_NAME_UNIX_A "libcoreclr" - -#define NETCORE_RUNTIME_MODULE_NAME_W W("coreclr") -#define NETCORE_RUNTIME_MODULE_NAME_A "coreclr" -#define NETCORE_RUNTIME_DLL_NAME_W MAKEDLLNAME_W(NETCORE_RUNTIME_MODULE_NAME_W) -#define NETCORE_RUNTIME_DLL_NAME_A MAKEDLLNAME_A(NETCORE_RUNTIME_MODULE_NAME_A) - #define NETCORE_DAC_MODULE_NAME_W W("mscordaccore") #define NETCORE_DAC_MODULE_NAME_A "mscordaccore" #define NETCORE_DAC_DLL_NAME_W MAKEDLLNAME_W(NETCORE_DAC_MODULE_NAME_W) @@ -43,11 +31,6 @@ #endif // FEATURE_PAL -#define DESKTOP_RUNTIME_MODULE_NAME_W W("clr") -#define DESKTOP_RUNTIME_MODULE_NAME_A "clr" -#define DESKTOP_RUNTIME_DLL_NAME_W MAKEDLLNAME_W(DESKTOP_RUNTIME_MODULE_NAME_W) -#define DESKTOP_RUNTIME_DLL_NAME_A MAKEDLLNAME_A(DESKTOP_RUNTIME_MODULE_NAME_A) - #define DESKTOP_DAC_MODULE_NAME_W W("mscordacwks") #define DESKTOP_DAC_MODULE_NAME_A "mscordacwks" #define DESKTOP_DAC_DLL_NAME_W MAKEDLLNAME_W(W("mscordacwks")) @@ -59,8 +42,26 @@ class IRuntime { public: - // Returns true if desktop CLR; false if .NET Core - virtual bool IsDesktop() const = 0; + enum RuntimeConfiguration + { + WindowsDesktop, + WindowsCore, + UnixCore, + OSXCore, + ConfigurationEnd, +#ifdef FEATURE_PAL +#ifdef __APPLE__ + Core = OSXCore +#else + Core = UnixCore +#endif +#else + Core = WindowsCore +#endif + }; + + // Returns the runtime configuration + virtual RuntimeConfiguration GetRuntimeConfiguration() const = 0; // Returns the runtime module index virtual ULONG GetModuleIndex() const = 0; @@ -90,6 +91,47 @@ public: virtual void DisplayStatus() = 0; }; +// Returns the runtime configuration as a string +inline static const char* GetRuntimeConfigurationName(IRuntime::RuntimeConfiguration config) +{ + static const char* name[IRuntime::ConfigurationEnd] = { + "Desktop", + ".NET Core (Windows)", + ".NET Core (Unix)", + ".NET Core (Mac)" + }; + return (config < IRuntime::ConfigurationEnd) ? name[config] : nullptr; +} + +// Returns the runtime module DLL name (clr.dll, coreclr.dll, libcoreclr.so, libcoreclr.dylib) +inline static const char* GetRuntimeDllName(IRuntime::RuntimeConfiguration config) +{ + static const char* name[IRuntime::ConfigurationEnd] = { + "clr.dll", + "coreclr.dll", + "libcoreclr.so", + "libcoreclr.dylib" + }; + return (config < IRuntime::ConfigurationEnd) ? name[config] : nullptr; +} + +// Returns the runtime module name (clr, coreclr, libcoreclr.so, libcoreclr.dylib). +inline static const char* GetRuntimeModuleName(IRuntime::RuntimeConfiguration config) +{ +#ifdef FEATURE_PAL + return GetRuntimeDllName(config); +#else + // On a windows host the module name does not include the extension. + static const char* name[IRuntime::ConfigurationEnd] = { + "clr", + "coreclr", + "libcoreclr", + "libcoreclr" + }; + return (config < IRuntime::ConfigurationEnd) ? name[config] : nullptr; +#endif +} + extern LPCSTR g_runtimeModulePath; extern IRuntime* g_pRuntime; @@ -99,7 +141,7 @@ extern IRuntime* g_pRuntime; class Runtime : public IRuntime { private: - bool m_isDesktop; + RuntimeConfiguration m_configuration; ULONG m_index; ULONG64 m_address; ULONG64 m_size; @@ -113,12 +155,12 @@ private: #ifndef FEATURE_PAL static Runtime* s_desktop; #endif - static bool s_isDesktop; + static RuntimeConfiguration s_configuration; static LPCSTR s_dacFilePath; static LPCSTR s_dbiFilePath; - Runtime(bool isDesktop, ULONG index, ULONG64 address, ULONG64 size) : - m_isDesktop(isDesktop), + Runtime(RuntimeConfiguration configuration,ULONG index, ULONG64 address, ULONG64 size) : + m_configuration(configuration), m_index(index), m_address(address), m_size(size), @@ -131,7 +173,7 @@ private: _ASSERTE(index != -1); _ASSERTE(address != 0); _ASSERTE(size != 0); - if (isDesktop == s_isDesktop) { + if (configuration == s_configuration) { SetDacFilePath(s_dacFilePath); SetDbiFilePath(s_dbiFilePath); } @@ -139,7 +181,7 @@ private: virtual Runtime::~Runtime(); - static HRESULT CreateInstance(bool isDesktop, Runtime** ppRuntime); + static HRESULT CreateInstance(RuntimeConfiguration configuration, Runtime** ppRuntime); HRESULT GetRuntimeDirectory(std::string& runtimeDirectory); @@ -177,7 +219,7 @@ public: static void SetDacDbiPath(bool isDesktop, LPCSTR dacFilePath, LPCSTR dbiFilePath) { - s_isDesktop = isDesktop; + s_configuration = isDesktop ? IRuntime::WindowsDesktop : IRuntime::Core; if (dacFilePath != nullptr) { s_dacFilePath = _strdup(dacFilePath); } @@ -188,7 +230,7 @@ public: static void Flush(); - virtual bool IsDesktop() const { return m_isDesktop; } + virtual RuntimeConfiguration GetRuntimeConfiguration() const { return m_configuration; } virtual ULONG GetModuleIndex() const { return m_index; } @@ -211,50 +253,50 @@ public: // Returns the runtime module DLL name (clr.dll, coreclr.dll, libcoreclr.so, libcoreclr.dylib) inline const char* GetRuntimeDllName() const { - return IsDesktop() ? DESKTOP_RUNTIME_DLL_NAME_A : NETCORE_RUNTIME_DLL_NAME_A; + return ::GetRuntimeDllName(GetRuntimeConfiguration()); } // Returns the DAC module name (mscordacwks.dll, mscordaccore.dll, libmscordaccore.so, libmscordaccore.dylib) inline const char* GetDacDllName() const { - return IsDesktop() ? DESKTOP_DAC_DLL_NAME_A : NETCORE_DAC_DLL_NAME_A; + return (GetRuntimeConfiguration() == IRuntime::WindowsDesktop) ? DESKTOP_DAC_DLL_NAME_A : NETCORE_DAC_DLL_NAME_A; } // Returns the DAC module name (mscordacwks, mscordaccore, libmscordaccore.so, libmscordaccore.dylib) inline const WCHAR* GetDacModuleNameW() const { - return IsDesktop() ? DESKTOP_DAC_MODULE_NAME_W : NETCORE_DAC_MODULE_NAME_W; + return (GetRuntimeConfiguration() == IRuntime::WindowsDesktop) ? DESKTOP_DAC_MODULE_NAME_W : NETCORE_DAC_MODULE_NAME_W; } // Returns the DAC module name (mscordacwks.dll, mscordaccore.dll, libmscordaccore.so, libmscordaccore.dylib) inline const WCHAR* GetDacDllNameW() const { - return IsDesktop() ? DESKTOP_DAC_DLL_NAME_W : NETCORE_DAC_DLL_NAME_W; + return (GetRuntimeConfiguration() == IRuntime::WindowsDesktop) ? DESKTOP_DAC_DLL_NAME_W : NETCORE_DAC_DLL_NAME_W; } }; // Returns the runtime module name (clr, coreclr, libcoreclr.so, libcoreclr.dylib). inline const char* GetRuntimeModuleName() { - return g_pRuntime->IsDesktop() ? DESKTOP_RUNTIME_MODULE_NAME_A : NETCORE_RUNTIME_MODULE_NAME_A; + return GetRuntimeModuleName(g_pRuntime->GetRuntimeConfiguration()); } // Returns the runtime module DLL name (clr.dll, coreclr.dll, libcoreclr.so, libcoreclr.dylib) inline const char* GetRuntimeDllName() { - return g_pRuntime->IsDesktop() ? DESKTOP_RUNTIME_DLL_NAME_A : NETCORE_RUNTIME_DLL_NAME_A; + return GetRuntimeDllName(g_pRuntime->GetRuntimeConfiguration()); } // Returns the DAC module name (mscordacwks, mscordaccore, libmscordaccore.so, libmscordaccore.dylib) inline const char* GetDacModuleName() { - return g_pRuntime->IsDesktop() ? DESKTOP_DAC_MODULE_NAME_A : NETCORE_DAC_MODULE_NAME_A; + return (g_pRuntime->GetRuntimeConfiguration() == IRuntime::WindowsDesktop) ? DESKTOP_DAC_MODULE_NAME_A : NETCORE_DAC_MODULE_NAME_A; } // Returns the DAC module name (mscordacwks.dll, mscordaccore.dll, libmscordaccore.so, libmscordaccore.dylib) inline const char* GetDacDllName() { - return g_pRuntime->IsDesktop() ? DESKTOP_DAC_DLL_NAME_A : NETCORE_DAC_DLL_NAME_A; + return (g_pRuntime->GetRuntimeConfiguration() == IRuntime::WindowsDesktop) ? DESKTOP_DAC_DLL_NAME_A : NETCORE_DAC_DLL_NAME_A; } #endif // __runtime_h__ diff --git a/src/SOS/Strike/strike.cpp b/src/SOS/Strike/strike.cpp index 8e18d42c2..fb44ec32a 100644 --- a/src/SOS/Strike/strike.cpp +++ b/src/SOS/Strike/strike.cpp @@ -7624,7 +7624,7 @@ public: // This is only needed for desktop runtime because OnCodeGenerated2 // isn't supported by the desktop DAC. - if (g_pRuntime->IsDesktop()) + if (g_pRuntime->GetRuntimeConfiguration() == IRuntime::WindowsDesktop) { // Some method has been generated, make a breakpoint and remove it. ULONG32 len = mdNameLen; @@ -9872,7 +9872,7 @@ DECLARE_API(DumpLog) _ASSERTE(g_pRuntime != nullptr); // Not supported on desktop runtime - if (g_pRuntime->IsDesktop()) + if (g_pRuntime->GetRuntimeConfiguration() == IRuntime::WindowsDesktop) { ExtErr("DumpLog not supported on desktop runtime\n"); return E_FAIL;