Browse Source

Merge pull request #191 from RKlier/dbg_arguments

Added dialog to specify arguments and working directory for debugged executable
pull/219/head
Eusebiu Marcu 14 years ago
parent
commit
d77139c80b
  1. 15
      Debugger/ILSpy.Debugger/DebuggerSettings.cs
  2. 6
      Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj
  3. 113
      Debugger/ILSpy.Debugger/UI/ExecuteProcessWindow.xaml
  4. 89
      Debugger/ILSpy.Debugger/UI/ExecuteProcessWindow.xaml.cs
  5. 96
      ILSpy/Commands/DebuggerCommands.cs
  6. 1
      ILSpy/Options/DebuggerSettingsPanel.xaml
  7. 5
      ILSpy/Options/DebuggerSettingsPanel.xaml.cs

15
Debugger/ILSpy.Debugger/DebuggerSettings.cs

@ -24,6 +24,7 @@ namespace ICSharpCode.ILSpy.Debugger @@ -24,6 +24,7 @@ namespace ICSharpCode.ILSpy.Debugger
public class DebuggerSettings : INotifyPropertyChanged
{
bool showWarnings = true;
bool askArguments = true;
bool debugWholeTypesOnly = false;
/// <summary>
@ -41,6 +42,20 @@ namespace ICSharpCode.ILSpy.Debugger @@ -41,6 +42,20 @@ namespace ICSharpCode.ILSpy.Debugger
}
}
/// <summary>
/// Ask for arguments and working directory before executing a process.
/// </summary>
[DefaultValue(true)]
public bool AskForArguments {
get { return askArguments; }
set {
if (askArguments != value) {
askArguments = value;
OnPropertyChanged("AskForArguments");
}
}
}
/// <summary>
/// True, if debug only whole types; otherwise false (debug only methods and properties).
/// <remarks>Default value is false.</remarks>

6
Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj

@ -45,6 +45,7 @@ @@ -45,6 +45,7 @@
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
@ -106,6 +107,10 @@ @@ -106,6 +107,10 @@
<DependentUpon>AttachToProcessWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="UI\ExecuteProcessWindow.xaml.cs">
<DependentUpon>ExecuteProcessWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="Images" />
@ -118,6 +123,7 @@ @@ -118,6 +123,7 @@
<Page Include="ToolTips\PinControlsDictionary.xaml" />
<Page Include="ToolTips\VisualizerPicker.xaml" />
<Page Include="UI\AttachToProcessWindow.xaml" />
<Page Include="UI\ExecuteProcessWindow.xaml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\AvalonEdit\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj">

113
Debugger/ILSpy.Debugger/UI/ExecuteProcessWindow.xaml

@ -0,0 +1,113 @@ @@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="ICSharpCode.ILSpy.Debugger.UI.ExecuteProcessWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Select process to debug..."
WindowStartupLocation="CenterOwner"
WindowState="Normal"
WindowStyle="ToolWindow"
ShowInTaskbar="False"
Height="250"
Width="596">
<Grid
Height="217">
<Grid.RowDefinitions>
<RowDefinition
Height="1.4*" />
<RowDefinition
Height="0.2*" />
</Grid.RowDefinitions>
<Label
Content="Executable"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="19.5,28.5,0,0"
Width="92"
Height="25" />
<TextBox
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,28.5,84.5,0"
Width="368"
Height="25"
Name="pathTextBox" />
<Button
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="502.5,28.5,0,0"
Width="25"
Height="25"
Content="..."
Name="pathButton"
Click="pathButton_Click" />
<TextBox
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="133.5,81,0,0"
Width="368"
Height="25"
Name="argumentsTextBox" />
<Label
Content="Arguments"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="19.5,81,0,0"
Width="92"
Height="31" />
<Button
Content="..."
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Left"
Width="25"
Click="workingDirectoryButton_Click"
Height="25"
VerticalAlignment="Bottom"
Margin="502.5,0,0,30.875"
Name="workingDirectoryButton" />
<TextBox
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="133.5,134,0,0"
Width="368"
Height="25"
Name="workingDirectoryTextBox" />
<Label
Content="Working directory"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="19.5,134,0,0"
Width="113"
Height="31" />
<DockPanel
Grid.Row="1"
LastChildFill="False">
<Button
DockPanel.Dock="Left"
HorizontalAlignment="Center"
x:Name="ExecuteButton"
Click="ExecuteButton_Click"
Content="Execute"
Width="100" />
<Button
DockPanel.Dock="Right"
x:Name="CancelButton"
Content="Cancel"
Click="CancelButton_Click"
Width="100" />
</DockPanel>
</Grid>
</Window>

