Browse Source

Some changes I wanted

pull/2067/head
Andrew Au 5 years ago
parent
commit
28a1382a52
  1. 4
      ILSpy.ReadyToRun/ILSpy.ReadyToRun.csproj
  2. 57
      ILSpy.ReadyToRun/ReadyToRunLanguage.cs
  3. 2
      ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml
  4. 14
      ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs
  5. 24
      ILSpy.ReadyToRun/ReadyToRunOptions.cs
  6. 4
      ILSpy/ILSpy.csproj

4
ILSpy.ReadyToRun/ILSpy.ReadyToRun.csproj

@ -37,9 +37,6 @@ @@ -37,9 +37,6 @@
<ProjectReference Include="..\SharpTreeView\ICSharpCode.TreeView.csproj">
<Private>False</Private>
</ProjectReference>
<Reference Include="ILCompiler.Reflection.ReadyToRun">
<HintPath>..\..\..\Desktop\r2r\ILCompiler.Reflection.ReadyToRun\bin\Debug\netstandard2.0\ILCompiler.Reflection.ReadyToRun.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Xaml" />
@ -60,6 +57,7 @@ @@ -60,6 +57,7 @@
<ItemGroup>
<PackageReference Include="Iced" Version="1.6.0" />
<PackageReference Include="ILCompiler.Reflection.ReadyToRun" Version="1.0.9-alpha" />
</ItemGroup>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />

57
ILSpy.ReadyToRun/ReadyToRunLanguage.cs

