gdb: More cleanup changes

- Move the message handler into its debugger class part,
- Move all message types into one file and collapse 3 of the ones with no data into a generic, stateless message with a single property being its type,
- Add an Fpscr helper property on IExecutionContext along with a comment about what Fpscr is (similar to the other registers in there)
- Moved the Rcmd helpers (such as GetRegisters, GetMinidump, etc) into a dedicated Debugger class part,
- Fixed the double-collection (ToArray being called twice) in GetThreadUids & GetThread in KProcess
This commit is contained in:
GreemDev
2025-10-19 04:26:12 -05:00
parent 6058af5119
commit 247e2e03d6
19 changed files with 319 additions and 328 deletions

View File

@@ -53,7 +53,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
switch (ss.ReadChar())
{
case '!':
if (!ss.IsEmpty())
if (!ss.IsEmpty)
{
goto unknownCommand;
}
@@ -62,7 +62,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
ReplyOK();
break;
case '?':
if (!ss.IsEmpty())
if (!ss.IsEmpty)
{
goto unknownCommand;
}
@@ -70,10 +70,10 @@ namespace Ryujinx.HLE.Debugger.Gdb
Commands.Query();
break;
case 'c':
Commands.Continue(ss.IsEmpty() ? null : ss.ReadRemainingAsHex());
Commands.Continue(ss.IsEmpty ? null : ss.ReadRemainingAsHex());
break;
case 'D':
if (!ss.IsEmpty())
if (!ss.IsEmpty)
{
goto unknownCommand;
}
@@ -81,7 +81,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
Commands.Detach();
break;
case 'g':
if (!ss.IsEmpty())
if (!ss.IsEmpty)
{
goto unknownCommand;
}
@@ -172,7 +172,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
if (ss.ConsumeRemaining("fThreadInfo"))
{
Reply(
$"m{Debugger.DebugProcess.GetThreadUids().Select(x => $"{x:x}").JoinToString(",")}");
$"m{Debugger.DebugProcess.ThreadUids.Select(x => $"{x:x}").JoinToString(",")}");
break;
}
@@ -225,7 +225,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
if (len >= (ulong)data.Length - offset)
{
Reply("l" + Helpers.ToBinaryFormat(data.Substring((int)offset)));
Reply("l" + Helpers.ToBinaryFormat(data[(int)offset..]));
}
else
{
@@ -274,7 +274,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
case 'Q':
goto unknownCommand;
case 's':
Commands.Step(ss.IsEmpty() ? null : ss.ReadRemainingAsHex());
Commands.Step(ss.IsEmpty ? null : ss.ReadRemainingAsHex());
break;
case 'T':
{

View File

@@ -53,7 +53,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
{
// GDB is performing initial contact. Stop everything.
Debugger.DebugProcess.DebugStop();
Debugger.GThread = Debugger.CThread = Debugger.DebugProcess.GetThreadUids().First();
Debugger.GThread = Debugger.CThread = Debugger.DebugProcess.ThreadUids.First();
Processor.Reply($"T05thread:{Debugger.CThread:x};");
}
@@ -63,7 +63,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
Debugger.DebugProcess.DebugStop();
if (Debugger.GThread == null || Debugger.GetThreads().All(x => x.ThreadUid != Debugger.GThread.Value))
{
Debugger.GThread = Debugger.CThread = Debugger.DebugProcess.GetThreadUids().First();
Debugger.GThread = Debugger.CThread = Debugger.DebugProcess.ThreadUids.First();
}
Processor.Reply($"T02thread:{Debugger.GThread:x};");
@@ -151,7 +151,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
}
}
Processor.Reply(ss.IsEmpty());
Processor.Reply(ss.IsEmpty);
}
internal void SetThread(char op, ulong? threadId)
@@ -251,7 +251,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
IExecutionContext ctx = Debugger.DebugProcess.GetThread(Debugger.GThread.Value).Context;
Processor.Reply(Debugger.WriteRegister(ctx, gdbRegId, ss) && ss.IsEmpty());
Processor.Reply(Debugger.WriteRegister(ctx, gdbRegId, ss) && ss.IsEmpty);
}
internal void Step(ulong? newPc)

View File

