GcInfo belongs to method, not runtime function
authorAmy Yu <amycmyu@gmail.com>
Thu, 7 Jun 2018 23:38:10 +0000 (16:38 -0700)
committerAmy Yu <amycmyu@gmail.com>
Thu, 7 Jun 2018 23:38:52 +0000 (16:38 -0700)
src/tools/r2rdump/GCInfo.cs
src/tools/r2rdump/R2RDump.cs
src/tools/r2rdump/R2RMethod.cs
src/tools/r2rdump/R2RReader.cs

index 358444f..d9e151b 100644 (file)
@@ -74,9 +74,11 @@ namespace R2RDump
         public IEnumerable<InterruptibleRange> InterruptibleRanges { get; }
         public GcSlotTable SlotTable { get; }
         public int Size { get; }
+        public int Offset { get; }
 
         public GcInfo(byte[] image, int offset, Machine machine, ushort majorVersion)
         {
+            Offset = offset;
             GcInfoTypes gcInfoTypes = new GcInfoTypes(machine);
 
             SecurityObjectStackSlot = -1;
index 6f099ea..a6baf3a 100644 (file)
@@ -156,6 +156,16 @@ namespace R2RDump
         {
             WriteSubDivider();
             _writer.WriteLine(method.ToString());
+            if (_gc)
+            {
+                _writer.WriteLine("GcInfo:");
+                _writer.Write(method.GcInfo);
+                if (_raw)
+                {
+                    DumpBytes(r2r, method.GcInfo.Offset, (uint)method.GcInfo.Size);
+                }
+            }
+            _writer.WriteLine();
 
             foreach (RuntimeFunction runtimeFunction in method.RuntimeFunctions)
             {
@@ -191,15 +201,6 @@ namespace R2RDump
                     DumpBytes(r2r, rtf.UnwindRVA, (uint)rtf.UnwindInfo.Size);
                 }
             }
-            if (_gc)
-            {
-                _writer.WriteLine("GcInfo:");
-                _writer.Write(rtf.GcInfo);
-                if (_raw)
-                {
-                    DumpBytes(r2r, rtf.UnwindRVA + rtf.UnwindInfo.Size, (uint)rtf.GcInfo.Size);
-                }
-            }
             _writer.WriteLine();
         }
 
index 115e834..356d1eb 100644 (file)
@@ -44,7 +44,6 @@ namespace R2RDump
         public R2RMethod Method { get; }
 
         public UnwindInfo UnwindInfo { get; }
-        public GcInfo GcInfo { get; }
 
         public RuntimeFunction(int id, int startRva, int endRva, int unwindRva, R2RMethod method, UnwindInfo unwindInfo, GcInfo gcInfo)
         {
@@ -53,8 +52,15 @@ namespace R2RDump
             UnwindRVA = unwindRva;
             Method = method;
             UnwindInfo = unwindInfo;
-            GcInfo = gcInfo;
-            Size = gcInfo.CodeLength;
+            if (endRva != -1)
+            {
+                Size = endRva - startRva;
+            }
+            else if (gcInfo != null)
+            {
+                Size = gcInfo.CodeLength;
+            }
+            method.GcInfo = gcInfo;
         }
 
         public override string ToString()
@@ -71,6 +77,7 @@ namespace R2RDump
             {
                 sb.AppendLine($"Size: {Size} bytes");
             }
+            sb.AppendLine($"UnwindRVA: 0x{UnwindRVA:X8}");
 
             return sb.ToString();
         }
@@ -95,16 +102,6 @@ namespace R2RDump
 
         public bool IsGeneric { get; }
 
-        /*/// <summary>
-        /// The return type of the method
-        /// </summary>
-        public string ReturnType { get; }
-
-        /// <summary>
-        /// The argument types of the method
-        /// </summary>
-        public string[] ArgTypes { get; }*/
-
         public MethodSignature<string> Signature { get; }
 
         /// <summary>
@@ -132,6 +129,8 @@ namespace R2RDump
         /// </summary>
         public int EntryPointRuntimeFunctionId { get; }
 
+        public GcInfo GcInfo { get; set; }
+
         /// <summary>
         /// Maps all the generic parameters to the type in the instance
         /// </summary>
index 4d0dbda..566928c 100644 (file)
@@ -207,6 +207,7 @@ namespace R2RDump
                 if (runtimeFunctionId == -1)
                     continue;
                 curOffset = runtimeFunctionOffset + runtimeFunctionId * runtimeFunctionSize;
+                GcInfo gcInfo = null;
                 do
                 {
                     int startRva = NativeReader.ReadInt32(Image, ref curOffset);
@@ -219,7 +220,10 @@ namespace R2RDump
                     int unwindOffset = GetOffset(unwindRva);
 
                     UnwindInfo unwindInfo = new UnwindInfo(Image, unwindOffset);
-                    GcInfo gcInfo = new GcInfo(Image, unwindOffset + unwindInfo.Size, Machine, R2RHeader.MajorVersion);
+                    if (isEntryPoint[runtimeFunctionId])
+                    {
+                        gcInfo = new GcInfo(Image, unwindOffset + unwindInfo.Size, Machine, R2RHeader.MajorVersion);
+                    }
 
                     method.RuntimeFunctions.Add(new RuntimeFunction(runtimeFunctionId, startRva, endRva, unwindRva, method, unwindInfo, gcInfo));
                     runtimeFunctionId++;