Added variable number for tracking (#39861)
authorEdward Kazuya Carlson <kazuya@comcast.net>
Sun, 2 Aug 2020 18:04:56 +0000 (11:04 -0700)
committerGitHub <noreply@github.com>
Sun, 2 Aug 2020 18:04:56 +0000 (11:04 -0700)
src/coreclr/src/tools/aot/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs
src/coreclr/src/tools/aot/ILCompiler.Reflection.ReadyToRun/DebugInfoTypes.cs
src/coreclr/src/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs
src/coreclr/src/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs

index 706e987..8a6766d 100644 (file)
@@ -17,15 +17,15 @@ namespace ILCompiler.Reflection.ReadyToRun
     /// </summary>
     public class DebugInfo
     {
-        private readonly ReadyToRunReader _readyToRunReader;
+        private readonly RuntimeFunction _runtimeFunction;
         private readonly int _offset;
         private List<DebugInfoBoundsEntry> _boundsList;
         private List<NativeVarInfo> _variablesList;
         private Machine _machine;
 
-        public DebugInfo(ReadyToRunReader readyToRunReader, int offset)
+        public DebugInfo(RuntimeFunction runtimeFunction, int offset)
         {
-            this._readyToRunReader = readyToRunReader;
+            this._runtimeFunction = runtimeFunction;
             this._offset = offset;
         }
 
@@ -83,6 +83,7 @@ namespace ILCompiler.Reflection.ReadyToRun
             {
                 return;
             }
+            ReadyToRunReader _readyToRunReader = _runtimeFunction.ReadyToRunReader;
             int offset = _offset;
             _boundsList = new List<DebugInfoBoundsEntry>();
             _variablesList = new List<NativeVarInfo>();
@@ -156,6 +157,19 @@ namespace ILCompiler.Reflection.ReadyToRun
                 entry.StartOffset = reader.ReadUInt();
                 entry.EndOffset = entry.StartOffset + reader.ReadUInt();
                 entry.VariableNumber = (uint)(reader.ReadUInt() + (int)ImplicitILArguments.Max);
+                entry.Variable = new Variable();
+                // TODO: This is probably incomplete
+                // This does not handle any implicit arguments or var args
+                if (entry.VariableNumber < this._runtimeFunction.Method.Signature.ParameterTypes.Length)
+                {
+                    entry.Variable.Type = VariableType.Parameter;
+                    entry.Variable.Index = (int)entry.VariableNumber;
+                }
+                else
+                {
+                    entry.Variable.Type = VariableType.Local;
+                    entry.Variable.Index = (int)entry.VariableNumber - this._runtimeFunction.Method.Signature.ParameterTypes.Length;
+                }
 
                 var varLoc = new VarLoc();
                 varLoc.VarLocType = (VarLocType)reader.ReadUInt();
index 73782f2..eef0ab4 100644 (file)
@@ -17,10 +17,25 @@ namespace ILCompiler.Reflection.ReadyToRun
     {
         public uint StartOffset;
         public uint EndOffset;
+        // TODO: Eliminate this
         public uint VariableNumber;
+        public Variable Variable { get; internal set; }
         public VarLoc VariableLocation;
     }
 
+    public enum VariableType
+    {
+        Parameter,
+        Local,
+        // TODO: Special
+    }
+
+    public class Variable
+    {
+        public VariableType Type { get; internal set; }
+        public int Index { get; internal set; }
+    }
+
     [Flags]
     public enum SourceTypes
     {
index a00419f..266a75b 100644 (file)
@@ -144,12 +144,24 @@ namespace ILCompiler.Reflection.ReadyToRun
             {
                 if (_debugInfo == null)
                 {
-                    _readyToRunReader.RuntimeFunctionToDebugInfo.TryGetValue(Id, out _debugInfo);
+                    int offset;
+                    if (_readyToRunReader.RuntimeFunctionToDebugInfo.TryGetValue(Id, out offset))
+                    {
+                        this._debugInfo = new DebugInfo(this, offset);
+                    }
                 }
                 return _debugInfo;
             }
         }
 
+        internal ReadyToRunReader ReadyToRunReader
+        {
+            get
+            {
+                return _readyToRunReader;
+            }
+        }
+
         public RuntimeFunction(
             ReadyToRunReader readyToRunReader,
             int id,
@@ -218,6 +230,8 @@ namespace ILCompiler.Reflection.ReadyToRun
 
         public MethodSignature<string> Signature { get; }
 
+        public ImmutableArray<string> LocalSignature { get; }
+
         /// <summary>
         /// The type that the method belongs to
         /// </summary>
@@ -282,6 +296,7 @@ namespace ILCompiler.Reflection.ReadyToRun
         /// </summary>
         public ReadyToRunMethod(
             ReadyToRunReader readyToRunReader,
+            PEReader peReader,
             MetadataReader metadataReader,
             EntityHandle methodHandle,
             int entryPointId,
@@ -309,6 +324,15 @@ namespace ILCompiler.Reflection.ReadyToRun
                 case HandleKind.MethodDefinition:
                     {
                         MethodDefinition methodDef = MetadataReader.GetMethodDefinition((MethodDefinitionHandle)MethodHandle);
+                        if (methodDef.RelativeVirtualAddress != 0)
+                        {
+                            MethodBodyBlock mbb = peReader.GetMethodBody(methodDef.RelativeVirtualAddress);
+                            if (!mbb.LocalSignature.IsNil)
+                            {
+                                StandaloneSignature ss = MetadataReader.GetStandaloneSignature(mbb.LocalSignature);
+                                LocalSignature = ss.DecodeLocalSignature(typeProvider, genericContext);
+                            }
+                        }
                         Name = MetadataReader.GetString(methodDef.Name);
                         Signature = methodDef.DecodeSignature<string, DisassemblingGenericContext>(typeProvider, genericContext);
                         owningTypeHandle = methodDef.GetDeclaringType();
index a829b58..3fdb03f 100644 (file)
@@ -80,7 +80,7 @@ namespace ILCompiler.Reflection.ReadyToRun
         private List<ReadyToRunCoreHeader> _readyToRunAssemblyHeaders;
 
         // DebugInfo
-        private Dictionary<int, DebugInfo> _runtimeFunctionToDebugInfo;
+        private Dictionary<int, int> _runtimeFunctionIdToDebugOffset;
 
         // ManifestReferences
         private MetadataReader _manifestReader;
@@ -322,12 +322,12 @@ namespace ILCompiler.Reflection.ReadyToRun
 
         }
 
-        internal Dictionary<int, DebugInfo> RuntimeFunctionToDebugInfo
+        internal Dictionary<int, int> RuntimeFunctionToDebugInfo
         {
             get
             {
                 EnsureDebugInfo();
-                return _runtimeFunctionToDebugInfo;
+                return _runtimeFunctionIdToDebugOffset;
             }
         }
 
@@ -583,11 +583,11 @@ namespace ILCompiler.Reflection.ReadyToRun
 
         private void EnsureDebugInfo()
         {
-            if (_runtimeFunctionToDebugInfo != null)
+            if (_runtimeFunctionIdToDebugOffset != null)
             {
                 return;
             }
-            _runtimeFunctionToDebugInfo = new Dictionary<int, DebugInfo>();
+            _runtimeFunctionIdToDebugOffset = new Dictionary<int, int>();
             if (!ReadyToRunHeader.Sections.TryGetValue(ReadyToRunSectionType.DebugInfo, out ReadyToRunSection debugInfoSection))
             {
                 return;
@@ -604,8 +604,7 @@ namespace ILCompiler.Reflection.ReadyToRun
                     continue;
                 }
 
-                var debugInfo = new DebugInfo(this, offset);
-                _runtimeFunctionToDebugInfo.Add((int)i, debugInfo);
+                _runtimeFunctionIdToDebugOffset.Add((int)i, offset);
             }
         }
 
@@ -741,7 +740,7 @@ namespace ILCompiler.Reflection.ReadyToRun
                     int runtimeFunctionId;
                     int? fixupOffset;
                     GetRuntimeFunctionIndexFromOffset(offset, out runtimeFunctionId, out fixupOffset);
-                    ReadyToRunMethod method = new ReadyToRunMethod(this, metadataReader, methodHandle, runtimeFunctionId, owningType: null, constrainedType: null, instanceArgs: null, fixupOffset: fixupOffset);
+                    ReadyToRunMethod method = new ReadyToRunMethod(this, this.PEReader, metadataReader, methodHandle, runtimeFunctionId, owningType: null, constrainedType: null, instanceArgs: null, fixupOffset: fixupOffset);
 
                     if (method.EntryPointRuntimeFunctionId < 0 || method.EntryPointRuntimeFunctionId >= isEntryPoint.Length)
                     {
@@ -889,6 +888,7 @@ namespace ILCompiler.Reflection.ReadyToRun
                 GetRuntimeFunctionIndexFromOffset((int)decoder.Offset, out runtimeFunctionId, out fixupOffset);
                 ReadyToRunMethod method = new ReadyToRunMethod(
                     this,
+                    this.PEReader,
                     mdReader,
                     methodHandle,
                     runtimeFunctionId,