@ -86,8 +86,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -86,8 +86,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun
.GroupBy(m => m.MethodHandle)
.ToDictionary(g => g.Key, g => g.ToArray());
}
bool showMetadataTokens = ILSpy.Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokens;
bool showMetadataTokensInBase10 = ILSpy.Options.DisplaySettingsPanel.CurrentDisplaySettings.ShowMetadataTokensInBase10;
if (cacheEntry.methodMap.TryGetValue(method.MetadataToken, out var methods)) {
@ -115,7 +113,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -115,7 +113,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun
for (int i = 0; i < debugInfo.VariablesList.Count; ++i) {
var varLoc = debugInfo.VariablesList[i];
try {
HashSet <Tuple<DebugInfo, NativeVarInfo>> typeSet = new HashSet<Tuple<DebugInfo, NativeVarInfo>>();
HashSet<Tuple<DebugInfo, NativeVarInfo>> typeSet = new HashSet<Tuple<DebugInfo, NativeVarInfo>>();
bool found = debugInfoDict.TryGetValue(varLoc.VariableLocation.VarLocType, out typeSet);
if (found) {
typeSet.Add(new Tuple<DebugInfo, NativeVarInfo>(debugInfo, varLoc));
@ -124,14 +122,12 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -124,14 +122,12 @@ namespace ICSharpCode.ILSpy.ReadyToRun
debugInfoDict.Add(varLoc.VariableLocation.VarLocType, typeSet);
typeSet.Add(new Tuple<DebugInfo, NativeVarInfo>(debugInfo, varLoc));
}
} catch (ArgumentNullException) {
output.WriteLine("Failed to find hash set of Debug info type");
}
if (varLoc.VariableLocation.VarLocType != VarLocType.VLT_REG && varLoc.VariableLocation.VarLocType != VarLocType.VLT_STK
&& varLoc.VariableLocation.VarLocType != VarLocType.VLT_STK_BYREF) {
//debugInfoDict.Add(varLoc.VariableLocation.VarLocType, )
output.WriteLine($" Variable Number: {varLoc.VariableNumber}");
output.WriteLine($" Start Offset: 0x{varLoc.StartOffset:X}");
output.WriteLine($" End Offset: 0x{varLoc.EndOffset:X}");
@ -142,7 +138,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -142,7 +138,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun
case VarLocType.VLT_REG_BYREF:
output.WriteLine($" Register: {DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varLoc.VariableLocation.Data1)}");
break;
case VarLocType.VLT_STK:
case VarLocType.VLT_STK_BYREF:
output.WriteLine($" Base Register: {DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varLoc.VariableLocation.Data1)}");
@ -172,25 +167,20 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -172,25 +167,20 @@ namespace ICSharpCode.ILSpy.ReadyToRun
case VarLocType.VLT_FIXED_VA:
output.WriteLine($" Offset: {DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varLoc.VariableLocation.Data1)}");
break;
default:
throw new BadImageFormatException("Unexpected var loc type");
}
output.WriteLine("");
}
}
}
}
return debugInfoDict;
}
private Dictionary<ulong, HashSet<UnwindCode>> WriteUnwindInfo(RuntimeFunction runtimeFunction, ITextOutput output)
private Dictionary<ulong, UnwindCode> WriteUnwindInfo(RuntimeFunction runtimeFunction, ITextOutput output)
{
Dictionary<ulong, HashSet<UnwindCode>> unwindCodes = new Dictionary<ulong, HashSet<UnwindCode>>();
Dictionary<ulong, UnwindCode> unwindCodes = new Dictionary<ulong, UnwindCode>();
if (runtimeFunction.UnwindInfo is UnwindInfo amd64UnwindInfo) {
string parsedFlags = "";
if ((amd64UnwindInfo.Flags & (int)UnwindFlags.UNW_FLAG_EHANDLER) != 0) {
@ -210,13 +200,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -210,13 +200,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun
WriteCommentLine(output, $"Flags: 0x{amd64UnwindInfo.Flags:X2}{parsedFlags}");
WriteCommentLine(output, $"FrameRegister: {((amd64UnwindInfo.FrameRegister == 0) ? "none" : amd64UnwindInfo.FrameRegister.ToString())}");
for (int unwindCodeIndex = 0; unwindCodeIndex < amd64UnwindInfo.CountOfUnwindCodes; unwindCodeIndex++) {
if (unwindCodes.ContainsKey((ulong)(amd64UnwindInfo.UnwindCodeArray[unwindCodeIndex].CodeOffset))) {
unwindCodes[(ulong)(amd64UnwindInfo.UnwindCodeArray[unwindCodeIndex].CodeOffset)].Add(amd64UnwindInfo.UnwindCodeArray[unwindCodeIndex]);
} else {
HashSet<UnwindCode> codeSet = new HashSet<UnwindCode>();
codeSet.Add(amd64UnwindInfo.UnwindCodeArray[unwindCodeIndex]);
unwindCodes.Add((ulong)(amd64UnwindInfo.UnwindCodeArray[unwindCodeIndex].CodeOffset), codeSet);
}
unwindCodes.Add((ulong)(amd64UnwindInfo.UnwindCodeArray[unwindCodeIndex].CodeOffset), amd64UnwindInfo.UnwindCodeArray[unwindCodeIndex]);
}
}
return unwindCodes;
@ -224,19 +208,25 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -224,19 +208,25 @@ namespace ICSharpCode.ILSpy.ReadyToRun
private void Disassemble(PEFile currentFile, ITextOutput output, ReadyToRunReader reader, ReadyToRunMethod readyToRunMethod, RuntimeFunction runtimeFunction, int bitness, ulong address, bool showMetadataTokens, bool showMetadataTokensInBase10)
{
WriteCommentLine(output, readyToRunMethod.SignatureString);
Dictionary<ulong, HashSet<UnwindCode>> unwindInfo = null;
Dictionary<ulong, UnwindCode> unwindInfo = null;
if (ReadyToRunOptions.GetIsShowUnwindInfo(null) && bitness == 64) {
unwindInfo = WriteUnwindInfo(runtimeFunction, output);
}
Dictionary<VarLocType, HashSet<Tuple<DebugInfo, NativeVarInfo>>> debugInfo = WriteDebugInfo(readyToRunMethod, output);
bool isShowDebugInfo = ReadyToRunOptions.GetIsShowDebugInfo(null);
Dictionary<VarLocType, HashSet<Tuple<DebugInfo, NativeVarInfo>>> debugInfo = null;
if (isShowDebugInfo) {
debugInfo = WriteDebugInfo(readyToRunMethod, output);
}
byte[] codeBytes = new byte[runtimeFunction.Size];
for (int i = 0; i < runtimeFunction.Size; i++) {
codeBytes[i] = reader.Image[reader.GetOffset(runtimeFunction.StartAddress) + i];
}
// TODO: Decorate the disassembly with GC
// TODO: Decorate the disassembly with GCInfo
var codeReader = new ByteArrayCodeReader(codeBytes);
var decoder = Decoder.Create(bitness, codeReader);
decoder.IP = address;
@ -259,12 +249,9 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -259,12 +249,9 @@ namespace ICSharpCode.ILSpy.ReadyToRun
formatter.Options.FirstOperandCharIndex = 10;
var tempOutput = new StringOutput();
ulong baseInstrIP = instructions[0].IP;
int counter = -1;
foreach (var instr in instructions) {
counter++;
int byteBaseIndex = (int)(instr.IP - address);
if (runtimeFunction.DebugInfo != null) {
if (isShowDebugInfo && runtimeFunction.DebugInfo != null) {
foreach (var bound in runtimeFunction.DebugInfo.BoundsList) {
if (bound.NativeOffset == byteBaseIndex) {
if (bound.ILOffset == (uint)DebugInfoBoundsType.Prolog) {
@ -277,7 +264,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -277,7 +264,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun
}
}
}
formatter.Format(instr, tempOutput);
output.Write(instr.IP.ToString("X16"));
output.Write(" ");
@ -286,8 +272,9 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -286,8 +272,9 @@ namespace ICSharpCode.ILSpy.ReadyToRun
output.Write(codeBytes[byteBaseIndex + i].ToString("X2"));
}
int missingBytes = 10 - instrLen;
for (int i = 0; i < missingBytes; i++)
for (int i = 0; i < missingBytes; i++) {
output.Write(" ");
}
output.Write(" ");
output.Write(tempOutput.ToStringAndReset());
DecorateUnwindInfo(output, unwindInfo, baseInstrIP, instr);
@ -297,13 +284,12 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -297,13 +284,12 @@ namespace ICSharpCode.ILSpy.ReadyToRun
output.WriteLine();
}
private static void DecorateUnwindInfo(ITextOutput output, Dictionary<ulong, HashSet<UnwindCode>> unwindInfo, ulong baseInstrIP, Instruction instr)
private static void DecorateUnwindInfo(ITextOutput output, Dictionary<ulong, UnwindCode> unwindInfo, ulong baseInstrIP, Instruction instr)
{
ulong nextInstructionOffset = instr.NextIP - baseInstrIP;
if (unwindInfo != null && unwindInfo.ContainsKey(nextInstructionOffset)) {
foreach (var unwindCode in unwindInfo[nextInstructionOffset]) {
output.Write($" ; {unwindCode.UnwindOp}({unwindCode.OpInfoStr})");
}
UnwindCode unwindCode = unwindInfo[nextInstructionOffset];
output.Write($" ; {unwindCode.UnwindOp}({unwindCode.OpInfoStr})");
}
}
@ -338,7 +324,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -338,7 +324,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun
if (varInfo.StartOffset < instr.IP - baseInstrIP && varInfo.EndOffset > instr.IP - baseInstrIP &&
DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varInfo.VariableLocation.Data1) == usedMemInfo.Base.ToString() &&
adjOffset == usedMemInfo.Displacement) {
output.Write($"; [{usedMemInfo.Base.ToString()}{(negativeOffset ? '-' : '+')}{Math.Abs(stackOffset)}] = {varInfo.Variable.Type} {varInfo.Variable.Index}");
}
}
@ -361,7 +346,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -361,7 +346,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun
var varInfo = tuple.Item2;
if (varInfo.StartOffset < instr.IP - baseInstrIP && varInfo.EndOffset > instr.IP - baseInstrIP &&
DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varInfo.VariableLocation.Data1) == usedMemInfo.Register.ToString()) {
output.Write($"; {usedMemInfo.Register.ToString()} = {varInfo.Variable.Type} {varInfo.Variable.Index}");
}
}
@ -402,7 +386,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -402,7 +386,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun
output.WriteLine(reader.ImportCellNames[importCellAddress]);
break;
}
output.WriteLine();
} else {
output.WriteLine();

2
ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml

@ -15,5 +15,7 @@ @@ -15,5 +15,7 @@
<ComboBox Grid.Column="1" Margin="3" ItemsSource="{Binding DisassemblyFormats}" SelectedItem="{Binding DisassemblyFormat}" />
<TextBlock Grid.Row="1" Margin="3">Show Unwind Info</TextBlock>
<CheckBox Grid.Row="1" Grid.Column="1" Margin="3" IsChecked="{Binding IsShowUnwindInfo}" />
<TextBlock Grid.Row="2" Margin="3">Show Debug Info</TextBlock>
<CheckBox Grid.Row="2" Grid.Column="1" Margin="3" IsChecked="{Binding IsShowDebugInfo}" />
</Grid>
</UserControl>

14
ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs

@ -36,6 +36,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -36,6 +36,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun
Options s = new Options();
s.DisassemblyFormat = ReadyToRunOptions.GetDisassemblyFormat(settings);
s.IsShowUnwindInfo = ReadyToRunOptions.GetIsShowUnwindInfo(settings);
s.IsShowDebugInfo = ReadyToRunOptions.GetIsShowDebugInfo(settings);
this.DataContext = s;
}
@ -48,7 +49,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -48,7 +49,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun
public void Save(XElement root)
{
Options s = (Options)this.DataContext;
ReadyToRunOptions.SetDisassemblyOptions(root, s.DisassemblyFormat, s.IsShowUnwindInfo);
ReadyToRunOptions.SetDisassemblyOptions(root, s.DisassemblyFormat, s.IsShowUnwindInfo, s.IsShowDebugInfo);
}
}
@ -71,6 +72,17 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -71,6 +72,17 @@ namespace ICSharpCode.ILSpy.ReadyToRun
}
}
private bool isShowDebugInfo;
public bool IsShowDebugInfo {
get {
return isShowDebugInfo;
}
set {
isShowDebugInfo = value;
OnPropertyChanged(nameof(IsShowDebugInfo));
}
}
private string disassemblyFormat;

