From 7b0affb6e0f282fb4d91339baf8e0ed8a4b8909e Mon Sep 17 00:00:00 2001 From: lat9nq Date: Thu, 30 Jun 2022 12:40:01 -0400 Subject: gdbstub_arch: Directly access SP register Currently to access the SP register, RegRead and RegWrite rely on a out-of-bounds array access to reach the next element in a struct. As of writing only git versions of GCC catch this error. Specify the SP register when we want to access it in these functions. --- src/core/debugger/gdbstub_arch.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/debugger/gdbstub_arch.cpp b/src/core/debugger/gdbstub_arch.cpp index 750c353b9..4bef09bd7 100644 --- a/src/core/debugger/gdbstub_arch.cpp +++ b/src/core/debugger/gdbstub_arch.cpp @@ -191,8 +191,10 @@ std::string GDBStubA64::RegRead(const Kernel::KThread* thread, size_t id) const const auto& gprs{context.cpu_registers}; const auto& fprs{context.vector_registers}; - if (id <= SP_REGISTER) { + if (id < SP_REGISTER) { return ValueToHex(gprs[id]); + } else if (id == SP_REGISTER) { + return ValueToHex(context.sp); } else if (id == PC_REGISTER) { return ValueToHex(context.pc); } else if (id == PSTATE_REGISTER) { @@ -215,8 +217,10 @@ void GDBStubA64::RegWrite(Kernel::KThread* thread, size_t id, std::string_view v auto& context{thread->GetContext64()}; - if (id <= SP_REGISTER) { + if (id < SP_REGISTER) { context.cpu_registers[id] = HexToValue(value); + } else if (id == SP_REGISTER) { + context.sp = HexToValue(value); } else if (id == PC_REGISTER) { context.pc = HexToValue(value); } else if (id == PSTATE_REGISTER) { -- cgit v1.2.3