Browse Source

Allow arguments for debugged executable

pull/191/head
Ronny Klier 15 years ago
parent
commit
fa3941e1fd
  1. 15
      Debugger/ILSpy.Debugger/DebuggerSettings.cs
  2. 6
      Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj
  3. 96
      ILSpy/Commands/DebuggerCommands.cs
  4. 1
      ILSpy/Options/DebuggerSettingsPanel.xaml
  5. 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">

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