Browse Source

Prepare for debugging single methods or properties.

pull/191/merge
Eusebiu Marcu 15 years ago
parent
commit
e9d0de44fc
  1. 18
      Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs
  2. 2
      Debugger/ILSpy.Debugger/AvalonEdit/TextMarkerService.cs
  3. 6
      Debugger/ILSpy.Debugger/Bookmarks/BookmarkBase.cs
  4. 10
      Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs
  5. 4
      Debugger/ILSpy.Debugger/Bookmarks/BreakpointBookmark.cs
  6. 2
      Debugger/ILSpy.Debugger/Bookmarks/CurrentLineBookmark.cs
  7. 2
      Debugger/ILSpy.Debugger/Bookmarks/MarkerBookmark.cs
  8. 4
      Debugger/ILSpy.Debugger/DebuggedData.cs
  9. 6
      Debugger/ILSpy.Debugger/Services/Debugger/DebuggerService.cs
  10. 6
      Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs
  11. 4
      ILSpy/Commands/DebuggerCommands.cs
  12. 41
      ILSpy/TextView/DecompilerTextView.cs
  13. 3
      ILSpy/TreeNodes/MethodTreeNode.cs
  14. 2
      ILSpy/TreeNodes/PropertyTreeNode.cs
  15. 2
      ILSpy/TreeNodes/TypeTreeNode.cs

18
Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs

