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
93 changes: 93 additions & 0 deletions diagnostics.sln
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,96 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Diagnostics.Monit
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Diagnostics.Monitoring.RestServer", "src\Microsoft.Diagnostics.Monitoring.RestServer\Microsoft.Diagnostics.Monitoring.RestServer.csproj", "{B54DE8DD-6591-45C2-B9F7-22C4A23A384C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "inc", "inc", "{41BDFD6D-D165-4D67-BEF6-4E539040D30A}"
ProjectSection(SolutionItems) = preProject
src\inc\arrayholder.h = src\inc\arrayholder.h
src\inc\bitvector.h = src\inc\bitvector.h
src\inc\clrdata.idl = src\inc\clrdata.idl
src\inc\clrinternal.idl = src\inc\clrinternal.idl
src\inc\clrprivappxhosting.idl = src\inc\clrprivappxhosting.idl
src\inc\clrprivbinding.idl = src\inc\clrprivbinding.idl
src\inc\clrprivhosting.idl = src\inc\clrprivhosting.idl
src\inc\clrprivruntimebinders.idl = src\inc\clrprivruntimebinders.idl
src\inc\CMakeLists.txt = src\inc\CMakeLists.txt
src\inc\cor.h = src\inc\cor.h
src\inc\cordebug.idl = src\inc\cordebug.idl
src\inc\coreclrhost.h = src\inc\coreclrhost.h
src\inc\corexcep.h = src\inc\corexcep.h
src\inc\corhdr.h = src\inc\corhdr.h
src\inc\corhlpr.cpp = src\inc\corhlpr.cpp
src\inc\corhlpr.h = src\inc\corhlpr.h
src\inc\corjitflags.h = src\inc\corjitflags.h
src\inc\corprof.idl = src\inc\corprof.idl
src\inc\corpub.idl = src\inc\corpub.idl
src\inc\corsym.idl = src\inc\corsym.idl
src\inc\cortypeinfo.h = src\inc\cortypeinfo.h
src\inc\crosscomp.h = src\inc\crosscomp.h
src\inc\daccess.h = src\inc\daccess.h
src\inc\dacprivate.h = src\inc\dacprivate.h
src\inc\dbgportable.h = src\inc\dbgportable.h
src\inc\dbgtargetcontext.h = src\inc\dbgtargetcontext.h
src\inc\dbgutil.h = src\inc\dbgutil.h
src\inc\debugmacros.h = src\inc\debugmacros.h
src\inc\debugmacrosext.h = src\inc\debugmacrosext.h
src\inc\fusion.idl = src\inc\fusion.idl
src\inc\gcdecoder.cpp = src\inc\gcdecoder.cpp
src\inc\gcdesc.h = src\inc\gcdesc.h
src\inc\gcdump.h = src\inc\gcdump.h
src\inc\gcinfo.h = src\inc\gcinfo.h
src\inc\gcinfodecoder.h = src\inc\gcinfodecoder.h
src\inc\gcinfodumper.h = src\inc\gcinfodumper.h
src\inc\gcinfotypes.h = src\inc\gcinfotypes.h
src\inc\genericstackprobe.h = src\inc\genericstackprobe.h
src\inc\hillclimbing.h = src\inc\hillclimbing.h
src\inc\holder.h = src\inc\holder.h
src\inc\iallocator.h = src\inc\iallocator.h
src\inc\livedatatarget.h = src\inc\livedatatarget.h
src\inc\log.h = src\inc\log.h
src\inc\loglf.h = src\inc\loglf.h
src\inc\longfilepathwrappers.h = src\inc\longfilepathwrappers.h
src\inc\metahost.idl = src\inc\metahost.idl
src\inc\MSCOREE.IDL = src\inc\MSCOREE.IDL
src\inc\mscorsvc.idl = src\inc\mscorsvc.idl
src\inc\msodw.h = src\inc\msodw.h
src\inc\new.hpp = src\inc\new.hpp
src\inc\opcode.def = src\inc\opcode.def
src\inc\openum.h = src\inc\openum.h
src\inc\palclr.h = src\inc\palclr.h
src\inc\palclr_win.h = src\inc\palclr_win.h
src\inc\predeftlsslot.h = src\inc\predeftlsslot.h
src\inc\random.h = src\inc\random.h
src\inc\regdisp.h = src\inc\regdisp.h
src\inc\runtimeinfo.h = src\inc\runtimeinfo.h
src\inc\safemath.h = src\inc\safemath.h
src\inc\sospriv.idl = src\inc\sospriv.idl
src\inc\stacktrace.h = src\inc\stacktrace.h
src\inc\static_assert.h = src\inc\static_assert.h
src\inc\staticcontract.h = src\inc\staticcontract.h
src\inc\stresslog.h = src\inc\stresslog.h
src\inc\switches.h = src\inc\switches.h
src\inc\tls.h = src\inc\tls.h
src\inc\volatile.h = src\inc\volatile.h
src\inc\warningcontrol.h = src\inc\warningcontrol.h
src\inc\xclrdata.idl = src\inc\xclrdata.idl
src\inc\xcordebug.idl = src\inc\xcordebug.idl
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "clr_std", "clr_std", "{33239640-6F4B-4DA4-A780-2F5B26D57EAD}"
ProjectSection(SolutionItems) = preProject
src\inc\clr_std\algorithm = src\inc\clr_std\algorithm
src\inc\clr_std\string = src\inc\clr_std\string
src\inc\clr_std\type_traits = src\inc\clr_std\type_traits
src\inc\clr_std\utility = src\inc\clr_std\utility
src\inc\clr_std\vector = src\inc\clr_std\vector
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "llvm", "llvm", "{06730767-421B-465F-BB63-A3A07D72D7A2}"
ProjectSection(SolutionItems) = preProject
src\inc\llvm\Dwarf.def = src\inc\llvm\Dwarf.def
src\inc\llvm\Dwarf.h = src\inc\llvm\Dwarf.h
src\inc\llvm\ELF.h = src\inc\llvm\ELF.h
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Checked|Any CPU = Checked|Any CPU
Expand Down Expand Up @@ -1188,6 +1278,9 @@ Global
{C57F7656-6663-4A3C-BE38-B75C6C57E77D} = {B62728C8-1267-4043-B46F-5537BBAEC692}
{CFCF90E5-91CF-44FD-819D-97F530AEF769} = {19FAB78C-3351-4911-8F0C-8C6056401740}
{B54DE8DD-6591-45C2-B9F7-22C4A23A384C} = {19FAB78C-3351-4911-8F0C-8C6056401740}
{41BDFD6D-D165-4D67-BEF6-4E539040D30A} = {19FAB78C-3351-4911-8F0C-8C6056401740}
{33239640-6F4B-4DA4-A780-2F5B26D57EAD} = {41BDFD6D-D165-4D67-BEF6-4E539040D30A}
{06730767-421B-465F-BB63-A3A07D72D7A2} = {41BDFD6D-D165-4D67-BEF6-4E539040D30A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46465737-C938-44FC-BE1A-4CE139EBB5E0}
Expand Down
2 changes: 1 addition & 1 deletion src/SOS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ endif(WIN32)

add_definitions(-D_SECURE_SCL=0)

add_subdirectory(dbgutil)
add_subdirectory(SOS.NETCore)
add_subdirectory(Strike)

Expand All @@ -32,4 +33,3 @@ if(CLR_CMAKE_PLATFORM_UNIX)
endif(CLR_CMAKE_PLATFORM_UNIX)

add_subdirectory(debugshim)
add_subdirectory(dbgutil)
12 changes: 12 additions & 0 deletions src/SOS/SOS.Hosting/SOSHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,21 @@ private delegate void DisplaySymbolStoreDelegate(
private delegate void LoadNativeSymbolsDelegate(
SymbolReader.SymbolFileCallback callback,
IntPtr parameter,
SymbolReader.RuntimeConfiguration config,
string moduleFilePath,
ulong address,
int size,
SymbolReader.ReadMemoryDelegate readMemory);

private delegate void LoadNativeSymbolsFromIndexDelegate(
SymbolReader.SymbolFileCallback callback,
IntPtr parameter,
SymbolReader.RuntimeConfiguration config,
string moduleFilePath,
bool specialKeys,
int moduleIndexSize,
IntPtr moduleIndex);

private delegate IntPtr LoadSymbolsForModuleDelegate(
string assemblyPath,
bool isFileLayout,
Expand Down Expand Up @@ -130,6 +140,7 @@ struct SOSNetCoreCallbacks
public DisplaySymbolStoreDelegate DisplaySymbolStoreDelegate;
public DisableSymbolStoreDelegate DisableSymbolStoreDelegate;
public LoadNativeSymbolsDelegate LoadNativeSymbolsDelegate;
public LoadNativeSymbolsFromIndexDelegate LoadNativeSymbolsFromIndexDelegate;
public LoadSymbolsForModuleDelegate LoadSymbolsForModuleDelegate;
public DisposeDelegate DisposeDelegate;
public ResolveSequencePointDelegate ResolveSequencePointDelegate;
Expand All @@ -144,6 +155,7 @@ struct SOSNetCoreCallbacks
DisplaySymbolStoreDelegate = SymbolReader.DisplaySymbolStore,
DisableSymbolStoreDelegate = SymbolReader.DisableSymbolStore,
LoadNativeSymbolsDelegate = SymbolReader.LoadNativeSymbols,
LoadNativeSymbolsFromIndexDelegate = SymbolReader.LoadNativeSymbolsFromIndex,
LoadSymbolsForModuleDelegate = SymbolReader.LoadSymbolsForModule,
DisposeDelegate = SymbolReader.Dispose,
ResolveSequencePointDelegate = SymbolReader.ResolveSequencePoint,
Expand Down
167 changes: 119 additions & 48 deletions src/SOS/SOS.NETCore/SymbolReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ internal struct MethodDebugInfo
public int localsSize;
}

/// <summary>
/// Matches the IRuntime::RuntimeConfiguration in runtime.h
/// </summary>
public enum RuntimeConfiguration
{
WindowsDesktop = 0,
WindowsCore = 1,
UnixCore = 2,
OSXCore = 3
}

private sealed class OpenedReader : IDisposable
{
public readonly MetadataReaderProvider Provider;
Expand Down Expand Up @@ -253,79 +264,62 @@ public static void DisableSymbolStore()
}

/// <summary>
/// Load native symbols and modules (i.e. dac, dbi).
/// Load native symbols and modules (i.e. DAC, DBI).
/// </summary>
/// <param name="callback">called back for each symbol file loaded</param>
/// <param name="parameter">callback parameter</param>
/// <param name="config">Target configuration: Windows, Linux or OSX</param>
/// <param name="moduleFilePath">module path</param>
/// <param name="address">module base address</param>
/// <param name="size">module size</param>
/// <param name="readMemory">read memory callback delegate</param>
public static void LoadNativeSymbols(SymbolFileCallback callback, IntPtr parameter, string moduleFilePath, ulong address, int size, ReadMemoryDelegate readMemory)
public static void LoadNativeSymbols(
SymbolFileCallback callback,
IntPtr parameter,
RuntimeConfiguration config,
string moduleFilePath,
ulong address,
int size,
ReadMemoryDelegate readMemory)
{
if (IsSymbolStoreEnabled())
{
Stream stream = new TargetStream(address, size, readMemory);
KeyTypeFlags flags = KeyTypeFlags.SymbolKey | KeyTypeFlags.ClrKeys;
KeyGenerator generator = null;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var elfFile = new ELFFile(new StreamAddressSpace(stream), 0, true);
generator = new ELFFileKeyGenerator(s_tracer, elfFile, moduleFilePath);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
switch (config)
{
var machOFile = new MachOFile(new StreamAddressSpace(stream), 0, true);
generator = new MachOFileKeyGenerator(s_tracer, machOFile, moduleFilePath);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var peFile = new PEFile(new StreamAddressSpace(stream), true);
if (peFile.IsValid())
{
generator = new PEFileKeyGenerator(s_tracer, peFile, moduleFilePath);
}
else
{
// Support loading ELF files on Windows for the cross-dac
case RuntimeConfiguration.UnixCore:
var elfFile = new ELFFile(new StreamAddressSpace(stream), 0, true);
generator = new ELFFileKeyGenerator(s_tracer, elfFile, moduleFilePath);
}
}
else {
return;
break;
case RuntimeConfiguration.OSXCore:
var machOFile = new MachOFile(new StreamAddressSpace(stream), 0, true);
generator = new MachOFileKeyGenerator(s_tracer, machOFile, moduleFilePath);
break;
case RuntimeConfiguration.WindowsCore:
case RuntimeConfiguration.WindowsDesktop:
var peFile = new PEFile(new StreamAddressSpace(stream), true);
generator = new PEFileKeyGenerator(s_tracer, peFile, moduleFilePath);
break;
default:
s_tracer.Error("Unsupported platform {0}", config);
return;
}

try
{
IEnumerable<SymbolStoreKey> keys = generator.GetKeys(flags);
foreach (SymbolStoreKey forKey in keys)
IEnumerable<SymbolStoreKey> keys = generator.GetKeys(KeyTypeFlags.SymbolKey | KeyTypeFlags.DacDbiKeys);
foreach (SymbolStoreKey key in keys)
{
SymbolStoreKey key = forKey;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && key.FullPathName.Equals("libmscordaccore.so"))
{
// 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"),
"mscordaccore.dll",
key.IsClrSpecialFile,
key.PdbChecksums);
}
string moduleFileName = Path.GetFileName(key.FullPathName);
s_tracer.Verbose("{0} {1}", key.FullPathName, key.Index);

// Don't download the sos binaries that come with the runtime
if (!IsPathEqual(moduleFileName, "SOS.NETCore.dll") &&
!IsPathEqual(moduleFileName, "sos.dll") &&
!moduleFileName.StartsWith("libsos."))
string downloadFilePath = GetSymbolFile(key);
if (downloadFilePath != null)
{
string downloadFilePath = GetSymbolFile(key);
if (downloadFilePath != null)
{
s_tracer.Information("{0}: {1}", moduleFileName, downloadFilePath);
callback(parameter, moduleFileName, downloadFilePath);
}
s_tracer.Information("{0}: {1}", moduleFileName, downloadFilePath);
callback(parameter, moduleFileName, downloadFilePath);
}
}
}
Expand All @@ -336,6 +330,83 @@ public static void LoadNativeSymbols(SymbolFileCallback callback, IntPtr paramet
}
}

/// <summary>
/// Load native modules (i.e. DAC, DBI) from the runtime build id.
/// </summary>
/// <param name="callback">called back for each symbol file loaded</param>
/// <param name="parameter">callback parameter</param>
/// <param name="config">Target configuration: Windows, Linux or OSX</param>
/// <param name="moduleFilePath">module path</param>
/// <param name="specialKeys">if true, returns the DBI/DAC keys, otherwise the identity key</param>
/// <param name="moduleIndexSize">build id size</param>
/// <param name="moduleIndex">pointer to build id</param>
public static void LoadNativeSymbolsFromIndex(
SymbolFileCallback callback,
IntPtr parameter,
RuntimeConfiguration config,
string moduleFilePath,
bool specialKeys,
int moduleIndexSize,
IntPtr moduleIndex)
{
try
{
KeyTypeFlags flags = specialKeys ? KeyTypeFlags.DacDbiKeys : KeyTypeFlags.IdentityKey;
byte[] id = new byte[moduleIndexSize];
Marshal.Copy(moduleIndex, id, 0, moduleIndexSize);

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:
s_tracer.Error("Unsupported platform {0}", config);
return;
}
foreach (SymbolStoreKey key in keys)
{
string moduleFileName = Path.GetFileName(key.FullPathName);
s_tracer.Verbose("{0} {1}", key.FullPathName, key.Index);

string downloadFilePath = GetSymbolFile(key);
if (downloadFilePath != null)
{
s_tracer.Information("{0}: {1}", moduleFileName, downloadFilePath);
callback(parameter, moduleFileName, downloadFilePath);
}
}
}
catch (Exception ex) when (ex is BadInputFormatException || ex is InvalidVirtualAddressException || ex is TaskCanceledException)
{
s_tracer.Error("{0} - {1}", ex.Message, moduleFilePath);
}
}

