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 committed by KeatonTheBot
parent 91a5f69805
commit a7af26bc1f
19 changed files with 321 additions and 332 deletions

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(state.Fpsr)),
67 => Helpers.ToHex(BitConverter.GetBytes(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;