Browse Source

Refactored CallStack Pad

newNRvisualizers
David Srbecký 13 years ago
parent
commit
1022ad705b
  1. 4
      src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj
  2. 178
      src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.cs
  3. 41
      src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.xaml
  4. 16
      src/AddIns/Debugger/Debugger.AddIn/Pads/Common/CommonResources.xaml
  5. 2
      src/AddIns/Debugger/Debugger.AddIn/Pads/ParallelPad/ThreadStack.xaml.cs
  6. 4
      src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs

4
src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj

@ -103,8 +103,7 @@ @@ -103,8 +103,7 @@
<DependentUpon>DebuggingOptionsPanel.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Pads\CallStackPad.xaml.cs">
<DependentUpon>CallStackPad.xaml</DependentUpon>
<Compile Include="Pads\CallStackPad.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Pads\Commands\MemoryPadCommands.cs" />
@ -338,7 +337,6 @@ @@ -338,7 +337,6 @@
</ItemGroup>
<ItemGroup>
<Page Include="Options\DebuggingOptionsPanel.xaml" />
<Page Include="Pads\CallStackPad.xaml" />
<Page Include="Pads\Common\CommonResources.xaml" />
<Page Include="Pads\ParallelPad\DrawSurface.xaml" />
<Page Include="Pads\ParallelPad\ThreadStack.xaml" />

178
src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.xaml.cs → src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.cs

