|
|
|
@ -16,6 +16,7 @@ using ICSharpCode.NRefactory.Utils;
@@ -16,6 +16,7 @@ using ICSharpCode.NRefactory.Utils;
|
|
|
|
|
using ICSharpCode.SharpDevelop; |
|
|
|
|
using ICSharpCode.SharpDevelop.Bookmarks; |
|
|
|
|
using ICSharpCode.SharpDevelop.Debugging; |
|
|
|
|
using ICSharpCode.SharpDevelop.Editor; |
|
|
|
|
using ICSharpCode.SharpDevelop.Gui; |
|
|
|
|
using Mono.Cecil; |
|
|
|
|
|
|
|
|
@ -24,7 +25,7 @@ namespace ICSharpCode.ILSpyAddIn
@@ -24,7 +25,7 @@ namespace ICSharpCode.ILSpyAddIn
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Hosts a decompiled type.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DecompiledViewContent : AbstractViewContentWithoutFile |
|
|
|
|
class DecompiledViewContent : AbstractViewContentWithoutFile |
|
|
|
|
{ |
|
|
|
|
readonly string assemblyFile; |
|
|
|
|
readonly string fullTypeName; |
|
|
|
@ -43,14 +44,17 @@ namespace ICSharpCode.ILSpyAddIn
@@ -43,14 +44,17 @@ namespace ICSharpCode.ILSpyAddIn
|
|
|
|
|
#region Constructor
|
|
|
|
|
public DecompiledViewContent(string assemblyFile, string fullTypeName, string entityTag) |
|
|
|
|
{ |
|
|
|
|
codeView = new CodeView(string.Format("{0},{1}", assemblyFile, fullTypeName)); |
|
|
|
|
// TODO: create options for decompiling in a specific language
|
|
|
|
|
this.tempFileName = string.Format("{0}{1}{2}.cs", assemblyFile, DecompiledBreakpointBookmark.SEPARATOR, fullTypeName); |
|
|
|
|
this.codeView = new CodeView(tempFileName); |
|
|
|
|
|
|
|
|
|
this.assemblyFile = assemblyFile; |
|
|
|
|
this.fullTypeName = fullTypeName; |
|
|
|
|
this.jumpToEntityTagWhenDecompilationFinished = entityTag; |
|
|
|
|
|
|
|
|
|
string shortTypeName = fullTypeName.Substring(fullTypeName.LastIndexOf('.') + 1); |
|
|
|
|
this.TitleName = "[" + shortTypeName + "]"; |
|
|
|
|
tempFileName = string.Format("decompiled/{0}.cs", fullTypeName); |
|
|
|
|
|
|
|
|
|
this.InfoTip = tempFileName; |
|
|
|
|
|
|
|
|
|
Thread thread = new Thread(DecompilationThread); |
|
|
|
@ -59,6 +63,9 @@ namespace ICSharpCode.ILSpyAddIn
@@ -59,6 +63,9 @@ namespace ICSharpCode.ILSpyAddIn
|
|
|
|
|
|
|
|
|
|
BookmarkManager.Removed += BookmarkManager_Removed; |
|
|
|
|
BookmarkManager.Added += BookmarkManager_Added; |
|
|
|
|
|
|
|
|
|
// add services
|
|
|
|
|
this.Services.AddService(typeof(ITextEditor), this.codeView.TextEditor); |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
@ -83,6 +90,10 @@ namespace ICSharpCode.ILSpyAddIn
@@ -83,6 +90,10 @@ namespace ICSharpCode.ILSpyAddIn
|
|
|
|
|
get; private set; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override object Tag { |
|
|
|
|
get { return MemberReference; } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Dispose
|
|
|
|
@ -194,9 +205,8 @@ namespace ICSharpCode.ILSpyAddIn
@@ -194,9 +205,8 @@ namespace ICSharpCode.ILSpyAddIn
|
|
|
|
|
|
|
|
|
|
// update UI
|
|
|
|
|
UpdateIconMargin(output.ToString()); |
|
|
|
|
UpdateDebuggingUI(); |
|
|
|
|
|
|
|
|
|
// fire event
|
|
|
|
|
// fire events
|
|
|
|
|
OnDecompilationFinished(EventArgs.Empty); |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
@ -207,13 +217,13 @@ namespace ICSharpCode.ILSpyAddIn
@@ -207,13 +217,13 @@ namespace ICSharpCode.ILSpyAddIn
|
|
|
|
|
codeView.IconBarManager.UpdateClassMemberBookmarks(ParserService.ParseFile(tempFileName, new StringTextBuffer(text))); |
|
|
|
|
|
|
|
|
|
// load bookmarks
|
|
|
|
|
foreach (SDBookmark bookmark in BookmarkManager.GetBookmarks(codeView.Adapter.FileName)) { |
|
|
|
|
bookmark.Document = codeView.Adapter.Document; |
|
|
|
|
foreach (SDBookmark bookmark in BookmarkManager.GetBookmarks(this.codeView.TextEditor.FileName)) { |
|
|
|
|
bookmark.Document = this.codeView.TextEditor.Document; |
|
|
|
|
codeView.IconBarManager.Bookmarks.Add(bookmark); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void UpdateDebuggingUI() |
|
|
|
|
public void UpdateDebuggingUI() |
|
|
|
|
{ |
|
|
|
|
if (!DebuggerService.IsDebuggerStarted) |
|
|
|
|
return; |
|
|
|
@ -223,33 +233,35 @@ namespace ICSharpCode.ILSpyAddIn
@@ -223,33 +233,35 @@ namespace ICSharpCode.ILSpyAddIn
|
|
|
|
|
int typeToken = MemberReference.MetadataToken.ToInt32(); |
|
|
|
|
if (!DebuggerDecompilerService.DebugInformation.ContainsKey(typeToken)) |
|
|
|
|
return; |
|
|
|
|
if (DebuggerDecompilerService.Instance == null || DebuggerDecompilerService.Instance.DebugStepInformation == null) |
|
|
|
|
var decompilerService = DebuggerDecompilerService.Instance; |
|
|
|
|
if (decompilerService == null || decompilerService.DebugStepInformation == null) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
// get debugging information
|
|
|
|
|
DecompileInformation debugInformation = (DecompileInformation)DebuggerDecompilerService.DebugInformation[typeToken]; |
|
|
|
|
int token = DebuggerDecompilerService.Instance.DebugStepInformation.Item1; |
|
|
|
|
int ilOffset = DebuggerDecompilerService.Instance.DebugStepInformation.Item2; |
|
|
|
|
int methodToken = decompilerService.DebugStepInformation.Item1; |
|
|
|
|
int ilOffset = decompilerService.DebugStepInformation.Item2; |
|
|
|
|
int line; |
|
|
|
|
MemberReference member; |
|
|
|
|
if (debugInformation.CodeMappings == null || !debugInformation.CodeMappings.ContainsKey(token)) |
|
|
|
|
if (debugInformation.CodeMappings == null || !debugInformation.CodeMappings.ContainsKey(methodToken)) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
debugInformation.CodeMappings[token].GetInstructionByTokenAndOffset(token, ilOffset, out member, out line); |
|
|
|
|
debugInformation.CodeMappings[methodToken].GetInstructionByTokenAndOffset(methodToken, ilOffset, out member, out line); |
|
|
|
|
|
|
|
|
|
// HACK : if the codemappings are not built
|
|
|
|
|
// if the codemappings are not built
|
|
|
|
|
if (line <= 0) { |
|
|
|
|
DebuggerService.CurrentDebugger.StepOver(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// update bookmark & marker
|
|
|
|
|
codeView.UnfoldAndScroll(line); |
|
|
|
|
CurrentLineBookmark.SetPosition(this, line, 0, line, 0); |
|
|
|
|
|
|
|
|
|
// jump to line - scoll and unfold
|
|
|
|
|
this.UpdateCurrentLineBookmark(line); |
|
|
|
|
this.JumpToLineNumber(line); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void JumpTo(int lineNumber) |
|
|
|
|
public void JumpToLineNumber(int lineNumber) |
|
|
|
|
{ |
|
|
|
|
if (codeView == null) |
|
|
|
|
if (codeView == null || codeView.Document == null) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (lineNumber <= 0 || lineNumber > codeView.Document.LineCount) |
|
|
|
@ -257,6 +269,21 @@ namespace ICSharpCode.ILSpyAddIn
@@ -257,6 +269,21 @@ namespace ICSharpCode.ILSpyAddIn
|
|
|
|
|
|
|
|
|
|
codeView.UnfoldAndScroll(lineNumber); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void UpdateCurrentLineBookmark(int lineNumber) |
|
|
|
|
{ |
|
|
|
|
if (lineNumber <= 0) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
CurrentLineBookmark.SetPosition(codeView.TextEditor.FileName, codeView.TextEditor.Document, lineNumber, 0, lineNumber, 0); |
|
|
|
|
var currentLineBookmark = BookmarkManager.Bookmarks.OfType<CurrentLineBookmark>().FirstOrDefault(); |
|
|
|
|
if (currentLineBookmark != null) { |
|
|
|
|
// update bookmark & marker
|
|
|
|
|
codeView.IconBarManager.Bookmarks.Add(currentLineBookmark); |
|
|
|
|
currentLineBookmark.Document = this.codeView.TextEditor.Document; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Bookmarks
|
|
|
|
@ -272,14 +299,15 @@ namespace ICSharpCode.ILSpyAddIn
@@ -272,14 +299,15 @@ namespace ICSharpCode.ILSpyAddIn
|
|
|
|
|
void BookmarkManager_Added(object sender, BookmarkEventArgs e) |
|
|
|
|
{ |
|
|
|
|
var mark = e.Bookmark; |
|
|
|
|
if (mark != null && mark is BreakpointBookmark && mark.FileName == codeView.DecompiledFullTypeName) { |
|
|
|
|
if (mark != null && mark is BreakpointBookmark && mark.FileName == this.codeView.TextEditor.FileName) { |
|
|
|
|
codeView.IconBarManager.Bookmarks.Add(mark); |
|
|
|
|
mark.Document = codeView.Adapter.Document; |
|
|
|
|
mark.Document = this.codeView.TextEditor.Document; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Events
|
|
|
|
|
|
|
|
|
|
public event EventHandler DecompilationFinished; |
|
|
|
|
|
|
|
|
|
protected virtual void OnDecompilationFinished(EventArgs e) |
|
|
|
@ -288,6 +316,7 @@ namespace ICSharpCode.ILSpyAddIn
@@ -288,6 +316,7 @@ namespace ICSharpCode.ILSpyAddIn
|
|
|
|
|
DecompilationFinished(this, e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|