diff --git a/Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs b/Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs index cf9907c8e..ae5337fe6 100644 --- a/Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs +++ b/Debugger/ILSpy.Debugger/Bookmarks/BookmarkManager.cs @@ -163,7 +163,7 @@ namespace ILSpy.Debugger.Bookmarks TypeDefinition type; 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 CurrentLineBookmark.SetPosition(type, newline, 0, newline, 0); } @@ -197,7 +197,7 @@ namespace ILSpy.Debugger.Bookmarks TypeDefinition type; 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 var bookmark = new BreakpointBookmark(type, new AstLocation(line, 0), BreakpointAction.Break, newLanguage); AddMark(bookmark); diff --git a/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs b/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs index 513e3e0ec..057bc3f6d 100644 --- a/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs +++ b/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs @@ -818,7 +818,8 @@ namespace ILSpy.Debugger.Services int ilOffset = frame.IP; int line; 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); } else { // 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 int line; 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); } else { // continue since we cannot find the debugged type diff --git a/ICSharpCode.Decompiler/CodeMappings.cs b/ICSharpCode.Decompiler/CodeMappings.cs index cb27c520f..fff4fee41 100644 --- a/ICSharpCode.Decompiler/CodeMappings.cs +++ b/ICSharpCode.Decompiler/CodeMappings.cs @@ -49,8 +49,8 @@ namespace ICSharpCode.Decompiler // add list for the current source code line currentList.AddRange(ILRange.OrderAndJoint(MemberMapping.MemberCodeMappings - .FindAll(m => m.SourceCodeLine == this.SourceCodeLine) - .ConvertAll(m => m.ILInstructionOffset))); + .FindAll(m => m.SourceCodeLine == this.SourceCodeLine) + .ConvertAll(m => m.ILInstructionOffset))); if (!isMatch) { // add inverted @@ -248,12 +248,15 @@ namespace ICSharpCode.Decompiler /// Gets the source code and type name from metadata token and offset. /// /// Code mappings storage. + /// Current type name. /// Metadata token. /// IL offset. /// Type definition. /// Line number. + /// It is possible to exist to different types from different assemblies with the same metadata token. public static bool GetSourceCodeFromMetadataTokenAndOffset( this ConcurrentDictionary> codeMappings, + string currentTypeFullName, uint token, int ilOffset, out TypeDefinition type, @@ -262,27 +265,25 @@ namespace ICSharpCode.Decompiler type = null; line = 0; - foreach (var typename in codeMappings.Keys) { - var mapping = codeMappings[typename].Find(m => m.MetadataToken == token); - if (mapping == null) - continue; - var codeMapping = mapping.MemberCodeMappings.Find( - cm => cm.ILInstructionOffset.From <= ilOffset && ilOffset <= cm.ILInstructionOffset.To - 1); + if (!codeMappings.ContainsKey(currentTypeFullName)) + return false; + + var mapping = codeMappings[currentTypeFullName].Find(m => m.MetadataToken == token); + if (mapping == null) + 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) { - codeMapping = mapping.MemberCodeMappings.Find(cm => (cm.ILInstructionOffset.From >= ilOffset)); - if (codeMapping == null) { - codeMapping = mapping.MemberCodeMappings.LastOrDefault(); - if (codeMapping == null) - continue; - } + codeMapping = mapping.MemberCodeMappings.LastOrDefault(); } - - type = mapping.Type; - line = codeMapping.SourceCodeLine; - return true; } - return false; + type = mapping.Type; + line = codeMapping.SourceCodeLine; + return true; } } }