Browse Source

Fix StepInto uncompiled code.

pull/191/merge
Eusebiu Marcu 14 years ago
parent
commit
eafc08a181
  1. 6
      Debugger/ILSpy.Debugger/DebuggedType.cs
  2. 38
      Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs
  3. 1
      ICSharpCode.Decompiler/PlainTextOutput.cs
  4. 29
      ILSpy/Commands/DebuggerCommands.cs

6
Debugger/ILSpy.Debugger/DebuggedType.cs

@ -17,6 +17,7 @@ @@ -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 @@ -36,5 +37,10 @@ namespace ILSpy.Debugger
/// Gets or sets the decompiled language.
/// </summary>
public static DecompiledLanguages Language { get; set; }
/// <summary>
/// List of loaded assemblies.
/// </summary>
public static IEnumerable<AssemblyDefinition> LoadedAssemblies { get; set; }
}
}

38
Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs

@ -4,6 +4,7 @@ using System; @@ -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; @@ -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 @@ -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 @@ -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();
}
}
}
}

1
ICSharpCode.Decompiler/PlainTextOutput.cs

@ -38,6 +38,7 @@ namespace ICSharpCode.Decompiler @@ -38,6 +38,7 @@ namespace ICSharpCode.Decompiler
public PlainTextOutput()
{
this.writer = new StringWriter();
CurrentLine = 1;
}
public int CurrentLine { get; set; }

29
ILSpy/Commands/DebuggerCommands.cs

@ -17,9 +17,9 @@ using Microsoft.Win32; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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)
{

Loading…
Cancel
Save