Skip to content

Commit

Permalink
[SymbolStore] Replace SOS and DAC key generation method
Browse files Browse the repository at this point in the history
  • Loading branch information
mdh1418 committed Apr 18, 2024
1 parent ba80051 commit a171274
Showing 1 changed file with 32 additions and 82 deletions.
114 changes: 32 additions & 82 deletions src/Microsoft.SymbolStore/KeyGenerators/PEFileKeyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ namespace Microsoft.SymbolStore.KeyGenerators
public class PEFileKeyGenerator : KeyGenerator
{
private const string CoreClrFileName = "coreclr.dll";
private const string ClrFileName = "clr.dll";

private const string SosFileName = "sos";
private const string CoreClrDACFileName = "mscordaccore";
private static readonly string[] s_knownFilesWithLongNameVariant = new string[] { SosFileName, CoreClrDACFileName };
private const string ClrDACFileName = "mscordacwks";
private static readonly string[] s_knownFilesWithLongNameVariant = new string[] { SosFileName, CoreClrDACFileName, ClrDACFileName };

private readonly PEFile _peFile;
private readonly string _path;
Expand Down Expand Up @@ -88,17 +90,26 @@ public override IEnumerable<SymbolStoreKey> GetKeys(KeyTypeFlags flags)
}
}

// Return keys for SOS modules for a given runtime module
if ((flags & (KeyTypeFlags.ClrKeys)) != 0)
{
string coreclrId = string.Format("{0:X8}{1:x}", _peFile.Timestamp, _peFile.SizeOfImage);
foreach (string specialFileName in GetSOSFiles(GetFileName(_path)))
{
yield return BuildKey(specialFileName, coreclrId);
}
}

// Return keys for DAC and DBI modules for a given runtime module
if ((flags & (KeyTypeFlags.ClrKeys | KeyTypeFlags.DacDbiKeys)) != 0)
{
if (GetFileName(_path) == CoreClrFileName)
string coreclrId = string.Format("{0:X8}{1:x}", _peFile.Timestamp, _peFile.SizeOfImage);
foreach (string specialFileName in GetDACFiles(GetFileName(_path)))
{
string coreclrId = string.Format("{0:X8}{1:x}", _peFile.Timestamp, _peFile.SizeOfImage);
foreach (string specialFileName in GetSpecialFiles(flags))
{
yield return BuildKey(specialFileName, coreclrId);
}
yield return BuildKey(specialFileName, coreclrId);
}
}

if ((flags & KeyTypeFlags.HostKeys) != 0)
{
if ((_peFile.FileHeader.Characteristics & (ushort)ImageFile.Dll) == 0 && !_peFile.IsILImage)
Expand All @@ -124,6 +135,13 @@ private IEnumerable<string> GetSOSFiles(string runtimeFileName)
return coreClrSOSFiles.Concat(longNameSOSFiles);
}

if (runtimeFileName == ClrFileName)
{
string[] clrSOSFiles = new string[] { "SOS.dll" };
IEnumerable<string> longNameSOSFiles = GetFilesLongNameVariants(SosFileName);
return clrSOSFiles.Concat(longNameSOSFiles);
}

return default;
}

Expand All @@ -136,6 +154,13 @@ private IEnumerable<string> GetDACFiles(string runtimeFileName)
return coreClrDACFiles.Concat(longNameDACFiles);
}

if (runtimeFileName == ClrFileName)
{
string[] clrDACFiles = new string[] { "mscordacwks.dll", "mscordbi.dll" };
IEnumerable<string> longNameDACFiles = GetFilesLongNameVariants(ClrDACFileName);
return clrDACFiles.Concat(longNameDACFiles);
}

return default;
}

Expand Down Expand Up @@ -201,81 +226,6 @@ private IEnumerable<string> GetFilesLongNameVariants(string[] filesWithLongNameV
return longNameFileVariants;
}

private IEnumerable<string> GetSpecialFiles(KeyTypeFlags flags)
{
List<string> specialFiles = new((flags & KeyTypeFlags.ClrKeys) != 0 ? s_coreClrSpecialFiles : s_dacdbiSpecialFiles);

VsFixedFileInfo fileVersion = _peFile.VersionInfo;
if (fileVersion != null)
{
ushort major = fileVersion.ProductVersionMajor;
ushort minor = fileVersion.ProductVersionMinor;
ushort build = fileVersion.ProductVersionBuild;
ushort revision = fileVersion.ProductVersionRevision;

List<string> hostArchitectures = new();
string targetArchitecture = null;

ImageFileMachine machine = (ImageFileMachine)_peFile.FileHeader.Machine;
switch (machine)
{
case ImageFileMachine.Amd64:
targetArchitecture = "amd64";
break;

case ImageFileMachine.I386:
targetArchitecture = "x86";
break;

case ImageFileMachine.ArmNT:
targetArchitecture = "arm";
hostArchitectures.Add("x86");
break;

case ImageFileMachine.Arm64:
targetArchitecture = "arm64";
hostArchitectures.Add("amd64");
break;
}

if (targetArchitecture != null)
{
hostArchitectures.Add(targetArchitecture);

foreach (string hostArchitecture in hostArchitectures)
{
string buildFlavor = "";

if ((fileVersion.FileFlags & FileInfoFlags.Debug) != 0)
{
if ((fileVersion.FileFlags & FileInfoFlags.SpecialBuild) != 0)
{
buildFlavor = ".dbg";
}
else
{
buildFlavor = ".chk";
}
}

foreach (string name in (flags & KeyTypeFlags.ClrKeys) != 0 ? s_longNameBinaryPrefixes : s_daclongNameBinaryPrefixes)
{
// The name prefixes include the trailing "_".
string longName = string.Format("{0}{1}_{2}_{3}.{4}.{5}.{6:00}{7}.dll",
name, hostArchitecture, targetArchitecture, major, minor, build, revision, buildFlavor);
specialFiles.Add(longName);
}
}
}
}
else
{
Tracer.Warning("{0} has no version resource", _path);
}

return specialFiles;
}

/// <summary>
/// Creates a PE file symbol store key identity key.
/// </summary>
Expand Down

0 comments on commit a171274

Please sign in to comment.