Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Runtime::GetRuntime*Name() for cross-dac #930

Merged
merged 3 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SOS/SOS.UnitTests/Scripts/DualRuntimes.script
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ VERIFY:\s*Total\s+<DECVAL>\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%
Expand Down
15 changes: 11 additions & 4 deletions src/SOS/Strike/EventCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/SOS/Strike/exts.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ class __ExtensionCleanUp
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");
}
Expand Down
6 changes: 3 additions & 3 deletions src/SOS/Strike/hostcoreclr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
31 changes: 13 additions & 18 deletions src/SOS/Strike/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
112 changes: 77 additions & 35 deletions src/SOS/Strike/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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"))
Expand All @@ -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;
Expand Down Expand Up @@ -90,6 +91,47 @@ class IRuntime
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;

Expand All @@ -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;
Expand All @@ -113,12 +155,12 @@ class Runtime : public IRuntime
#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),
Expand All @@ -131,15 +173,15 @@ class Runtime : public IRuntime
_ASSERTE(index != -1);
_ASSERTE(address != 0);
_ASSERTE(size != 0);
if (isDesktop == s_isDesktop) {
if (configuration == s_configuration) {
SetDacFilePath(s_dacFilePath);
SetDbiFilePath(s_dbiFilePath);
}
}

virtual Runtime::~Runtime();

static HRESULT CreateInstance(bool isDesktop, Runtime** ppRuntime);
static HRESULT CreateInstance(RuntimeConfiguration configuration, Runtime** ppRuntime);

HRESULT GetRuntimeDirectory(std::string& runtimeDirectory);

Expand Down Expand Up @@ -177,7 +219,7 @@ class Runtime : public IRuntime

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);
}
Expand All @@ -188,7 +230,7 @@ class Runtime : public IRuntime

static void Flush();

virtual bool IsDesktop() const { return m_isDesktop; }
virtual RuntimeConfiguration GetRuntimeConfiguration() const { return m_configuration; }

virtual ULONG GetModuleIndex() const { return m_index; }

Expand All @@ -211,50 +253,50 @@ class Runtime : public IRuntime
// 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__
Loading