Browse Source

fix code mappings helper method

pull/191/merge
Eusebiu Marcu 15 years ago
parent
commit
4c44c55278
  1. 4
      Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs
  2. 5
      Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs
  3. 39
      ICSharpCode.Decompiler/CodeMappings.cs

4
Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs

@ -163,7 +163,7 @@ namespace ILSpy.Debugger.Bookmarks
TypeDefinition type; TypeDefinition type;
int newline; int newline;
if (newMappings.GetSourceCodeFromMetadataTokenAndOffset(token, instruction.ILInstructionOffset.From, out type, out newline)) { if (newMappings.GetSourceCodeFromMetadataTokenAndOffset(markerType.FullName, token, instruction.ILInstructionOffset.From, out type, out newline)) {
// 4. create breakpoint for new languages // 4. create breakpoint for new languages
CurrentLineBookmark.SetPosition(type, newline, 0, newline, 0); CurrentLineBookmark.SetPosition(type, newline, 0, newline, 0);
} }
@ -197,7 +197,7 @@ namespace ILSpy.Debugger.Bookmarks
TypeDefinition type; TypeDefinition type;
int line; int line;
if (newMappings.GetSourceCodeFromMetadataTokenAndOffset(token, instruction.ILInstructionOffset.From, out type, out line)) { if (newMappings.GetSourceCodeFromMetadataTokenAndOffset(bp.Type.FullName, token, instruction.ILInstructionOffset.From, out type, out line)) {
// 2. create breakpoint for new languages // 2. create breakpoint for new languages
var bookmark = new BreakpointBookmark(type, new AstLocation(line, 0), BreakpointAction.Break, newLanguage); var bookmark = new BreakpointBookmark(type, new AstLocation(line, 0), BreakpointAction.Break, newLanguage);
AddMark(bookmark); AddMark(bookmark);

5
Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs

@ -818,7 +818,8 @@ namespace ILSpy.Debugger.Services
int ilOffset = frame.IP; int ilOffset = frame.IP;
int line; int line;
TypeDefinition type; TypeDefinition type;
if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out type, out line)) {
if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(frame.MethodInfo.DeclaringType.FullName, token, ilOffset, out type, out line)) {
DebuggerService.JumpToCurrentLine(type, line, 0, line, 0); DebuggerService.JumpToCurrentLine(type, line, 0, line, 0);
} 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
@ -857,7 +858,7 @@ namespace ILSpy.Debugger.Services
// try jump // try jump
int line; int line;
TypeDefinition type; TypeDefinition type;
if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out type, out line)) { if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(typeRef.FullName, token, ilOffset, out type, out line)) {
DebuggerService.JumpToCurrentLine(type, line, 0, line, 0); DebuggerService.JumpToCurrentLine(type, line, 0, line, 0);
} else { } else {
// continue since we cannot find the debugged type // continue since we cannot find the debugged type

39
ICSharpCode.Decompiler/CodeMappings.cs

@ -49,8 +49,8 @@ namespace ICSharpCode.Decompiler
// add list for the current source code line // add list for the current source code line
currentList.AddRange(ILRange.OrderAndJoint(MemberMapping.MemberCodeMappings currentList.AddRange(ILRange.OrderAndJoint(MemberMapping.MemberCodeMappings
.FindAll(m => m.SourceCodeLine == this.SourceCodeLine) .FindAll(m => m.SourceCodeLine == this.SourceCodeLine)
.ConvertAll<ILRange>(m => m.ILInstructionOffset))); .ConvertAll<ILRange>(m => m.ILInstructionOffset)));
if (!isMatch) { if (!isMatch) {
// add inverted // add inverted
@ -248,12 +248,15 @@ namespace ICSharpCode.Decompiler
/// Gets the source code and type name from metadata token and offset. /// Gets the source code and type name from metadata token and offset.
/// </summary> /// </summary>
/// <param name="codeMappings">Code mappings storage.</param> /// <param name="codeMappings">Code mappings storage.</param>
/// <param name="currentTypeFullName">Current type name.</param>
/// <param name="token">Metadata token.</param> /// <param name="token">Metadata token.</param>
/// <param name="ilOffset">IL offset.</param> /// <param name="ilOffset">IL offset.</param>
/// <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>
public static bool GetSourceCodeFromMetadataTokenAndOffset( public static bool GetSourceCodeFromMetadataTokenAndOffset(
this ConcurrentDictionary<string, List<MemberMapping>> codeMappings, this ConcurrentDictionary<string, List<MemberMapping>> codeMappings,
string currentTypeFullName,
uint token, uint token,
int ilOffset, int ilOffset,
out TypeDefinition type, out TypeDefinition type,
@ -262,27 +265,25 @@ namespace ICSharpCode.Decompiler
type = null; type = null;
line = 0; line = 0;
foreach (var typename in codeMappings.Keys) { if (!codeMappings.ContainsKey(currentTypeFullName))
var mapping = codeMappings[typename].Find(m => m.MetadataToken == token); return false;
if (mapping == null)
continue; var mapping = codeMappings[currentTypeFullName].Find(m => m.MetadataToken == token);
var codeMapping = mapping.MemberCodeMappings.Find( if (mapping == null)
cm => cm.ILInstructionOffset.From <= ilOffset && ilOffset <= cm.ILInstructionOffset.To - 1); return false;
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));
if (codeMapping == null) { if (codeMapping == null) {
codeMapping = mapping.MemberCodeMappings.Find(cm => (cm.ILInstructionOffset.From >= ilOffset)); codeMapping = mapping.MemberCodeMappings.LastOrDefault();
if (codeMapping == null) {
codeMapping = mapping.MemberCodeMappings.LastOrDefault();
if (codeMapping == null)
continue;
}
} }
type = mapping.Type;
line = codeMapping.SourceCodeLine;
return true;
} }
return false; type = mapping.Type;
line = codeMapping.SourceCodeLine;
return true;
} }
} }
} }

Loading…
Cancel
Save