Browse Source

synchronize bookmarks between languages

pull/191/merge
Eusebiu Marcu 15 years ago
parent
commit
2c03ab8812
  1. 49
      Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs
  2. 38
      Debugger/ILSpy.Debugger/DebuggedType.cs
  3. 3
      Debugger/ILSpy.Debugger/Services/Debugger/DebuggerService.cs
  4. 5
      ICSharpCode.Decompiler/CodeMappings.cs
  5. 4
      ILSpy/MainWindow.xaml
  6. 9
      ILSpy/MainWindow.xaml.cs
  7. 4
      ILSpy/TextView/DecompilerTextView.cs

49
Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs

@ -3,7 +3,9 @@ @@ -3,7 +3,9 @@
using System;
using System.Collections.Generic;
using ICSharpCode.Decompiler;
using ICSharpCode.NRefactory.CSharp;
using Mono.Cecil;
using Mono.CSharp;
namespace ILSpy.Debugger.Bookmarks
@ -13,6 +15,53 @@ namespace ILSpy.Debugger.Bookmarks @@ -13,6 +15,53 @@ namespace ILSpy.Debugger.Bookmarks
/// </summary>
public static class BookmarkManager
{
static BookmarkManager()
{
DebugData.LanguageChanged += OnLanguageChanged;
}
static void OnLanguageChanged(object sender, LanguageEventArgs e)
{
var oldLanguage = e.OldLanguage;
var newLanguage = e.NewLanguage;
// synchronize the IL<->C# breakpoints
// 1. map the breakpoint lines
var oldbps = bookmarks.FindAll(b => b is BreakpointBookmark && ((BreakpointBookmark)b).Language == oldLanguage);
if (oldbps == null || oldbps.Count == 0)
return;
var oldMappings = CodeMappings.GetStorage(oldLanguage);
var newMappings = CodeMappings.GetStorage(newLanguage);
if (oldMappings == null || oldMappings.Count == 0 ||
newMappings == null || newMappings.Count == 0)
return;
foreach (var bp in oldbps) {
uint token;
var instruction = oldMappings.GetInstructionByTypeAndLine(DebugData.CurrentType.FullName, bp.LineNumber, out token);
if (instruction == null)
continue;
TypeDefinition type;
int line;
if (newMappings.GetSourceCodeFromMetadataTokenAndOffset(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);
}
}
// 3. remove all breakpoints for the old language
for (int i = bookmarks.Count - 1; i >= 0; --i) {
var bm = bookmarks[i];
if (bm is BreakpointBookmark && ((BreakpointBookmark)bm).Language == oldLanguage)
RemoveMark(bm);
}
}
static List<BookmarkBase> bookmarks = new List<BookmarkBase>();
public static List<BookmarkBase> Bookmarks {

38
Debugger/ILSpy.Debugger/DebuggedType.cs

@ -28,6 +28,8 @@ namespace ILSpy.Debugger @@ -28,6 +28,8 @@ namespace ILSpy.Debugger
/// </summary>
public static class DebugData
{
static DecompiledLanguages language;
/// <summary>
/// Gets or sets the current debugged type
/// </summary>
@ -36,11 +38,45 @@ namespace ILSpy.Debugger @@ -36,11 +38,45 @@ namespace ILSpy.Debugger
/// <summary>
/// Gets or sets the decompiled language.
/// </summary>
public static DecompiledLanguages Language { get; set; }
public static DecompiledLanguages Language {
get { return language; }
set {
var oldLanguage = language;
if (value != language) {
language = value;
OnLanguageChanged(new LanguageEventArgs(oldLanguage, language));
}
}
}
/// <summary>
/// List of loaded assemblies.
/// </summary>
public static IEnumerable<AssemblyDefinition> LoadedAssemblies { get; set; }
/// <summary>
/// Occures when the language is changed.
/// </summary>
public static event EventHandler<LanguageEventArgs> LanguageChanged;
private static void OnLanguageChanged(LanguageEventArgs e)
{
if (LanguageChanged != null) {
LanguageChanged(null, e);
}
}
}
public class LanguageEventArgs : EventArgs
{
public DecompiledLanguages OldLanguage { get; private set; }
public DecompiledLanguages NewLanguage { get; private set; }
public LanguageEventArgs(DecompiledLanguages oldLanguage, DecompiledLanguages newLanguage)
{
this.OldLanguage = oldLanguage;
this.NewLanguage = newLanguage;
}
}
}

3
Debugger/ILSpy.Debugger/Services/Debugger/DebuggerService.cs

@ -205,6 +205,9 @@ namespace ILSpy.Debugger.Services @@ -205,6 +205,9 @@ namespace ILSpy.Debugger.Services
var doc = (TextDocument)e.Editor.Document;
var line = doc.GetLineByNumber(logicPos.Line);
if (line.Offset + logicPos.Column >= doc.TextLength)
return;
var c = doc.GetText(line.Offset + logicPos.Column, 1);
if (string.IsNullOrEmpty(c) || c == "\n" || c == "\t")
return;

5
ICSharpCode.Decompiler/CodeMappings.cs

@ -34,11 +34,6 @@ namespace ICSharpCode.Decompiler @@ -34,11 +34,6 @@ namespace ICSharpCode.Decompiler
/// </summary>
public ILRange ILInstructionOffset { get; set; }
/// <summary>
/// Gets or sets the current types at the source code line. E.g.: for int a = dictionary.Count; the list will contain System.Int32 and System.Collections.Generic.Dictionary&lt;TKey, TValue&gt;.
/// </summary>
public List<TypeDefinition> InnerTypes { get; set; }
public int[] ToArray()
{
int[] result = new int[2];

4
ILSpy/MainWindow.xaml

@ -70,9 +70,7 @@ @@ -70,9 +70,7 @@
<Separator />
<ComboBox Name="languageComboBox" DisplayMemberPath="Name" Width="100"
ItemsSource="{x:Static local:Languages.AllLanguages}"
SelectedItem="{Binding FilterSettings.Language}"
SelectionChanged="LanguageComboBox_SelectionChanged"
/>
SelectedItem="{Binding FilterSettings.Language}"/>
</ToolBar>
<!-- Status bar -->
<StatusBar x:Name="statusBar" DockPanel.Dock="Bottom" Height="26">

9
ILSpy/MainWindow.xaml.cs

@ -49,7 +49,7 @@ namespace ICSharpCode.ILSpy @@ -49,7 +49,7 @@ namespace ICSharpCode.ILSpy
{
NavigationHistory history = new NavigationHistory();
ILSpySettings spySettings;
SessionSettings sessionSettings;
internal SessionSettings sessionSettings;
AssemblyListManager assemblyListManager;
AssemblyList assemblyList;
AssemblyListTreeNode assemblyListTreeNode;
@ -548,12 +548,7 @@ namespace ICSharpCode.ILSpy @@ -548,12 +548,7 @@ namespace ICSharpCode.ILSpy
analyzerRow.MinHeight = 0;
analyzerRow.Height = new GridLength(0);
}
void LanguageComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
DebugData.Language = sessionSettings.FilterSettings.Language.Name.StartsWith("IL") ? DecompiledLanguages.IL : DecompiledLanguages.CSharp;
}
public void UnselectAll()
{
treeView.UnselectAll();

4
ILSpy/TextView/DecompilerTextView.cs

@ -401,6 +401,10 @@ namespace ICSharpCode.ILSpy.TextView @@ -401,6 +401,10 @@ namespace ICSharpCode.ILSpy.TextView
ShowOutput(output);
}
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

Loading…
Cancel
Save