diff --git a/Debugger/ILSpy.Debugger/DebuggedType.cs b/Debugger/ILSpy.Debugger/DebuggedType.cs index e3769105f..b649334b3 100644 --- a/Debugger/ILSpy.Debugger/DebuggedType.cs +++ b/Debugger/ILSpy.Debugger/DebuggedType.cs @@ -17,6 +17,7 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Collections.Generic; using ICSharpCode.Decompiler; using Mono.Cecil; @@ -36,5 +37,10 @@ namespace ILSpy.Debugger /// Gets or sets the decompiled language. /// public static DecompiledLanguages Language { get; set; } + + /// + /// List of loaded assemblies. + /// + public static IEnumerable LoadedAssemblies { get; set; } } } diff --git a/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs b/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs index 23bab2173..f8d298e3c 100644 --- a/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs +++ b/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; @@ -13,6 +14,7 @@ using System.Windows.Media; using Debugger; using Debugger.Interop.CorPublish; using ICSharpCode.Decompiler; +using ICSharpCode.Decompiler.Ast; using ICSharpCode.NRefactory; using ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.Visitors; @@ -567,8 +569,8 @@ namespace ILSpy.Debugger.Services uint token; SourceCodeMapping map = CodeMappings - .GetStorage(bookmark.Language) - .GetInstructionByTypeAndLine(bookmark.Type.FullName, bookmark.LineNumber, out token); + .GetStorage(bookmark.Language) + .GetInstructionByTypeAndLine(bookmark.Type.FullName, bookmark.LineNumber, out token); if (map != null) { breakpoint = new ILBreakpoint( @@ -824,6 +826,38 @@ namespace ILSpy.Debugger.Services TypeDefinition type; if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out type, out line)) { DebuggerService.JumpToCurrentLine(type, line, 0, line, 0); + } else { + var debugType = frame.MethodInfo.DeclaringType; + string fullName = debugType.Namespace + "." + debugType.Name; + FileStream ds = new FileStream("dasda", FileMode.Create); + + // search for type in the current assembly list + TypeReference typeRef = null; + foreach (var assembly in DebugData.LoadedAssemblies) { + foreach (var module in assembly.Modules) { + if (module.TryGetTypeReference(fullName, out typeRef)) { + break; + } + } + + if (typeRef != null) + break; + } + + if (typeRef != null) { + // decompile on demand + AstBuilder builder = new AstBuilder(new DecompilerContext()); + builder.AddType(typeRef.Resolve()); + builder.GenerateCode(new PlainTextOutput()); + + // jump + if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out type, out line)) { + DebuggerService.JumpToCurrentLine(type, line, 0, line, 0); + } + } else { + // continue since we cannot find the debugged type + Continue(); + } } } } diff --git a/ICSharpCode.Decompiler/PlainTextOutput.cs b/ICSharpCode.Decompiler/PlainTextOutput.cs index 8464c22d5..3e167b01b 100644 --- a/ICSharpCode.Decompiler/PlainTextOutput.cs +++ b/ICSharpCode.Decompiler/PlainTextOutput.cs @@ -38,6 +38,7 @@ namespace ICSharpCode.Decompiler public PlainTextOutput() { this.writer = new StringWriter(); + CurrentLine = 1; } public int CurrentLine { get; set; } diff --git a/ILSpy/Commands/DebuggerCommands.cs b/ILSpy/Commands/DebuggerCommands.cs index 304955318..ebe36cf2a 100644 --- a/ILSpy/Commands/DebuggerCommands.cs +++ b/ILSpy/Commands/DebuggerCommands.cs @@ -17,9 +17,9 @@ using Microsoft.Win32; namespace ICSharpCode.ILSpy.Commands { - internal abstract class DebuggerCommands : SimpleCommand + internal abstract class DebuggerCommand : SimpleCommand { - public DebuggerCommands() + public DebuggerCommand() { MainWindow.Instance.KeyUp += OnKeyUp; } @@ -75,6 +75,11 @@ namespace ICSharpCode.ILSpy.Commands } #endregion + public override void Execute(object parameter) + { + DebugData.LoadedAssemblies = MainWindow.Instance.AssemblyList.assemblies.Select(a => a.AssemblyDefinition); + } + protected static IDebugger CurrentDebugger { get { return DebuggerService.CurrentDebugger; @@ -166,7 +171,7 @@ namespace ICSharpCode.ILSpy.Commands MenuCategory = "Debugger1", Header = "Attach to _running application", MenuOrder = 0)] - internal sealed class AttachCommand : DebuggerCommands + internal sealed class AttachCommand : DebuggerCommand { public override void Execute(object parameter) { @@ -186,7 +191,7 @@ namespace ICSharpCode.ILSpy.Commands InputGestureText = "F5", IsEnabled = false, MenuOrder = 1)] - internal sealed class ContinueDebuggingCommand : DebuggerCommands + internal sealed class ContinueDebuggingCommand : DebuggerCommand { public override void Execute(object parameter) { @@ -202,12 +207,14 @@ namespace ICSharpCode.ILSpy.Commands InputGestureText = "F11", IsEnabled = false, MenuOrder = 2)] - internal sealed class StepIntoCommand : DebuggerCommands + internal sealed class StepIntoCommand : DebuggerCommand { public override void Execute(object parameter) { - if (CurrentDebugger.IsDebugging && !CurrentDebugger.IsProcessRunning) + if (CurrentDebugger.IsDebugging && !CurrentDebugger.IsProcessRunning) { + base.Execute(null); CurrentDebugger.StepInto(); + } } } @@ -218,7 +225,7 @@ namespace ICSharpCode.ILSpy.Commands InputGestureText = "F10", IsEnabled = false, MenuOrder = 3)] - internal sealed class StepOverCommand : DebuggerCommands + internal sealed class StepOverCommand : DebuggerCommand { public override void Execute(object parameter) { @@ -233,7 +240,7 @@ namespace ICSharpCode.ILSpy.Commands Header = "Step out", IsEnabled = false, MenuOrder = 4)] - internal sealed class StepOutCommand : DebuggerCommands + internal sealed class StepOutCommand : DebuggerCommand { public override void Execute(object parameter) { @@ -247,7 +254,7 @@ namespace ICSharpCode.ILSpy.Commands Header = "_Detach from running application", IsEnabled = false, MenuOrder = 5)] - internal sealed class DetachCommand : DebuggerCommands + internal sealed class DetachCommand : DebuggerCommand { public override void Execute(object parameter) { @@ -265,7 +272,7 @@ namespace ICSharpCode.ILSpy.Commands MenuCategory = "Debugger2", Header = "Remove all _breakpoints", MenuOrder = 6)] - internal sealed class RemoveBreakpointsCommand : DebuggerCommands + internal sealed class RemoveBreakpointsCommand : DebuggerCommand { public override void Execute(object parameter) { @@ -288,7 +295,7 @@ namespace ICSharpCode.ILSpy.Commands MenuCategory = "Debugger3", Header = "Debug an _executable", MenuOrder = 7)] - internal sealed class DebugExecutableCommand : DebuggerCommands + internal sealed class DebugExecutableCommand : DebuggerCommand { public override void Execute(object parameter) {