Browse Source

Minor clean-ups.

pull/191/merge
Eusebiu Marcu 14 years ago
parent
commit
6bae4e5180
  1. 2
      Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs
  2. 13
      Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs
  3. 12
      ICSharpCode.Decompiler/CodeMappings.cs
  4. 9
      ICSharpCode.Decompiler/PlainTextOutput.cs

2
Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs

@ -166,7 +166,7 @@ namespace ICSharpCode.ILSpy.Debugger.Bookmarks
MemberReference memberReference; MemberReference memberReference;
int newline; 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 // 4. create breakpoint for new languages
CurrentLineBookmark.SetPosition(memberReference, newline, 0, newline, 0); CurrentLineBookmark.SetPosition(memberReference, newline, 0, newline, 0);
} }

13
Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs

@ -808,14 +808,10 @@ namespace ICSharpCode.ILSpy.Debugger.Services
int line; int line;
MemberReference memberReference; MemberReference memberReference;
if (DebugData.CodeMappings.ContainsKey(token)) { if (DebugData.CodeMappings.ContainsKey(token) &&
if (DebugData.CodeMappings[token].GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out memberReference, out line)) { DebugData.CodeMappings[token].GetInstructionByTokenAndOffset(token, ilOffset, out memberReference, out line)) {
DebuggerService.RemoveCurrentLineMarker(); DebuggerService.RemoveCurrentLineMarker();
DebuggerService.JumpToCurrentLine(memberReference, line, 0, line, 0); 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);
}
} }
else { else {
// is possible that the type is not decompiled yet, so we must do a decompilation on demand // 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) else if (memberReference is EventDefinition)
builder.AddEvent(memberReference as EventDefinition); builder.AddEvent(memberReference as EventDefinition);
builder.GenerateCode(new PlainTextOutput()); var output = new PlainTextOutput();
builder.GenerateCode(output);
DebugData.CodeMappings = codeMappings = builder.CodeMappings; DebugData.CodeMappings = codeMappings = builder.CodeMappings;
DebugData.DecompiledMemberReferences = members = builder.DecompiledMemberReferences; DebugData.DecompiledMemberReferences = members = builder.DecompiledMemberReferences;
} }
@ -897,7 +894,7 @@ namespace ICSharpCode.ILSpy.Debugger.Services
// try jump // try jump
int line; int line;
codeMappings = codeMappings ?? DebugData.CodeMappings; 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.RemoveCurrentLineMarker();
DebuggerService.JumpToCurrentLine(memberReference, line, 0, line, 0); DebuggerService.JumpToCurrentLine(memberReference, line, 0, line, 0);
} else { } else {

12
ICSharpCode.Decompiler/CodeMappings.cs

@ -105,9 +105,9 @@ namespace ICSharpCode.Decompiler
currentList.AddRange(MemberMapping.InvertedList); currentList.AddRange(MemberMapping.InvertedList);
} else { } else {
// if the current list contains the last mapping, add also the last gap // if the current list contains the last mapping, add also the last gap
// var lastInverted = MemberMapping.InvertedList.LastOrDefault(); var lastInverted = MemberMapping.InvertedList.LastOrDefault();
// if (lastInverted != null && lastInverted.From == currentList[currentList.Count - 1].To) if (lastInverted != null && lastInverted.From == currentList[currentList.Count - 1].To)
// currentList.Add(lastInverted); currentList.Add(lastInverted);
} }
// set the output // set the output
@ -262,7 +262,7 @@ namespace ICSharpCode.Decompiler
if (map == null) { if (map == null) {
// get the immediate next one // 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; isMatch = false;
if (map == null) if (map == null)
map = maping.MemberCodeMappings.LastOrDefault(); // get the last map = maping.MemberCodeMappings.LastOrDefault(); // get the last
@ -283,7 +283,7 @@ namespace ICSharpCode.Decompiler
/// <param name="typeName">Type definition.</param> /// <param name="typeName">Type definition.</param>
/// <param name="line">Line number.</param> /// <param name="line">Line number.</param>
/// <remarks>It is possible to exist to different types from different assemblies with the same metadata token.</remarks> /// <remarks>It is possible to exist to different types from different assemblies with the same metadata token.</remarks>
public static bool GetSourceCodeFromMetadataTokenAndOffset( public static bool GetInstructionByTokenAndOffset(
this List<MemberMapping> codeMappings, this List<MemberMapping> codeMappings,
int token, int token,
int ilOffset, int ilOffset,
@ -303,7 +303,7 @@ namespace ICSharpCode.Decompiler
var codeMapping = mapping.MemberCodeMappings.Find( var codeMapping = mapping.MemberCodeMappings.Find(
cm => cm.ILInstructionOffset.From <= ilOffset && ilOffset <= cm.ILInstructionOffset.To - 1); cm => cm.ILInstructionOffset.From <= ilOffset && ilOffset <= cm.ILInstructionOffset.To - 1);
if (codeMapping == null) { if (codeMapping == null) {
codeMapping = mapping.MemberCodeMappings.Find(cm => (cm.ILInstructionOffset.From >= ilOffset)); codeMapping = mapping.MemberCodeMappings.Find(cm => cm.ILInstructionOffset.From > ilOffset);
if (codeMapping == null) { if (codeMapping == null) {
codeMapping = mapping.MemberCodeMappings.LastOrDefault(); codeMapping = mapping.MemberCodeMappings.LastOrDefault();
if (codeMapping == null) if (codeMapping == null)

9
ICSharpCode.Decompiler/PlainTextOutput.cs

@ -26,22 +26,23 @@ namespace ICSharpCode.Decompiler
readonly TextWriter writer; readonly TextWriter writer;
int indent; int indent;
bool needsIndent; bool needsIndent;
int lineNumber = 1;
public PlainTextOutput(TextWriter writer) public PlainTextOutput(TextWriter writer)
{ {
if (writer == null) if (writer == null)
throw new ArgumentNullException("writer"); throw new ArgumentNullException("writer");
this.writer = writer; this.writer = writer;
CurrentLine = 1;
} }
public PlainTextOutput() public PlainTextOutput()
{ {
this.writer = new StringWriter(); this.writer = new StringWriter();
CurrentLine = 1;
} }
public int CurrentLine { get; set; } public int CurrentLine {
get { return lineNumber; }
}
public override string ToString() public override string ToString()
{ {
@ -82,9 +83,9 @@ namespace ICSharpCode.Decompiler
public void WriteLine() public void WriteLine()
{ {
lineNumber++;
writer.WriteLine(); writer.WriteLine();
needsIndent = true; needsIndent = true;
++CurrentLine;
} }
public void WriteDefinition(string text, object definition) public void WriteDefinition(string text, object definition)

Loading…
Cancel
Save