@@ -13,65 +13,56 @@ namespace Ryujinx.HLE.Debugger.Gdb
*/
private const uint FpcrMask = 0xfc1fffff;
public static string ReadRegister64(this IExecutionContext state, int gdbRegId)
{
switch (gdbRegId)
public static string ReadRegister64(this IExecutionContext state, int registerId) =>
registerId switch
{
case >= 0 and <= 31:
return Helpers.ToHex(BitConverter.GetBytes(state.GetX(gdbRegId)));
case 32:
return Helpers.ToHex(BitConverter.GetBytes(state.DebugPc));
case 33:
return Helpers.ToHex(BitConverter.GetBytes(state.Pstate));
case >= 34 and <= 65:
return Helpers.ToHex(state.GetV(gdbRegId - 34).ToArray());
case 66:
return Helpers.ToHex(BitConverter.GetBytes((uint)state.Fpsr));
case 67:
return Helpers.ToHex(BitConverter.GetBytes((uint)state.Fpcr));
default:
return null;
}
}
>= 0 and <= 31 => Helpers.ToHex(BitConverter.GetBytes(state.GetX(registerId))),
32 => Helpers.ToHex(BitConverter.GetBytes(state.DebugPc)),
33 => Helpers.ToHex(BitConverter.GetBytes(state.Pstate)),
>= 34 and <= 65 => Helpers.ToHex(state.GetV(registerId - 34).ToArray()),
66 => Helpers.ToHex(BitConverter.GetBytes((uint)state.Fpsr)),
67 => Helpers.ToHex(BitConverter.GetBytes((uint)state.Fpcr)),
_ => null
};
public static bool WriteRegister64(this IExecutionContext state, int gdbRegId, StringStream ss)
public static bool WriteRegister64(this IExecutionContext state, int registerId, StringStream ss)
{
switch (gdbRegId)
switch (registerId)
{
case >= 0 and <= 31:
{
ulong value = ss.ReadLengthAsLEHex(16);
state.SetX(gdbRegId, value);
ulong value = ss.ReadLengthAsLittleEndianHex(16);
state.SetX(registerId, value);
return true;
}
case 32:
{
ulong value = ss.ReadLengthAsLEHex(16);
ulong value = ss.ReadLengthAsLittleEndianHex(16);
state.DebugPc = value;
return true;
}
case 33:
{
ulong value = ss.ReadLengthAsLEHex(8);
ulong value = ss.ReadLengthAsLittleEndianHex(8);
state.Pstate = (uint)value;
return true;
}
case >= 34 and <= 65:
{
ulong value0 = ss.ReadLengthAsLEHex(16);
ulong value1 = ss.ReadLengthAsLEHex(16);
state.SetV(gdbRegId - 34, new V128(value0, value1));
ulong value0 = ss.ReadLengthAsLittleEndianHex(16);
ulong value1 = ss.ReadLengthAsLittleEndianHex(16);
state.SetV(registerId - 34, new V128(value0, value1));
return true;
}
case 66:
{
ulong value = ss.ReadLengthAsLEHex(8);
ulong value = ss.ReadLengthAsLittleEndianHex(8);
state.Fpsr = (uint)value;
return true;
}
case 67:
{
ulong value = ss.ReadLengthAsLEHex(8);
ulong value = ss.ReadLengthAsLittleEndianHex(8);
state.Fpcr = (uint)value;
return true;
}
@@ -80,65 +71,64 @@ namespace Ryujinx.HLE.Debugger.Gdb
}
}
public static string ReadRegister32(this IExecutionContext state, int gdbRegId)
public static string ReadRegister32(this IExecutionContext state, int registerId)
{
switch (gdbRegId)
switch (registerId)
{
case >= 0 and <= 14:
return Helpers.ToHex(BitConverter.GetBytes((uint)state.GetX(gdbRegId)));
return Helpers.ToHex(BitConverter.GetBytes((uint)state.GetX(registerId)));
case 15:
return Helpers.ToHex(BitConverter.GetBytes((uint)state.DebugPc));
case 16:
return Helpers.ToHex(BitConverter.GetBytes((uint)state.Pstate));
return Helpers.ToHex(BitConverter.GetBytes(state.Pstate));
case >= 17 and <= 32:
return Helpers.ToHex(state.GetV(gdbRegId - 17).ToArray());
return Helpers.ToHex(state.GetV(registerId - 17).ToArray());
case >= 33 and <= 64:
int reg = (gdbRegId - 33);
int reg = (registerId - 33);
int n = reg / 2;
int shift = reg % 2;
ulong value = state.GetV(n).Extract<ulong>(shift);
return Helpers.ToHex(BitConverter.GetBytes(value));
case 65:
uint fpscr = (uint)state.Fpsr | (uint)state.Fpcr;
return Helpers.ToHex(BitConverter.GetBytes(fpscr));
return Helpers.ToHex(BitConverter.GetBytes(state.Fpscr));
default:
return null;
}
}
public static bool WriteRegister32(this IExecutionContext state, int gdbRegId, StringStream ss)
public static bool WriteRegister32(this IExecutionContext state, int registerId, StringStream ss)
{
switch (gdbRegId)
switch (registerId)
{
case >= 0 and <= 14:
{
ulong value = ss.ReadLengthAsLEHex(8);
state.SetX(gdbRegId, value);
ulong value = ss.ReadLengthAsLittleEndianHex(8);
state.SetX(registerId, value);
return true;
}
case 15:
{
ulong value = ss.ReadLengthAsLEHex(8);
ulong value = ss.ReadLengthAsLittleEndianHex(8);
state.DebugPc = value;
return true;
}
case 16:
{
ulong value = ss.ReadLengthAsLEHex(8);
ulong value = ss.ReadLengthAsLittleEndianHex(8);
state.Pstate = (uint)value;
return true;
}
case >= 17 and <= 32:
{
ulong value0 = ss.ReadLengthAsLEHex(16);
ulong value1 = ss.ReadLengthAsLEHex(16);
state.SetV(gdbRegId - 17, new V128(value0, value1));
ulong value0 = ss.ReadLengthAsLittleEndianHex(16);
ulong value1 = ss.ReadLengthAsLittleEndianHex(16);
state.SetV(registerId - 17, new V128(value0, value1));
return true;
}
case >= 33 and <= 64:
{
ulong value = ss.ReadLengthAsLEHex(16);
int regId = (gdbRegId - 33);
ulong value = ss.ReadLengthAsLittleEndianHex(16);
int regId = (registerId - 33);
int regNum = regId / 2;
int shift = regId % 2;
V128 reg = state.GetV(regNum);
@@ -147,7 +137,7 @@ namespace Ryujinx.HLE.Debugger.Gdb
}
case 65:
{
ulong value = ss.ReadLengthAsLEHex(8);
ulong value = ss.ReadLengthAsLittleEndianHex(8);
state.Fpsr = (uint)value & FpcrMask;
state.Fpcr = (uint)value & ~FpcrMask;
return true;