Minor R2RDump improvements (#32178)
authorTomáš Rylek <trylek@microsoft.com>
Wed, 12 Feb 2020 19:55:03 +0000 (20:55 +0100)
committerGitHub <noreply@github.com>
Wed, 12 Feb 2020 19:55:03 +0000 (20:55 +0100)
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

src/coreclr/src/tools/Common/Internal/Runtime/ModuleHeaders.cs
src/coreclr/src/tools/r2rdump/CommandLineOptions.cs
src/coreclr/src/tools/r2rdump/R2RDump.cs
src/coreclr/src/tools/r2rdump/TextDumper.cs

index 5d3ccec..57722b4 100644 (file)
@@ -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
index ccd3186..5ddfd1d 100644 (file)
@@ -28,6 +28,7 @@ namespace R2RDump
             command.AddOption(new Option(new[] { "--sectionContents", "--sc" }, "Dump section contents", new Argument<bool>()));
             command.AddOption(new Option(new[] { "--entrypoints", "-e" }, "Dump list of method / instance entrypoints in the R2R file", new Argument<bool>()));
             command.AddOption(new Option(new[] { "--normalize", "-n" }, "Normalize dump by sorting the various tables and methods (default = unsorted i.e. file order)", new Argument<bool>()));
+            command.AddOption(new Option(new[] { "--hide-transitions", "--ht" }, "Don't include GC transitions in disassembly output", new Argument<bool>()));
             command.AddOption(new Option(new[] { "--verbose", "-v" }, "Dump disassembly, unwindInfo, gcInfo and sectionContents", new Argument<bool>()));
             command.AddOption(new Option(new[] { "--diff" }, "Compare two R2R images", new Argument<bool>()));
             command.AddOption(new Option(new[] { "--diff-hide-same-disasm" }, "In matching method diff dump, hide functions with identical disassembly", new Argument<bool>()));
index f40a610..ce459a5 100644 (file)
@@ -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; }
index 8f7293a..b5610d7 100644 (file)
@@ -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<BaseGcTransition> 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;
             }
         }