From 333e3644b760060d34d92245b93ed6ce9876de83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Tue, 5 Feb 2013 23:46:10 +0000 Subject: [PATCH] Slightly improve mapping from IL to source code --- src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs | 10 ++++++++-- src/AddIns/Debugger/Debugger.Core/StackFrame.cs | 1 + .../DisplayBindings/ILSpyAddIn/DebuggerTextOutput.cs | 2 ++ .../DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs | 9 +++++++-- .../ILSpyAddIn/ViewContent/DecompiledViewContent.cs | 4 ++++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs b/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs index ebb6468f94..9711582ab7 100644 --- a/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs +++ b/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs @@ -28,10 +28,11 @@ namespace Debugger public override string ToString() { - return string.Format("{0}:{1},{2}-{3},{4}", + return string.Format("{0}:{1},{2}-{3},{4} IL:{5}", Path.GetFileName(this.Filename ?? string.Empty), this.StartLine, this.StartColumn, - this.EndLine, this.EndColumn); + this.EndLine, this.EndColumn, + string.Join(" ", this.ILRanges)); } } @@ -45,6 +46,11 @@ namespace Debugger this.From = from; this.To = to; } + + public override string ToString() + { + return string.Format("{0:X2}-{1:X2}", From, To); + } } public class ILLocalVariable diff --git a/src/AddIns/Debugger/Debugger.Core/StackFrame.cs b/src/AddIns/Debugger/Debugger.Core/StackFrame.cs index 35acdd82e7..105259272e 100644 --- a/src/AddIns/Debugger/Debugger.Core/StackFrame.cs +++ b/src/AddIns/Debugger/Debugger.Core/StackFrame.cs @@ -156,6 +156,7 @@ namespace Debugger List stepRanges = new List(); var seq = this.Module.SymbolSource.GetSequencePoint(this.MethodInfo, this.IP); if (seq != null) { + Process.TraceMessage("Step over: {0}", seq); stepRanges.AddRange(seq.ILRanges); stepRanges.AddRange(this.Module.SymbolSource.GetIgnoredILRanges(this.MethodInfo)); } diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/DebuggerTextOutput.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/DebuggerTextOutput.cs index 5dce8fa0b0..a8e99300e5 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/DebuggerTextOutput.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/DebuggerTextOutput.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using ICSharpCode.Core; using ICSharpCode.Decompiler; using Mono.Cecil; @@ -66,6 +67,7 @@ namespace ICSharpCode.ILSpyAddIn public void AddDebugSymbols(MethodDebugSymbols methodDebugSymbols) { var id = XmlDocKeyProvider.GetKey(methodDebugSymbols.CecilMethod); + methodDebugSymbols.SequencePoints = methodDebugSymbols.SequencePoints.OrderBy(s => s.ILOffset).ToList(); this.DebugSymbols.Add(id, methodDebugSymbols); output.AddDebugSymbols(methodDebugSymbols); } diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs index f35d64a4d9..82244b0995 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs @@ -15,7 +15,8 @@ namespace ICSharpCode.ILSpyAddIn { public static MethodDebugSymbols GetSymbols(IMethod method) { - var id = IdStringProvider.GetIdString(method); + // Use the non-specialised method definition to look up decompiled symbols + var id = IdStringProvider.GetIdString(method.MemberDefinition); var content = DecompiledViewContent.Get(method); if (content != null && content.DebugSymbols.ContainsKey(id)) { return content.DebugSymbols[id]; @@ -31,7 +32,11 @@ namespace ICSharpCode.ILSpyAddIn var content = DecompiledViewContent.Get(method); var seq = symbols.SequencePoints.FirstOrDefault(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To)); - return seq.ToDebugger(symbols, content.VirtualFileName); + if (seq == null) + seq = symbols.SequencePoints.FirstOrDefault(p => iloffset <= p.ILOffset); + if (seq != null) + return seq.ToDebugger(symbols, content.VirtualFileName); + return null; } public Debugger.SequencePoint GetSequencePoint(Module module, string filename, int line, int column) diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/DecompiledViewContent.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/DecompiledViewContent.cs index 327d1db451..287d0e57e6 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/DecompiledViewContent.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/DecompiledViewContent.cs @@ -13,6 +13,7 @@ using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.Core; using ICSharpCode.Decompiler; using ICSharpCode.Decompiler.Ast; +using ICSharpCode.Decompiler.Disassembler; using ICSharpCode.NRefactory.Documentation; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.ILSpyAddIn.LaunchILSpy; @@ -235,6 +236,9 @@ namespace ICSharpCode.ILSpyAddIn astBuilder.AddType(typeDefinition); astBuilder.GenerateCode(textOutput); + // ReflectionDisassembler disasm = new ReflectionDisassembler(textOutput, true, cancellationToken); + // disasm.DisassembleType(typeDefinition); + // save decompilation data memberLocations = textOutput.MemberLocations; this.DebugSymbols = textOutput.DebugSymbols;