Add Module Override Recognition to R2RDump (#21617)
authorAndon Andonov <anandono@microsoft.com>
Sun, 23 Dec 2018 23:51:05 +0000 (15:51 -0800)
committerTomáš Rylek <trylek@microsoft.com>
Sun, 23 Dec 2018 23:51:05 +0000 (00:51 +0100)
This was added to help debug work with large version bubbles. The changes should allow R2RDump to have some rudimentary understanding of ENCODE_METHOD_OVERRIDE.

The big TODO here is allow loading of external dependency assemblies to be able to resolve the tokens coming after the override.

src/tools/r2rdump/R2RConstants.cs
src/tools/r2rdump/R2RSignature.cs

index bf19230..84340f4 100644 (file)
@@ -32,6 +32,14 @@ namespace R2RDump
     };
 
     /// <summary>
+    /// based on <a href="https://github.com/dotnet/coreclr/blob/master/src/inc/corcompile.h">src/inc/corcompile.h</a> CorCompileImportFlags
+    /// </summary>
+    public enum CORCOMPILE_FIXUP_BLOB_KIND
+    {
+        ENCODE_MODULE_OVERRIDE = 0x80,     /* When the high bit is set, override of the module immediately follows */
+    }
+
+    /// <summary>
     /// Constants for method and field encoding
     /// </summary>
     [Flags]
index a714383..f999aca 100644 (file)
@@ -460,7 +460,17 @@ namespace R2RDump
         /// <param name="builder"></param>
         private void ParseSignature(StringBuilder builder)
         {
-            uint fixupType = ReadUInt();
+            uint fixupType = ReadByte();
+            bool moduleOverride = (fixupType & (byte)CORCOMPILE_FIXUP_BLOB_KIND.ENCODE_MODULE_OVERRIDE) != 0;
+            // Check first byte for a module override being encoded
+            if (moduleOverride)
+            {
+                builder.Append("ENCODE_MODULE_OVERRIDE @ ");
+                fixupType &= ~(uint)CORCOMPILE_FIXUP_BLOB_KIND.ENCODE_MODULE_OVERRIDE;
+                uint moduleIndex = ReadUInt();
+                builder.Append(string.Format(" Index:  {0:X2}", moduleIndex));
+            }
+
             switch ((ReadyToRunFixupKind)fixupType)
             {
                 case ReadyToRunFixupKind.READYTORUN_FIXUP_ThisObjDictionaryLookup:
@@ -502,7 +512,10 @@ namespace R2RDump
                     break;
 
                 case ReadyToRunFixupKind.READYTORUN_FIXUP_MethodEntry_DefToken:
-                    ParseMethodDefToken(builder, owningTypeOverride: null);
+                    if (!moduleOverride)
+                    {
+                        ParseMethodDefToken(builder, owningTypeOverride: null);
+                    }
                     builder.Append(" (METHOD_ENTRY_DEF_TOKEN)");
                     break;
 
@@ -513,7 +526,10 @@ namespace R2RDump
 
 
                 case ReadyToRunFixupKind.READYTORUN_FIXUP_VirtualEntry:
-                    ParseMethod(builder);
+                    if(!moduleOverride)
+                    {
+                        ParseMethod(builder);
+                    }
                     builder.Append(" (VIRTUAL_ENTRY)");
                     break;
 
@@ -530,7 +546,11 @@ namespace R2RDump
                 case ReadyToRunFixupKind.READYTORUN_FIXUP_VirtualEntry_Slot:
                     {
                         uint slot = ReadUInt();
-                        ParseType(builder);
+                        if (!moduleOverride)
+                        {
+                            ParseType(builder);
+                        }
+
                         builder.Append($@" #{slot} (VIRTUAL_ENTRY_SLOT)");
                     }
                     break;