Skip to content
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
4 changes: 2 additions & 2 deletions src/SOS/SOS.Hosting/RuntimeWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ protected override void Destroy()
private void Flush()
{
// TODO: there is a better way to flush _corDebugProcess with ICorDebugProcess4::ProcessStateChanged(FLUSH_ALL)
if (_corDebugProcess == IntPtr.Zero)
if (_corDebugProcess != IntPtr.Zero)
{
COMHelper.Release(_corDebugProcess);
_corDebugProcess = IntPtr.Zero;
}
// TODO: there is a better way to flush _clrDataProcess with ICLRDataProcess::Flush()
if (_clrDataProcess == IntPtr.Zero)
if (_clrDataProcess != IntPtr.Zero)
{
COMHelper.Release(_clrDataProcess);
_clrDataProcess = IntPtr.Zero;
Expand Down
79 changes: 41 additions & 38 deletions src/SOS/SOS.Hosting/SymbolServiceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,52 +273,55 @@ private void LoadNativeSymbolsFromIndex(
int moduleIndexSize,
IntPtr moduleIndex)
{
try
if (_symbolService.IsSymbolStoreEnabled)
{
KeyTypeFlags flags = specialKeys ? KeyTypeFlags.DacDbiKeys : KeyTypeFlags.IdentityKey;
byte[] id = new byte[moduleIndexSize];
Marshal.Copy(moduleIndex, id, 0, moduleIndexSize);

IEnumerable<SymbolStoreKey> keys = null;
switch (config)
try
{
case RuntimeConfiguration.UnixCore:
keys = ELFFileKeyGenerator.GetKeys(flags, moduleFilePath, id, symbolFile: false, symbolFileName: null);
break;
KeyTypeFlags flags = specialKeys ? KeyTypeFlags.DacDbiKeys : KeyTypeFlags.IdentityKey;
byte[] id = new byte[moduleIndexSize];
Marshal.Copy(moduleIndex, id, 0, moduleIndexSize);

case RuntimeConfiguration.OSXCore:
keys = MachOFileKeyGenerator.GetKeys(flags, moduleFilePath, id, symbolFile: false, symbolFileName: null);
break;

case RuntimeConfiguration.WindowsCore:
case RuntimeConfiguration.WindowsDesktop:
uint timeStamp = BitConverter.ToUInt32(id, 0);
uint fileSize = BitConverter.ToUInt32(id, 4);
SymbolStoreKey key = PEFileKeyGenerator.GetKey(moduleFilePath, timeStamp, fileSize);
keys = new SymbolStoreKey[] { key };
break;
IEnumerable<SymbolStoreKey> keys = null;
switch (config)
{
case RuntimeConfiguration.UnixCore:
keys = ELFFileKeyGenerator.GetKeys(flags, moduleFilePath, id, symbolFile: false, symbolFileName: null);
break;

case RuntimeConfiguration.OSXCore:
keys = MachOFileKeyGenerator.GetKeys(flags, moduleFilePath, id, symbolFile: false, symbolFileName: null);
break;

case RuntimeConfiguration.WindowsCore:
case RuntimeConfiguration.WindowsDesktop:
uint timeStamp = BitConverter.ToUInt32(id, 0);
uint fileSize = BitConverter.ToUInt32(id, 4);
SymbolStoreKey key = PEFileKeyGenerator.GetKey(moduleFilePath, timeStamp, fileSize);
keys = new SymbolStoreKey[] { key };
break;

default:
Trace.TraceError("LoadNativeSymbolsFromIndex: unsupported platform {0}", config);
return;
}
foreach (SymbolStoreKey key in keys)
{
string moduleFileName = Path.GetFileName(key.FullPathName);
Trace.TraceInformation("{0} {1}", key.FullPathName, key.Index);

default:
Trace.TraceError("LoadNativeSymbolsFromIndex: unsupported platform {0}", config);
return;
string downloadFilePath = _symbolService.DownloadFile(key);
if (downloadFilePath != null)
{
Trace.TraceInformation("{0}: {1}", moduleFileName, downloadFilePath);
callback(parameter, moduleFileName, downloadFilePath);
}
}
}
foreach (SymbolStoreKey key in keys)
catch (Exception ex) when (ex is BadInputFormatException || ex is InvalidVirtualAddressException || ex is TaskCanceledException)
{
string moduleFileName = Path.GetFileName(key.FullPathName);
Trace.TraceInformation("{0} {1}", key.FullPathName, key.Index);

string downloadFilePath = _symbolService.DownloadFile(key);
if (downloadFilePath != null)
{
Trace.TraceInformation("{0}: {1}", moduleFileName, downloadFilePath);
callback(parameter, moduleFileName, downloadFilePath);
}
Trace.TraceError("{0} - {1}", ex.Message, moduleFilePath);
}
}
catch (Exception ex) when (ex is BadInputFormatException || ex is InvalidVirtualAddressException || ex is TaskCanceledException)
{
Trace.TraceError("{0} - {1}", ex.Message, moduleFilePath);
}
}

/// <summary>
Expand Down
4 changes: 1 addition & 3 deletions src/SOS/Strike/platform/runtimeimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,15 +700,13 @@ void Runtime::DisplayStatus()
}
}