24
ILSpy.ReadyToRun/ReadyToRunOptions.cs

@ -43,7 +43,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -43,7 +43,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun
}
public static bool GetIsShowUnwindInfo(ILSpySettings settings)
{
if (settings == null) {
settings = ILSpySettings.Load();
@ -58,11 +57,27 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -58,11 +57,27 @@ namespace ICSharpCode.ILSpy.ReadyToRun
}
}
public static void SetDisassemblyOptions(XElement root, string disassemblyFormat, bool IsShowUnwindInfo)
public static bool GetIsShowDebugInfo(ILSpySettings settings)
{
if (settings == null) {
settings = ILSpySettings.Load();
}
XElement e = settings[ns + "ReadyToRunOptions"];
XAttribute a = e.Attribute("IsShowDebugInfo");
if (a == null) {
return true;
} else {
return (bool)a;
}
}
public static void SetDisassemblyOptions(XElement root, string disassemblyFormat, bool isShowUnwindInfo, bool isShowDebugInfo)
{
XElement section = new XElement(ns + "ReadyToRunOptions");
section.SetAttributeValue("DisassemblyFormat", disassemblyFormat);
section.SetAttributeValue("IsShowUnwindInfo", IsShowUnwindInfo);
section.SetAttributeValue("IsShowUnwindInfo", isShowUnwindInfo);
section.SetAttributeValue("IsShowDebugInfo", isShowDebugInfo);
XElement existingElement = root.Element(ns + "ReadyToRunOptions");
if (existingElement != null) {
existingElement.ReplaceWith(section);
@ -70,8 +85,5 @@ namespace ICSharpCode.ILSpy.ReadyToRun @@ -70,8 +85,5 @@ namespace ICSharpCode.ILSpy.ReadyToRun
root.Add(section);
}
}
}
}

4
ILSpy/ILSpy.csproj

@ -128,7 +128,9 @@ @@ -128,7 +128,9 @@
<Compile Include="Commands\ShowDebugSteps.cs" />
<Compile Include="Commands\SortAssemblyListCommand.cs" />
<Compile Include="Controls\BoolToVisibilityConverter.cs" />
<Compile Include="Controls\CustomDialog.cs" />
<Compile Include="Controls\CustomDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Controls\GridViewColumnAutoSize.cs" />
<Compile Include="Controls\MarkupExtensions.cs" />
<Compile Include="Controls\ResourceObjectTable.xaml.cs">

Loading…
Cancel
Save