Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit environment variables in when starting the debugging session #320

Merged
merged 3 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ You should have received a copy of the GNU General Public License
using System.IO;
using System.Windows.Input;
using dnSpy.Contracts.Debugger;
using dnSpy.Contracts.Debugger.Dialogs;
using dnSpy.Contracts.Debugger.DotNet.CorDebug;
using dnSpy.Contracts.Debugger.StartDebugging.Dialog;
using dnSpy.Contracts.MVVM;
Expand Down Expand Up @@ -70,8 +71,24 @@ public string WorkingDirectory {
}
string workingDirectory = string.Empty;

public string EnvironmentString {
get {
var sb = new System.Text.StringBuilder();
foreach (var kv in Environment.Environment) {
sb.Append(kv.Key);
sb.Append('=');
sb.Append(kv.Value);
sb.Append(';');
}
return sb.ToString();
}
}

public DbgEnvironment Environment { get; } = new DbgEnvironment();

public ICommand PickFilenameCommand => new RelayCommand(a => PickNewFilename());
public ICommand PickWorkingDirectoryCommand => new RelayCommand(a => PickNewWorkingDirectory());
public ICommand EditEnvironmentCommand => new RelayCommand(a => EditEnvironment());

public EnumListVM BreakProcessKindVM => breakProcessKindVM;
readonly EnumListVM breakProcessKindVM = new EnumListVM(BreakProcessKindsUtils.BreakProcessKindList);
Expand All @@ -96,10 +113,12 @@ protected void UpdateIsValid() {

protected readonly IPickFilename pickFilename;
readonly IPickDirectory pickDirectory;
readonly IDbgEnvironmentEditorService environmentEditorService;

protected DotNetCommonStartDebuggingOptionsPage(IPickFilename pickFilename, IPickDirectory pickDirectory) {
protected DotNetCommonStartDebuggingOptionsPage(IPickFilename pickFilename, IPickDirectory pickDirectory, IDbgEnvironmentEditorService environmentEditorService) {
this.pickFilename = pickFilename ?? throw new ArgumentNullException(nameof(pickFilename));
this.pickDirectory = pickDirectory ?? throw new ArgumentNullException(nameof(pickDirectory));
this.environmentEditorService = environmentEditorService ?? throw new ArgumentNullException(nameof(environmentEditorService));
}

static string? GetPath(string file) {
Expand All @@ -126,6 +145,11 @@ void PickNewWorkingDirectory() {
WorkingDirectory = newDir;
}

void EditEnvironment() {
if (environmentEditorService.ShowEditDialog(Environment))
OnPropertyChanged(nameof(EnvironmentString));
}

static string FilterBreakKind(string? breakKind) {
foreach (var info in BreakProcessKindsUtils.BreakProcessKindList) {
if (StringComparer.Ordinal.Equals(breakKind, (string)info.Value))
Expand All @@ -139,6 +163,8 @@ protected void Initialize(CorDebugStartDebuggingOptions options) {
CommandLine = options.CommandLine ?? string.Empty;
// Must be init'd after Filename since it also overwrites this property
WorkingDirectory = options.WorkingDirectory ?? string.Empty;
Environment.Clear();
Environment.AddRange(options.Environment.Environment);
BreakKind = FilterBreakKind(options.BreakKind);
}

Expand All @@ -151,6 +177,8 @@ protected T GetOptions<T>(T options) where T : CorDebugStartDebuggingOptions {
options.Filename = Filename;
options.CommandLine = CommandLine;
options.WorkingDirectory = WorkingDirectory;
options.Environment.Clear();
options.Environment.AddRange(Environment.Environment);
options.BreakKind = FilterBreakKind(BreakKind);
return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ You should have received a copy of the GNU General Public License
using System.Collections.Generic;
using System.IO;
using System.Linq;
using dnSpy.Contracts.App;
using dnSpy.Contracts.Controls.ToolWindows;
using dnSpy.Contracts.Debugger;
using dnSpy.Contracts.Debugger.Dialogs;
using dnSpy.Contracts.Debugger.DotNet.CorDebug;
using dnSpy.Contracts.Debugger.StartDebugging;
using dnSpy.Contracts.Debugger.StartDebugging.Dialog;
Expand All @@ -47,8 +50,8 @@ static string[] CreateRuntimeVersions() {
return list.ToArray();
}

public DotNetFrameworkStartDebuggingOptionsPage(IPickFilename pickFilename, IPickDirectory pickDirectory)
: base(pickFilename, pickDirectory) {
public DotNetFrameworkStartDebuggingOptionsPage(IPickFilename pickFilename, IPickDirectory pickDirectory, IDbgEnvironmentEditorService environmentEditorService)
: base(pickFilename, pickDirectory, environmentEditorService) {
}

protected override void PickNewFilename() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ You should have received a copy of the GNU General Public License
using System;
using System.IO;
using System.Windows.Input;
using dnSpy.Contracts.App;
using dnSpy.Contracts.Controls.ToolWindows;
using dnSpy.Contracts.Debugger;
using dnSpy.Contracts.Debugger.Dialogs;
using dnSpy.Contracts.Debugger.DotNet.CorDebug;
using dnSpy.Contracts.Debugger.StartDebugging;
using dnSpy.Contracts.Debugger.StartDebugging.Dialog;
Expand Down Expand Up @@ -75,8 +78,8 @@ public string HostArguments {

public ICommand PickHostFilenameCommand => new RelayCommand(a => PickNewHostFilename(), a => CanPickNewHostFilename);

public DotNetStartDebuggingOptionsPage(IPickFilename pickFilename, IPickDirectory pickDirectory)
: base(pickFilename, pickDirectory) => ConnectionTimeout = new UInt32VM(a => UpdateIsValid(), useDecimal: true);
public DotNetStartDebuggingOptionsPage(IPickFilename pickFilename, IPickDirectory pickDirectory, IDbgEnvironmentEditorService environmentEditorService)
: base(pickFilename, pickDirectory, environmentEditorService) => ConnectionTimeout = new UInt32VM(a => UpdateIsValid(), useDecimal: true);

bool CanPickNewHostFilename => UseHost;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,29 @@ You should have received a copy of the GNU General Public License

using System.Collections.Generic;
using System.ComponentModel.Composition;
using dnSpy.Contracts.App;
using dnSpy.Contracts.Debugger.StartDebugging.Dialog;
using dnSpy.Contracts.MVVM;
using dnSpy.Contracts.Controls.ToolWindows;
using dnSpy.Contracts.Debugger.Dialogs;

namespace dnSpy.Debugger.DotNet.CorDebug.Dialogs.DebugProgram {
[Export(typeof(StartDebuggingOptionsPageProvider))]
sealed class StartDebuggingOptionsPageProviderImpl : StartDebuggingOptionsPageProvider {
readonly IPickFilename pickFilename;
readonly IPickDirectory pickDirectory;
readonly IDbgEnvironmentEditorService environmentEditorService;

[ImportingConstructor]
StartDebuggingOptionsPageProviderImpl(IPickFilename pickFilename, IPickDirectory pickDirectory) {
StartDebuggingOptionsPageProviderImpl(IPickFilename pickFilename, IPickDirectory pickDirectory, IDbgEnvironmentEditorService environmentEditorService) {
this.pickFilename = pickFilename;
this.pickDirectory = pickDirectory;
this.environmentEditorService = environmentEditorService;
}

public override IEnumerable<StartDebuggingOptionsPage> Create(StartDebuggingOptionsPageContext context) {
yield return new DotNetFrameworkStartDebuggingOptionsPage(pickFilename, pickDirectory);
yield return new DotNetStartDebuggingOptionsPage(pickFilename, pickDirectory);
yield return new DotNetFrameworkStartDebuggingOptionsPage(pickFilename, pickDirectory, environmentEditorService);
yield return new DotNetStartDebuggingOptionsPage(pickFilename, pickDirectory, environmentEditorService);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="DbgAsm_BreakAt" xml:space="preserve">
<value>_Break at</value>
</data>
<data name="DbgAsm_Environment" xml:space="preserve">
<value>Environment</value>
</data>
<data name="DbgAsm_Host" xml:space="preserve">
<value>_Host</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand All @@ -47,11 +48,15 @@
<TextBox Grid.Row="2" Grid.Column="1" Margin="5 5 0 0" Name="cwdTextBox" Text="{Binding WorkingDirectory, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
<Button Grid.Row="2" Grid.Column="2" Margin="5 5 0 0" Style="{StaticResource EllipsisButton}" Command="{Binding PickWorkingDirectoryCommand}" />

<Label Grid.Row="3" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_RuntimeVersion}" Target="{Binding ElementName=runtimeVersionComboBox}" />
<ComboBox Grid.Row="3" Grid.Column="1" Margin="5 5 0 0" HorizontalAlignment="Stretch" Name="runtimeVersionComboBox" ItemsSource="{Binding RuntimeVersionsVM.Items}" SelectedIndex="{Binding RuntimeVersionsVM.SelectedIndex}" VerticalContentAlignment="Center" />
<Label Grid.Row="3" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_Environment}" Target="{Binding ElementName=envTextBox}" />
<TextBox Grid.Row="3" Grid.Column="1" Margin="5 5 0 0" Name="envTextBox" Text="{Binding EnvironmentString, Mode=OneWay}" IsReadOnly="True" />
<Button Grid.Row="3" Grid.Column="2" Margin="5 5 0 0" Style="{StaticResource EllipsisButton}" Command="{Binding EditEnvironmentCommand}" />

<Label Grid.Row="4" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_RuntimeVersion}" Target="{Binding ElementName=runtimeVersionComboBox}" />
<ComboBox Grid.Row="4" Grid.Column="1" Margin="5 5 0 0" HorizontalAlignment="Stretch" Name="runtimeVersionComboBox" ItemsSource="{Binding RuntimeVersionsVM.Items}" SelectedIndex="{Binding RuntimeVersionsVM.SelectedIndex}" VerticalContentAlignment="Center" />

<Label Grid.Row="4" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_BreakAt}" Target="{Binding ElementName=breakComboBox}" />
<ComboBox Grid.Row="4" Grid.Column="1" Margin="5 5 0 0" HorizontalAlignment="Stretch" Name="breakComboBox" DisplayMemberPath="Name" ItemsSource="{Binding BreakProcessKindVM.Items}" SelectedIndex="{Binding BreakProcessKindVM.SelectedIndex}" VerticalContentAlignment="Center" />
<Label Grid.Row="5" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_BreakAt}" Target="{Binding ElementName=breakComboBox}" />
<ComboBox Grid.Row="5" Grid.Column="1" Margin="5 5 0 0" HorizontalAlignment="Stretch" Name="breakComboBox" DisplayMemberPath="Name" ItemsSource="{Binding BreakProcessKindVM.Items}" SelectedIndex="{Binding BreakProcessKindVM.SelectedIndex}" VerticalContentAlignment="Center" />
</Grid>
</DataTemplate>

Expand All @@ -66,6 +71,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand All @@ -84,20 +90,24 @@
<TextBox Grid.Row="2" Grid.Column="1" Margin="5 5 0 0" Name="cwdTextBox" Text="{Binding WorkingDirectory, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
<Button Grid.Row="2" Grid.Column="2" Margin="5 5 0 0" Style="{StaticResource EllipsisButton}" Command="{Binding PickWorkingDirectoryCommand}" />

<CheckBox Grid.Row="3" Grid.ColumnSpan="2" Margin="5 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_UseHostExecutable}" IsChecked="{Binding UseHost}" />
<Label Grid.Row="3" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_Environment}" Target="{Binding ElementName=envTextBox}" />
<TextBox Grid.Row="3" Grid.Column="1" Margin="5 5 0 0" Name="envTextBox" Text="{Binding EnvironmentString, Mode=OneWay}" IsReadOnly="True" />
<Button Grid.Row="3" Grid.Column="2" Margin="5 5 0 0" Style="{StaticResource EllipsisButton}" Command="{Binding EditEnvironmentCommand}" />

<CheckBox Grid.Row="4" Grid.ColumnSpan="2" Margin="5 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_UseHostExecutable}" IsChecked="{Binding UseHost}" />

<Label Grid.Row="4" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_Host}" Target="{Binding ElementName=hostTextBox}" />
<TextBox Grid.Row="4" Grid.Column="1" Margin="5 5 0 0" Name="hostTextBox" Text="{Binding HostFilename, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding UseHost}" />
<Button Grid.Row="4" Grid.Column="2" Margin="5 5 0 0" Style="{StaticResource EllipsisButton}" Command="{Binding PickHostFilenameCommand}" />
<Label Grid.Row="5" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_Host}" Target="{Binding ElementName=hostTextBox}" />
<TextBox Grid.Row="5" Grid.Column="1" Margin="5 5 0 0" Name="hostTextBox" Text="{Binding HostFilename, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding UseHost}" />
<Button Grid.Row="5" Grid.Column="2" Margin="5 5 0 0" Style="{StaticResource EllipsisButton}" Command="{Binding PickHostFilenameCommand}" />

<Label Grid.Row="5" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_HostArgs}" Target="{Binding ElementName=hostArgsTextBox}" />
<TextBox Grid.Row="5" Grid.Column="1" Margin="5 5 0 0" Name="hostArgsTextBox" Text="{Binding HostArguments, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding UseHost}" />
<Label Grid.Row="6" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_HostArgs}" Target="{Binding ElementName=hostArgsTextBox}" />
<TextBox Grid.Row="6" Grid.Column="1" Margin="5 5 0 0" Name="hostArgsTextBox" Text="{Binding HostArguments, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding UseHost}" />

<Label Grid.Row="6" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_Timeout}" Target="{Binding ElementName=timoutTextBox}" />
<TextBox Grid.Row="6" Grid.Column="1" Margin="5 5 0 0" Name="timoutTextBox" Text="{Binding ConnectionTimeout.StringValue, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
<Label Grid.Row="7" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_Timeout}" Target="{Binding ElementName=timoutTextBox}" />
<TextBox Grid.Row="7" Grid.Column="1" Margin="5 5 0 0" Name="timoutTextBox" Text="{Binding ConnectionTimeout.StringValue, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />

