Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Text;
using System.Xml.Serialization;

namespace R2RDump.Amd64
namespace ILCompiler.Reflection.ReadyToRun.Amd64
{
public class GcInfo : BaseGcInfo
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Text;
using System.Xml.Serialization;

namespace R2RDump.Amd64
namespace ILCompiler.Reflection.ReadyToRun.Amd64
{
public class GcSlotTable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Text;
using System.Xml.Serialization;

namespace R2RDump.Amd64
namespace ILCompiler.Reflection.ReadyToRun.Amd64
{
public struct InterruptibleRange
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Collections.Generic;
using System.Text;

namespace R2RDump.Amd64
namespace ILCompiler.Reflection.ReadyToRun.Amd64
{
/// <summary>
/// based on <a href="https://github.com/dotnet/coreclr/blob/master/src/gcdump/gcdumpnonx86.cpp">src\gcdump\gcdumpnonx86.cpp</a> GetRegName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Text;
using System.Xml.Serialization;

namespace R2RDump.Amd64
namespace ILCompiler.Reflection.ReadyToRun.Amd64
{
/// <summary>
/// based on <a href="https://github.com/dotnet/coreclr/blob/master/src/inc/win64unwind.h">src\inc\win64unwind.h</a> _UNWIND_OP_CODES
Expand Down Expand Up @@ -239,7 +239,8 @@ private void ParseUnwindCode(ref int i)
code.NextFrameOffset = (int)offset * 16;
if ((UnwindCodeArray[i].FrameOffset & 0xF0000000) != 0)
{
R2RDump.WriteWarning("Illegal unwindInfo unscaled offset: too large");
// TODO (refactoring) - what should we do?
// R2RDump.WriteWarning("Illegal unwindInfo unscaled offset: too large");
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Collections.Generic;
using System.Text;

namespace R2RDump.Arm
namespace ILCompiler.Reflection.ReadyToRun.Arm
{
/// <summary>
/// based on <a href="https://github.com/dotnet/coreclr/blob/master/src/jit/unwindarm.cpp">src/jit/unwindarm.cpp</a> mapRegNumToDwarfReg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Xml.Serialization;

namespace R2RDump.Arm
namespace ILCompiler.Reflection.ReadyToRun.Arm
{
public class Epilog
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Collections.Generic;
using System.Text;

namespace R2RDump.Arm64
namespace ILCompiler.Reflection.ReadyToRun.Arm64
{
public enum Registers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Xml.Serialization;

namespace R2RDump.Arm64
namespace ILCompiler.Reflection.ReadyToRun.Arm64
{
public class Epilog
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Reflection.PortableExecutable;
using System.Text;

namespace R2RDump
namespace ILCompiler.Reflection.ReadyToRun
{
/// <summary>
/// Represents the debug information for a single method in the ready-to-run image.
Expand All @@ -21,12 +21,10 @@ public class DebugInfo
private List<DebugInfoBoundsEntry> _boundsList = new List<DebugInfoBoundsEntry>();
private List<NativeVarInfo> _variablesList = new List<NativeVarInfo>();
private Machine _machine;
private bool _normalize;

public DebugInfo(byte[] image, int offset, Machine machine, bool normalize)
public DebugInfo(byte[] image, int offset, Machine machine)
{
_machine = machine;
_normalize = normalize;

// Get the id of the runtime function from the NativeArray
uint lookback = 0;
Expand Down Expand Up @@ -55,83 +53,14 @@ public DebugInfo(byte[] image, int offset, Machine machine, bool normalize)
}
}

public void WriteTo(TextWriter writer, DumpOptions dumpOptions)
{
if (_boundsList.Count > 0)
writer.WriteLine("Debug Info");

writer.WriteLine("\tBounds:");
for (int i = 0; i < _boundsList.Count; ++i)
{
writer.Write('\t');
if (!dumpOptions.Naked)
{
writer.Write($"Native Offset: 0x{_boundsList[i].NativeOffset:X}, ");
}
writer.WriteLine($"IL Offset: 0x{_boundsList[i].ILOffset:X}, Source Types: {_boundsList[i].SourceTypes}");
}

writer.WriteLine("");

if (_variablesList.Count > 0)
writer.WriteLine("\tVariable Locations:");

for (int i = 0; i < _variablesList.Count; ++i)
{
var varLoc = _variablesList[i];
writer.WriteLine($"\tVariable Number: {varLoc.VariableNumber}");
writer.WriteLine($"\tStart Offset: 0x{varLoc.StartOffset:X}");
writer.WriteLine($"\tEnd Offset: 0x{varLoc.EndOffset:X}");
writer.WriteLine($"\tLoc Type: {varLoc.VariableLocation.VarLocType}");

switch (varLoc.VariableLocation.VarLocType)
{
case VarLocType.VLT_REG:
case VarLocType.VLT_REG_FP:
case VarLocType.VLT_REG_BYREF:
writer.WriteLine($"\tRegister: {GetPlatformSpecificRegister(_machine, varLoc.VariableLocation.Data1)}");
break;
case VarLocType.VLT_STK:
case VarLocType.VLT_STK_BYREF:
writer.WriteLine($"\tBase Register: {GetPlatformSpecificRegister(_machine, varLoc.VariableLocation.Data1)}");
writer.WriteLine($"\tStack Offset: {varLoc.VariableLocation.Data2}");
break;
case VarLocType.VLT_REG_REG:
writer.WriteLine($"\tRegister 1: {GetPlatformSpecificRegister(_machine, varLoc.VariableLocation.Data1)}");
writer.WriteLine($"\tRegister 2: {GetPlatformSpecificRegister(_machine, varLoc.VariableLocation.Data2)}");
break;
case VarLocType.VLT_REG_STK:
writer.WriteLine($"\tRegister: {GetPlatformSpecificRegister(_machine, varLoc.VariableLocation.Data1)}");
writer.WriteLine($"\tBase Register: {GetPlatformSpecificRegister(_machine, varLoc.VariableLocation.Data2)}");
writer.WriteLine($"\tStack Offset: {varLoc.VariableLocation.Data3}");
break;
case VarLocType.VLT_STK_REG:
writer.WriteLine($"\tStack Offset: {varLoc.VariableLocation.Data1}");
writer.WriteLine($"\tBase Register: {GetPlatformSpecificRegister(_machine, varLoc.VariableLocation.Data2)}");
writer.WriteLine($"\tRegister: {GetPlatformSpecificRegister(_machine, varLoc.VariableLocation.Data3)}");
break;
case VarLocType.VLT_STK2:
writer.WriteLine($"\tBase Register: {GetPlatformSpecificRegister(_machine, varLoc.VariableLocation.Data1)}");
writer.WriteLine($"\tStack Offset: {varLoc.VariableLocation.Data2}");
break;
case VarLocType.VLT_FPSTK:
writer.WriteLine($"\tOffset: {GetPlatformSpecificRegister(_machine, varLoc.VariableLocation.Data1)}");
break;
case VarLocType.VLT_FIXED_VA:
writer.WriteLine($"\tOffset: {GetPlatformSpecificRegister(_machine, varLoc.VariableLocation.Data1)}");
break;
default:
throw new BadImageFormatException("Unexpected var loc type");
}

writer.WriteLine("");
}
}
public List<DebugInfoBoundsEntry> BoundsList => _boundsList;
public List<NativeVarInfo> VariablesList => _variablesList;
public Machine Machine => _machine;

/// <summary>
/// Convert a register number in debug info into a machine-specific register
/// </summary>
private static string GetPlatformSpecificRegister(Machine machine, int regnum)
public static string GetPlatformSpecificRegister(Machine machine, int regnum)
{
switch (machine)
{
Expand Down Expand Up @@ -233,35 +162,6 @@ private void ParseNativeVarInfo(byte[] image, int offset)
entry.VariableLocation = varLoc;
_variablesList.Add(entry);
}

if (_normalize)
{
_variablesList.Sort(CompareNativeVarInfo);
}
}

private static int CompareNativeVarInfo(NativeVarInfo left, NativeVarInfo right)
{
if (left.VariableNumber < right.VariableNumber)
{
return -1;
}
else if (left.VariableNumber > right.VariableNumber)
{
return 1;
}
else if (left.StartOffset < right.StartOffset)
{
return -1;
}
else if (left.StartOffset > right.StartOffset)
{
return 1;
}
else
{
return 0;
}
}

private int ReadEncodedStackOffset(NibbleReader reader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;

namespace R2RDump
namespace ILCompiler.Reflection.ReadyToRun
{
struct DebugInfoBoundsEntry
public struct DebugInfoBoundsEntry
{
public uint NativeOffset;
public uint ILOffset;
public SourceTypes SourceTypes;
}

struct NativeVarInfo
public struct NativeVarInfo
{
public uint StartOffset;
public uint EndOffset;
Expand All @@ -22,7 +23,7 @@ struct NativeVarInfo
}

[Flags]
enum SourceTypes
public enum SourceTypes
{
/// <summary>
/// Indicates that no other options apply
Expand Down Expand Up @@ -50,15 +51,15 @@ enum SourceTypes
CallInstruction = 0x10
}

enum MappingTypes : int
public enum MappingTypes : int
{
NoMapping = -1,
Prolog = -2,
Epilog = -3,
MaxMappingValue = Epilog
}

enum ImplicitILArguments
public enum ImplicitILArguments
{
VarArgsHandle = -1,
ReturnBuffer = -2,
Expand All @@ -67,7 +68,7 @@ enum ImplicitILArguments
Max = Unknown
}

enum VarLocType
public enum VarLocType
{
VLT_REG, // variable is in a register
VLT_REG_BYREF, // address of the variable is in a register
Expand All @@ -85,7 +86,7 @@ enum VarLocType
VLT_INVALID,
}

struct VarLoc
public struct VarLoc
{
public VarLocType VarLocType;
// What's stored in the Data# fields changes based on VarLocType and will be
Expand All @@ -94,4 +95,30 @@ struct VarLoc
public int Data2;
public int Data3;
}
public class NativeVarInfoComparer : IComparer<NativeVarInfo>
{
public int Compare(NativeVarInfo left, NativeVarInfo right)
{
if (left.VariableNumber < right.VariableNumber)
{
return -1;
}
else if (left.VariableNumber > right.VariableNumber)
{
return 1;
}
else if (left.StartOffset < right.StartOffset)
{
return -1;
}
else if (left.StartOffset > right.StartOffset)
{
return 1;
}
else
{
return 0;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Reflection.Metadata;
using System.Text;

namespace R2RDump
namespace ILCompiler.Reflection.ReadyToRun
{
public class DisassemblingGenericContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System.Reflection.PortableExecutable;
using System.Text;

namespace R2RDump
namespace ILCompiler.Reflection.ReadyToRun
{
/// <summary>
/// If COR_ILMETHOD_SECT_HEADER::Kind() = CorILMethod_Sect_EHTable then the attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Reflection.PortableExecutable;
using System.Text;

namespace R2RDump
namespace ILCompiler.Reflection.ReadyToRun
{
/// <summary>
/// based on <a href="https://github.com/dotnet/coreclr/blob/master/src/inc/gcinfotypes.h">src\inc\gcinfotypes.h</a> infoHdrAdjustConstants
Expand Down
Loading