Make suspension on start work

This commit is contained in:
svc64 2023-12-22 22:15:09 +02:00
parent 1bf244173d
commit 8a1c48e035
8 changed files with 24 additions and 13 deletions

View file

@ -674,8 +674,8 @@ namespace Ryujinx.UI.Windows
ConfigurationState.Instance.Graphics.ScalingFilterLevel.Value = (int)_scalingFilterLevel.Value; ConfigurationState.Instance.Graphics.ScalingFilterLevel.Value = (int)_scalingFilterLevel.Value;
ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value = _multiLanSelect.ActiveId; ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value = _multiLanSelect.ActiveId;
ConfigurationState.Instance.Debug.EnableGdbStub.Value = _gdbStubToggle.Active; 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.GdbStubPort.Value = (ushort)_gdbStubPortSpinAdjustment.Value;
ConfigurationState.Instance.Debug.DebuggerSuspendOnStart.Value = _suspendOnStartToggle.Active;
_previousVolumeLevel = ConfigurationState.Instance.System.AudioVolume.Value; _previousVolumeLevel = ConfigurationState.Instance.System.AudioVolume.Value;

View file

@ -21,7 +21,6 @@ namespace Ryujinx.HLE.Debugger
internal Switch Device { get; private set; } internal Switch Device { get; private set; }
public ushort GdbStubPort { get; private set; } public ushort GdbStubPort { get; private set; }
public bool SuspendOnStart { get; private set; }
private TcpListener ListenerSocket; private TcpListener ListenerSocket;
private Socket ClientSocket = null; private Socket ClientSocket = null;
@ -35,11 +34,10 @@ namespace Ryujinx.HLE.Debugger
private ulong? cThread; private ulong? cThread;
private ulong? gThread; private ulong? gThread;
public Debugger(Switch device, ushort port, bool suspendOnStart) public Debugger(Switch device, ushort port)
{ {
Device = device; Device = device;
GdbStubPort = port; GdbStubPort = port;
SuspendOnStart = suspendOnStart;
ARMeilleure.Optimizations.EnableDebugging = true; ARMeilleure.Optimizations.EnableDebugging = true;

View file

@ -93,6 +93,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
public HleProcessDebugger Debugger { get; private set; } public HleProcessDebugger Debugger { get; private set; }
public IDebuggableProcess DebugInterface { get; private set; } public IDebuggableProcess DebugInterface { get; private set; }
protected int debugState = (int)DebugState.Running;
public KProcess(KernelContext context, bool allowCodeMemoryForJit = false) : base(context) public KProcess(KernelContext context, bool allowCodeMemoryForJit = false) : base(context)
{ {
@ -685,6 +686,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
SetState(newState); SetState(newState);
if (KernelContext.Device.Configuration.DebuggerSuspendOnStart && IsApplication)
{
mainThread.Suspend(ThreadSchedState.ThreadPauseFlag);
debugState = (int)DebugState.Stopped;
}
result = mainThread.Start(); result = mainThread.Start();
if (result != Result.Success) if (result != Result.Success)
@ -1197,7 +1204,6 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
private readonly KProcess _parent; private readonly KProcess _parent;
private readonly KernelContext _kernelContext; private readonly KernelContext _kernelContext;
private KThread steppingThread; private KThread steppingThread;
private int _debugState = (int)DebugState.Running;
public DebuggerInterface(KProcess p) public DebuggerInterface(KProcess p)
{ {
@ -1208,7 +1214,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
public void DebugStop() 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) (int)DebugState.Running) != (int)DebugState.Running)
{ {
return; return;
@ -1225,13 +1231,13 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
} }
} }
_debugState = (int)DebugState.Stopped; _parent.debugState = (int)DebugState.Stopped;
_kernelContext.CriticalSection.Leave(); _kernelContext.CriticalSection.Leave();
} }
public void DebugContinue() 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) (int)DebugState.Stopped) != (int)DebugState.Stopped)
{ {
return; return;
@ -1250,7 +1256,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
public bool DebugStep(KThread target) public bool DebugStep(KThread target)
{ {
if (_debugState != (int)DebugState.Stopped) if (_parent.debugState != (int)DebugState.Stopped)
{ {
return false; return false;
} }
@ -1299,7 +1305,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
public DebugState GetDebugState() public DebugState GetDebugState()
{ {
return (DebugState)_debugState; return (DebugState)_parent.debugState;
} }
public ulong[] GetThreadUids() public ulong[] GetThreadUids()

View file

@ -205,6 +205,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
} }
Context.TpidrroEl0 = (long)_tlsAddress; Context.TpidrroEl0 = (long)_tlsAddress;
Context.DebugPc = _entrypoint;
ThreadUid = KernelContext.NewThreadUid(); ThreadUid = KernelContext.NewThreadUid();
Context.ThreadUid = ThreadUid; Context.ThreadUid = ThreadUid;

View file

@ -54,7 +54,7 @@ namespace Ryujinx.HLE
AudioDeviceDriver = new CompatLayerHardwareDeviceDriver(Configuration.AudioDeviceDriver); AudioDeviceDriver = new CompatLayerHardwareDeviceDriver(Configuration.AudioDeviceDriver);
Memory = new MemoryBlock(Configuration.MemoryConfiguration.ToDramSize(), memoryAllocationFlags); Memory = new MemoryBlock(Configuration.MemoryConfiguration.ToDramSize(), memoryAllocationFlags);
Gpu = new GpuContext(Configuration.GpuRenderer); 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); System = new HOS.Horizon(this);
Statistics = new PerformanceStatistics(); Statistics = new PerformanceStatistics();
Hid = new Hid(this, System.HidStorage); Hid = new Hid(this, System.HidStorage);

View file

@ -397,9 +397,9 @@ namespace Ryujinx.UI.Common.Configuration
public ushort GdbStubPort { get; set; } public ushort GdbStubPort { get; set; }
/// <summary> /// <summary>
/// Which TCP port should the GDB stub listen on /// Suspend execution when starting an application
/// </summary> /// </summary>
public ushort DebuggerSuspendOnStart { get; set; } public bool DebuggerSuspendOnStart { get; set; }
/// <summary> /// <summary>
/// Loads a configuration file from disk /// Loads a configuration file from disk

View file

@ -805,6 +805,7 @@ namespace Ryujinx.UI.Common.Configuration
MultiplayerMode = Multiplayer.Mode, MultiplayerMode = Multiplayer.Mode,
EnableGdbStub = Debug.EnableGdbStub, EnableGdbStub = Debug.EnableGdbStub,
GdbStubPort = Debug.GdbStubPort, GdbStubPort = Debug.GdbStubPort,
DebuggerSuspendOnStart = Debug.DebuggerSuspendOnStart,
}; };
return configurationFile; return configurationFile;
@ -964,6 +965,7 @@ namespace Ryujinx.UI.Common.Configuration
}; };
Debug.EnableGdbStub.Value = false; Debug.EnableGdbStub.Value = false;
Debug.GdbStubPort.Value = 55555; Debug.GdbStubPort.Value = 55555;
Debug.DebuggerSuspendOnStart.Value = false;
} }
public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath) public void Load(ConfigurationFileFormat configurationFileFormat, string configurationFilePath)
@ -1484,6 +1486,7 @@ namespace Ryujinx.UI.Common.Configuration
configurationFileFormat.EnableGdbStub = false; configurationFileFormat.EnableGdbStub = false;
configurationFileFormat.GdbStubPort = 55555; configurationFileFormat.GdbStubPort = 55555;
configurationFileFormat.DebuggerSuspendOnStart = false;
configurationFileUpdated = true; configurationFileUpdated = true;
} }
@ -1616,6 +1619,7 @@ namespace Ryujinx.UI.Common.Configuration
Hid.InputConfig.Value = configurationFileFormat.InputConfig; Hid.InputConfig.Value = configurationFileFormat.InputConfig;
Debug.EnableGdbStub.Value = configurationFileFormat.EnableGdbStub; Debug.EnableGdbStub.Value = configurationFileFormat.EnableGdbStub;
Debug.GdbStubPort.Value = configurationFileFormat.GdbStubPort; Debug.GdbStubPort.Value = configurationFileFormat.GdbStubPort;
Debug.DebuggerSuspendOnStart.Value = configurationFileFormat.DebuggerSuspendOnStart;
if (Hid.InputConfig.Value == null) if (Hid.InputConfig.Value == null)
{ {

View file

@ -511,6 +511,7 @@ namespace Ryujinx.Ava.UI.ViewModels
// Debug // Debug
EnableGdbStub = config.Debug.EnableGdbStub.Value; EnableGdbStub = config.Debug.EnableGdbStub.Value;
GDBStubPort = config.Debug.GdbStubPort.Value; GDBStubPort = config.Debug.GdbStubPort.Value;
DebuggerSuspendOnStart = config.Debug.DebuggerSuspendOnStart.Value;
} }
public void SaveSettings() public void SaveSettings()
@ -623,6 +624,7 @@ namespace Ryujinx.Ava.UI.ViewModels
// Debug // Debug
config.Debug.EnableGdbStub.Value = EnableGdbStub; config.Debug.EnableGdbStub.Value = EnableGdbStub;
config.Debug.GdbStubPort.Value = GDBStubPort; config.Debug.GdbStubPort.Value = GDBStubPort;
config.Debug.DebuggerSuspendOnStart.Value = DebuggerSuspendOnStart;
config.ToFileFormat().SaveConfig(Program.ConfigurationPath); config.ToFileFormat().SaveConfig(Program.ConfigurationPath);