From fb4b9a30030f39cd3e7ec19ee6e527aeaf47295e Mon Sep 17 00:00:00 2001 From: merry Date: Tue, 8 Feb 2022 19:49:54 +0000 Subject: [PATCH] Configuration: Add GDB stub related configuration --- Ryujinx.HLE/HLEConfiguration.cs | 16 +- .../Configuration/ConfigurationFileFormat.cs | 14 +- Ryujinx/Configuration/ConfigurationState.cs | 48 +++++- Ryujinx/Ui/MainWindow.cs | 22 ++- Ryujinx/Ui/Windows/SettingsWindow.cs | 12 +- Ryujinx/Ui/Windows/SettingsWindow.glade | 137 ++++++++++++++++++ 6 files changed, 243 insertions(+), 6 deletions(-) diff --git a/Ryujinx.HLE/HLEConfiguration.cs b/Ryujinx.HLE/HLEConfiguration.cs index 8fd02a962..2e3a1a699 100644 --- a/Ryujinx.HLE/HLEConfiguration.cs +++ b/Ryujinx.HLE/HLEConfiguration.cs @@ -153,6 +153,16 @@ namespace Ryujinx.HLE /// public Action RefreshInputConfig { internal get; set; } + /// + /// Enables gdbstub to allow for debugging of the guest . + /// + public bool EnableGdbStub { get; internal set; } + + /// + /// A TCP port to use to expose a gdbstub for a debugger to connect to. + /// + public ushort GdbStubPort { get; internal set; } + public HLEConfiguration(VirtualFileSystem virtualFileSystem, LibHacHorizonManager libHacHorizonManager, ContentManager contentManager, @@ -175,7 +185,9 @@ namespace Ryujinx.HLE MemoryManagerMode memoryManagerMode, bool ignoreMissingServices, AspectRatio aspectRatio, - float audioVolume) + float audioVolume, + bool enableGdbStub, + ushort gdbStubPort) { VirtualFileSystem = virtualFileSystem; LibHacHorizonManager = libHacHorizonManager; @@ -200,6 +212,8 @@ namespace Ryujinx.HLE IgnoreMissingServices = ignoreMissingServices; AspectRatio = aspectRatio; AudioVolume = audioVolume; + EnableGdbStub = enableGdbStub; + GdbStubPort = gdbStubPort; } } } \ No newline at end of file diff --git a/Ryujinx/Configuration/ConfigurationFileFormat.cs b/Ryujinx/Configuration/ConfigurationFileFormat.cs index 27b0c3629..303dd5528 100644 --- a/Ryujinx/Configuration/ConfigurationFileFormat.cs +++ b/Ryujinx/Configuration/ConfigurationFileFormat.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Configuration /// /// The current version of the file format /// - public const int CurrentVersion = 37; + public const int CurrentVersion = 38; /// /// Version of the configuration file format @@ -275,6 +275,16 @@ namespace Ryujinx.Configuration /// public List InputConfig { get; set; } + /// + /// Enables or disables the GDB stub + /// + public bool EnableGdbStub { get; set; } + + /// + /// Which TCP port should the GDB stub listen on + /// + public ushort GdbStubPort { get; set; } + /// /// Loads a configuration file from disk /// @@ -305,4 +315,4 @@ namespace Ryujinx.Configuration JsonHelper.Serialize(fileStream, this, true); } } -} +} \ No newline at end of file diff --git a/Ryujinx/Configuration/ConfigurationState.cs b/Ryujinx/Configuration/ConfigurationState.cs index 1200fb528..f8423b543 100644 --- a/Ryujinx/Configuration/ConfigurationState.cs +++ b/Ryujinx/Configuration/ConfigurationState.cs @@ -389,6 +389,30 @@ namespace Ryujinx.Configuration } } + /// + /// Debug configuration section + /// + public class DebugSection + { + /// + /// Enables or disables the GDB stub + /// + public ReactiveObject EnableGdbStub { get; private set; } + + /// + /// Which TCP port should the GDB stub listen on + /// + public ReactiveObject GdbStubPort { get; private set; } + + public DebugSection() + { + EnableGdbStub = new ReactiveObject(); + EnableGdbStub.Event += static (sender, e) => LogValueChange(sender, e, nameof(EnableGdbStub)); + GdbStubPort = new ReactiveObject(); + GdbStubPort.Event += static (sender, e) => LogValueChange(sender, e, nameof(GdbStubPort)); + } + } + /// /// The default configuration instance /// @@ -419,6 +443,11 @@ namespace Ryujinx.Configuration /// public HidSection Hid { get; private set; } + /// + /// The Debug + /// + public DebugSection Debug { get; private set; } + /// /// Enables or disables Discord Rich Presence /// @@ -446,6 +475,7 @@ namespace Ryujinx.Configuration System = new SystemSection(); Graphics = new GraphicsSection(); Hid = new HidSection(); + Debug = new DebugSection(); EnableDiscordIntegration = new ReactiveObject(); CheckUpdatesOnStart = new ReactiveObject(); ShowConfirmExit = new ReactiveObject(); @@ -523,6 +553,8 @@ namespace Ryujinx.Configuration KeyboardConfig = new List(), ControllerConfig = new List(), InputConfig = Hid.InputConfig, + EnableGdbStub = Debug.EnableGdbStub, + GdbStubPort = Debug.GdbStubPort, }; return configurationFile; @@ -648,6 +680,8 @@ namespace Ryujinx.Configuration } } }; + Debug.EnableGdbStub.Value = false; + Debug.GdbStubPort.Value = 55555; } public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath) @@ -1027,6 +1061,16 @@ namespace Ryujinx.Configuration configurationFileUpdated = true; } + if (configurationFileFormat.Version < 38) + { + Common.Logging.Logger.Warning?.Print(LogClass.Application, $"Outdated configuration version {configurationFileFormat.Version}, migrating to version 38."); + + configurationFileFormat.EnableGdbStub = false; + configurationFileFormat.GdbStubPort = 55555; + + configurationFileUpdated = true; + } + Logger.EnableFileLog.Value = configurationFileFormat.EnableFileLog; Graphics.BackendThreading.Value = configurationFileFormat.BackendThreading; Graphics.ResScale.Value = configurationFileFormat.ResScale; @@ -1085,6 +1129,8 @@ namespace Ryujinx.Configuration Hid.EnableMouse.Value = configurationFileFormat.EnableMouse; Hid.Hotkeys.Value = configurationFileFormat.Hotkeys; Hid.InputConfig.Value = configurationFileFormat.InputConfig; + Debug.EnableGdbStub.Value = configurationFileFormat.EnableGdbStub; + Debug.GdbStubPort.Value = configurationFileFormat.GdbStubPort; if (Hid.InputConfig.Value == null) { @@ -1114,4 +1160,4 @@ namespace Ryujinx.Configuration Instance = new ConfigurationState(); } } -} +} \ No newline at end of file diff --git a/Ryujinx/Ui/MainWindow.cs b/Ryujinx/Ui/MainWindow.cs index 54e28765a..850e18eb2 100644 --- a/Ryujinx/Ui/MainWindow.cs +++ b/Ryujinx/Ui/MainWindow.cs @@ -571,7 +571,9 @@ namespace Ryujinx.Ui ConfigurationState.Instance.System.MemoryManagerMode, ConfigurationState.Instance.System.IgnoreMissingServices, ConfigurationState.Instance.Graphics.AspectRatio, - ConfigurationState.Instance.System.AudioVolume); + ConfigurationState.Instance.System.AudioVolume, + ConfigurationState.Instance.Debug.EnableGdbStub, + ConfigurationState.Instance.Debug.GdbStubPort); _emulationContext = new HLE.Switch(configuration); } @@ -673,6 +675,24 @@ namespace Ryujinx.Ui shadersDumpWarningDialog.Dispose(); } + + if (ConfigurationState.Instance.Debug.EnableGdbStub.Value) + { + MessageDialog gdbStubWarningDialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.YesNo, null) + { + Title = "Ryujinx - Warning", + Text = "You have the GDB stub enabled, which is designed to be used by developers only.", + SecondaryText = "For optimal performance, it's recommended to disable the GDB stub. Would you like to disable the GDB stub now?" + }; + + if (gdbStubWarningDialog.Run() == (int)ResponseType.Yes) + { + ConfigurationState.Instance.Debug.EnableGdbStub.Value = false; + SaveConfig(); + } + + gdbStubWarningDialog.Dispose(); + } } public void LoadApplication(string path, bool startFullscreen = false) diff --git a/Ryujinx/Ui/Windows/SettingsWindow.cs b/Ryujinx/Ui/Windows/SettingsWindow.cs index f0e937301..649f8a455 100644 --- a/Ryujinx/Ui/Windows/SettingsWindow.cs +++ b/Ryujinx/Ui/Windows/SettingsWindow.cs @@ -102,7 +102,8 @@ namespace Ryujinx.Ui.Windows [GUI] ToggleButton _configureController7; [GUI] ToggleButton _configureController8; [GUI] ToggleButton _configureControllerH; - + [GUI] ToggleButton _gdbStubToggle; + [GUI] Adjustment _gdbStubPortSpinAdjustment; #pragma warning restore CS0649, IDE0044 public SettingsWindow(MainWindow parent, VirtualFileSystem virtualFileSystem, ContentManager contentManager) : this(parent, new Builder("Ryujinx.Ui.Windows.SettingsWindow.glade"), virtualFileSystem, contentManager) { } @@ -282,6 +283,11 @@ namespace Ryujinx.Ui.Windows _custThemeToggle.Click(); } + if (ConfigurationState.Instance.Debug.EnableGdbStub) + { + _gdbStubToggle.Click(); + } + // Custom EntryCompletion Columns. If added to glade, need to override more signals ListStore tzList = new ListStore(typeof(string), typeof(string), typeof(string)); _systemTimeZoneCompletion.Model = tzList; @@ -329,6 +335,8 @@ namespace Ryujinx.Ui.Windows _fsLogSpinAdjustment.Value = ConfigurationState.Instance.System.FsGlobalAccessLogMode; _systemTimeOffset = ConfigurationState.Instance.System.SystemTimeOffset; + _gdbStubPortSpinAdjustment.Value = ConfigurationState.Instance.Debug.GdbStubPort; + _gameDirsBox.AppendColumn("", new CellRendererText(), "text", 0); _gameDirsBoxStore = new ListStore(typeof(string)); _gameDirsBox.Model = _gameDirsBoxStore; @@ -531,6 +539,8 @@ namespace Ryujinx.Ui.Windows ConfigurationState.Instance.Graphics.ResScale.Value = int.Parse(_resScaleCombo.ActiveId); ConfigurationState.Instance.Graphics.ResScaleCustom.Value = resScaleCustom; ConfigurationState.Instance.System.AudioVolume.Value = (float)_audioVolumeSlider.Value / 100.0f; + ConfigurationState.Instance.Debug.EnableGdbStub.Value = _gdbStubToggle.Active; + ConfigurationState.Instance.Debug.GdbStubPort.Value = (ushort)_gdbStubPortSpinAdjustment.Value; _previousVolumeLevel = ConfigurationState.Instance.System.AudioVolume.Value; diff --git a/Ryujinx/Ui/Windows/SettingsWindow.glade b/Ryujinx/Ui/Windows/SettingsWindow.glade index c9d19a27f..e7a46b491 100644 --- a/Ryujinx/Ui/Windows/SettingsWindow.glade +++ b/Ryujinx/Ui/Windows/SettingsWindow.glade @@ -40,6 +40,12 @@ True True + + 1 + 65535 + 1 + 5 + False Ryujinx - Settings @@ -2621,6 +2627,137 @@ False + + + True + False + 5 + 10 + 5 + vertical + + + True + False + 5 + 5 + vertical + + + True + False + start + 5 + Debug (WARNING: For Developer Use Only) + + + + + + False + True + 0 + + + + + True + False + start + 10 + 10 + vertical + + + Enable GDB Stub + True + True + False + Enables or disables GDB stub (for developer use only) + start + 5 + 5 + True + + + False + True + 0 + + + + + True + False + + + True + False + Specifies which TCP port for the GDB stub to listen on. Possible values are 1-65535. + GDB Stub Port + + + False + True + 5 + 0 + + + + + True + True + Specifies which TCP port for the GDB stub to listen on. Possible values are 1-65535. + 55555 + number + _gdbStubPortSpinAdjustment + True + + + True + True + 1 + + + + + False + True + 5 + 9 + + + + + True + True + 1 + + + + + False + True + 5 + 0 + + + + + 5 + + + + + True + False + Debug + + + 5 + False + +