Browse Source

More DebugStep UI options

pull/728/merge
Siegfried Pammer 9 years ago
parent
commit
94d1d76ec3
  1. 22
      ICSharpCode.Decompiler/IL/Transforms/Stepper.cs
  2. 9
      ILSpy/DebugSteps.xaml
  3. 23
      ILSpy/DebugSteps.xaml.cs
  4. 1
      ILSpy/DecompilationOptions.cs
  5. 1
      ILSpy/Languages/ILAstLanguage.cs

22
ICSharpCode.Decompiler/IL/Transforms/Stepper.cs

@ -54,12 +54,20 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -54,12 +54,20 @@ namespace ICSharpCode.Decompiler.IL.Transforms
public IList<Node> Steps => steps;
public int StepLimit { get; set; } = int.MaxValue;
public bool IsDebug { get; set; }
public class Node
{
public string Description { get; set; }
public ILInstruction Position { get; set; }
public int Step { get; set; }
/// <summary>
/// BeginStep is inclusive.
/// </summary>
public int BeginStep { get; set; }
/// <summary>
/// EndStep is exclusive.
/// </summary>
public int EndStep { get; set; }
public IList<Node> Children { get; } = new List<Node>();
}
@ -87,12 +95,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -87,12 +95,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms
private Node StepInternal(string description, ILInstruction near)
{
if (step >= StepLimit)
throw new StepLimitReachedException();
if (step >= StepLimit) {
if (IsDebug)
Debugger.Break();
else
throw new StepLimitReachedException();
}
var stepNode = new Node {
Description = $"{step}: {description}",
Position = near,
Step = step
BeginStep = step,
EndStep = step + 1
};
var p = groups.PeekOrDefault();
if (p != null)
@ -116,6 +129,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -116,6 +129,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Debug.Assert(col.Last() == node);
col.RemoveAt(col.Count - 1);
}
node.EndStep = step;
}
}
}

9
ILSpy/DebugSteps.xaml

@ -7,12 +7,19 @@ @@ -7,12 +7,19 @@
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TreeView Name="tree" MouseDoubleClick="tree_MouseDoubleClick">
<TreeView Name="tree" MouseDoubleClick="ShowStateAfter_Click">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Description}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
<TreeView.ContextMenu>
<ContextMenu>
<MenuItem Header="Show state before this step" Click="ShowStateBefore_Click" />
<MenuItem Header="Show state after this step" Click="ShowStateAfter_Click" />
<MenuItem Header="Debug this step" Click="DebugStep_Click" />
</ContextMenu>
</TreeView.ContextMenu>
</TreeView>
</Grid>
</UserControl>

23
ILSpy/DebugSteps.xaml.cs

@ -76,12 +76,31 @@ namespace ICSharpCode.ILSpy @@ -76,12 +76,31 @@ namespace ICSharpCode.ILSpy
}
}
private void tree_MouseDoubleClick(object sender, MouseButtonEventArgs e)
private void ShowStateAfter_Click(object sender, RoutedEventArgs e)
{
Stepper.Node n = (Stepper.Node)tree.SelectedItem;
if (n == null) return;
DecompileAsync(n.EndStep);
}
private void ShowStateBefore_Click(object sender, RoutedEventArgs e)
{
Stepper.Node n = (Stepper.Node)tree.SelectedItem;
if (n == null) return;
DecompileAsync(n.BeginStep);
}
private void DebugStep_Click(object sender, RoutedEventArgs e)
{
Stepper.Node n = (Stepper.Node)tree.SelectedItem;
if (n == null) return;
DecompileAsync(n.BeginStep, true);
}
void DecompileAsync(int step, bool isDebug = false)
{
var window = MainWindow.Instance;
window.TextView.DecompileAsync(window.CurrentLanguage, window.SelectedNodes, new DecompilationOptions() { StepLimit = n.Step + 1 });
window.TextView.DecompileAsync(window.CurrentLanguage, window.SelectedNodes, new DecompilationOptions() { StepLimit = step, IsDebug = isDebug });
}
}
}

1
ILSpy/DecompilationOptions.cs

@ -66,6 +66,7 @@ namespace ICSharpCode.ILSpy @@ -66,6 +66,7 @@ namespace ICSharpCode.ILSpy
/// Used internally for debugging.
/// </summary>
internal int StepLimit = int.MaxValue;
internal bool IsDebug = false;
public DecompilationOptions()
{

1
ILSpy/Languages/ILAstLanguage.cs

@ -157,6 +157,7 @@ namespace ICSharpCode.ILSpy @@ -157,6 +157,7 @@ namespace ICSharpCode.ILSpy
ILFunction il = reader.ReadIL(method.Body, options.CancellationToken);
ILTransformContext context = new ILTransformContext { Settings = options.DecompilerSettings, TypeSystem = typeSystem };
context.Stepper.StepLimit = options.StepLimit;
context.Stepper.IsDebug = options.IsDebug;
try {
il.RunTransforms(transforms, context);
} catch (StepLimitReachedException) {

Loading…
Cancel
Save