From 6bae4e5180bc5e61432c625589182ad44b9be54a Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Fri, 6 May 2011 13:52:25 +0300 Subject: [PATCH] Minor clean-ups. --- .../ILSpy.Debugger/Bookmarks/BookmarkManager.cs | 2 +- .../Services/Debugger/WindowsDebugger.cs | 17 +++++++---------- ICSharpCode.Decompiler/CodeMappings.cs | 12 ++++++------ ICSharpCode.Decompiler/PlainTextOutput.cs | 9 +++++---- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs b/Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs index a068e010c..c88cca52c 100644 --- a/Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs +++ b/Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs @@ -166,7 +166,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks MemberReference memberReference; int newline; - if (newMappings[markerType.MetadataToken.ToInt32()].GetSourceCodeFromMetadataTokenAndOffset(token, instruction.ILInstructionOffset.From, out memberReference, out newline)) { + if (newMappings[markerType.MetadataToken.ToInt32()].GetInstructionByTokenAndOffset(token, instruction.ILInstructionOffset.From, out memberReference, out newline)) { // 4. create breakpoint for new languages CurrentLineBookmark.SetPosition(memberReference, newline, 0, newline, 0); } diff --git a/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs b/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs index e512baf27..5e2be0085 100644 --- a/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs +++ b/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs @@ -808,14 +808,10 @@ namespace ICSharpCode.ILSpy.Debugger.Services int line; MemberReference memberReference; - if (DebugData.CodeMappings.ContainsKey(token)) { - if (DebugData.CodeMappings[token].GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out memberReference, out line)) { - DebuggerService.RemoveCurrentLineMarker(); - DebuggerService.JumpToCurrentLine(memberReference, line, 0, line, 0); - } else { - // is possible that the type is not decompiled yet, so we must do a decompilation on demand - DecompileOnDemand(frame); - } + if (DebugData.CodeMappings.ContainsKey(token) && + DebugData.CodeMappings[token].GetInstructionByTokenAndOffset(token, ilOffset, out memberReference, out line)) { + DebuggerService.RemoveCurrentLineMarker(); + DebuggerService.JumpToCurrentLine(memberReference, line, 0, line, 0); } else { // is possible that the type is not decompiled yet, so we must do a decompilation on demand @@ -888,7 +884,8 @@ namespace ICSharpCode.ILSpy.Debugger.Services else if (memberReference is EventDefinition) builder.AddEvent(memberReference as EventDefinition); - builder.GenerateCode(new PlainTextOutput()); + var output = new PlainTextOutput(); + builder.GenerateCode(output); DebugData.CodeMappings = codeMappings = builder.CodeMappings; DebugData.DecompiledMemberReferences = members = builder.DecompiledMemberReferences; } @@ -897,7 +894,7 @@ namespace ICSharpCode.ILSpy.Debugger.Services // try jump int line; codeMappings = codeMappings ?? DebugData.CodeMappings; - if (codeMappings[token].GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out memberReference, out line)) { + if (codeMappings[token].GetInstructionByTokenAndOffset(token, ilOffset, out memberReference, out line)) { DebuggerService.RemoveCurrentLineMarker(); DebuggerService.JumpToCurrentLine(memberReference, line, 0, line, 0); } else { diff --git a/ICSharpCode.Decompiler/CodeMappings.cs b/ICSharpCode.Decompiler/CodeMappings.cs index e6f44c1b4..485792f4a 100644 --- a/ICSharpCode.Decompiler/CodeMappings.cs +++ b/ICSharpCode.Decompiler/CodeMappings.cs @@ -105,9 +105,9 @@ namespace ICSharpCode.Decompiler currentList.AddRange(MemberMapping.InvertedList); } else { // if the current list contains the last mapping, add also the last gap -// var lastInverted = MemberMapping.InvertedList.LastOrDefault(); -// if (lastInverted != null && lastInverted.From == currentList[currentList.Count - 1].To) -// currentList.Add(lastInverted); + var lastInverted = MemberMapping.InvertedList.LastOrDefault(); + if (lastInverted != null && lastInverted.From == currentList[currentList.Count - 1].To) + currentList.Add(lastInverted); } // set the output @@ -262,7 +262,7 @@ namespace ICSharpCode.Decompiler if (map == null) { // get the immediate next one - map = maping.MemberCodeMappings.Find(m => m.ILInstructionOffset.From >= ilOffset); + map = maping.MemberCodeMappings.Find(m => m.ILInstructionOffset.From > ilOffset); isMatch = false; if (map == null) map = maping.MemberCodeMappings.LastOrDefault(); // get the last @@ -283,7 +283,7 @@ namespace ICSharpCode.Decompiler /// Type definition. /// Line number. /// It is possible to exist to different types from different assemblies with the same metadata token. - public static bool GetSourceCodeFromMetadataTokenAndOffset( + public static bool GetInstructionByTokenAndOffset( this List codeMappings, int token, int ilOffset, @@ -303,7 +303,7 @@ namespace ICSharpCode.Decompiler var codeMapping = mapping.MemberCodeMappings.Find( cm => cm.ILInstructionOffset.From <= ilOffset && ilOffset <= cm.ILInstructionOffset.To - 1); if (codeMapping == null) { - codeMapping = mapping.MemberCodeMappings.Find(cm => (cm.ILInstructionOffset.From >= ilOffset)); + codeMapping = mapping.MemberCodeMappings.Find(cm => cm.ILInstructionOffset.From > ilOffset); if (codeMapping == null) { codeMapping = mapping.MemberCodeMappings.LastOrDefault(); if (codeMapping == null) diff --git a/ICSharpCode.Decompiler/PlainTextOutput.cs b/ICSharpCode.Decompiler/PlainTextOutput.cs index 3e167b01b..7078b6785 100644 --- a/ICSharpCode.Decompiler/PlainTextOutput.cs +++ b/ICSharpCode.Decompiler/PlainTextOutput.cs @@ -26,22 +26,23 @@ namespace ICSharpCode.Decompiler readonly TextWriter writer; int indent; bool needsIndent; + int lineNumber = 1; public PlainTextOutput(TextWriter writer) { if (writer == null) throw new ArgumentNullException("writer"); this.writer = writer; - CurrentLine = 1; } public PlainTextOutput() { this.writer = new StringWriter(); - CurrentLine = 1; } - public int CurrentLine { get; set; } + public int CurrentLine { + get { return lineNumber; } + } public override string ToString() { @@ -82,9 +83,9 @@ namespace ICSharpCode.Decompiler public void WriteLine() { + lineNumber++; writer.WriteLine(); needsIndent = true; - ++CurrentLine; } public void WriteDefinition(string text, object definition)