Browse Source

Using the structured signature

pull/1991/head
Andrew Au 6 years ago
parent
commit
b935b4d065
  1. 38
      ILSpy.ReadyToRun/ReadyToRunLanguage.cs

38
ILSpy.ReadyToRun/ReadyToRunLanguage.cs

@ -22,6 +22,7 @@ using System.ComponentModel.Composition;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using System.Reflection.PortableExecutable; using System.Reflection.PortableExecutable;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Iced.Intel; using Iced.Intel;
@ -128,14 +129,16 @@ namespace ICSharpCode.ILSpy.ReadyToRun
var tempOutput = new StringOutput(); var tempOutput = new StringOutput();
foreach (var instr in instructions) { foreach (var instr in instructions) {
int byteBaseIndex = (int)(instr.IP - address); int byteBaseIndex = (int)(instr.IP - address);
foreach (var bound in runtimeFunction.DebugInfo.BoundsList) { if (runtimeFunction.DebugInfo != null) {
if (bound.NativeOffset == byteBaseIndex) { foreach (var bound in runtimeFunction.DebugInfo.BoundsList) {
if (bound.ILOffset == (uint)DebugInfoBoundsType.Prolog) { if (bound.NativeOffset == byteBaseIndex) {
WriteCommentLine(output, "Prolog"); if (bound.ILOffset == (uint)DebugInfoBoundsType.Prolog) {
} else if (bound.ILOffset == (uint)DebugInfoBoundsType.Epilog) { WriteCommentLine(output, "Prolog");
WriteCommentLine(output, "Epilog"); } else if (bound.ILOffset == (uint)DebugInfoBoundsType.Epilog) {
} else { WriteCommentLine(output, "Epilog");
WriteCommentLine(output, $"IL_{bound.ILOffset:x4}"); } else {
WriteCommentLine(output, $"IL_{bound.ILOffset:x4}");
}
} }
} }
} }
@ -150,11 +153,22 @@ namespace ICSharpCode.ILSpy.ReadyToRun
output.Write(" "); output.Write(" ");
output.Write(" "); output.Write(" ");
output.Write(tempOutput.ToStringAndReset()); output.Write(tempOutput.ToStringAndReset());
if (instr.IsCallNearIndirect && reader.ImportCellNames.ContainsKey((int)instr.IPRelativeMemoryAddress)) { int importCellAddress = (int)instr.IPRelativeMemoryAddress;
if (instr.IsCallNearIndirect && reader.ImportCellNames.ContainsKey(importCellAddress)) {
output.Write(" ;"); output.Write(" ;");
// TODO: Get the right PEFile ReadyToRunSignature signature = reader.ImportSignatures[(int)instr.IPRelativeMemoryAddress];
// TODO: Get the right method def token string formattedSignatureString = reader.ImportCellNames[importCellAddress];
output.WriteReference(method.ParentModule.PEFile, System.Reflection.Metadata.Ecma335.MetadataTokens.Handle(0x06001e24), reader.ImportCellNames[(int)instr.IPRelativeMemoryAddress]); MethodDefEntrySignature methodDefSignature = signature as MethodDefEntrySignature;
MethodRefEntrySignature methodRefSignature = signature as MethodRefEntrySignature;
if (methodDefSignature != null) {
int methodDefToken = unchecked((int)methodDefSignature.MethodDefToken);
output.WriteReference(method.ParentModule.PEFile, MetadataTokens.Handle(methodDefToken), formattedSignatureString);
} else if (methodRefSignature != null) {
int methodRefToken = unchecked((int)methodRefSignature.MethodRefToken);
output.WriteReference(method.ParentModule.PEFile, MetadataTokens.Handle(methodRefToken), formattedSignatureString);
} else {
output.WriteLine(formattedSignatureString);
}
output.WriteLine(); output.WriteLine();
} else { } else {
output.WriteLine(); output.WriteLine();

Loading…
Cancel
Save