From f9a4fbff8693a11aea4af9ac5bb07d9e3fe34be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Rylek?= Date: Sun, 6 Dec 2020 20:10:56 +0100 Subject: [PATCH] Add support for diffing GC ref map info to R2RDump; small bugfix (#45619) --- src/coreclr/src/tools/r2rdump/Extensions.cs | 2 +- src/coreclr/src/tools/r2rdump/R2RDiff.cs | 46 +++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/coreclr/src/tools/r2rdump/Extensions.cs b/src/coreclr/src/tools/r2rdump/Extensions.cs index 3d297963a85b8..5240a70fc586a 100644 --- a/src/coreclr/src/tools/r2rdump/Extensions.cs +++ b/src/coreclr/src/tools/r2rdump/Extensions.cs @@ -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++) { diff --git a/src/coreclr/src/tools/r2rdump/R2RDiff.cs b/src/coreclr/src/tools/r2rdump/R2RDiff.cs index 1e0c639139957..91962d3ee929a 100644 --- a/src/coreclr/src/tools/r2rdump/R2RDiff.cs +++ b/src/coreclr/src/tools/r2rdump/R2RDiff.cs @@ -57,6 +57,7 @@ public void Run() DiffTitle(); DiffPESections(); DiffR2RSections(); + DiffImportSections(); DiffR2RMethods(); DiffMethodsForModule(AllModules, AllModules); @@ -144,6 +145,37 @@ private void DiffR2RSections() ShowDiff(GetR2RSectionMap(_leftDumper.Reader), GetR2RSectionMap(_rightDumper.Reader), "R2R sections"); } + private void DiffImportSections() + { + Dictionary leftImports = GetImports(_leftDumper.Reader); + Dictionary rightImports = GetImports(_rightDumper.Reader); + HashSet commonKeys = new HashSet(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(); + } + /// /// Diff the R2R method maps. /// @@ -349,6 +381,20 @@ private void DumpCommonMethods(Dumper dumper, int moduleIndex, Dictionary GetImports(ReadyToRunReader reader) + { + var result = new Dictionary(); + 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; + } + /// /// Filter out methods that have identical left / right disassembly. ///