From 76bc84bf206d350b05cc297a94dfe1f6bb85adbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tom=C3=A1=C5=A1=20Rylek?= Date: Wed, 12 Feb 2020 20:55:03 +0100 Subject: [PATCH] Minor R2RDump improvements (#32178) Based on JanV's suggestions and based on my own composite R2R work I have made a few small improvements in R2RDump: 1) When normalization is on, we newly also normalize transition records for a particular IP address. 2) New option --hide-transitions suppresses transition information in the disassembly completely. 3) Logic for parsing the new OwnerCompositeExecutable R2R section. Thanks Tomas --- .../tools/Common/Internal/Runtime/ModuleHeaders.cs | 1 + .../src/tools/r2rdump/CommandLineOptions.cs | 1 + src/coreclr/src/tools/r2rdump/R2RDump.cs | 1 + src/coreclr/src/tools/r2rdump/TextDumper.cs | 23 ++++++++++++++++++++-- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/tools/Common/Internal/Runtime/ModuleHeaders.cs b/src/coreclr/src/tools/Common/Internal/Runtime/ModuleHeaders.cs index 5d3ccec..57722b4 100644 --- a/src/coreclr/src/tools/Common/Internal/Runtime/ModuleHeaders.cs +++ b/src/coreclr/src/tools/Common/Internal/Runtime/ModuleHeaders.cs @@ -65,6 +65,7 @@ namespace Internal.Runtime AttributePresence = 113, // Added in V3.1 InliningInfo2 = 114, // Added in 4.1 ComponentAssemblies = 115, // Added in 4.1 + OwnerCompositeExecutable = 116, // Added in 4.1 // // CoreRT ReadyToRun sections diff --git a/src/coreclr/src/tools/r2rdump/CommandLineOptions.cs b/src/coreclr/src/tools/r2rdump/CommandLineOptions.cs index ccd3186..5ddfd1d 100644 --- a/src/coreclr/src/tools/r2rdump/CommandLineOptions.cs +++ b/src/coreclr/src/tools/r2rdump/CommandLineOptions.cs @@ -28,6 +28,7 @@ namespace R2RDump command.AddOption(new Option(new[] { "--sectionContents", "--sc" }, "Dump section contents", new Argument())); command.AddOption(new Option(new[] { "--entrypoints", "-e" }, "Dump list of method / instance entrypoints in the R2R file", new Argument())); command.AddOption(new Option(new[] { "--normalize", "-n" }, "Normalize dump by sorting the various tables and methods (default = unsorted i.e. file order)", new Argument())); + command.AddOption(new Option(new[] { "--hide-transitions", "--ht" }, "Don't include GC transitions in disassembly output", new Argument())); command.AddOption(new Option(new[] { "--verbose", "-v" }, "Dump disassembly, unwindInfo, gcInfo and sectionContents", new Argument())); command.AddOption(new Option(new[] { "--diff" }, "Compare two R2R images", new Argument())); command.AddOption(new Option(new[] { "--diff-hide-same-disasm" }, "In matching method diff dump, hide functions with identical disassembly", new Argument())); diff --git a/src/coreclr/src/tools/r2rdump/R2RDump.cs b/src/coreclr/src/tools/r2rdump/R2RDump.cs index f40a610..ce459a5 100644 --- a/src/coreclr/src/tools/r2rdump/R2RDump.cs +++ b/src/coreclr/src/tools/r2rdump/R2RDump.cs @@ -39,6 +39,7 @@ namespace R2RDump public bool SectionContents { get; set; } public bool EntryPoints { get; set; } public bool Normalize { get; set; } + public bool HideTransitions { get; set; } public bool Verbose { get; set; } public bool Diff { get; set; } public bool DiffHideSameDisasm { get; set; } diff --git a/src/coreclr/src/tools/r2rdump/TextDumper.cs b/src/coreclr/src/tools/r2rdump/TextDumper.cs index 8f7293a..b5610d7 100644 --- a/src/coreclr/src/tools/r2rdump/TextDumper.cs +++ b/src/coreclr/src/tools/r2rdump/TextDumper.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; using System.Reflection.PortableExecutable; +using System.Text; using ILCompiler.Reflection.ReadyToRun; using Internal.Runtime; @@ -212,9 +213,18 @@ namespace R2RDump } } - if (rtf.Method.GcInfo?.Transitions != null && rtf.Method.GcInfo.Transitions.ContainsKey(codeOffset)) + if (!_options.HideTransitions && rtf.Method.GcInfo?.Transitions != null && rtf.Method.GcInfo.Transitions.TryGetValue(codeOffset, out List transitionsForOffset)) { - foreach (BaseGcTransition transition in rtf.Method.GcInfo.Transitions[codeOffset]) + string[] formattedTransitions = new string[transitionsForOffset.Count]; + for (int transitionIndex = 0; transitionIndex < formattedTransitions.Length; transitionIndex++) + { + formattedTransitions[transitionIndex] = transitionsForOffset[transitionIndex].ToString(); + } + if (_options.Normalize) + { + Array.Sort(formattedTransitions); + } + foreach (string transition in formattedTransitions) { _writer.WriteLine($"{indentString}{transition}"); } @@ -408,6 +418,15 @@ namespace R2RDump InliningInfoSection2 inliningInfoSection2 = new InliningInfoSection2(_r2r, ii2Offset, ii2EndOffset); _writer.WriteLine(inliningInfoSection2.ToString()); break; + case ReadyToRunSectionType.OwnerCompositeExecutable: + int oceOffset = _r2r.GetOffset(section.RelativeVirtualAddress); + Decoder decoder = Encoding.UTF8.GetDecoder(); + int charLength = decoder.GetCharCount(_r2r.Image, oceOffset, section.Size); + char[] charArray = new char[charLength]; + decoder.GetChars(_r2r.Image, oceOffset, section.Size, charArray, 0, flush: true); + string ownerCompositeExecutable = new string(charArray); + _writer.WriteLine("Composite executable: {0}", ownerCompositeExecutable); + break; } } -- 2.7.4