diff --git a/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs b/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs index 3dd4253fd..f2226b18e 100644 --- a/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs +++ b/Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs @@ -308,7 +308,7 @@ namespace ILSpy.Debugger.Services return null; } else { var frame = debuggedProcess.SelectedThread.MostRecentStackFrame; - frame.SourceCodeLine = CurrentLineBookmark.Instance.LineNumber; + frame.SourceCodeLine = map.SourceCodeLine; frame.ILRanges = map.ToArray(); return frame; } @@ -833,8 +833,7 @@ namespace ILSpy.Debugger.Services int ilOffset = frame.IP; int line; string typeName; - CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out typeName, out line); - if (typeName != null) + if (CodeMappingsStorage.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out typeName, out line)) DebuggerService.JumpToCurrentLine(typeName, line, 0, line, 0); } } diff --git a/ICSharpCode.Decompiler/CodeMappings.cs b/ICSharpCode.Decompiler/CodeMappings.cs index 895aa4776..1efb6387b 100644 --- a/ICSharpCode.Decompiler/CodeMappings.cs +++ b/ICSharpCode.Decompiler/CodeMappings.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Linq; using Decompiler; using ICSharpCode.Decompiler.Disassembler; @@ -30,7 +31,7 @@ namespace ICSharpCode.Decompiler { int[] result = new int[2]; result[0] = ILInstructionOffset.From; - result[1] = ILInstructionOffset.To; + result[1] = ILInstructionOffset.To + 1; return result; } @@ -92,7 +93,7 @@ namespace ICSharpCode.Decompiler this MethodDefinition method, ConcurrentDictionary> sourceCodeMappings) { - // create IL code mappings - used in debugger + // create IL/CSharp code mappings - used in debugger MethodMapping currentMethodMapping = null; if (sourceCodeMappings.ContainsKey(method.DeclaringType.FullName)) { var mapping = sourceCodeMappings[method.DeclaringType.FullName]; @@ -154,7 +155,7 @@ namespace ICSharpCode.Decompiler /// IL offset. /// Type name. /// Line number. - public static void GetSourceCodeFromMetadataTokenAndOffset( + public static bool GetSourceCodeFromMetadataTokenAndOffset( this ConcurrentDictionary> codeMappings, uint token, int ilOffset, @@ -174,15 +175,20 @@ namespace ICSharpCode.Decompiler (cm.ILInstructionOffset.From == ilOffset && ilOffset == cm.ILInstructionOffset.To)); // for IL if (codeMapping == null) { codeMapping = mapping.MethodCodeMappings.Find(cm => (cm.ILInstructionOffset.From >= ilOffset)); - if (codeMapping == null) - continue; + if (codeMapping == null) { + codeMapping = mapping.MethodCodeMappings.LastOrDefault(); + if (codeMapping == null) + continue; + } } typeName = typename; line = codeMapping.SourceCodeLine; - break; + return true; } + + return false; } } }