diff --git a/ILSpy.ReadyToRun/ReadyToRunLanguage.cs b/ILSpy.ReadyToRun/ReadyToRunLanguage.cs index 187f1b8e9..0cbef4902 100644 --- a/ILSpy.ReadyToRun/ReadyToRunLanguage.cs +++ b/ILSpy.ReadyToRun/ReadyToRunLanguage.cs @@ -103,114 +103,33 @@ namespace ICSharpCode.ILSpy.ReadyToRun output.WriteLine("; " + comment); } - private void WriteDebugInfo(ReadyToRunMethod readyToRunMethod, ITextOutput output) - { - IReadOnlyList runTimeList = readyToRunMethod.RuntimeFunctions; - foreach (RuntimeFunction runtimeFunction in runTimeList) { - DebugInfo debugInfo = runtimeFunction.DebugInfo; - if (debugInfo.BoundsList.Count > 0) - output.WriteLine("Debug Info"); - - output.WriteLine(" Bounds:"); - for (int i = 0; i < debugInfo.BoundsList.Count; ++i) { - output.Write(" "); - output.Write($"Native Offset: 0x{debugInfo.BoundsList[i].NativeOffset:X}, "); - if (debugInfo.BoundsList[i].ILOffset == (uint)DebugInfoBoundsType.NoMapping) { - output.Write("NoMapping"); - } else if (debugInfo.BoundsList[i].ILOffset == (uint)DebugInfoBoundsType.Prolog) { - output.Write("Prolog"); - } else if (debugInfo.BoundsList[i].ILOffset == (uint)DebugInfoBoundsType.Epilog) { - output.Write("Epilog"); - } else { - output.WriteLine($"IL Offset: 0x{debugInfo.BoundsList[i].ILOffset:x4}"); - } - output.Write($", Srouce Types: {debugInfo.BoundsList[i].SourceTypes}"); - output.WriteLine(); - } - output.WriteLine(""); - - if (debugInfo.VariablesList.Count > 0) - output.WriteLine(" Variable Locations:"); - - for (int i = 0; i < debugInfo.VariablesList.Count; ++i) { - var varLoc = debugInfo.VariablesList[i]; - output.WriteLine($" Variable Number: {varLoc.VariableNumber}"); - output.WriteLine($" Start Offset: 0x{varLoc.StartOffset:X}"); - output.WriteLine($" End Offset: 0x{varLoc.EndOffset:X}"); - output.WriteLine($" Loc Type: {varLoc.VariableLocation.VarLocType}"); - switch (varLoc.VariableLocation.VarLocType) { - case VarLocType.VLT_REG: - case VarLocType.VLT_REG_FP: - 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)}"); - output.WriteLine($" Stack Offset: {varLoc.VariableLocation.Data2}"); - break; - case VarLocType.VLT_REG_REG: - output.WriteLine($" Register 1: {DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varLoc.VariableLocation.Data1)}"); - output.WriteLine($" Register 2: {DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varLoc.VariableLocation.Data2)}"); - break; - case VarLocType.VLT_REG_STK: - output.WriteLine($" Register: {DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varLoc.VariableLocation.Data1)}"); - output.WriteLine($" Base Register: {DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varLoc.VariableLocation.Data2)}"); - output.WriteLine($" Stack Offset: {varLoc.VariableLocation.Data3}"); - break; - case VarLocType.VLT_STK_REG: - output.WriteLine($" Stack Offset: {varLoc.VariableLocation.Data1}"); - output.WriteLine($" Base Register: {DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varLoc.VariableLocation.Data2)}"); - output.WriteLine($" Register: {DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varLoc.VariableLocation.Data3)}"); - break; - case VarLocType.VLT_STK2: - output.WriteLine($" Base Register: {DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varLoc.VariableLocation.Data1)}"); - output.WriteLine($" Stack Offset: {varLoc.VariableLocation.Data2}"); - break; - case VarLocType.VLT_FPSTK: - output.WriteLine($" Offset: {DebugInfo.GetPlatformSpecificRegister(debugInfo.Machine, varLoc.VariableLocation.Data1)}"); - break; - 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(""); - } - } - } - private Dictionary WriteUnwindInfo(ReadyToRunMethod readyToRunMethod, ITextOutput output) + private Dictionary WriteUnwindInfo(RuntimeFunction runtimeFunction, ITextOutput output) { - IReadOnlyList runTimeList = readyToRunMethod.RuntimeFunctions; Dictionary unwindCodes = new Dictionary(); - foreach (RuntimeFunction i in runTimeList) { - if (i.UnwindInfo is UnwindInfo amd64UnwindInfo) { - string parsedFlags = ""; - if ((amd64UnwindInfo.Flags & (int)UnwindFlags.UNW_FLAG_EHANDLER) != 0) { - parsedFlags += " EHANDLER"; - } - if ((amd64UnwindInfo.Flags & (int)UnwindFlags.UNW_FLAG_UHANDLER) != 0) { - parsedFlags += " UHANDLER"; - } - if ((amd64UnwindInfo.Flags & (int)UnwindFlags.UNW_FLAG_CHAININFO) != 0) { - parsedFlags += " CHAININFO"; - } - if (parsedFlags.Length == 0) { - parsedFlags = " NHANDLER"; - } - WriteCommentLine(output, $"UnwindInfo:"); - WriteCommentLine(output, $"Version: {amd64UnwindInfo.Version}"); - 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++) { - unwindCodes.Add(amd64UnwindInfo.UnwindCodeArray[unwindCodeIndex].CodeOffset, amd64UnwindInfo.UnwindCodeArray[unwindCodeIndex]); + if (runtimeFunction.UnwindInfo is UnwindInfo amd64UnwindInfo) { + string parsedFlags = ""; + if ((amd64UnwindInfo.Flags & (int)UnwindFlags.UNW_FLAG_EHANDLER) != 0) { + parsedFlags += " EHANDLER"; + } + if ((amd64UnwindInfo.Flags & (int)UnwindFlags.UNW_FLAG_UHANDLER) != 0) { + parsedFlags += " UHANDLER"; + } + if ((amd64UnwindInfo.Flags & (int)UnwindFlags.UNW_FLAG_CHAININFO) != 0) { + parsedFlags += " CHAININFO"; + } + if (parsedFlags.Length == 0) { + parsedFlags = " NHANDLER"; + } + WriteCommentLine(output, $"UnwindInfo:"); + WriteCommentLine(output, $"Version: {amd64UnwindInfo.Version}"); + 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++) { + unwindCodes.Add((ulong)(amd64UnwindInfo.UnwindCodeArray[unwindCodeIndex].CodeOffset), amd64UnwindInfo.UnwindCodeArray[unwindCodeIndex]); - } } } return unwindCodes; @@ -221,12 +140,10 @@ namespace ICSharpCode.ILSpy.ReadyToRun WriteCommentLine(output, readyToRunMethod.SignatureString); Dictionary unwindInfo = null; if (ReadyToRunOptions.GetIsShowUnwindInfo(null) && bitness == 64) { - unwindInfo = WriteUnwindInfo(readyToRunMethod, output); + unwindInfo = WriteUnwindInfo(runtimeFunction, output); } - if (ReadyToRunOptions.GetIsShowDebugInfo(null)) { - 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]; @@ -289,7 +206,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun private static void DecorateUnwindInfo(ITextOutput output, Dictionary unwindInfo, ulong baseInstrIP, Instruction instr) { - ulong nextInstructionOffset = instr.IP + (ulong)instr.Length - baseInstrIP; + ulong nextInstructionOffset = instr.NextIP; if (unwindInfo != null && unwindInfo.ContainsKey(nextInstructionOffset)) { UnwindCode unwindCode = unwindInfo[nextInstructionOffset]; output.Write($" ; {unwindCode.UnwindOp}({unwindCode.OpInfoStr})"); diff --git a/ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs b/ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs index 3285434ee..3e81b1c7c 100644 --- a/ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs +++ b/ILSpy.ReadyToRun/ReadyToRunOptionPage.xaml.cs @@ -36,7 +36,6 @@ 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; } @@ -49,7 +48,7 @@ namespace ICSharpCode.ILSpy.ReadyToRun public void Save(XElement root) { Options s = (Options)this.DataContext; - ReadyToRunOptions.SetDisassemblyOptions(root, s.DisassemblyFormat, s.IsShowUnwindInfo, s.IsShowDebugInfo); + ReadyToRunOptions.SetDisassemblyOptions(root, s.DisassemblyFormat, s.IsShowUnwindInfo); } } @@ -73,17 +72,6 @@ namespace ICSharpCode.ILSpy.ReadyToRun } - private bool isShowDebugInfo; - public bool IsShowDebugInfo { - get { - return isShowDebugInfo; - } - set { - isShowDebugInfo = value; - OnPropertyChanged(nameof(isShowDebugInfo)); - } - } - private string disassemblyFormat; public string DisassemblyFormat {