@ -59,7 +59,7 @@ namespace ICSharpCode.ILSpy.Debugger.AvalonEdit @@ -59,7 +59,7 @@ namespace ICSharpCode.ILSpy.Debugger.AvalonEdit
// create a dictionary line number => first bookmark
Dictionary<int, BookmarkBase> bookmarkDict = new Dictionary<int, BookmarkBase>();
foreach (var bm in BookmarkManager.Bookmarks) {
if (DebugData.CurrentType == null || bm.Type.FullName != DebugData.CurrentType.FullName)
if (DebugData.CurrentMember == null || bm.Member.FullName != DebugData.CurrentMember.FullName)
continue;
if (bm is BreakpointBookmark &&
((BreakpointBookmark)bm).Language != DebugData.Language)
@ -121,8 +121,8 @@ namespace ICSharpCode.ILSpy.Debugger.AvalonEdit @@ -121,8 +121,8 @@ namespace ICSharpCode.ILSpy.Debugger.AvalonEdit
BookmarkBase result = null;
foreach (BookmarkBase bm in BookmarkManager.Bookmarks) {
if (bm.LineNumber == line &&
DebugData.CurrentType != null &&
bm.Type.FullName == DebugData.CurrentType.FullName) {
DebugData.CurrentMember != null &&
bm.Member.FullName == DebugData.CurrentMember.FullName) {
if (result == null || bm.ZOrder > result.ZOrder)
result = bm;
}
@ -191,11 +191,11 @@ namespace ICSharpCode.ILSpy.Debugger.AvalonEdit @@ -191,11 +191,11 @@ namespace ICSharpCode.ILSpy.Debugger.AvalonEdit
InvalidateVisual();
}
if (DebugData.CurrentType == null)
if (DebugData.CurrentMember == null)
return;
BreakpointBookmark bm = BookmarkManager.Bookmarks.Find(
b => b.Type.FullName == DebugData.CurrentType.FullName &&
b => b.Member.FullName == DebugData.CurrentMember.FullName &&
b.LineNumber == GetLineFromMousePosition(e)
&& b is BreakpointBookmark) as BreakpointBookmark;
@ -228,22 +228,22 @@ namespace ICSharpCode.ILSpy.Debugger.AvalonEdit @@ -228,22 +228,22 @@ namespace ICSharpCode.ILSpy.Debugger.AvalonEdit
return;
}
if (e.ChangedButton == MouseButton.Left) {
if (DebugData.CurrentType != null) {
if (DebugData.CurrentMember != null) {
// check if the codemappings exists for this line
var storage = CodeMappings.GetStorage(DebugData.Language);
uint token;
var instruction = storage.GetInstructionByTypeAndLine(DebugData.CurrentType.FullName, line, out token);
var instruction = storage.GetInstructionByTypeAndLine(DebugData.CurrentMember.FullName, line, out token);
if (instruction == null) {
MessageBox.Show(string.Format("Missing code mappings for {0} at line {1}", DebugData.CurrentType.FullName, line),
MessageBox.Show(string.Format("Missing code mappings for {0} at line {1}", DebugData.CurrentMember.FullName, line),
"Code mappings", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
// no bookmark on the line: create a new breakpoint
DebuggerService.ToggleBreakpointAt(
DebugData.CurrentType,
DebugData.CurrentMember,
line,
DebugData.Language);
}

2
Debugger/ILSpy.Debugger/AvalonEdit/TextMarkerService.cs

@ -53,7 +53,7 @@ namespace ICSharpCode.ILSpy.Debugger.AvalonEdit @@ -53,7 +53,7 @@ namespace ICSharpCode.ILSpy.Debugger.AvalonEdit
{
if (e.Bookmark is MarkerBookmark) {
var bm = (MarkerBookmark)e.Bookmark;
if (DebugData.CurrentType != null && DebugData.CurrentType == bm.Type) {
if (DebugData.CurrentMember != null && DebugData.CurrentMember == bm.Member) {
// add bookmark for the current type
DocumentLine line = codeEditor.Document.GetLineByNumber(bm.LineNumber);
bm.CreateMarker(this, line.Offset, line.Length);

6
Debugger/ILSpy.Debugger/Bookmarks/BookmarkBase.cs

@ -41,7 +41,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks @@ -41,7 +41,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
}
public TypeDefinition Type { get; set; }
public MemberReference Member { get; set; }
public int LineNumber {
get { return location.Line; }
@ -64,9 +64,9 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks @@ -64,9 +64,9 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
}
}
public BookmarkBase(TypeDefinition type, AstLocation location)
public BookmarkBase(MemberReference member, AstLocation location)
{
this.Type = type;
this.Member = member;
this.Location = location;
}

10
Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks @@ -31,7 +31,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
List<BookmarkBase> marks = new List<BookmarkBase>();
foreach (BookmarkBase mark in bookmarks) {
if (typeName == mark.Type.FullName) {
if (typeName == mark.Member.FullName) {
marks.Add(mark);
}
}
@ -56,7 +56,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks @@ -56,7 +56,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
return false;
if (a.GetType() != b.GetType())
return false;
if (a.Type.FullName != b.Type.FullName)
if (a.Member.FullName != b.Member.FullName)
return false;
return a.LineNumber == b.LineNumber;
}
@ -150,7 +150,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks @@ -150,7 +150,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
// 1. Save it's data
int line = CurrentLineBookmark.Instance.LineNumber;
var markerType = CurrentLineBookmark.Instance.Type;
var markerType = CurrentLineBookmark.Instance.Member;
// 2. Remove it
CurrentLineBookmark.Remove();
@ -191,13 +191,13 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks @@ -191,13 +191,13 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
foreach (var bp in oldbps) {
uint token;
var instruction = oldMappings.GetInstructionByTypeAndLine(bp.Type.FullName, bp.LineNumber, out token);
var instruction = oldMappings.GetInstructionByTypeAndLine(bp.Member.FullName, bp.LineNumber, out token);
if (instruction == null)
continue;
TypeDefinition type;
int line;
if (newMappings.GetSourceCodeFromMetadataTokenAndOffset(bp.Type.FullName, token, instruction.ILInstructionOffset.From, out type, out line)) {
if (newMappings.GetSourceCodeFromMetadataTokenAndOffset(bp.Member.FullName, token, instruction.ILInstructionOffset.From, out type, out line)) {
// 2. create breakpoint for new languages
var bookmark = new BreakpointBookmark(type, new AstLocation(line, 0), BreakpointAction.Break, newLanguage);
AddMark(bookmark);

4
Debugger/ILSpy.Debugger/Bookmarks/BreakpointBookmark.cs

@ -73,7 +73,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks @@ -73,7 +73,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
set { tooltip = value; }
}
public BreakpointBookmark(TypeDefinition type, AstLocation location, BreakpointAction action, DecompiledLanguages language) : base(type, location)
public BreakpointBookmark(MemberReference member, AstLocation location, BreakpointAction action, DecompiledLanguages language) : base(member, location)
{
this.action = action;
this.tooltip = language.ToString();
@ -91,7 +91,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks @@ -91,7 +91,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
ITextMarker marker = markerService.Create(offset, length);
marker.BackgroundColor = Color.FromRgb(180, 38, 38);
marker.ForegroundColor = Colors.White;
marker.IsVisible = b => b is MarkerBookmark && ((MarkerBookmark)b).Type == DebugData.CurrentType;
marker.IsVisible = b => b is MarkerBookmark && ((MarkerBookmark)b).Member == DebugData.CurrentMember;
marker.Bookmark = this;
this.Marker = marker;

2
Debugger/ILSpy.Debugger/Bookmarks/CurrentLineBookmark.cs

@ -81,7 +81,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks @@ -81,7 +81,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
ITextMarker marker = markerService.Create(offset + startColumn - 1, length + 1);
marker.BackgroundColor = Colors.Yellow;
marker.ForegroundColor = Colors.Blue;
marker.IsVisible = b => b is MarkerBookmark && ((MarkerBookmark)b).Type == DebugData.CurrentType;
marker.IsVisible = b => b is MarkerBookmark && ((MarkerBookmark)b).Member == DebugData.CurrentMember;
marker.Bookmark = this;
this.Marker = marker;
return marker;

2
Debugger/ILSpy.Debugger/Bookmarks/MarkerBookmark.cs

@ -10,7 +10,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks @@ -10,7 +10,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
{
public abstract class MarkerBookmark : BookmarkBase
{
public MarkerBookmark(TypeDefinition type, AstLocation location) : base(type, location)
public MarkerBookmark(MemberReference member, AstLocation location) : base(member, location)
{
}

4
Debugger/ILSpy.Debugger/DebuggedData.cs

@ -16,9 +16,9 @@ namespace ICSharpCode.ILSpy.Debugger @@ -16,9 +16,9 @@ namespace ICSharpCode.ILSpy.Debugger
static DecompiledLanguages language;
/// <summary>
/// Gets or sets the current debugged type
/// Gets or sets the current debugged member reference. Can be a type or a member of a type (method, property).
/// </summary>
public static TypeDefinition CurrentType { get; set; }
public static MemberReference CurrentMember { get; set; }
/// <summary>
/// Gets or sets the decompiled language.

6
Debugger/ILSpy.Debugger/Services/Debugger/DebuggerService.cs

@ -163,12 +163,12 @@ namespace ICSharpCode.ILSpy.Debugger.Services @@ -163,12 +163,12 @@ namespace ICSharpCode.ILSpy.Debugger.Services
}
}
public static void ToggleBreakpointAt(TypeDefinition type, int lineNumber, DecompiledLanguages language)
public static void ToggleBreakpointAt(MemberReference member, int lineNumber, DecompiledLanguages language)
{
BookmarkManager.ToggleBookmark(
type.FullName, lineNumber,
member.FullName, lineNumber,
b => b.CanToggle && b is BreakpointBookmark,
location => new BreakpointBookmark(type, location, BreakpointAction.Break, language));
location => new BreakpointBookmark(member, location, BreakpointAction.Break, language));
}
/* TODO: reimplement this stuff

6
Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs

@ -568,12 +568,12 @@ namespace ICSharpCode.ILSpy.Debugger.Services @@ -568,12 +568,12 @@ namespace ICSharpCode.ILSpy.Debugger.Services
uint token;
SourceCodeMapping map = CodeMappings
.GetStorage(bookmark.Language)
.GetInstructionByTypeAndLine(bookmark.Type.FullName, bookmark.LineNumber, out token);
.GetInstructionByTypeAndLine(bookmark.Member.FullName, bookmark.LineNumber, out token);
if (map != null) {
breakpoint = new ILBreakpoint(
debugger,
bookmark.Type.FullName,
bookmark.Member.FullName,
bookmark.LineNumber,
token,
map.ILInstructionOffset.From,
@ -752,7 +752,7 @@ namespace ICSharpCode.ILSpy.Debugger.Services @@ -752,7 +752,7 @@ namespace ICSharpCode.ILSpy.Debugger.Services
foreach (var bookmark in DebuggerService.Breakpoints) {
var breakpoint =
debugger.Breakpoints.FirstOrDefault(
b => b.Line == bookmark.LineNumber && b.TypeName == bookmark.Type.FullName);
b => b.Line == bookmark.LineNumber && b.TypeName == bookmark.Member.FullName);
if (breakpoint == null)
continue;
// set the breakpoint only if the module contains the type

4
ILSpy/Commands/DebuggerCommands.cs

@ -163,8 +163,8 @@ namespace ICSharpCode.ILSpy.Commands @@ -163,8 +163,8 @@ namespace ICSharpCode.ILSpy.Commands
// jump to type & expand folding
if (CurrentLineBookmark.Instance != null) {
if (CurrentLineBookmark.Instance.Type != DebugData.CurrentType)
MainWindow.Instance.JumpToReference(CurrentLineBookmark.Instance.Type);
if (CurrentLineBookmark.Instance.Member != DebugData.CurrentMember)
MainWindow.Instance.JumpToReference(CurrentLineBookmark.Instance.Member);
MainWindow.Instance.TextView.UnfoldAndScroll(CurrentLineBookmark.Instance.LineNumber);
}

41
ILSpy/TextView/DecompilerTextView.cs

@ -300,7 +300,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -300,7 +300,7 @@ namespace ICSharpCode.ILSpy.TextView
/// </summary>
void ShowOutput(AvalonEditTextOutput textOutput, IHighlightingDefinition highlighting = null, DecompilerTextViewState state = null)
{
Debug.WriteLine("Showing {0} characters of output", textOutput.TextLength);
Debug.WriteLine("Showing {0} characters of output", textOutput.TextLength);
Stopwatch w = Stopwatch.StartNew();
textEditor.ScrollToHome();
@ -345,7 +345,6 @@ namespace ICSharpCode.ILSpy.TextView @@ -345,7 +345,6 @@ namespace ICSharpCode.ILSpy.TextView
/// </summary>
public void Decompile(ILSpy.Language language, IEnumerable<ILSpyTreeNode> treeNodes, DecompilationOptions options)
{
DebugData.CurrentType = null;
// Some actions like loading an assembly list cause several selection changes in the tree view,
// and each of those will start a decompilation action.
bool isDecompilationScheduled = this.nextDecompilationRun != null;
@ -378,6 +377,8 @@ namespace ICSharpCode.ILSpy.TextView @@ -378,6 +377,8 @@ namespace ICSharpCode.ILSpy.TextView
void DoDecompile(DecompilationContext context, int outputLengthLimit)
{
// reset type
DebugData.CurrentMember = null;
TextEditorListener.Instance.ClosePopup();
RunWithCancellation(
@ -404,29 +405,37 @@ namespace ICSharpCode.ILSpy.TextView @@ -404,29 +405,37 @@ namespace ICSharpCode.ILSpy.TextView
output.WriteLine(ex.ToString());
}
ShowOutput(output);
// reset type
DebugData.CurrentMember = null;
}
finally {
// set the language
DebugData.Language = MainWindow.Instance.sessionSettings.FilterSettings.Language.Name.StartsWith("IL") ? DecompiledLanguages.IL : DecompiledLanguages.CSharp;
if (DebugData.CurrentType != null && context.TreeNodes.Count() == 1) {
iconMargin.Visibility = Visibility.Visible;
// repaint bookmarks
iconMargin.InvalidateVisual();
// show the currentline marker
var bm = CurrentLineBookmark.Instance;
if (bm != null && DebugData.CurrentType != null) {
if (DebugData.CurrentType == bm.Type) {
DocumentLine line = textEditor.Document.GetLineByNumber(bm.LineNumber);
bm.Marker = bm.CreateMarker(textMarkerService, line.Offset, line.Length);
if (DebugData.CurrentMember != null) {
if (context.TreeNodes.Count() == 1) {
iconMargin.Visibility = Visibility.Visible;
// repaint bookmarks
iconMargin.InvalidateVisual();
// show the currentline marker
var bm = CurrentLineBookmark.Instance;
if (bm != null && DebugData.CurrentMember != null) {
if (DebugData.CurrentMember == bm.Member) {
DocumentLine line = textEditor.Document.GetLineByNumber(bm.LineNumber);
bm.Marker = bm.CreateMarker(textMarkerService, line.Offset, line.Length);
}
UnfoldAndScroll(bm.LineNumber);
}
UnfoldAndScroll(bm.LineNumber);
} else {
// hide the margin
iconMargin.Visibility = Visibility.Collapsed;
}
} else {
// hide the margin
iconMargin.Visibility = Visibility.Collapsed;
// remove currentline marker
CurrentLineBookmark.Remove();
}
}
});

3
ILSpy/TreeNodes/MethodTreeNode.cs

@ -19,7 +19,9 @@ @@ -19,7 +19,9 @@
using System;
using System.Text;
using System.Windows.Media;
using ICSharpCode.Decompiler;
using ICSharpCode.ILSpy.Debugger;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes
@ -122,6 +124,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -122,6 +124,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
DebugData.CurrentMember = method;
language.DecompileMethod(method, output, options);
}

2
ILSpy/TreeNodes/PropertyTreeNode.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
using System;
using System.Windows.Media;
using ICSharpCode.Decompiler;
using ICSharpCode.ILSpy.Debugger;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes
@ -146,6 +147,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -146,6 +147,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
DebugData.CurrentMember = property;
language.DecompileProperty(property, output, options);
}

2
ILSpy/TreeNodes/TypeTreeNode.cs

@ -121,7 +121,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -121,7 +121,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
DebugData.CurrentType = type;
DebugData.CurrentMember = type;
language.DecompileType(type, output, options);
}

Loading…
Cancel
Save