extern bool g_symbolStoreInitialized;

/**********************************************************************\
* Attempt to download the runtime modules (runtime, DAC and DBI)
\**********************************************************************/
void Runtime::LoadRuntimeModules()
{
HRESULT hr = InitializeSymbolService();
if (SUCCEEDED(hr) && g_symbolStoreInitialized)
if (SUCCEEDED(hr))
{
if (m_runtimeInfo != nullptr)
{
Expand Down
37 changes: 20 additions & 17 deletions src/SOS/Strike/symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#define IfFailRet(EXPR) do { Status = (EXPR); if(FAILED(Status)) { return (Status); } } while (0)
#endif

bool g_symbolStoreInitialized = false;

#ifndef FEATURE_PAL
HMODULE g_hmoduleSymBinder = nullptr;
ISymUnmanagedBinder3 *g_pSymBinder = nullptr;
Expand Down Expand Up @@ -78,15 +76,16 @@ extern "C" void STDMETHODCALLTYPE SOSUninitializeByHost()
\**********************************************************************/
HRESULT InitializeSymbolService()
{
if (!g_symbolStoreInitialized)
static bool initialized = false;
if (!initialized)
{
ISymbolService* symbolService = GetSymbolService();
if (symbolService == nullptr) {
return E_NOINTERFACE;
}
g_symbolStoreInitialized = symbolService->IsSymbolStoreEnabled();
initialized = true;
#ifndef FEATURE_PAL
// When SOS is hosted on dotnet-dump, the ExtensionApis are not set so
// When SOS is hosted on dotnet-dump on Windows, the ExtensionApis are not set so
// the expression evaluation function needs to be supplied.
if (GetExpression == nullptr)
{
Expand All @@ -96,6 +95,7 @@ HRESULT InitializeSymbolService()
}
#endif
OnUnloadTask::Register([]() {
initialized = false;
DisableSymbolStore();
});
}
Expand Down Expand Up @@ -137,7 +137,6 @@ HRESULT InitializeSymbolStore(
return E_FAIL;
}
}
g_symbolStoreInitialized = true;
return S_OK;
}

Expand Down Expand Up @@ -175,9 +174,13 @@ static void LoadNativeSymbolsCallback(void* param, const char* moduleFilePath, U
\**********************************************************************/
HRESULT LoadNativeSymbols(bool runtimeOnly)
{
if (g_symbolStoreInitialized)
ISymbolService* symbolService = GetSymbolService();
if (symbolService != nullptr)
{
return g_ExtServices2->LoadNativeSymbols(runtimeOnly, LoadNativeSymbolsCallback);
if (symbolService->IsSymbolStoreEnabled())
{
return g_ExtServices2->LoadNativeSymbols(runtimeOnly, LoadNativeSymbolsCallback);
}
}
return E_FAIL;
}
Expand All @@ -189,9 +192,10 @@ HRESULT LoadNativeSymbols(bool runtimeOnly)
\**********************************************************************/
void DisplaySymbolStore()
{
if (g_symbolStoreInitialized)
ISymbolService* symbolService = GetSymbolService();
if (symbolService != nullptr)
{
GetSymbolService()->DisplaySymbolStore([] (const char* message) {
symbolService->DisplaySymbolStore([] (const char* message) {
ExtOut(message);
ExtOut("\n");
});
Expand All @@ -203,10 +207,10 @@ void DisplaySymbolStore()
\**********************************************************************/
void DisableSymbolStore()
{
if (g_symbolStoreInitialized)
ISymbolService* symbolService = GetSymbolService();
if (symbolService != nullptr)
{
g_symbolStoreInitialized = false;
GetSymbolService()->DisableSymbolStore();
symbolService->DisableSymbolStore();
}
}

Expand All @@ -226,7 +230,6 @@ HRESULT GetMetadataLocator(
{
HRESULT Status = S_OK;
IfFailRet(InitializeSymbolService());

return GetSymbolService()->GetMetadataLocator(imagePath, imageTimestamp, imageSize, mvid, mdRva, flags, bufferSize, buffer, dataSize);
}

Expand Down Expand Up @@ -438,7 +441,7 @@ HRESULT SymbolReader::LoadSymbols(___in IMetaDataImport* pMD, ___in IXCLRDataMod
ExtOut("LoadSymbols GetClrModuleImages FAILED 0x%08x\n", hr);
return hr;
}
if (!HasPortablePDB(moduleBase))
if (GetSymbolService() == nullptr || !HasPortablePDB(moduleBase))
{
hr = LoadSymbolsForWindowsPDB(pMD, moduleBase, pModuleName, FALSE);
if (SUCCEEDED(hr))
Expand All @@ -453,9 +456,9 @@ HRESULT SymbolReader::LoadSymbols(___in IMetaDataImport* pMD, ___in IXCLRDataMod
}

#ifndef FEATURE_PAL
// TODO: in-memory windows PDB not supported
if (!HasPortablePDB(moduleData.LoadedPEAddress))
if (GetSymbolService() == nullptr || !HasPortablePDB(moduleData.LoadedPEAddress))
{
// TODO: in-memory windows PDB not supported
hr = LoadSymbolsForWindowsPDB(pMD, moduleData.LoadedPEAddress, pModuleName, moduleData.IsFileLayout);
if (SUCCEEDED(hr))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public object GetValue(Type type)
/// <param name="result">resulting object</param>
public static void GetValue(Type type, string valueString, ref object result)
{
valueString = valueString.Trim();
if (type == typeof(string))
{
result = valueString ?? "";
Expand Down Expand Up @@ -287,24 +288,24 @@ public static void CompareMembers(

if (nullableType != null && memberValue == null)
{
memberValue = "";
memberValue = string.Empty;
}
else if (memberType == typeof(string))
{
memberValue ??= "";
memberValue ??= string.Empty;
}
else if (memberValue is ImmutableArray<byte> buildId)
{
memberType = typeof(string);
memberValue = !buildId.IsDefaultOrEmpty ? string.Concat(buildId.Select((b) => b.ToString("x2"))) : "";
memberValue = !buildId.IsDefaultOrEmpty ? string.Concat(buildId.Select((b) => b.ToString("x2"))) : string.Empty;
}
else if (!memberType.IsPrimitive && !memberType.IsEnum)
{
memberType = typeof(string);
memberValue = memberValue?.ToString() ?? "";
memberValue = memberValue?.ToString() ?? string.Empty;
}
object testDataValue = testData.Value.GetValue(memberType);
Trace.TraceInformation($"CompareMembers {testData.Key}: {memberValue} == {testDataValue}");
Trace.TraceInformation($"CompareMembers {testData.Key}: '{memberValue}' == '{testDataValue}'");
Assert.Equal(memberValue, testDataValue);
}
}
Expand Down