@ -16,19 +16,24 @@ using ICSharpCode.SharpDevelop.Services; @@ -16,19 +16,24 @@ using ICSharpCode.SharpDevelop.Services;
namespace ICSharpCode.SharpDevelop.Gui.Pads
{
/// <summary>
/// Interaction logic for CallStackPadContent.xaml
/// </summary>
public partial class CallStackPadContent : UserControl
public class CallStackPad : AbstractPadContent
{
public CallStackPadContent()
ListView listView;
public override object Control {
get { return this.listView; }
}
public CallStackPad()
{
InitializeComponent();
var res = new CommonResources();
res.InitializeComponent();
view.ContextMenu = CreateMenu();
listView = new ListView();
listView.View = (GridView)res["callstackGridView"];
listView.MouseDoubleClick += listView_MouseDoubleClick;
((GridView)view.View).Columns[0].Width = DebuggingOptions.Instance.ShowModuleNames ? 100d : 0d;
((GridView)view.View).Columns[2].Width = DebuggingOptions.Instance.ShowLineNumbers ? 50d : 0d;
listView.ContextMenu = CreateMenu();
WindowsDebugger.RefreshingPads += RefreshPad;
RefreshPad();
@ -49,7 +54,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -49,7 +54,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
moduleItem.IsChecked = DebuggingOptions.Instance.ShowModuleNames;
moduleItem.Click += delegate {
moduleItem.IsChecked = DebuggingOptions.Instance.ShowModuleNames = !DebuggingOptions.Instance.ShowModuleNames;
((GridView)view.View).Columns[0].Width = DebuggingOptions.Instance.ShowModuleNames ? 100d : 0d;
WindowsDebugger.RefreshPads();
};
@ -74,7 +78,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -74,7 +78,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
lineItem.IsChecked = DebuggingOptions.Instance.ShowLineNumbers;
lineItem.Click += delegate {
lineItem.IsChecked = DebuggingOptions.Instance.ShowLineNumbers = !DebuggingOptions.Instance.ShowLineNumbers;
((GridView)view.View).Columns[2].Width = DebuggingOptions.Instance.ShowLineNumbers ? 50d : 0d;
WindowsDebugger.RefreshPads();
};
@ -90,9 +93,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -90,9 +93,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
};
}
void View_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
void listView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
CallStackItem item = view.SelectedItem as CallStackItem;
CallStackItem item = listView.SelectedItem as CallStackItem;
if (item == null)
return;
@ -105,6 +108,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -105,6 +108,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
return;
}
WindowsDebugger.CurrentStackFrame = item.Frame;
WindowsDebugger.Instance.JumpToCurrentLine();
WindowsDebugger.RefreshPads();
}
} else {
@ -112,157 +116,95 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -112,157 +116,95 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
}
}
void View_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter) {
View_MouseLeftButtonUp(sender, null);
e.Handled = true;
}
}
void RefreshPad()
{
Thread thead = WindowsDebugger.CurrentThread;
if (thead == null) {
view.ItemsSource = null;
listView.ItemsSource = null;
} else {
var items = new ObservableCollection<CallStackItem>();
bool showExternalMethods = DebuggingOptions.Instance.ShowExternalMethods;
bool previousItemIsExternalMethod = false;
WindowsDebugger.CurrentProcess.EnqueueForEach(
Dispatcher,
listView.Dispatcher,
thead.GetCallstack(100),
f => items.AddIfNotNull(CreateItem(f, showExternalMethods, ref previousItemIsExternalMethod))
f => items.AddIfNotNull(CreateItem(f, ref previousItemIsExternalMethod))
);
view.ItemsSource = items;
listView.ItemsSource = items;
}
}
CallStackItem CreateItem(StackFrame frame, bool showExternalMethods, ref bool previousItemIsExternalMethod)
CallStackItem CreateItem(StackFrame frame, ref bool previousItemIsExternalMethod)
{
CallStackItem item;
// line number
string lineNumber = string.Empty;
if (DebuggingOptions.Instance.ShowLineNumbers) {
if (frame.NextStatement != null)
lineNumber = frame.NextStatement.StartLine.ToString();
}
// show modules names
string moduleName = string.Empty;
if (DebuggingOptions.Instance.ShowModuleNames) {
moduleName = frame.MethodInfo.DebugModule.ToString();
}
bool showExternalMethods = DebuggingOptions.Instance.ShowExternalMethods;
if (frame.HasSymbols || showExternalMethods) {
// Show the method in the list
item = new CallStackItem() {
Name = GetFullName(frame), Language = "", Line = lineNumber, ModuleName = moduleName
};
previousItemIsExternalMethod = false;
item.Frame = frame;
return new CallStackItem() {
Frame = frame,
ImageSource = new ResourceServiceImage("Icons.16x16.Method").ImageSource,
Name = GetFullName(frame)
};
} else {
// Show [External methods] in the list
if (previousItemIsExternalMethod) return null;
item = new CallStackItem() {
Name = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ExternalMethods"),
Language = ""
};
if (previousItemIsExternalMethod)
return null;
previousItemIsExternalMethod = true;
return new CallStackItem() {
Name = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ExternalMethods")
};
}
return item;
}
internal static string GetFullName(StackFrame frame)
{
bool showArgumentNames = DebuggingOptions.Instance.ShowArgumentNames;
bool showArgumentValues = DebuggingOptions.Instance.ShowArgumentValues;
bool showLineNumber = DebuggingOptions.Instance.ShowLineNumbers;
bool showModuleNames = DebuggingOptions.Instance.ShowModuleNames;
StringBuilder name = new StringBuilder();
StringBuilder name = new StringBuilder(64);
if (DebuggingOptions.Instance.ShowModuleNames) {
name.Append(frame.MethodInfo.DebugModule.ToString());
name.Append('!');
}
name.Append(frame.MethodInfo.DeclaringType.FullName);
name.Append('.');
name.Append(frame.MethodInfo.Name);
if (showArgumentNames || showArgumentValues) {
name.Append("(");
if (DebuggingOptions.Instance.ShowArgumentNames || DebuggingOptions.Instance.ShowArgumentValues) {
name.Append('(');
for (int i = 0; i < frame.ArgumentCount; i++) {
string parameterName = null;
string argValue = null;
if (showArgumentNames) {
try {
parameterName = frame.MethodInfo.GetParameters()[i].Name;
} catch { }
if (parameterName == "") parameterName = null;
if (DebuggingOptions.Instance.ShowArgumentNames) {
name.Append(frame.MethodInfo.GetParameters()[i].Name);
if (DebuggingOptions.Instance.ShowArgumentValues) {
name.Append('=');
}
}
if (showArgumentValues) {
if (DebuggingOptions.Instance.ShowArgumentValues) {
try {
argValue = frame.GetArgumentValue(i).AsString(100);
} catch { }
}
if (parameterName != null && argValue != null) {
name.Append(parameterName);
name.Append("=");
name.Append(argValue);
}
if (parameterName != null && argValue == null) {
name.Append(parameterName);
}
if (parameterName == null && argValue != null) {
name.Append(argValue);
}
if (parameterName == null && argValue == null) {
name.Append(ResourceService.GetString("Global.NA"));
name.Append(frame.GetArgumentValue(i).AsString(100));
} catch (GetValueException) {
name.Append(ResourceService.GetString("Global.NA"));
}
}
if (i < frame.ArgumentCount - 1) {
name.Append(", ");
}
}
name.Append(")");
name.Append(')');
}
if (DebuggingOptions.Instance.ShowLineNumbers) {
if (frame.NextStatement != null) {
name.Append(':');
name.Append(frame.NextStatement.StartLine.ToString());
}
}
return name.ToString();
}
}
public class CallStackItem
{
public string Name { get; set; }
public string Language { get; set; }
public StackFrame Frame { get; set; }
public string Line { get; set; }
public string ModuleName { get; set; }
public ImageSource ImageSource { get; set; }
public string Name { get; set; }
public Brush FontColor {
get { return Frame == null || Frame.HasSymbols ? Brushes.Black : Brushes.Gray; }
}
}
public class CallStackPad : AbstractPadContent
{
CallStackPadContent callStackList;
static CallStackPad instance;
public static CallStackPad Instance {
get { return instance; }
}
public CallStackPad()
{
instance = this;
callStackList = new CallStackPadContent();
}
public override object Control {
get {
return callStackList;
}
get { return this.Frame == null || this.Frame.HasSymbols ? Brushes.Black : Brushes.Gray; }
}
}
}

