Browse Source

Fix code stepping without symbols.

pull/191/merge
Eusebiu Marcu 14 years ago
parent
commit
311944c674
  1. 2
      Debugger/Debugger.Core/Options.cs
  2. 2
      Debugger/Debugger.Core/SourcecodeSegment.cs
  3. 4
      Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs
  4. 55
      Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs
  5. 17
      ICSharpCode.Decompiler/CodeMappings.cs
  6. 10
      ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs
  7. 8
      ILSpy/MainWindow.xaml.cs

2
Debugger/Debugger.Core/Options.cs

@ -6,7 +6,7 @@ namespace Debugger @@ -6,7 +6,7 @@ namespace Debugger
public class Options
{
public bool EnableJustMyCode = true;
public bool StepOverNoSymbols = true;
public bool StepOverNoSymbols = false;
public bool StepOverDebuggerAttributes = true;
public bool StepOverAllProperties = false;
public bool StepOverSingleLineProperties = false;

2
Debugger/Debugger.Core/SourcecodeSegment.cs

@ -383,7 +383,7 @@ namespace Debugger @@ -383,7 +383,7 @@ namespace Debugger
segment.endColumn = 0;
segment.corFunction = corFunction;
segment.ilStart = offset;
segment.ilEnd = offset;
segment.ilEnd = ranges[ranges.Length - 1];
segment.stepRanges = ranges;
return segment;

4
Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs

@ -253,7 +253,9 @@ namespace ILSpy.Debugger.AvalonEdit @@ -253,7 +253,9 @@ namespace ILSpy.Debugger.AvalonEdit
// check if the codemappings exists for this line
var storage = CodeMappings.GetStorage(DebuggerService.CurrentDebugger.Language);
uint token;
if (storage.GetInstructionByTypeAndLine(CurrentType.FullName, line, out token) == null) {
var instruction = storage.GetInstructionByTypeAndLine(CurrentType.FullName, line, out token);
if (instruction == null || instruction.ILInstructionOffset.From == 0) {
MessageBox.Show(string.Format("Missing code mappings for {0} at line {1}", CurrentType.FullName, line),
"Code mappings", MessageBoxButton.OK, MessageBoxImage.Information);
return;

55
Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs

@ -24,6 +24,7 @@ using ILSpy.Debugger.Services.Debugger; @@ -24,6 +24,7 @@ using ILSpy.Debugger.Services.Debugger;
using ILSpy.Debugger.Tooltips;
using CorDbg = Debugger;
using Process = Debugger.Process;
using StackFrame = Debugger.StackFrame;
namespace ILSpy.Debugger.Services
{
@ -284,6 +285,10 @@ namespace ILSpy.Debugger.Services @@ -284,6 +285,10 @@ namespace ILSpy.Debugger.Services
SourceCodeMapping GetNextCodeMapping()
{
if (CurrentLineBookmark.Instance == null)
return null;
// get the mapped instruction from the current line marker or the next one
uint token;
var instruction = CodeMappingsStorage.GetInstructionByTypeAndLine(
CurrentLineBookmark.Instance.TypeName,
@ -293,7 +298,22 @@ namespace ILSpy.Debugger.Services @@ -293,7 +298,22 @@ namespace ILSpy.Debugger.Services
var mapping = val.Find(m => m.MetadataToken == token);
return mapping.MethodCodeMappings.FirstOrDefault(s => s.ILInstructionOffset.From <= instruction.ILInstructionOffset.To);
return mapping.MethodCodeMappings.FirstOrDefault(s => s.ILInstructionOffset.From == instruction.ILInstructionOffset.From);
}
StackFrame GetStackFrame()
{
var map = GetNextCodeMapping();
if (map == null) {
CurrentLineBookmark.Remove();
Continue();
return null;
} else {
var frame = debuggedProcess.SelectedThread.MostRecentStackFrame;
frame.SourceCodeLine = CurrentLineBookmark.Instance.LineNumber;
frame.ILRanges = map.ToArray();
return frame;
}
}
public void StepInto()
@ -309,16 +329,9 @@ namespace ILSpy.Debugger.Services @@ -309,16 +329,9 @@ namespace ILSpy.Debugger.Services
debuggedProcess.IsRunning) {
MessageBox.Show(errorCannotStepNoActiveFunction, "StepInto");
} else {
var map = GetNextCodeMapping();
if (map == null) {
CurrentLineBookmark.Remove();
Continue();
} else {
var frame = debuggedProcess.SelectedThread.MostRecentStackFrame;
frame.SourceCodeLine = CurrentLineBookmark.Instance.LineNumber;
frame.ILRanges = map.ToArray();
var frame = GetStackFrame();
if (frame != null)
frame.AsyncStepInto();
}
}
}
@ -335,16 +348,9 @@ namespace ILSpy.Debugger.Services @@ -335,16 +348,9 @@ namespace ILSpy.Debugger.Services
debuggedProcess.IsRunning) {
MessageBox.Show(errorCannotStepNoActiveFunction, "StepOver");
} else {
var map = GetNextCodeMapping();
if (map == null) {
CurrentLineBookmark.Remove();
Continue();
} else {
var frame = debuggedProcess.SelectedThread.MostRecentStackFrame;
frame.SourceCodeLine = CurrentLineBookmark.Instance.LineNumber;
frame.ILRanges = map.ToArray();
var frame = GetStackFrame();
if (frame != null)
frame.AsyncStepOver();
}
}
}
@ -361,16 +367,9 @@ namespace ILSpy.Debugger.Services @@ -361,16 +367,9 @@ namespace ILSpy.Debugger.Services
debuggedProcess.IsRunning) {
MessageBox.Show(errorCannotStepNoActiveFunction, "StepOut");
} else {
var map = GetNextCodeMapping();
if (map == null) {
CurrentLineBookmark.Remove();
Continue();
} else {
var frame = debuggedProcess.SelectedThread.MostRecentStackFrame;
frame.SourceCodeLine = CurrentLineBookmark.Instance.LineNumber;
frame.ILRanges = map.ToArray();
var frame = GetStackFrame();
if (frame != null)
frame.AsyncStepOut();
}
}
}

