Skip to content

Commit

Permalink
Add support for diffing GC ref map info to R2RDump; small bugfix (#45619
Browse files Browse the repository at this point in the history
)
  • Loading branch information
trylek authored Dec 6, 2020
1 parent 6b7ea56 commit f9a4fbf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/coreclr/src/tools/r2rdump/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static void WriteTo(this GCRefMap theThis, TextWriter writer)
{
if (theThis.StackPop != GCRefMap.InvalidStackPop)
{
writer.Write(@"POP(0x{StackPop:X}) ");
writer.Write($@"POP(0x{theThis.StackPop:X}) ");
}
for (int entryIndex = 0; entryIndex < theThis.Entries.Length; entryIndex++)
{
Expand Down
46 changes: 46 additions & 0 deletions src/coreclr/src/tools/r2rdump/R2RDiff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void Run()
DiffTitle();
DiffPESections();
DiffR2RSections();
DiffImportSections();
DiffR2RMethods();

DiffMethodsForModule(AllModules, AllModules);
Expand Down Expand Up @@ -144,6 +145,37 @@ private void DiffR2RSections()
ShowDiff(GetR2RSectionMap(_leftDumper.Reader), GetR2RSectionMap(_rightDumper.Reader), "R2R sections");
}

private void DiffImportSections()
{
Dictionary<string, ReadyToRunImportSection.ImportSectionEntry> leftImports = GetImports(_leftDumper.Reader);
Dictionary<string, ReadyToRunImportSection.ImportSectionEntry> rightImports = GetImports(_rightDumper.Reader);
HashSet<string> commonKeys = new HashSet<string>(leftImports.Keys);
commonKeys.IntersectWith(rightImports.Keys);

_writer.WriteLine("Import entries");
_writer.WriteLine("--------------");

foreach (string key in commonKeys.OrderBy(k => k))
{
ReadyToRunImportSection.ImportSectionEntry leftEntry = leftImports[key];
ReadyToRunImportSection.ImportSectionEntry rightEntry = rightImports[key];
StringWriter leftInfo = new StringWriter();
StringWriter rightInfo = new StringWriter();
leftEntry.GCRefMap?.WriteTo(leftInfo);
rightEntry.GCRefMap?.WriteTo(rightInfo);
string leftGCRefMap = leftInfo.ToString();
string rightGCRefMap = rightInfo.ToString();
if (leftGCRefMap != rightGCRefMap)
{
_writer.WriteLine($@"Method: {key}");
_writer.WriteLine($@"Left GC ref map: {leftGCRefMap}");
_writer.WriteLine($@"Right GC ref map: {rightGCRefMap}");
}
}

_writer.WriteLine();
}

/// <summary>
/// Diff the R2R method maps.
/// </summary>
Expand Down Expand Up @@ -349,6 +381,20 @@ private void DumpCommonMethods(Dumper dumper, int moduleIndex, Dictionary<string
}
}

private static Dictionary<string, ReadyToRunImportSection.ImportSectionEntry> GetImports(ReadyToRunReader reader)
{
var result = new Dictionary<string, ReadyToRunImportSection.ImportSectionEntry>();
var signatureOptions = new SignatureFormattingOptions() { Naked = true };
foreach (ReadyToRunImportSection section in reader.ImportSections)
{
foreach (ReadyToRunImportSection.ImportSectionEntry entry in section.Entries)
{
result[entry.Signature.ToString(signatureOptions)] = entry;
}
}
return result;
}

/// <summary>
/// Filter out methods that have identical left / right disassembly.
/// </summary>
Expand Down

0 comments on commit f9a4fbf

Please sign in to comment.