/// <summary>
/// Load symbol or module files from the keys
/// </summary>
/// <param name="callback">called back for each symbol file loaded</param>
/// <param name="parameter">callback parameter</param>
/// <param name="keys">list of keys to download</param>
private static void LoadSymbolFiles(SymbolFileCallback callback, IntPtr parameter, IEnumerable<SymbolStoreKey> keys)
{
}

/// <summary>
/// Download a symbol from the symbol stores/server.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions src/SOS/SOS.UnitTests/SOSRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,6 @@ public static async Task<SOSRunner> StartDebugger(TestInformation information, D
{
throw new ArgumentException("No DotNetDumpHost in configuration");
}
initialCommands.Add("setsymbolserver -directory %DEBUG_ROOT%");

// Add the path to runtime so dotnet-dump/SOS can find DAC/DBI for triage dumps
if (information.DumpType == DumpType.Triage)
{
Expand All @@ -555,6 +553,7 @@ public static async Task<SOSRunner> StartDebugger(TestInformation information, D
initialCommands.Add("setclrpath " + runtimeSymbolsPath);
}
}
initialCommands.Add("setsymbolserver -directory %DEBUG_ROOT%");
arguments.Append(debuggerPath);
arguments.Append(@" analyze %DUMP_NAME%");
debuggerPath = config.DotNetDumpHost();
Expand Down
Loading