17
ICSharpCode.Decompiler/CodeMappings.cs

@ -49,14 +49,15 @@ namespace ICSharpCode.Decompiler @@ -49,14 +49,15 @@ namespace ICSharpCode.Decompiler
public int[] ToArray()
{
int[] result = new int[MethodCodeMappings.Count + 1];
int[] result = new int[MethodCodeMappings.Count * 2];
int i = 0;
foreach (var element in MethodCodeMappings) {
result[i] = MethodCodeMappings[i].ILInstructionOffset.From;
++i;
result[i] = element.ILInstructionOffset.From;
result[i+1] = element.ILInstructionOffset.To;
i+=2;
}
result[MethodCodeMappings.Count] = MethodCodeMappings[MethodCodeMappings.Count - 1].ILInstructionOffset.To;
//result[MethodCodeMappings.Count] = MethodCodeMappings[MethodCodeMappings.Count - 1].ILInstructionOffset.To;
return result;
}
@ -171,8 +172,12 @@ namespace ICSharpCode.Decompiler @@ -171,8 +172,12 @@ namespace ICSharpCode.Decompiler
var codeMapping = mapping.MethodCodeMappings.Find(
cm => (cm.ILInstructionOffset.From <= ilOffset && ilOffset <= cm.ILInstructionOffset.To - 1) || // for CSharp
(cm.ILInstructionOffset.From == ilOffset && ilOffset == cm.ILInstructionOffset.To)); // for IL
if (codeMapping == null)
continue;
if (codeMapping == null) {
codeMapping = mapping.MethodCodeMappings.Find(cm => (cm.ILInstructionOffset.From >= ilOffset));
if (codeMapping == null)
continue;
}
typeName = typename;
line = codeMapping.SourceCodeLine;

