/// </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;
}
{
return;
}
+ ReadyToRunReader _readyToRunReader = _runtimeFunction.ReadyToRunReader;
int offset = _offset;
_boundsList = new List<DebugInfoBoundsEntry>();
_variablesList = new List<NativeVarInfo>();
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();
{
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
{
{
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,
public MethodSignature<string> Signature { get; }
+ public ImmutableArray<string> LocalSignature { get; }
+
/// <summary>
/// The type that the method belongs to
/// </summary>
/// </summary>
public ReadyToRunMethod(
ReadyToRunReader readyToRunReader,
+ PEReader peReader,
MetadataReader metadataReader,
EntityHandle methodHandle,
int entryPointId,
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();
private List<ReadyToRunCoreHeader> _readyToRunAssemblyHeaders;
// DebugInfo
- private Dictionary<int, DebugInfo> _runtimeFunctionToDebugInfo;
+ private Dictionary<int, int> _runtimeFunctionIdToDebugOffset;
// ManifestReferences
private MetadataReader _manifestReader;
}
- internal Dictionary<int, DebugInfo> RuntimeFunctionToDebugInfo
+ internal Dictionary<int, int> RuntimeFunctionToDebugInfo
{
get
{
EnsureDebugInfo();
- return _runtimeFunctionToDebugInfo;
+ return _runtimeFunctionIdToDebugOffset;
}
}
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;
continue;
}
- var debugInfo = new DebugInfo(this, offset);
- _runtimeFunctionToDebugInfo.Add((int)i, debugInfo);
+ _runtimeFunctionIdToDebugOffset.Add((int)i, offset);
}
}
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)
{
GetRuntimeFunctionIndexFromOffset((int)decoder.Offset, out runtimeFunctionId, out fixupOffset);
ReadyToRunMethod method = new ReadyToRunMethod(
this,
+ this.PEReader,
mdReader,
methodHandle,
runtimeFunctionId,