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

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

@ -16,24 +16,29 @@ using ICSharpCode.SharpDevelop.Services;
namespace ICSharpCode.SharpDevelop.Gui.Pads namespace ICSharpCode.SharpDevelop.Gui.Pads
{ {
/// <summary> public class CallStackPad : AbstractPadContent
/// Interaction logic for CallStackPadContent.xaml
/// </summary>
public partial class CallStackPadContent : UserControl
{ {
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; listView.ContextMenu = CreateMenu();
((GridView)view.View).Columns[2].Width = DebuggingOptions.Instance.ShowLineNumbers ? 50d : 0d;
WindowsDebugger.RefreshingPads += RefreshPad; WindowsDebugger.RefreshingPads += RefreshPad;
RefreshPad(); RefreshPad();
} }
ContextMenu CreateMenu() ContextMenu CreateMenu()
{ {
MenuItem extMethodsItem = new MenuItem(); MenuItem extMethodsItem = new MenuItem();
@ -49,7 +54,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
moduleItem.IsChecked = DebuggingOptions.Instance.ShowModuleNames; moduleItem.IsChecked = DebuggingOptions.Instance.ShowModuleNames;
moduleItem.Click += delegate { moduleItem.Click += delegate {
moduleItem.IsChecked = DebuggingOptions.Instance.ShowModuleNames = !DebuggingOptions.Instance.ShowModuleNames; moduleItem.IsChecked = DebuggingOptions.Instance.ShowModuleNames = !DebuggingOptions.Instance.ShowModuleNames;
((GridView)view.View).Columns[0].Width = DebuggingOptions.Instance.ShowModuleNames ? 100d : 0d;
WindowsDebugger.RefreshPads(); WindowsDebugger.RefreshPads();
}; };
@ -74,7 +78,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
lineItem.IsChecked = DebuggingOptions.Instance.ShowLineNumbers; lineItem.IsChecked = DebuggingOptions.Instance.ShowLineNumbers;
lineItem.Click += delegate { lineItem.Click += delegate {
lineItem.IsChecked = DebuggingOptions.Instance.ShowLineNumbers = !DebuggingOptions.Instance.ShowLineNumbers; lineItem.IsChecked = DebuggingOptions.Instance.ShowLineNumbers = !DebuggingOptions.Instance.ShowLineNumbers;
((GridView)view.View).Columns[2].Width = DebuggingOptions.Instance.ShowLineNumbers ? 50d : 0d;
WindowsDebugger.RefreshPads(); WindowsDebugger.RefreshPads();
}; };
@ -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) if (item == null)
return; return;
@ -105,6 +108,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
return; return;
} }
WindowsDebugger.CurrentStackFrame = item.Frame; WindowsDebugger.CurrentStackFrame = item.Frame;
WindowsDebugger.Instance.JumpToCurrentLine();
WindowsDebugger.RefreshPads(); WindowsDebugger.RefreshPads();
} }
} else { } else {
@ -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() void RefreshPad()
{ {
Thread thead = WindowsDebugger.CurrentThread; Thread thead = WindowsDebugger.CurrentThread;
if (thead == null) { if (thead == null) {
view.ItemsSource = null; listView.ItemsSource = null;
} else { } else {
var items = new ObservableCollection<CallStackItem>(); var items = new ObservableCollection<CallStackItem>();
bool showExternalMethods = DebuggingOptions.Instance.ShowExternalMethods;
bool previousItemIsExternalMethod = false; bool previousItemIsExternalMethod = false;
WindowsDebugger.CurrentProcess.EnqueueForEach( WindowsDebugger.CurrentProcess.EnqueueForEach(
Dispatcher, listView.Dispatcher,
thead.GetCallstack(100), thead.GetCallstack(100),
f => items.AddIfNotNull(CreateItem(f, showExternalMethods, ref previousItemIsExternalMethod)) f => items.AddIfNotNull(CreateItem(f, ref previousItemIsExternalMethod))
); );
listView.ItemsSource = items;
view.ItemsSource = items;
} }
} }
CallStackItem CreateItem(StackFrame frame, bool showExternalMethods, ref bool previousItemIsExternalMethod) CallStackItem CreateItem(StackFrame frame, ref bool previousItemIsExternalMethod)
{ {
CallStackItem item; bool showExternalMethods = DebuggingOptions.Instance.ShowExternalMethods;
// 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();
}
if (frame.HasSymbols || showExternalMethods) { if (frame.HasSymbols || showExternalMethods) {
// Show the method in the list // Show the method in the list
item = new CallStackItem() {
Name = GetFullName(frame), Language = "", Line = lineNumber, ModuleName = moduleName
};
previousItemIsExternalMethod = false; previousItemIsExternalMethod = false;
item.Frame = frame; return new CallStackItem() {
Frame = frame,
ImageSource = new ResourceServiceImage("Icons.16x16.Method").ImageSource,
Name = GetFullName(frame)
};
} else { } else {
// Show [External methods] in the list // Show [External methods] in the list
if (previousItemIsExternalMethod) return null; if (previousItemIsExternalMethod)
item = new CallStackItem() { return null;
Name = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ExternalMethods"),
Language = ""
};
previousItemIsExternalMethod = true; previousItemIsExternalMethod = true;
return new CallStackItem() {
Name = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ExternalMethods")
};
} }
return item;
} }
internal static string GetFullName(StackFrame frame) internal static string GetFullName(StackFrame frame)
{ {
bool showArgumentNames = DebuggingOptions.Instance.ShowArgumentNames; StringBuilder name = new StringBuilder(64);
bool showArgumentValues = DebuggingOptions.Instance.ShowArgumentValues; if (DebuggingOptions.Instance.ShowModuleNames) {
bool showLineNumber = DebuggingOptions.Instance.ShowLineNumbers; name.Append(frame.MethodInfo.DebugModule.ToString());
bool showModuleNames = DebuggingOptions.Instance.ShowModuleNames; name.Append('!');
}
StringBuilder name = new StringBuilder();
name.Append(frame.MethodInfo.DeclaringType.FullName); name.Append(frame.MethodInfo.DeclaringType.FullName);
name.Append('.'); name.Append('.');
name.Append(frame.MethodInfo.Name); name.Append(frame.MethodInfo.Name);
if (showArgumentNames || showArgumentValues) { if (DebuggingOptions.Instance.ShowArgumentNames || DebuggingOptions.Instance.ShowArgumentValues) {
name.Append("("); name.Append('(');
for (int i = 0; i < frame.ArgumentCount; i++) { for (int i = 0; i < frame.ArgumentCount; i++) {
string parameterName = null; if (DebuggingOptions.Instance.ShowArgumentNames) {
string argValue = null; name.Append(frame.MethodInfo.GetParameters()[i].Name);
if (showArgumentNames) { if (DebuggingOptions.Instance.ShowArgumentValues) {
try { name.Append('=');
parameterName = frame.MethodInfo.GetParameters()[i].Name; }
} catch { }
if (parameterName == "") parameterName = null;
} }
if (showArgumentValues) { if (DebuggingOptions.Instance.ShowArgumentValues) {
try { try {
argValue = frame.GetArgumentValue(i).AsString(100); name.Append(frame.GetArgumentValue(i).AsString(100));
} catch { } } catch (GetValueException) {
} name.Append(ResourceService.GetString("Global.NA"));
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"));
} }
if (i < frame.ArgumentCount - 1) { if (i < frame.ArgumentCount - 1) {
name.Append(", "); 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(); return name.ToString();
} }
} }
public class CallStackItem public class CallStackItem
{ {
public string Name { get; set; }
public string Language { get; set; }
public StackFrame Frame { get; set; } public StackFrame Frame { get; set; }
public string Line { get; set; } public ImageSource ImageSource { get; set; }
public string ModuleName { get; set; } public string Name { get; set; }
public Brush FontColor { public Brush FontColor {
get { return Frame == null || Frame.HasSymbols ? Brushes.Black : Brushes.Gray; } get { return this.Frame == null || this.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;
}
} }
} }
} }

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

@ -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 @@
<!-- Local Variables Pad and Watch Pad --> <!-- Local Variables Pad and Watch Pad -->
<tv:SharpGridView x:Key="variableGridView"> <tv:SharpGridView x:Key="variableGridView">
<GridView.Columns> <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> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
@ -37,6 +37,20 @@
</GridView.Columns> </GridView.Columns>
</tv:SharpGridView> </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 --> <!-- Breakpoints Pad -->
<GridView x:Key="breakpointsGridView"> <GridView x:Key="breakpointsGridView">
<GridViewColumn Header="" Width="Auto"> <GridViewColumn Header="" Width="Auto">

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

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

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

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

Loading…
Cancel
Save