From 8a1c48e0359e884859b8c978e4547ce204236082 Mon Sep 17 00:00:00 2001 From: svc64 Date: Fri, 22 Dec 2023 22:15:09 +0200 Subject: [PATCH] Make suspension on start work --- src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.cs | 2 +- src/Ryujinx.HLE/Debugger/Debugger.cs | 4 +--- src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs | 18 ++++++++++++------ .../HOS/Kernel/Threading/KThread.cs | 1 + src/Ryujinx.HLE/Switch.cs | 2 +- .../Configuration/ConfigurationFileFormat.cs | 4 ++-- .../Configuration/ConfigurationState.cs | 4 ++++ src/Ryujinx/UI/ViewModels/SettingsViewModel.cs | 2 ++ 8 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.cs b/src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.cs index 9e029ac128..8cfc763ce9 100644 --- a/src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.cs +++ b/src/Ryujinx.Gtk3/UI/Windows/SettingsWindow.cs @@ -674,8 +674,8 @@ namespace Ryujinx.UI.Windows ConfigurationState.Instance.Graphics.ScalingFilterLevel.Value = (int)_scalingFilterLevel.Value; ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value = _multiLanSelect.ActiveId; ConfigurationState.Instance.Debug.EnableGdbStub.Value = _gdbStubToggle.Active; - ConfigurationState.Instance.Debug.DebuggerSuspendOnStart.Value = _suspendOnStartToggle.Active; ConfigurationState.Instance.Debug.GdbStubPort.Value = (ushort)_gdbStubPortSpinAdjustment.Value; + ConfigurationState.Instance.Debug.DebuggerSuspendOnStart.Value = _suspendOnStartToggle.Active; _previousVolumeLevel = ConfigurationState.Instance.System.AudioVolume.Value; diff --git a/src/Ryujinx.HLE/Debugger/Debugger.cs b/src/Ryujinx.HLE/Debugger/Debugger.cs index 9045cae614..e9f535440b 100644 --- a/src/Ryujinx.HLE/Debugger/Debugger.cs +++ b/src/Ryujinx.HLE/Debugger/Debugger.cs @@ -21,7 +21,6 @@ namespace Ryujinx.HLE.Debugger internal Switch Device { get; private set; } public ushort GdbStubPort { get; private set; } - public bool SuspendOnStart { get; private set; } private TcpListener ListenerSocket; private Socket ClientSocket = null; @@ -35,11 +34,10 @@ namespace Ryujinx.HLE.Debugger private ulong? cThread; private ulong? gThread; - public Debugger(Switch device, ushort port, bool suspendOnStart) + public Debugger(Switch device, ushort port) { Device = device; GdbStubPort = port; - SuspendOnStart = suspendOnStart; ARMeilleure.Optimizations.EnableDebugging = true; diff --git a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs index abd792cc56..9586a8080f 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Process/KProcess.cs @@ -93,6 +93,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public HleProcessDebugger Debugger { get; private set; } public IDebuggableProcess DebugInterface { get; private set; } + protected int debugState = (int)DebugState.Running; public KProcess(KernelContext context, bool allowCodeMemoryForJit = false) : base(context) { @@ -685,6 +686,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process SetState(newState); + if (KernelContext.Device.Configuration.DebuggerSuspendOnStart && IsApplication) + { + mainThread.Suspend(ThreadSchedState.ThreadPauseFlag); + debugState = (int)DebugState.Stopped; + } + result = mainThread.Start(); if (result != Result.Success) @@ -1197,7 +1204,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process private readonly KProcess _parent; private readonly KernelContext _kernelContext; private KThread steppingThread; - private int _debugState = (int)DebugState.Running; public DebuggerInterface(KProcess p) { @@ -1208,7 +1214,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public void DebugStop() { - if (Interlocked.CompareExchange(ref _debugState, (int)DebugState.Stopping, + if (Interlocked.CompareExchange(ref _parent.debugState, (int)DebugState.Stopping, (int)DebugState.Running) != (int)DebugState.Running) { return; @@ -1225,13 +1231,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Process } } - _debugState = (int)DebugState.Stopped; + _parent.debugState = (int)DebugState.Stopped; _kernelContext.CriticalSection.Leave(); } public void DebugContinue() { - if (Interlocked.CompareExchange(ref _debugState, (int)DebugState.Running, + if (Interlocked.CompareExchange(ref _parent.debugState, (int)DebugState.Running, (int)DebugState.Stopped) != (int)DebugState.Stopped) { return; @@ -1250,7 +1256,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public bool DebugStep(KThread target) { - if (_debugState != (int)DebugState.Stopped) + if (_parent.debugState != (int)DebugState.Stopped) { return false; } @@ -1299,7 +1305,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process public DebugState GetDebugState() { - return (DebugState)_debugState; + return (DebugState)_parent.debugState; } public ulong[] GetThreadUids() diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs index 2c6d77c15d..40d366bf4c 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs @@ -205,6 +205,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading } Context.TpidrroEl0 = (long)_tlsAddress; + Context.DebugPc = _entrypoint; ThreadUid = KernelContext.NewThreadUid(); Context.ThreadUid = ThreadUid; diff --git a/src/Ryujinx.HLE/Switch.cs b/src/Ryujinx.HLE/Switch.cs index 05d07c6ecf..e1e3861810 100644 --- a/src/Ryujinx.HLE/Switch.cs +++ b/src/Ryujinx.HLE/Switch.cs @@ -54,7 +54,7 @@ namespace Ryujinx.HLE AudioDeviceDriver = new CompatLayerHardwareDeviceDriver(Configuration.AudioDeviceDriver); Memory = new MemoryBlock(Configuration.MemoryConfiguration.ToDramSize(), memoryAllocationFlags); Gpu = new GpuContext(Configuration.GpuRenderer); - Debugger = Configuration.EnableGdbStub ? new Debugger.Debugger(this, Configuration.GdbStubPort, Configuration.DebuggerSuspendOnStart) : null; + Debugger = Configuration.EnableGdbStub ? new Debugger.Debugger(this, Configuration.GdbStubPort) : null; System = new HOS.Horizon(this); Statistics = new PerformanceStatistics(); Hid = new Hid(this, System.HidStorage); diff --git a/src/Ryujinx.UI.Common/Configuration/ConfigurationFileFormat.cs b/src/Ryujinx.UI.Common/Configuration/ConfigurationFileFormat.cs index a63d17145e..0090ff0dc4 100644 --- a/src/Ryujinx.UI.Common/Configuration/ConfigurationFileFormat.cs +++ b/src/Ryujinx.UI.Common/Configuration/ConfigurationFileFormat.cs @@ -397,9 +397,9 @@ namespace Ryujinx.UI.Common.Configuration public ushort GdbStubPort { get; set; } /// - /// Which TCP port should the GDB stub listen on + /// Suspend execution when starting an application /// - public ushort DebuggerSuspendOnStart { get; set; } + public bool DebuggerSuspendOnStart { get; set; } /// /// Loads a configuration file from disk diff --git a/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs b/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs index 255175fa39..d255eb217d 100644 --- a/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs +++ b/src/Ryujinx.UI.Common/Configuration/ConfigurationState.cs @@ -805,6 +805,7 @@ namespace Ryujinx.UI.Common.Configuration MultiplayerMode = Multiplayer.Mode, EnableGdbStub = Debug.EnableGdbStub, GdbStubPort = Debug.GdbStubPort, + DebuggerSuspendOnStart = Debug.DebuggerSuspendOnStart, }; return configurationFile; @@ -964,6 +965,7 @@ namespace Ryujinx.UI.Common.Configuration }; Debug.EnableGdbStub.Value = false; Debug.GdbStubPort.Value = 55555; + Debug.DebuggerSuspendOnStart.Value = false; } public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath) @@ -1484,6 +1486,7 @@ namespace Ryujinx.UI.Common.Configuration configurationFileFormat.EnableGdbStub = false; configurationFileFormat.GdbStubPort = 55555; + configurationFileFormat.DebuggerSuspendOnStart = false; configurationFileUpdated = true; } @@ -1616,6 +1619,7 @@ namespace Ryujinx.UI.Common.Configuration Hid.InputConfig.Value = configurationFileFormat.InputConfig; Debug.EnableGdbStub.Value = configurationFileFormat.EnableGdbStub; Debug.GdbStubPort.Value = configurationFileFormat.GdbStubPort; + Debug.DebuggerSuspendOnStart.Value = configurationFileFormat.DebuggerSuspendOnStart; if (Hid.InputConfig.Value == null) { diff --git a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs index d48ec95a2b..a0e4fd455b 100644 --- a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs @@ -511,6 +511,7 @@ namespace Ryujinx.Ava.UI.ViewModels // Debug EnableGdbStub = config.Debug.EnableGdbStub.Value; GDBStubPort = config.Debug.GdbStubPort.Value; + DebuggerSuspendOnStart = config.Debug.DebuggerSuspendOnStart.Value; } public void SaveSettings() @@ -623,6 +624,7 @@ namespace Ryujinx.Ava.UI.ViewModels // Debug config.Debug.EnableGdbStub.Value = EnableGdbStub; config.Debug.GdbStubPort.Value = GDBStubPort; + config.Debug.DebuggerSuspendOnStart.Value = DebuggerSuspendOnStart; config.ToFileFormat().SaveConfig(Program.ConfigurationPath);