From fa3941e1fdb4726febd17e193322796ef6855af0 Mon Sep 17 00:00:00 2001 From: Ronny Klier Date: Wed, 18 May 2011 17:18:45 +0200 Subject: [PATCH 1/2] Allow arguments for debugged executable --- Debugger/ILSpy.Debugger/DebuggerSettings.cs | 15 +++ Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj | 6 ++ ILSpy/Commands/DebuggerCommands.cs | 96 +++++++++++++++---- ILSpy/Options/DebuggerSettingsPanel.xaml | 1 + ILSpy/Options/DebuggerSettingsPanel.xaml.cs | 5 +- 5 files changed, 103 insertions(+), 20 deletions(-) diff --git a/Debugger/ILSpy.Debugger/DebuggerSettings.cs b/Debugger/ILSpy.Debugger/DebuggerSettings.cs index 1a9e6617f..9b2955a1c 100644 --- a/Debugger/ILSpy.Debugger/DebuggerSettings.cs +++ b/Debugger/ILSpy.Debugger/DebuggerSettings.cs @@ -24,6 +24,7 @@ namespace ICSharpCode.ILSpy.Debugger public class DebuggerSettings : INotifyPropertyChanged { bool showWarnings = true; + bool askArguments = true; bool debugWholeTypesOnly = false; /// @@ -41,6 +42,20 @@ namespace ICSharpCode.ILSpy.Debugger } } + /// + /// Ask for arguments and working directory before executing a process. + /// + [DefaultValue(true)] + public bool AskForArguments { + get { return askArguments; } + set { + if (askArguments != value) { + askArguments = value; + OnPropertyChanged("AskForArguments"); + } + } + } + /// /// True, if debug only whole types; otherwise false (debug only methods and properties). /// Default value is false. diff --git a/Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj b/Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj index 80f4efa04..1921b8dfd 100644 --- a/Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj +++ b/Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj @@ -45,6 +45,7 @@ 3.5 + 4.0 @@ -106,6 +107,10 @@ AttachToProcessWindow.xaml Code + + ExecuteProcessWindow.xaml + Code + @@ -118,6 +123,7 @@ + diff --git a/ILSpy/Commands/DebuggerCommands.cs b/ILSpy/Commands/DebuggerCommands.cs index 06c5736f3..061200ebe 100644 --- a/ILSpy/Commands/DebuggerCommands.cs +++ b/ILSpy/Commands/DebuggerCommands.cs @@ -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 } } - 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 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 { 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); + } } } } diff --git a/ILSpy/Options/DebuggerSettingsPanel.xaml b/ILSpy/Options/DebuggerSettingsPanel.xaml index 27c24d0b6..37581e90c 100644 --- a/ILSpy/Options/DebuggerSettingsPanel.xaml +++ b/ILSpy/Options/DebuggerSettingsPanel.xaml @@ -5,6 +5,7 @@ Show warning messages + Ask for arguments and working directory before executing a process \ No newline at end of file diff --git a/ILSpy/Options/DebuggerSettingsPanel.xaml.cs b/ILSpy/Options/DebuggerSettingsPanel.xaml.cs index ecc0fcbd2..6702f1371 100644 --- a/ILSpy/Options/DebuggerSettingsPanel.xaml.cs +++ b/ILSpy/Options/DebuggerSettingsPanel.xaml.cs @@ -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 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 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); From 92e8616aabf7f7a4816f28109022e0ac76e0cd26 Mon Sep 17 00:00:00 2001 From: Ronny Klier Date: Wed, 18 May 2011 23:13:57 +0200 Subject: [PATCH 2/2] Dialog for arguments and working directory was missing --- .../UI/ExecuteProcessWindow.xaml | 113 ++++++++++++++++++ .../UI/ExecuteProcessWindow.xaml.cs | 89 ++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 Debugger/ILSpy.Debugger/UI/ExecuteProcessWindow.xaml create mode 100644 Debugger/ILSpy.Debugger/UI/ExecuteProcessWindow.xaml.cs diff --git a/Debugger/ILSpy.Debugger/UI/ExecuteProcessWindow.xaml b/Debugger/ILSpy.Debugger/UI/ExecuteProcessWindow.xaml new file mode 100644 index 000000000..031927303 --- /dev/null +++ b/Debugger/ILSpy.Debugger/UI/ExecuteProcessWindow.xaml @@ -0,0 +1,113 @@ + + + + + + + +