10
ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs

@ -80,14 +80,14 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -80,14 +80,14 @@ namespace ICSharpCode.Decompiler.Disassembler
if (detectControlStructure && body.Instructions.Count > 0) {
Instruction inst = body.Instructions[0];
WriteStructureBody(new ILStructure(body), ref inst, methodMapping);
WriteStructureBody(new ILStructure(body), ref inst, methodMapping, method.Body.CodeSize);
} else {
foreach (var inst in method.Body.Instructions) {
// add IL code mappings
methodMapping.MethodCodeMappings.Add(
new SourceCodeMapping() {
SourceCodeLine = output.CurrentLine,
ILInstructionOffset = new ILRange { From = inst.Offset, To = inst.Offset }
ILInstructionOffset = new ILRange { From = inst.Offset, To = inst.Next == null ? method.Body.CodeSize : inst.Next.Offset }
});
inst.WriteTo(output);
@ -146,7 +146,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -146,7 +146,7 @@ namespace ICSharpCode.Decompiler.Disassembler
output.Indent();
}
void WriteStructureBody(ILStructure s, ref Instruction inst, MethodMapping currentMethodMapping)
void WriteStructureBody(ILStructure s, ref Instruction inst, MethodMapping currentMethodMapping, int codeSize)
{
int childIndex = 0;
while (inst != null && inst.Offset < s.EndOffset) {
@ -155,7 +155,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -155,7 +155,7 @@ namespace ICSharpCode.Decompiler.Disassembler
currentMethodMapping.MethodCodeMappings.Add(
new SourceCodeMapping() {
SourceCodeLine = output.CurrentLine,
ILInstructionOffset = new ILRange { From = inst.Offset, To = inst.Offset }
ILInstructionOffset = new ILRange { From = inst.Offset, To = inst.Next == null ? codeSize : inst.Next.Offset }
});
}
@ -163,7 +163,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -163,7 +163,7 @@ namespace ICSharpCode.Decompiler.Disassembler
if (childIndex < s.Children.Count && s.Children[childIndex].StartOffset <= offset && offset < s.Children[childIndex].EndOffset) {
ILStructure child = s.Children[childIndex++];
WriteStructureHeader(child);
WriteStructureBody(child, ref inst, currentMethodMapping);
WriteStructureBody(child, ref inst, currentMethodMapping, codeSize);
WriteStructureFooter(child);
} else {
inst.WriteTo(output);

8
ILSpy/MainWindow.xaml.cs

@ -377,25 +377,25 @@ namespace ICSharpCode.ILSpy @@ -377,25 +377,25 @@ namespace ICSharpCode.ILSpy
void ContinueDebuggingExecuted(object sender, ExecutedRoutedEventArgs e)
{
if (CurrentDebugger.IsDebugging)
if (CurrentDebugger.IsDebugging && !CurrentDebugger.IsProcessRunning)
CurrentDebugger.Continue();
}
void StepIntoExecuted(object sender, ExecutedRoutedEventArgs e)
{
if (CurrentDebugger.IsDebugging)
if (CurrentDebugger.IsDebugging && !CurrentDebugger.IsProcessRunning)
CurrentDebugger.StepInto();
}
void StepOverExecuted(object sender, ExecutedRoutedEventArgs e)
{
if (CurrentDebugger.IsDebugging)
if (CurrentDebugger.IsDebugging && !CurrentDebugger.IsProcessRunning)
CurrentDebugger.StepOver();
}
void StepOutExecuted(object sender, ExecutedRoutedEventArgs e)
{
if (CurrentDebugger.IsDebugging)
if (CurrentDebugger.IsDebugging && !CurrentDebugger.IsProcessRunning)
CurrentDebugger.StepOut();
}

Loading…
Cancel
Save