<Label Grid.Row="7" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_BreakAt}" Target="{Binding ElementName=breakComboBox}" />
<ComboBox Grid.Row="7" Grid.Column="1" Margin="5 5 0 0" HorizontalAlignment="Stretch" Name="breakComboBox" DisplayMemberPath="Name" ItemsSource="{Binding BreakProcessKindVM.Items}" SelectedIndex="{Binding BreakProcessKindVM.SelectedIndex}" VerticalContentAlignment="Center" />
<Label Grid.Row="8" Grid.Column="0" Margin="0 5 0 0" Content="{x:Static p:dnSpy_Debugger_DotNet_CorDebug_Resources.DbgAsm_BreakAt}" Target="{Binding ElementName=breakComboBox}" />
<ComboBox Grid.Row="8" Grid.Column="1" Margin="5 5 0 0" HorizontalAlignment="Stretch" Name="breakComboBox" DisplayMemberPath="Name" ItemsSource="{Binding BreakProcessKindVM.Items}" SelectedIndex="{Binding BreakProcessKindVM.SelectedIndex}" VerticalContentAlignment="Center" />
</Grid>
</DataTemplate>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ You should have received a copy of the GNU General Public License
using System.IO;
using System.Windows.Input;
using dnSpy.Contracts.Debugger;
using dnSpy.Contracts.Debugger.Dialogs;
using dnSpy.Contracts.Debugger.DotNet.Mono;
using dnSpy.Contracts.Debugger.StartDebugging;
using dnSpy.Contracts.Debugger.StartDebugging.Dialog;
Expand All @@ -47,8 +48,8 @@ public string? MonoExePath {

public ICommand PickMonoExePathCommand => new RelayCommand(a => PickMonoExePath());

public MonoStartDebuggingOptionsPage(IPickFilename pickFilename, IPickDirectory pickDirectory)
: base(pickFilename, pickDirectory) {
public MonoStartDebuggingOptionsPage(IPickFilename pickFilename, IPickDirectory pickDirectory, IDbgEnvironmentEditorService environmentEditorService)
: base(pickFilename, pickDirectory, environmentEditorService) {
}

static readonly string MonoExeFilter = $"mono.exe|mono.exe";
Expand Down
Loading