Browse Source

Merge pull request #2 from cshung/patches

Some changes I wanted
pull/2067/head
Edward Kazuya Carlson 5 years ago committed by GitHub
parent
commit
005135be0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      ILSpy.ReadyToRun/ILSpy.ReadyToRun.csproj
  2. 53
      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 @@
<ProjectReference Include="..\SharpTreeView\ICSharpCode.TreeView.csproj"> <ProjectReference Include="..\SharpTreeView\ICSharpCode.TreeView.csproj">
<Private>False</Private> <Private>False</Private>
</ProjectReference> </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="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="System.Xaml" /> <Reference Include="System.Xaml" />
@ -60,6 +57,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Iced" Version="1.6.0" /> <PackageReference Include="Iced" Version="1.6.0" />
<PackageReference Include="ILCompiler.Reflection.ReadyToRun" Version="1.0.9-alpha" />
</ItemGroup> </ItemGroup>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" /> <Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />

53
ILSpy.ReadyToRun/ReadyToRunLanguage.cs

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

2
ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml

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

14
ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs

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

24
ILSpy.ReadyToRun/ReadyToRunOptions.cs

@ -43,7 +43,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun
} }
public static bool GetIsShowUnwindInfo(ILSpySettings settings) public static bool GetIsShowUnwindInfo(ILSpySettings settings)
{ {
if (settings == null) { if (settings == null) {
settings = ILSpySettings.Load(); settings = ILSpySettings.Load();
@ -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"); XElement section = new XElement(ns + "ReadyToRunOptions");
section.SetAttributeValue("DisassemblyFormat", disassemblyFormat); section.SetAttributeValue("DisassemblyFormat", disassemblyFormat);
section.SetAttributeValue("IsShowUnwindInfo", IsShowUnwindInfo); section.SetAttributeValue("IsShowUnwindInfo", isShowUnwindInfo);
section.SetAttributeValue("IsShowDebugInfo", isShowDebugInfo);
XElement existingElement = root.Element(ns + "ReadyToRunOptions"); XElement existingElement = root.Element(ns + "ReadyToRunOptions");
if (existingElement != null) { if (existingElement != null) {
existingElement.ReplaceWith(section); existingElement.ReplaceWith(section);
@ -70,8 +85,5 @@ namespace ICSharpCode.ILSpy.ReadyToRun
root.Add(section); root.Add(section);
} }
} }
} }
} }

4
ILSpy/ILSpy.csproj

@ -128,7 +128,9 @@
<Compile Include="Commands\ShowDebugSteps.cs" /> <Compile Include="Commands\ShowDebugSteps.cs" />
<Compile Include="Commands\SortAssemblyListCommand.cs" /> <Compile Include="Commands\SortAssemblyListCommand.cs" />
<Compile Include="Controls\BoolToVisibilityConverter.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\GridViewColumnAutoSize.cs" />
<Compile Include="Controls\MarkupExtensions.cs" /> <Compile Include="Controls\MarkupExtensions.cs" />
<Compile Include="Controls\ResourceObjectTable.xaml.cs"> <Compile Include="Controls\ResourceObjectTable.xaml.cs">

Loading…
Cancel
Save