From a25c5b764305947fd4c9d475db3118dd9b0d5c14 Mon Sep 17 00:00:00 2001 From: Mitch Capper Date: Tue, 19 Jul 2022 12:38:39 -0700 Subject: [PATCH] Add option to not auto-update debug start settings when selected assembly changes --- .../DbgUI/StartDebuggingOptionsProvider.cs | 7 +++- .../dnSpy.Debugger.Resources.Designer.cs | 9 ++++ .../Properties/dnSpy.Debugger.Resources.resx | 3 ++ .../Settings/DebuggerSettingsImpl.cs | 20 +++++++++ .../Themes/wpf.styles.templates.xaml | 42 ++++++++++--------- .../DebuggerSettings.cs | 5 +++ 6 files changed, 65 insertions(+), 21 deletions(-) diff --git a/Extensions/dnSpy.Debugger/dnSpy.Debugger/DbgUI/StartDebuggingOptionsProvider.cs b/Extensions/dnSpy.Debugger/dnSpy.Debugger/DbgUI/StartDebuggingOptionsProvider.cs index b2c97f0cd9..8b80cc35a5 100644 --- a/Extensions/dnSpy.Debugger/dnSpy.Debugger/DbgUI/StartDebuggingOptionsProvider.cs +++ b/Extensions/dnSpy.Debugger/dnSpy.Debugger/DbgUI/StartDebuggingOptionsProvider.cs @@ -43,10 +43,12 @@ sealed class StartDebuggingOptionsProvider { readonly Lazy[] startDebuggingOptionsPageProviders; readonly Lazy dbgProcessStarterService; readonly Lazy[] genericDebugEngineGuidProviders; + readonly Lazy debuggerSettingsImpl; readonly StartDebuggingOptionsMru mru; [ImportingConstructor] - StartDebuggingOptionsProvider(IAppWindow appWindow, IDocumentTabService documentTabService, Lazy dbgProcessStarterService, [ImportMany] IEnumerable> startDebuggingOptionsPageProviders, [ImportMany] IEnumerable> genericDebugEngineGuidProviders) { + StartDebuggingOptionsProvider(IAppWindow appWindow, IDocumentTabService documentTabService, Lazy dbgProcessStarterService, [ImportMany] IEnumerable> startDebuggingOptionsPageProviders, [ImportMany] IEnumerable> genericDebugEngineGuidProviders, Lazy debuggerSettingsImpl) { + this.debuggerSettingsImpl = debuggerSettingsImpl; this.appWindow = appWindow; this.documentTabService = documentTabService; this.dbgProcessStarterService = dbgProcessStarterService; @@ -87,6 +89,9 @@ string GetCurrentFilename() { var oldOptions = mru.TryGetOptions(filename); var lastOptions = mru.TryGetLastOptions(); + if (oldOptions == null && lastOptions.HasValue && lastOptions!.Value.options != null && debuggerSettingsImpl.Value.DontAutoUpdateDebugLaunchSettings) + oldOptions = lastOptions.Value; + foreach (var page in pages) { if (oldOptions?.pageGuid == page.Guid) page.InitializePreviousOptions(WithBreakKind(oldOptions!.Value.options, defaultBreakKind)); diff --git a/Extensions/dnSpy.Debugger/dnSpy.Debugger/Properties/dnSpy.Debugger.Resources.Designer.cs b/Extensions/dnSpy.Debugger/dnSpy.Debugger/Properties/dnSpy.Debugger.Resources.Designer.cs index e43c75a131..0161b45599 100644 --- a/Extensions/dnSpy.Debugger/dnSpy.Debugger/Properties/dnSpy.Debugger.Resources.Designer.cs +++ b/Extensions/dnSpy.Debugger/dnSpy.Debugger/Properties/dnSpy.Debugger.Resources.Designer.cs @@ -1202,6 +1202,15 @@ public static string DbgSettings_DisableDebuggerDetection { } } + /// + /// Looks up a localized string similar to Don't auto update debugger launch settings unless first time since dnSpy launch. + /// + public static string DbgSettings_DontAutoUpdateDebugLaunchSettings { + get { + return ResourceManager.GetString("DbgSettings_DontAutoUpdateDebugLaunchSettings", resourceCulture); + } + } + /// /// Looks up a localized string similar to Enable Just My Code debugging support. /// diff --git a/Extensions/dnSpy.Debugger/dnSpy.Debugger/Properties/dnSpy.Debugger.Resources.resx b/Extensions/dnSpy.Debugger/dnSpy.Debugger/Properties/dnSpy.Debugger.Resources.resx index 74a0901247..fbbd304ecd 100644 --- a/Extensions/dnSpy.Debugger/dnSpy.Debugger/Properties/dnSpy.Debugger.Resources.resx +++ b/Extensions/dnSpy.Debugger/dnSpy.Debugger/Properties/dnSpy.Debugger.Resources.resx @@ -1554,4 +1554,7 @@ Do you wish to continue? Load + + Don't auto update debugger launch settings unless first time since dnSpy launch + diff --git a/Extensions/dnSpy.Debugger/dnSpy.Debugger/Settings/DebuggerSettingsImpl.cs b/Extensions/dnSpy.Debugger/dnSpy.Debugger/Settings/DebuggerSettingsImpl.cs index ef4807458e..781ad882bf 100644 --- a/Extensions/dnSpy.Debugger/dnSpy.Debugger/Settings/DebuggerSettingsImpl.cs +++ b/Extensions/dnSpy.Debugger/dnSpy.Debugger/Settings/DebuggerSettingsImpl.cs @@ -471,6 +471,23 @@ public override bool HideDeprecatedError { } bool hideDeprecatedError = false; + public override bool DontAutoUpdateDebugLaunchSettings { + get { + lock (lockObj) + return dontAutoUpdateDebugLaunchSettings; + } + set { + bool modified; + lock (lockObj) { + modified = dontAutoUpdateDebugLaunchSettings != value; + dontAutoUpdateDebugLaunchSettings = value; + } + if (modified) + OnPropertyChanged(nameof(DontAutoUpdateDebugLaunchSettings)); + } + } + bool dontAutoUpdateDebugLaunchSettings = false; + public override bool SuppressJITOptimization_SystemModules { get { lock (lockObj) @@ -707,6 +724,7 @@ public DebuggerSettingsBase CopyTo(DebuggerSettingsBase other) { other.SuppressJITOptimization_SystemModules = SuppressJITOptimization_SystemModules; other.SuppressJITOptimization_ProgramModules = SuppressJITOptimization_ProgramModules; other.FocusActiveProcess = FocusActiveProcess; + other.DontAutoUpdateDebugLaunchSettings = DontAutoUpdateDebugLaunchSettings; other.FocusDebuggerWhenProcessBreaks = FocusDebuggerWhenProcessBreaks; other.ShowReturnValues = ShowReturnValues; other.RedirectGuiConsoleOutput = RedirectGuiConsoleOutput; @@ -761,6 +779,7 @@ sealed class DebuggerSettingsImpl : DebuggerSettingsBase { SuppressJITOptimization_SystemModules = sect.Attribute(nameof(SuppressJITOptimization_SystemModules)) ?? SuppressJITOptimization_SystemModules; SuppressJITOptimization_ProgramModules = sect.Attribute(nameof(SuppressJITOptimization_ProgramModules)) ?? SuppressJITOptimization_ProgramModules; FocusActiveProcess = sect.Attribute(nameof(FocusActiveProcess)) ?? FocusActiveProcess; + DontAutoUpdateDebugLaunchSettings = sect.Attribute(nameof(DontAutoUpdateDebugLaunchSettings)) ?? DontAutoUpdateDebugLaunchSettings; FocusDebuggerWhenProcessBreaks = sect.Attribute(nameof(FocusDebuggerWhenProcessBreaks)) ?? FocusDebuggerWhenProcessBreaks; ShowReturnValues = sect.Attribute(nameof(ShowReturnValues)) ?? ShowReturnValues; RedirectGuiConsoleOutput = sect.Attribute(nameof(RedirectGuiConsoleOutput)) ?? RedirectGuiConsoleOutput; @@ -804,6 +823,7 @@ void DebuggerSettingsImpl_PropertyChanged(object? sender, PropertyChangedEventAr sect.Attribute(nameof(SuppressJITOptimization_SystemModules), SuppressJITOptimization_SystemModules); sect.Attribute(nameof(SuppressJITOptimization_ProgramModules), SuppressJITOptimization_ProgramModules); sect.Attribute(nameof(FocusActiveProcess), FocusActiveProcess); + sect.Attribute(nameof(DontAutoUpdateDebugLaunchSettings), DontAutoUpdateDebugLaunchSettings); sect.Attribute(nameof(FocusDebuggerWhenProcessBreaks), FocusDebuggerWhenProcessBreaks); sect.Attribute(nameof(ShowReturnValues), ShowReturnValues); sect.Attribute(nameof(RedirectGuiConsoleOutput), RedirectGuiConsoleOutput); diff --git a/Extensions/dnSpy.Debugger/dnSpy.Debugger/Themes/wpf.styles.templates.xaml b/Extensions/dnSpy.Debugger/dnSpy.Debugger/Themes/wpf.styles.templates.xaml index 19572c7d3b..577f4a3f49 100644 --- a/Extensions/dnSpy.Debugger/dnSpy.Debugger/Themes/wpf.styles.templates.xaml +++ b/Extensions/dnSpy.Debugger/dnSpy.Debugger/Themes/wpf.styles.templates.xaml @@ -63,6 +63,7 @@ + @@ -90,13 +91,14 @@ - - - - - - - + + + + + + + + @@ -106,19 +108,19 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/dnSpy/dnSpy.Contracts.Debugger/DebuggerSettings.cs b/dnSpy/dnSpy.Contracts.Debugger/DebuggerSettings.cs index 940119964b..f2c6af5350 100644 --- a/dnSpy/dnSpy.Contracts.Debugger/DebuggerSettings.cs +++ b/dnSpy/dnSpy.Contracts.Debugger/DebuggerSettings.cs @@ -168,6 +168,11 @@ public abstract class DebuggerSettings : INotifyPropertyChanged { /// public abstract bool HideDeprecatedError { get; set; } + /// + /// Reuse the last launch debug settings unless first time since dnSpy launch + /// + public abstract bool DontAutoUpdateDebugLaunchSettings { get; set; } + /// /// Suppress JIT optimization on module load (system modules). If false, the code will be optimized and /// much more difficult to debug (it will be like when attaching to a process).