89
Debugger/ILSpy.Debugger/UI/ExecuteProcessWindow.xaml.cs

@ -0,0 +1,89 @@ @@ -0,0 +1,89 @@
/*
* Created by SharpDevelop.
* User: klier
* Date: 05/13/2011
* Time: 08:44
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Forms;
namespace ICSharpCode.ILSpy.Debugger.UI
{
/// <summary>
/// Interaction logic for ExecuteProcessWindow.xaml
/// </summary>
public partial class ExecuteProcessWindow : Window
{
public ExecuteProcessWindow()
{
InitializeComponent();
}
public string SelectedExecutable {
get {
return pathTextBox.Text;
}
set {
pathTextBox.Text = value;
workingDirectoryTextBox.Text = Path.GetDirectoryName(value);
}
}
public string WorkingDirectory {
get {
return workingDirectoryTextBox.Text;
}
set {
workingDirectoryTextBox.Text = value;
}
}
public string Arguments {
get {
return argumentsTextBox.Text;
}
}
void pathButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog() {
Filter = ".NET Executable (*.exe) | *.exe",
InitialDirectory = workingDirectoryTextBox.Text,
RestoreDirectory = true,
DefaultExt = "exe"
};
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
SelectedExecutable = dialog.FileName;
}
}
void ExecuteButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(SelectedExecutable))
return;
this.DialogResult = true;
}
void CancelButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
void workingDirectoryButton_Click(object sender, RoutedEventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog() {
SelectedPath = workingDirectoryTextBox.Text
};
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
workingDirectoryTextBox.Text = dialog.SelectedPath;
}
}
}
}

96
ILSpy/Commands/DebuggerCommands.cs

@ -16,6 +16,8 @@ using ICSharpCode.ILSpy.Debugger; @@ -16,6 +16,8 @@ using ICSharpCode.ILSpy.Debugger;
using ICSharpCode.ILSpy.Debugger.Bookmarks;
using ICSharpCode.ILSpy.Debugger.Services;
using ICSharpCode.ILSpy.Debugger.UI;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.TreeView;
using Microsoft.Win32;
namespace ICSharpCode.ILSpy.Commands
@ -89,11 +91,12 @@ namespace ICSharpCode.ILSpy.Commands @@ -89,11 +91,12 @@ namespace ICSharpCode.ILSpy.Commands
}
}
protected void StartExecutable(string fileName)
protected void StartExecutable(string fileName, string workingDirectory, string arguments)
{
CurrentDebugger.Start(new ProcessStartInfo {
FileName = fileName,
WorkingDirectory = Path.GetDirectoryName(fileName)
WorkingDirectory = workingDirectory ?? Path.GetDirectoryName(fileName),
Arguments = arguments
});
Finish();
}
@ -164,13 +167,53 @@ namespace ICSharpCode.ILSpy.Commands @@ -164,13 +167,53 @@ namespace ICSharpCode.ILSpy.Commands
SendWpfWindowPos(inst, HWND_TOP); inst.Activate();
// jump to type & expand folding
if (DebugData.DebugStepInformation != null)
inst.JumpToReference(DebugData.DebugStepInformation.Item3);
var bm = CurrentLineBookmark.Instance;
if (bm != null) {
inst.JumpToReference(bm.MemberReference);
inst.TextView.UnfoldAndScroll(bm.LineNumber);
}
inst.SetStatus("Debugging...", Brushes.Red);
}
}
[ExportContextMenuEntry(Header = "_Debug Assembly", Icon = "ILSpy.Debugger;component/Images/application-x-executable.png")]
internal sealed class DebugExecutableNodeCommand : DebuggerCommand, IContextMenuEntry
{
public bool IsVisible(SharpTreeNode[] selectedNodes)
{
return selectedNodes.All(n => n is AssemblyTreeNode && null != (n as AssemblyTreeNode).LoadedAssembly.AssemblyDefinition.EntryPoint);
}
public bool IsEnabled(SharpTreeNode[] selectedNodes)
{
return selectedNodes.Length == 1;
}
public void Execute(SharpTreeNode[] selectedNodes)
{
if (!CurrentDebugger.IsDebugging) {
AssemblyTreeNode n = selectedNodes[0] as AssemblyTreeNode;
var settings = ILSpySettings.Load();
XElement e = settings["DebuggerSettings"];
var askForArguments = (bool?)e.Attribute("askForArguments");
if (askForArguments.HasValue && askForArguments.Value) {
var window = new ExecuteProcessWindow { Owner = MainWindow.Instance,
SelectedExecutable = n.LoadedAssembly.FileName };
if (window.ShowDialog() == true) {
string fileName = window.SelectedExecutable;
// execute the process
this.StartExecutable(fileName, window.WorkingDirectory, window.Arguments);
}
} else {
this.StartExecutable(n.LoadedAssembly.FileName, null, null);
}
}
}
}
[ExportToolbarCommand(ToolTip = "Debug an executable",
ToolbarIcon = "ILSpy.Debugger;component/Images/application-x-executable.png",
ToolbarCategory = "Debugger",
@ -185,21 +228,36 @@ namespace ICSharpCode.ILSpy.Commands @@ -185,21 +228,36 @@ namespace ICSharpCode.ILSpy.Commands
{
public override void Execute(object parameter)
{
OpenFileDialog dialog = new OpenFileDialog() {
Filter = ".NET Executable (*.exe) | *.exe",
RestoreDirectory = true,
DefaultExt = "exe"
};
if (dialog.ShowDialog() == true) {
string fileName = dialog.FileName;
// add it to references
MainWindow.Instance.OpenFiles(new [] { fileName }, false);
if (!CurrentDebugger.IsDebugging) {
// execute the process
this.StartExecutable(fileName);
if (!CurrentDebugger.IsDebugging) {
var settings = ILSpySettings.Load();
XElement e = settings["DebuggerSettings"];
var askForArguments = (bool?)e.Attribute("askForArguments");
if (askForArguments.HasValue && askForArguments.Value) {
var window = new ExecuteProcessWindow { Owner = MainWindow.Instance };
if (window.ShowDialog() == true) {
string fileName = window.SelectedExecutable;
// add it to references
MainWindow.Instance.OpenFiles(new [] { fileName }, false);
// execute the process
this.StartExecutable(fileName, window.WorkingDirectory, window.Arguments);
}
} else {
OpenFileDialog dialog = new OpenFileDialog() {
Filter = ".NET Executable (*.exe) | *.exe",
RestoreDirectory = true,
DefaultExt = "exe"
};
if (dialog.ShowDialog() == true) {
string fileName = dialog.FileName;
// add it to references
MainWindow.Instance.OpenFiles(new [] { fileName }, false);
// execute the process
this.StartExecutable(fileName, null, null);
}
}
}
}

1
ILSpy/Options/DebuggerSettingsPanel.xaml

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
<Grid>
<StackPanel Margin="10">
<CheckBox IsChecked="{Binding ShowWarnings}">Show warning messages</CheckBox>
<CheckBox IsChecked="{Binding AskForArguments}">Ask for arguments and working directory before executing a process</CheckBox>
</StackPanel>
</Grid>
</UserControl>

5
ILSpy/Options/DebuggerSettingsPanel.xaml.cs

@ -21,6 +21,7 @@ namespace ICSharpCode.ILSpy.Options @@ -21,6 +21,7 @@ namespace ICSharpCode.ILSpy.Options
{
private const string DEBUGGER_SETTINGS = "DebuggerSettings";
private const string SHOW_WARNINGS = "showWarnings";
private const string ASK_ARGUMENTS = "askForArguments";
public DebuggerSettingsPanel()
{
@ -45,6 +46,7 @@ namespace ICSharpCode.ILSpy.Options @@ -45,6 +46,7 @@ namespace ICSharpCode.ILSpy.Options
XElement e = settings[DEBUGGER_SETTINGS];
DebuggerSettings s = new DebuggerSettings();
s.ShowWarnings = (bool?)e.Attribute(SHOW_WARNINGS) ?? s.ShowWarnings;
s.AskForArguments = (bool?)e.Attribute(ASK_ARGUMENTS) ?? s.AskForArguments;
return s;
}
@ -54,7 +56,8 @@ namespace ICSharpCode.ILSpy.Options @@ -54,7 +56,8 @@ namespace ICSharpCode.ILSpy.Options
var s = (DebuggerSettings)this.DataContext;
XElement section = new XElement(DEBUGGER_SETTINGS);
section.SetAttributeValue(SHOW_WARNINGS, s.ShowWarnings);
section.SetAttributeValue(ASK_ARGUMENTS, s.AskForArguments);
XElement existingElement = root.Element(DEBUGGER_SETTINGS);
if (existingElement != null)
existingElement.ReplaceWith(section);

Loading…
Cancel
Save