Skip to content

Commit

Permalink
Issue dotnet#942
Browse files Browse the repository at this point in the history
  • Loading branch information
mikem8361 committed Mar 28, 2020
1 parent 2600c77 commit 76fd35e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 37 deletions.
2 changes: 2 additions & 0 deletions src/SOS/SOS.Hosting/SOSHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private delegate int SOSInitializeDelegate(
[In, MarshalAs(UnmanagedType.Struct)] ref SOSNetCoreCallbacks callbacks,
int callbacksSize,
[In, MarshalAs(UnmanagedType.LPStr)] string tempDirectory,
[In, MarshalAs(UnmanagedType.LPStr)] string runtimeModulePath,
bool isDesktop,
[In, MarshalAs(UnmanagedType.LPStr)] string dacFilePath,
[In, MarshalAs(UnmanagedType.LPStr)] string dbiFilePath,
Expand Down Expand Up @@ -258,6 +259,7 @@ public void InitializeSOSHost(string tempDirectory, bool isDesktop, string dacFi
ref s_callbacks,
Marshal.SizeOf<SOSNetCoreCallbacks>(),
tempDirectory,
AnalyzeContext.RuntimeModuleDirectory,
isDesktop,
dacFilePath,
dbiFilePath,
Expand Down
14 changes: 13 additions & 1 deletion src/SOS/Strike/hostcoreclr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,15 @@ void CleanupTempDirectory()
/**********************************************************************\
* Called when the managed SOS Host loads/initializes SOS.
\**********************************************************************/
extern "C" HRESULT SOSInitializeByHost(SOSNetCoreCallbacks* callbacks, int callbacksSize, LPCSTR tempDirectory, bool isDesktop, LPCSTR dacFilePath, LPCSTR dbiFilePath, bool symbolStoreEnabled)
extern "C" HRESULT SOSInitializeByHost(
SOSNetCoreCallbacks* callbacks,
int callbacksSize,
LPCSTR tempDirectory,
LPCSTR runtimeModulePath,
bool isDesktop,
LPCSTR dacFilePath,
LPCSTR dbiFilePath,
bool symbolStoreEnabled)
{
if (memcpy_s(&g_SOSNetCoreCallbacks, sizeof(g_SOSNetCoreCallbacks), callbacks, callbacksSize) != 0)
{
Expand All @@ -468,6 +476,10 @@ extern "C" HRESULT SOSInitializeByHost(SOSNetCoreCallbacks* callbacks, int callb
{
g_tmpPath = _strdup(tempDirectory);
}
if (runtimeModulePath != nullptr)
{
g_runtimeModulePath = _strdup(runtimeModulePath);
}
Runtime::SetDacDbiPath(isDesktop, dacFilePath, dbiFilePath);
#ifndef FEATURE_PAL
// When SOS is hosted on dotnet-dump, the ExtensionApis are not set so
Expand Down
82 changes: 48 additions & 34 deletions src/Tools/dotnet-dump/Analyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,53 +222,67 @@ private ClrRuntime CreateRuntime(DataTarget target)
private string GetDacFile(ClrInfo clrInfo)
{
if (_dacFilePath == null)
{
string dac = clrInfo.LocalMatchingDac;
if (dac != null && File.Exists(dac))
{
Debug.Assert(!string.IsNullOrEmpty(clrInfo.DacInfo.FileName));
var analyzeContext = _serviceProvider.GetService<AnalyzeContext>();
string dacFilePath = null;
if (!string.IsNullOrEmpty(analyzeContext.RuntimeModuleDirectory))
{
_dacFilePath = dac;
dacFilePath = Path.Combine(analyzeContext.RuntimeModuleDirectory, clrInfo.DacInfo.FileName);
if (File.Exists(dacFilePath))
{
_dacFilePath = dacFilePath;
}
}
else if (SymbolReader.IsSymbolStoreEnabled())
if (_dacFilePath == null)
{
string dacFileName = Path.GetFileName(dac ?? clrInfo.DacInfo.FileName);
if (dacFileName != null)
dacFilePath = clrInfo.LocalMatchingDac;
if (!string.IsNullOrEmpty(dacFilePath) && File.Exists(dacFilePath))
{
SymbolStoreKey key = null;

if (clrInfo.ModuleInfo.BuildId != null)
_dacFilePath = dacFilePath;
}
else if (SymbolReader.IsSymbolStoreEnabled())
{
string dacFileName = Path.GetFileName(dacFilePath ?? clrInfo.DacInfo.FileName);
if (dacFileName != null)
{
IEnumerable<SymbolStoreKey> keys = ELFFileKeyGenerator.GetKeys(
KeyTypeFlags.ClrKeys, clrInfo.ModuleInfo.FileName, clrInfo.ModuleInfo.BuildId, symbolFile: false, symbolFileName: null);
SymbolStoreKey key = null;

if (clrInfo.ModuleInfo.BuildId != null)
{
IEnumerable<SymbolStoreKey> keys = ELFFileKeyGenerator.GetKeys(
KeyTypeFlags.ClrKeys, clrInfo.ModuleInfo.FileName, clrInfo.ModuleInfo.BuildId, symbolFile: false, symbolFileName: null);

key = keys.SingleOrDefault((k) => Path.GetFileName(k.FullPathName) == dacFileName);
key = keys.SingleOrDefault((k) => Path.GetFileName(k.FullPathName) == dacFileName);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// We are opening a Linux dump on Windows
// We need to use the Windows index and filename
key = new SymbolStoreKey(key.Index.Replace("libmscordaccore.so", "mscordaccore.dll"),
key.FullPathName.Replace("libmscordaccore.so", "mscordaccore.dll"),
key.IsClrSpecialFile,
key.PdbChecksums);
}
}
else
{
// We are opening a Linux dump on Windows
// We need to use the Windows index and filename
key = new SymbolStoreKey(key.Index.Replace("libmscordaccore.so", "mscordaccore.dll"),
key.FullPathName.Replace("libmscordaccore.so", "mscordaccore.dll"),
key.IsClrSpecialFile,
key.PdbChecksums);
// Use the coreclr.dll's id (timestamp/filesize) to download the the dac module.
key = PEFileKeyGenerator.GetKey(dacFileName, clrInfo.ModuleInfo.TimeStamp, clrInfo.ModuleInfo.FileSize);
}
}
else
{
// Use the coreclr.dll's id (timestamp/filesize) to download the the dac module.
key = PEFileKeyGenerator.GetKey(dacFileName, clrInfo.ModuleInfo.TimeStamp, clrInfo.ModuleInfo.FileSize);
}

if (key != null)
{
// Now download the DAC module from the symbol server
_dacFilePath = SymbolReader.GetSymbolFile(key);
if (key != null)
{
// Now download the DAC module from the symbol server
_dacFilePath = SymbolReader.GetSymbolFile(key);
}
}
}
}

if (_dacFilePath == null)
{
throw new FileNotFoundException($"Could not find matching DAC for this runtime: {clrInfo.ModuleInfo.FileName}");
if (_dacFilePath == null)
{
throw new FileNotFoundException($"Could not find matching DAC for this runtime: {clrInfo.ModuleInfo.FileName}");
}
}
_isDesktop = clrInfo.Flavor == ClrFlavor.Desktop;
}
Expand Down
1 change: 0 additions & 1 deletion src/Tools/dotnet-dump/Commands/SOSCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace Microsoft.Diagnostics.Tools.Dump
[Command(Name = "histobjfind", AliasExpansion = "HistObjFind", Help = "Displays all the log entries that reference an object at the specified address.")]
[Command(Name = "histroot", AliasExpansion = "HistRoot", Help = "Displays information related to both promotions and relocations of the specified root.")]
[Command(Name = "setsymbolserver", AliasExpansion = "SetSymbolServer", Help = "Enables the symbol server support ")]
[Command(Name = "setclrpath", AliasExpansion = "setclrpath", Platform = CommandPlatform.Windows, Help = "Set the path to load the runtime DAC/DBI files.")]
[Command(Name = "dumprcw", AliasExpansion = "DumpRCW", Platform = CommandPlatform.Windows, Help = "Displays information about a Runtime Callable Wrapper.")]
[Command(Name = "dumpccw", AliasExpansion = "DumpCCW", Platform = CommandPlatform.Windows, Help = "Displays information about a COM Callable Wrapper.")]
[Command(Name = "dumppermissionset",AliasExpansion = "DumpPermissionSet", Platform = CommandPlatform.Windows, Help = "Displays a PermissionSet object (debug build only).")]
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/dotnet-dump/Commands/SetClrPathCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Microsoft.Diagnostics.Tools.Dump
{
[Command(Name = "setclrpath", Platform = CommandPlatform.Linux | CommandPlatform.OSX, Help = "Set the path to load coreclr DAC/DBI files.")]
[Command(Name = "setclrpath", Help = "Set the path to load coreclr DAC/DBI files.")]
public class SetClrPath: CommandBase
{
public AnalyzeContext AnalyzeContext { get; set; }
Expand Down

0 comments on commit 76fd35e

Please sign in to comment.