mirror of
https://git.ryujinx.app/kenji-nx/ryujinx.git
synced 2025-12-12 10:37:06 +00:00
gdb: YACC (yet another cleanup commit)
This commit is contained in:
parent
f30d832847
commit
e720e4a87b
9 changed files with 62 additions and 54 deletions
|
|
@ -34,7 +34,7 @@ namespace Ryujinx.HLE.Debugger
|
||||||
|
|
||||||
case ThreadBreakMessage { Context: { } ctx }:
|
case ThreadBreakMessage { Context: { } ctx }:
|
||||||
DebugProcess.DebugStop();
|
DebugProcess.DebugStop();
|
||||||
GThread = CThread = ctx.ThreadUid;
|
GThreadId = CThreadId = ctx.ThreadUid;
|
||||||
_breakHandlerEvent.Set();
|
_breakHandlerEvent.Set();
|
||||||
_commands.Processor.Reply($"T05thread:{ctx.ThreadUid:x};");
|
_commands.Processor.Reply($"T05thread:{ctx.ThreadUid:x};");
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -45,18 +45,18 @@ namespace Ryujinx.HLE.Debugger
|
||||||
|
|
||||||
public string GetStackTrace()
|
public string GetStackTrace()
|
||||||
{
|
{
|
||||||
if (GThread == null)
|
if (GThreadId == null)
|
||||||
return "No thread selected\n";
|
return "No thread selected\n";
|
||||||
|
|
||||||
return Process?.Debugger?.GetGuestStackTrace(DebugProcess.GetThread(GThread.Value)) ?? "No application process found\n";
|
return Process?.Debugger?.GetGuestStackTrace(DebugProcess.GetThread(GThreadId.Value)) ?? "No application process found\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetRegisters()
|
public string GetRegisters()
|
||||||
{
|
{
|
||||||
if (GThread == null)
|
if (GThreadId == null)
|
||||||
return "No thread selected\n";
|
return "No thread selected\n";
|
||||||
|
|
||||||
return Process?.Debugger?.GetCpuRegisterPrintout(DebugProcess.GetThread(GThread.Value)) ?? "No application process found\n";
|
return Process?.Debugger?.GetCpuRegisterPrintout(DebugProcess.GetThread(GThreadId.Value)) ?? "No application process found\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetMinidump()
|
public string GetMinidump()
|
||||||
|
|
@ -65,9 +65,9 @@ namespace Ryujinx.HLE.Debugger
|
||||||
return "No application process found\n";
|
return "No application process found\n";
|
||||||
|
|
||||||
if (kProcess.Debugger is not { } debugger)
|
if (kProcess.Debugger is not { } debugger)
|
||||||
return $"Error getting minidump: debugger is null\n";
|
return "Error getting minidump: debugger is null\n";
|
||||||
|
|
||||||
var response = debugger.GetMinidump();
|
string response = debugger.GetMinidump();
|
||||||
|
|
||||||
Logger.Info?.Print(LogClass.GdbStub, response);
|
Logger.Info?.Print(LogClass.GdbStub, response);
|
||||||
return response;
|
return response;
|
||||||
|
|
@ -80,10 +80,8 @@ namespace Ryujinx.HLE.Debugger
|
||||||
if (Process is not { } kProcess)
|
if (Process is not { } kProcess)
|
||||||
return "No application process found\n";
|
return "No application process found\n";
|
||||||
|
|
||||||
if (kProcess.Debugger is not { } debugger)
|
return kProcess.Debugger?.GetProcessInfoPrintout()
|
||||||
return $"Error getting process info: debugger is null\n";
|
?? "Error getting process info: debugger is null\n";
|
||||||
|
|
||||||
return debugger.GetProcessInfoPrintout();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
|
using Gommon;
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
using Ryujinx.HLE.Debugger.Gdb;
|
using Ryujinx.HLE.Debugger.Gdb;
|
||||||
using Ryujinx.HLE.HOS.Kernel.Process;
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
||||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
@ -32,8 +34,12 @@ namespace Ryujinx.HLE.Debugger
|
||||||
private bool _shuttingDown;
|
private bool _shuttingDown;
|
||||||
private readonly ManualResetEventSlim _breakHandlerEvent = new(false);
|
private readonly ManualResetEventSlim _breakHandlerEvent = new(false);
|
||||||
|
|
||||||
internal ulong? CThread;
|
internal ulong? CThreadId;
|
||||||
internal ulong? GThread;
|
internal ulong? GThreadId;
|
||||||
|
|
||||||
|
internal KThread CThread => CThreadId?.Into(DebugProcess.GetThread);
|
||||||
|
|
||||||
|
internal KThread GThread => GThreadId?.Into(DebugProcess.GetThread);
|
||||||
|
|
||||||
public readonly BreakpointManager BreakpointManager;
|
public readonly BreakpointManager BreakpointManager;
|
||||||
|
|
||||||
|
|
@ -56,7 +62,7 @@ namespace Ryujinx.HLE.Debugger
|
||||||
|
|
||||||
internal KThread[] GetThreads() => DebugProcess.ThreadUids.Select(DebugProcess.GetThread).ToArray();
|
internal KThread[] GetThreads() => DebugProcess.ThreadUids.Select(DebugProcess.GetThread).ToArray();
|
||||||
|
|
||||||
internal bool IsProcess32Bit => DebugProcess.GetThread(GThread ?? DebugProcess.ThreadUids.First()).Context.IsAarch32;
|
internal bool IsProcess32Bit => DebugProcess.GetThread(GThreadId ?? DebugProcess.ThreadUids.First()).Context.IsAarch32;
|
||||||
|
|
||||||
internal bool WriteRegister(IExecutionContext ctx, int registerId, StringStream ss) =>
|
internal bool WriteRegister(IExecutionContext ctx, int registerId, StringStream ss) =>
|
||||||
IsProcess32Bit
|
IsProcess32Bit
|
||||||
|
|
|
||||||
|
|
@ -181,7 +181,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
if (ss.ConsumeRemaining("fThreadInfo"))
|
if (ss.ConsumeRemaining("fThreadInfo"))
|
||||||
{
|
{
|
||||||
Reply(
|
Reply(
|
||||||
$"m{Debugger.DebugProcess.ThreadUids.Select(x => $"{x:x}").JoinToString(",")}");
|
$"m{DebugProcess.ThreadUids.Select(x => $"{x:x}").JoinToString(",")}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
|
|
||||||
private GdbCommandProcessor _processor;
|
private GdbCommandProcessor _processor;
|
||||||
|
|
||||||
public GdbCommandProcessor Processor
|
public GdbCommandProcessor Processor
|
||||||
=> _processor ??= new GdbCommandProcessor(this);
|
=> _processor ??= new GdbCommandProcessor(this);
|
||||||
|
|
||||||
internal readonly TcpListener ListenerSocket;
|
internal readonly TcpListener ListenerSocket;
|
||||||
|
|
@ -37,33 +37,33 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
{
|
{
|
||||||
// GDB is performing initial contact. Stop everything.
|
// GDB is performing initial contact. Stop everything.
|
||||||
Debugger.DebugProcess.DebugStop();
|
Debugger.DebugProcess.DebugStop();
|
||||||
Debugger.GThread = Debugger.CThread = Debugger.DebugProcess.ThreadUids.First();
|
Debugger.GThreadId = Debugger.CThreadId = Debugger.DebugProcess.ThreadUids.First();
|
||||||
Processor.Reply($"T05thread:{Debugger.CThread:x};");
|
Processor.Reply($"T05thread:{Debugger.CThreadId:x};");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Interrupt()
|
internal void Interrupt()
|
||||||
{
|
{
|
||||||
// GDB is requesting an interrupt. Stop everything.
|
// GDB is requesting an interrupt. Stop everything.
|
||||||
Debugger.DebugProcess.DebugStop();
|
Debugger.DebugProcess.DebugStop();
|
||||||
if (Debugger.GThread == null || Debugger.GetThreads().All(x => x.ThreadUid != Debugger.GThread.Value))
|
if (Debugger.GThreadId == null || Debugger.GetThreads().All(x => x.ThreadUid != Debugger.GThreadId.Value))
|
||||||
{
|
{
|
||||||
Debugger.GThread = Debugger.CThread = Debugger.DebugProcess.ThreadUids.First();
|
Debugger.GThreadId = Debugger.CThreadId = Debugger.DebugProcess.ThreadUids.First();
|
||||||
}
|
}
|
||||||
|
|
||||||
Processor.Reply($"T02thread:{Debugger.GThread:x};");
|
Processor.Reply($"T02thread:{Debugger.GThreadId:x};");
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Continue(ulong? newPc)
|
internal void Continue(ulong? newPc)
|
||||||
{
|
{
|
||||||
if (newPc.HasValue)
|
if (newPc.HasValue)
|
||||||
{
|
{
|
||||||
if (Debugger.CThread == null)
|
if (Debugger.CThreadId == null)
|
||||||
{
|
{
|
||||||
Processor.ReplyError();
|
Processor.ReplyError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debugger.DebugProcess.GetThread(Debugger.CThread.Value).Context.DebugPc = newPc.Value;
|
Debugger.CThread.Context.DebugPc = newPc.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debugger.DebugProcess.DebugContinue();
|
Debugger.DebugProcess.DebugContinue();
|
||||||
|
|
@ -78,13 +78,13 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
|
|
||||||
internal void ReadRegisters()
|
internal void ReadRegisters()
|
||||||
{
|
{
|
||||||
if (Debugger.GThread == null)
|
if (Debugger.GThreadId == null)
|
||||||
{
|
{
|
||||||
Processor.ReplyError();
|
Processor.ReplyError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IExecutionContext ctx = Debugger.DebugProcess.GetThread(Debugger.GThread.Value).Context;
|
IExecutionContext ctx = Debugger.GThread.Context;
|
||||||
string registers = string.Empty;
|
string registers = string.Empty;
|
||||||
if (Debugger.IsProcess32Bit)
|
if (Debugger.IsProcess32Bit)
|
||||||
{
|
{
|
||||||
|
|
@ -106,13 +106,13 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
|
|
||||||
internal void WriteRegisters(StringStream ss)
|
internal void WriteRegisters(StringStream ss)
|
||||||
{
|
{
|
||||||
if (Debugger.GThread == null)
|
if (Debugger.GThreadId == null)
|
||||||
{
|
{
|
||||||
Processor.ReplyError();
|
Processor.ReplyError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IExecutionContext ctx = Debugger.DebugProcess.GetThread(Debugger.GThread.Value).Context;
|
IExecutionContext ctx = Debugger.GThread.Context;
|
||||||
if (Debugger.IsProcess32Bit)
|
if (Debugger.IsProcess32Bit)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < GdbRegisters.Count32; i++)
|
for (int i = 0; i < GdbRegisters.Count32; i++)
|
||||||
|
|
@ -162,11 +162,11 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
switch (op)
|
switch (op)
|
||||||
{
|
{
|
||||||
case 'c':
|
case 'c':
|
||||||
Debugger.CThread = threadId;
|
Debugger.CThreadId = threadId;
|
||||||
Processor.ReplyOK();
|
Processor.ReplyOK();
|
||||||
return;
|
return;
|
||||||
case 'g':
|
case 'g':
|
||||||
Debugger.GThread = threadId;
|
Debugger.GThreadId = threadId;
|
||||||
Processor.ReplyOK();
|
Processor.ReplyOK();
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
|
|
@ -214,13 +214,13 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
|
|
||||||
internal void ReadRegister(int gdbRegId)
|
internal void ReadRegister(int gdbRegId)
|
||||||
{
|
{
|
||||||
if (Debugger.GThread == null)
|
if (Debugger.GThreadId == null)
|
||||||
{
|
{
|
||||||
Processor.ReplyError();
|
Processor.ReplyError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IExecutionContext ctx = Debugger.DebugProcess.GetThread(Debugger.GThread.Value).Context;
|
IExecutionContext ctx = Debugger.GThread.Context;
|
||||||
string result = Debugger.ReadRegister(ctx, gdbRegId);
|
string result = Debugger.ReadRegister(ctx, gdbRegId);
|
||||||
|
|
||||||
Processor.Reply(result != null, result);
|
Processor.Reply(result != null, result);
|
||||||
|
|
@ -228,26 +228,26 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
|
|
||||||
internal void WriteRegister(int gdbRegId, StringStream ss)
|
internal void WriteRegister(int gdbRegId, StringStream ss)
|
||||||
{
|
{
|
||||||
if (Debugger.GThread == null)
|
if (Debugger.GThreadId == null)
|
||||||
{
|
{
|
||||||
Processor.ReplyError();
|
Processor.ReplyError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IExecutionContext ctx = Debugger.DebugProcess.GetThread(Debugger.GThread.Value).Context;
|
Processor.Reply(
|
||||||
|
success: Debugger.WriteRegister(Debugger.GThread.Context, gdbRegId, ss) && ss.IsEmpty
|
||||||
Processor.Reply(Debugger.WriteRegister(ctx, gdbRegId, ss) && ss.IsEmpty);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Step(ulong? newPc)
|
internal void Step(ulong? newPc)
|
||||||
{
|
{
|
||||||
if (Debugger.CThread == null)
|
if (Debugger.CThreadId == null)
|
||||||
{
|
{
|
||||||
Processor.ReplyError();
|
Processor.ReplyError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
KThread thread = Debugger.DebugProcess.GetThread(Debugger.CThread.Value);
|
KThread thread = Debugger.CThread;
|
||||||
|
|
||||||
if (newPc.HasValue)
|
if (newPc.HasValue)
|
||||||
{
|
{
|
||||||
|
|
@ -260,7 +260,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debugger.GThread = Debugger.CThread = thread.ThreadUid;
|
Debugger.GThreadId = Debugger.CThreadId = thread.ThreadUid;
|
||||||
Processor.Reply($"T05thread:{thread.ThreadUid:x};");
|
Processor.Reply($"T05thread:{thread.ThreadUid:x};");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -314,7 +314,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
_ => VContAction.None
|
_ => VContAction.None
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: We don't support signals yet.
|
// TODO: Note: We don't support signals yet.
|
||||||
//ushort? signal = null;
|
//ushort? signal = null;
|
||||||
if (cmd is 'C' or 'S')
|
if (cmd is 'C' or 'S')
|
||||||
{
|
{
|
||||||
|
|
@ -323,24 +323,22 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
// since that method advances the underlying string position
|
// since that method advances the underlying string position
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong? threadId = null;
|
ulong? threadId = stream.ConsumePrefix(":")
|
||||||
if (stream.ConsumePrefix(":"))
|
? stream.ReadRemainingAsThreadUid()
|
||||||
{
|
: null;
|
||||||
threadId = stream.ReadRemainingAsThreadUid();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (threadId.HasValue)
|
if (threadId.HasValue)
|
||||||
{
|
{
|
||||||
if (threadActionMap.ContainsKey(threadId.Value))
|
if (threadActionMap.ContainsKey(threadId.Value))
|
||||||
{
|
{
|
||||||
threadActionMap[threadId.Value] = new VContPendingAction(action/*, signal*/);
|
threadActionMap[threadId.Value] = new VContPendingAction(action /*, signal*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (ulong thread in threadActionMap.Keys)
|
foreach (ulong thread in threadActionMap.Keys)
|
||||||
{
|
{
|
||||||
threadActionMap[thread] = new VContPendingAction(action/*, signal*/);
|
threadActionMap[thread] = new VContPendingAction(action /*, signal*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == VContAction.Continue)
|
if (action == VContAction.Continue)
|
||||||
|
|
@ -393,7 +391,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
{
|
{
|
||||||
if (action.Action == VContAction.Step)
|
if (action.Action == VContAction.Step)
|
||||||
{
|
{
|
||||||
Debugger.GThread = Debugger.CThread = threadUid;
|
Debugger.GThreadId = Debugger.CThreadId = threadUid;
|
||||||
Processor.Reply($"T05thread:{threadUid:x};");
|
Processor.Reply($"T05thread:{threadUid:x};");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
{
|
{
|
||||||
public const int Count64 = 68;
|
public const int Count64 = 68;
|
||||||
public const int Count32 = 66;
|
public const int Count32 = 66;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
FPCR = FPSR & ~FpcrMask
|
FPCR = FPSR & ~FpcrMask
|
||||||
All of FPCR's bits are reserved in FPCR and vice versa,
|
All of FPCR's bits are reserved in FPCR and vice versa,
|
||||||
|
|
@ -16,6 +16,8 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
*/
|
*/
|
||||||
private const uint FpcrMask = 0xfc1fffff;
|
private const uint FpcrMask = 0xfc1fffff;
|
||||||
|
|
||||||
|
#region 64-bit
|
||||||
|
|
||||||
public static string ReadRegister64(this IExecutionContext state, int registerId) =>
|
public static string ReadRegister64(this IExecutionContext state, int registerId) =>
|
||||||
registerId switch
|
registerId switch
|
||||||
{
|
{
|
||||||
|
|
@ -74,6 +76,10 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 32-bit
|
||||||
|
|
||||||
public static string ReadRegister32(this IExecutionContext state, int registerId)
|
public static string ReadRegister32(this IExecutionContext state, int registerId)
|
||||||
{
|
{
|
||||||
switch (registerId)
|
switch (registerId)
|
||||||
|
|
@ -149,5 +155,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace Ryujinx.HLE.Debugger
|
||||||
IVirtualMemoryManager CpuMemory { get; }
|
IVirtualMemoryManager CpuMemory { get; }
|
||||||
ulong[] ThreadUids { get; }
|
ulong[] ThreadUids { get; }
|
||||||
DebugState DebugState { get; }
|
DebugState DebugState { get; }
|
||||||
|
|
||||||
void DebugStop();
|
void DebugStop();
|
||||||
void DebugContinue();
|
void DebugContinue();
|
||||||
void DebugContinue(KThread thread);
|
void DebugContinue(KThread thread);
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,9 @@ namespace Ryujinx.HLE.Debugger
|
||||||
public readonly string Command;
|
public readonly string Command;
|
||||||
|
|
||||||
public CommandMessage(string cmd)
|
public CommandMessage(string cmd)
|
||||||
{
|
=> Command = cmd;
|
||||||
Command = cmd;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ThreadBreakMessage : Message.IMarker
|
public class ThreadBreakMessage : Message.IMarker
|
||||||
{
|
{
|
||||||
public IExecutionContext Context { get; }
|
public IExecutionContext Context { get; }
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ using System.IO;
|
||||||
|
|
||||||
namespace Ryujinx.HLE.Debugger
|
namespace Ryujinx.HLE.Debugger
|
||||||
{
|
{
|
||||||
class RegisterInformation
|
static class RegisterInformation
|
||||||
{
|
{
|
||||||
public static readonly Dictionary<string, string> Features = new()
|
public static readonly Dictionary<string, string> Features = new()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue