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
public class DebuggerSettings : INotifyPropertyChanged public class DebuggerSettings : INotifyPropertyChanged
{ {
bool showWarnings = true; bool showWarnings = true;
bool askArguments = true;
bool debugWholeTypesOnly = false; bool debugWholeTypesOnly = false;
/// <summary> /// <summary>
@ -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> /// <summary>
/// True, if debug only whole types; otherwise false (debug only methods and properties). /// True, if debug only whole types; otherwise false (debug only methods and properties).
/// <remarks>Default value is false.</remarks> /// <remarks>Default value is false.</remarks>

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

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

96
ILSpy/Commands/DebuggerCommands.cs

@ -16,6 +16,8 @@ using ICSharpCode.ILSpy.Debugger;
using ICSharpCode.ILSpy.Debugger.Bookmarks; using ICSharpCode.ILSpy.Debugger.Bookmarks;
using ICSharpCode.ILSpy.Debugger.Services; using ICSharpCode.ILSpy.Debugger.Services;
using ICSharpCode.ILSpy.Debugger.UI; using ICSharpCode.ILSpy.Debugger.UI;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.TreeView;
using Microsoft.Win32; using Microsoft.Win32;
namespace ICSharpCode.ILSpy.Commands 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 { CurrentDebugger.Start(new ProcessStartInfo {
FileName = fileName, FileName = fileName,
WorkingDirectory = Path.GetDirectoryName(fileName) WorkingDirectory = workingDirectory ?? Path.GetDirectoryName(fileName),
Arguments = arguments
}); });
Finish(); Finish();
} }
@ -164,13 +167,53 @@ namespace ICSharpCode.ILSpy.Commands
SendWpfWindowPos(inst, HWND_TOP); inst.Activate(); SendWpfWindowPos(inst, HWND_TOP); inst.Activate();
// jump to type & expand folding // jump to type & expand folding
if (DebugData.DebugStepInformation != null) var bm = CurrentLineBookmark.Instance;
inst.JumpToReference(DebugData.DebugStepInformation.Item3); if (bm != null) {
inst.JumpToReference(bm.MemberReference);
inst.TextView.UnfoldAndScroll(bm.LineNumber);
}
inst.SetStatus("Debugging...", Brushes.Red); 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", [ExportToolbarCommand(ToolTip = "Debug an executable",
ToolbarIcon = "ILSpy.Debugger;component/Images/application-x-executable.png", ToolbarIcon = "ILSpy.Debugger;component/Images/application-x-executable.png",
ToolbarCategory = "Debugger", ToolbarCategory = "Debugger",
@ -185,21 +228,36 @@ namespace ICSharpCode.ILSpy.Commands
{ {
public override void Execute(object parameter) public override void Execute(object parameter)
{ {
OpenFileDialog dialog = new OpenFileDialog() { if (!CurrentDebugger.IsDebugging) {
Filter = ".NET Executable (*.exe) | *.exe", var settings = ILSpySettings.Load();
RestoreDirectory = true, XElement e = settings["DebuggerSettings"];
DefaultExt = "exe" var askForArguments = (bool?)e.Attribute("askForArguments");
}; if (askForArguments.HasValue && askForArguments.Value) {
var window = new ExecuteProcessWindow { Owner = MainWindow.Instance };
if (dialog.ShowDialog() == true) { if (window.ShowDialog() == true) {
string fileName = dialog.FileName; string fileName = window.SelectedExecutable;
// add it to references // add it to references
MainWindow.Instance.OpenFiles(new [] { fileName }, false); MainWindow.Instance.OpenFiles(new [] { fileName }, false);
if (!CurrentDebugger.IsDebugging) { // execute the process
// execute the process this.StartExecutable(fileName, window.WorkingDirectory, window.Arguments);
this.StartExecutable(fileName); }
} 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 @@
<Grid> <Grid>
<StackPanel Margin="10"> <StackPanel Margin="10">
<CheckBox IsChecked="{Binding ShowWarnings}">Show warning messages</CheckBox> <CheckBox IsChecked="{Binding ShowWarnings}">Show warning messages</CheckBox>
<CheckBox IsChecked="{Binding AskForArguments}">Ask for arguments and working directory before executing a process</CheckBox>
</StackPanel> </StackPanel>
</Grid> </Grid>
</UserControl> </UserControl>

5
ILSpy/Options/DebuggerSettingsPanel.xaml.cs

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

Loading…
Cancel
Save