41
src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.xaml

@ -1,41 +0,0 @@ @@ -1,41 +0,0 @@
<UserControl x:Class="ICSharpCode.SharpDevelop.Gui.Pads.CallStackPadContent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sd="http://icsharpcode.net/sharpdevelop/core"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DockPanel>
<ListView Name="view" MouseLeftButtonUp="View_MouseLeftButtonUp" KeyDown="View_KeyDown">
<ListView.View>
<GridView>
<GridViewColumn Header="{sd:Localize MainWindow.Windows.Debug.CallStack.Module}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ModuleName}" Foreground="{Binding FontColor}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="{sd:Localize Global.Name}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" Foreground="{Binding FontColor}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="{sd:Localize Global.TextLine}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Line}" Foreground="{Binding FontColor}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="{sd:Localize MainWindow.Windows.Debug.CallStack.Language}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Language}" Foreground="{Binding FontColor}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</DockPanel>
</UserControl>

16
src/AddIns/Debugger/Debugger.AddIn/Pads/Common/CommonResources.xaml

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
<!-- Local Variables Pad and Watch Pad -->
<tv:SharpGridView x:Key="variableGridView">
<GridView.Columns>
<GridViewColumn Header="{core:Localize MainWindow.Windows.Debug.LocalVariables.NameColumn}" Width="400">
<GridViewColumn Header="{core:Localize MainWindow.Windows.Debug.LocalVariables.NameColumn}" Width="200">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
@ -37,6 +37,20 @@ @@ -37,6 +37,20 @@
</GridView.Columns>
</tv:SharpGridView>
<!-- Callstack -->
<GridView x:Key="callstackGridView">
<GridViewColumn Header="{core:Localize Global.Name}" Width="400">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ImageSource}" Margin="1, 1, 5, 1" />
<TextBlock Text="{Binding Name}" Foreground="{Binding FontColor}" />
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
<!-- Breakpoints Pad -->
<GridView x:Key="breakpointsGridView">
<GridViewColumn Header="" Width="Auto">

2
src/AddIns/Debugger/Debugger.AddIn/Pads/ParallelPad/ThreadStack.xaml.cs

@ -271,7 +271,7 @@ namespace Debugger.AddIn.Pads.ParallelPad @@ -271,7 +271,7 @@ namespace Debugger.AddIn.Pads.ParallelPad
if (selectedItem.MethodName == frame.GetMethodName())
{
TextBlock tb = new TextBlock();
tb.Text = thread.ID + ": " + CallStackPadContent.GetFullName(frame);
tb.Text = thread.ID + ": " + CallStackPad.GetFullName(frame);
panel.Children.Add(tb);
}
}

4
src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs

@ -35,6 +35,8 @@ namespace ICSharpCode.SharpDevelop.Services @@ -35,6 +35,8 @@ namespace ICSharpCode.SharpDevelop.Services
{
public class WindowsDebugger : IDebugger
{
public static WindowsDebugger Instance { get; set; }
public static NDebugger CurrentDebugger { get; private set; }
public static Process CurrentProcess { get; private set; }
public static Thread CurrentThread { get; set; }
@ -93,7 +95,7 @@ namespace ICSharpCode.SharpDevelop.Services @@ -93,7 +95,7 @@ namespace ICSharpCode.SharpDevelop.Services
public WindowsDebugger()
{
Instance = this;
}
#region IDebugger Members

Loading…
Cancel
Save