diff --git a/thermosphere/src/gdb/context.c b/thermosphere/src/gdb/context.c index bd21d5c05..46b6d3bf3 100644 --- a/thermosphere/src/gdb/context.c +++ b/thermosphere/src/gdb/context.c @@ -42,14 +42,14 @@ #include "../software_breakpoints.h" #include "../watchpoints.h" -static TEMPORARY u8 g_gdbWorkBuffer[GDB_WORK_BUF_LEN]; +static TEMPORARY char g_gdbWorkBuffer[GDB_WORK_BUF_LEN]; static const struct{ char command; GDBCommandHandler handler; } gdbCommandHandlers[] = { { '?', GDB_HANDLER(GetStopReason) }, - { '!', GDB_HANDLER(EnableExtendedMode) }, + { '!', GDB_HANDLER(EnableExtendedMode) }, // note: stubbed { 'c', GDB_HANDLER(ContinueOrStepDeprecated) }, { 'C', GDB_HANDLER(ContinueOrStepDeprecated) }, { 'D', GDB_HANDLER(Detach) }, @@ -64,6 +64,8 @@ static const struct{ { 'P', GDB_HANDLER(WriteRegister) }, { 'q', GDB_HANDLER(ReadQuery) }, { 'Q', GDB_HANDLER(WriteQuery) }, + { 's', GDB_HANDLER(ContinueOrStepDeprecated) }, + { 'S', GDB_HANDLER(ContinueOrStepDeprecated) }, { 'T', GDB_HANDLER(IsThreadAlive) }, { 'v', GDB_HANDLER(VerboseCommand) }, { 'X', GDB_HANDLER(WriteMemoryRaw) }, @@ -91,7 +93,7 @@ static int GDB_ProcessPacket(GDBContext *ctx, size_t len) // Handle the packet... if (ctx->buffer[0] == '\x03') { - GDB_HandleBreak(ctx); + GDB_BreakAllCores(ctx); ret = 0; } else { GDBCommandHandler handler = GDB_GetCommandHandler(ctx->buffer[1]); @@ -226,7 +228,7 @@ void GDB_DetachFromContext(GDBContext *ctx) ctx->currentHioRequestTargetAddr = 0; memset(&ctx->currentHioRequest, 0, sizeof(PackedGdbHioRequest)); - debugManagerSetReportingFalse(true); + debugManagerSetReportingEnabled(false); debugManagerContinueCores(getActiveCoreMask()); } diff --git a/thermosphere/src/gdb/debug.c b/thermosphere/src/gdb/debug.c index 3a71e04bd..ef78015a9 100644 --- a/thermosphere/src/gdb/debug.c +++ b/thermosphere/src/gdb/debug.c @@ -71,7 +71,7 @@ static int GDB_ParseExceptionFrame(char *out, const DebugEventInfo *info, int si u32 coreId = info->coreId; ExceptionStackFrame *frame = info->frame; - int n = sprintf(out, "T%02xthread:%lx;core:%lx;", sig, 1 + coreId, coreId); + int n = sprintf(out, "T%02xthread:%x;core:%x;", sig, 1 + coreId, coreId); // Dump the GPRs & sp & pc & cpsr (cpsr is 32-bit in the xml desc) // For performance reasons, we don't include the FPU registers here @@ -83,13 +83,14 @@ static int GDB_ParseExceptionFrame(char *out, const DebugEventInfo *info, int si out + n, "1f:%016lx;20:%016lx;21:%08x", __builtin_bswap64(*exceptionGetSpPtr(frame)), - __builitin_bswap32((u32)frame->spsr_el2) + __builtin_bswap64(frame->elr_el2), + __builtin_bswap32((u32)frame->spsr_el2) ); return n; } -int GDB_SendStopReply(GDBContext *ctx, DebugEventInfo *info, bool asNotification) +int GDB_SendStopReply(GDBContext *ctx, const DebugEventInfo *info, bool asNotification) { char *buf = ctx->buffer + 1; int n; @@ -149,7 +150,7 @@ int GDB_SendStopReply(GDBContext *ctx, DebugEventInfo *info, bool asNotification // the only notable exceptions we get are stop point/single step events from the debugee (basically classes 0x3x) switch(ec) { case Exception_BreakpointLowerEl: { - n += GDB_ParseExceptionFrame(buf + n, ctx, SIGTRAP); + n += GDB_ParseExceptionFrame(buf + n, info, SIGTRAP); strcat(buf, "hwbreak:;"); } @@ -162,7 +163,7 @@ int GDB_SendStopReply(GDBContext *ctx, DebugEventInfo *info, bool asNotification if (!cr.enabled) { DEBUG("GDB: oops, unhandled watchpoint for core id %u, far=%016lx\n", info->coreId, info->frame->far_el2); } else { - n += GDB_ParseExceptionFrame(buf + n, ctx, SIGTRAP); + n += GDB_ParseExceptionFrame(buf + n, info, SIGTRAP); sprintf(buf + n, "%swatch:%016lx;", kinds[cr.lsc], info->frame->far_el2); } } @@ -171,7 +172,7 @@ int GDB_SendStopReply(GDBContext *ctx, DebugEventInfo *info, bool asNotification // if the guest has inserted some of them manually... case Exception_SoftwareBreakpointA64: case Exception_SoftwareBreakpointA32: { - n += GDB_ParseExceptionFrame(buf + n, ctx, SIGTRAP); + n += GDB_ParseExceptionFrame(buf + n, info, SIGTRAP); strcat(buf, "swbreak:;"); } @@ -333,7 +334,7 @@ GDB_DECLARE_HANDLER(GetStopReason) bool nonStop = (ctx->flags & GDB_FLAG_NONSTOP) != 0; if (!nonStop) { // Full-stop: - return GDB_SendStopReply(ctx, &ctx->lastDebugEvent, true); + return GDB_SendStopReply(ctx, ctx->lastDebugEvent, true); } else { // Non-stop, start new vStopped sequence ctx->sentDebugEventCoreList = 0; @@ -362,12 +363,12 @@ GDB_DECLARE_VERBOSE_HANDLER(CtrlC) { int ret = GDB_ReplyOk(ctx); GDB_BreakAllCores(ctx); + return ret; } GDB_DECLARE_HANDLER(ContinueOrStepDeprecated) { char *addrStart = NULL; - uintptr_t addr = 0; char cmd = ctx->commandData[-1]; diff --git a/thermosphere/src/gdb/debug.h b/thermosphere/src/gdb/debug.h index e5e782e84..668278029 100644 --- a/thermosphere/src/gdb/debug.h +++ b/thermosphere/src/gdb/debug.h @@ -11,7 +11,7 @@ #include "../core_ctx.h" #include "../debug_manager.h" -int GDB_SendStopReply(GDBContext *ctx, DebugEventInfo *info, bool asNotification); +int GDB_SendStopReply(GDBContext *ctx, const DebugEventInfo *info, bool asNotification); int GDB_TrySignalDebugEvent(GDBContext *ctx, DebugEventInfo *info); void GDB_BreakAllCores(GDBContext *ctx); diff --git a/thermosphere/src/gdb/hio.c b/thermosphere/src/gdb/hio.c index cf5c138b5..d8f090403 100644 --- a/thermosphere/src/gdb/hio.c +++ b/thermosphere/src/gdb/hio.c @@ -11,7 +11,7 @@ #include "net.h" #include "mem.h" #include "debug.h" - +/* bool GDB_FetchPackedHioRequest(GDBContext *ctx, u32 addr) { u32 total = GDB_ReadTargetMemory(&ctx->currentHioRequest, ctx, addr, sizeof(PackedGdbHioRequest)); @@ -65,11 +65,12 @@ int GDB_SendCurrentHioRequest(GDBContext *ctx) } return GDB_SendPacket(ctx, buf, strlen(buf)); -} +}*/ GDB_DECLARE_HANDLER(HioReply) { - if (!GDB_IsHioInProgress(ctx)) + return 0; +/* if (!GDB_IsHioInProgress(ctx)) return GDB_ReplyErrno(ctx, EPERM); // Reply in the form of Fretcode,errno,Ctrl-C flag;call-specific attachment @@ -128,5 +129,5 @@ GDB_DECLARE_HANDLER(HioReply) ctx->currentHioRequestTargetAddr = 0; GDB_ContinueExecution(ctx); - return total == sizeof(PackedGdbHioRequest) ? 0 : GDB_ReplyErrno(ctx, EFAULT); + return total == sizeof(PackedGdbHioRequest) ? 0 : GDB_ReplyErrno(ctx, EFAULT);*/ } diff --git a/thermosphere/src/gdb/mem.c b/thermosphere/src/gdb/mem.c index 42ad8cd14..2ee5ab1f0 100644 --- a/thermosphere/src/gdb/mem.c +++ b/thermosphere/src/gdb/mem.c @@ -173,7 +173,7 @@ GDB_DECLARE_QUERY_HANDLER(SearchMemory) patternLen = ctx->commandEnd - patternStart; // Unescape pattern in place - char *pattern = patternStart; + char *pattern = (char *)patternStart; patternLen = GDB_UnescapeBinaryData(pattern, patternStart, patternLen); foundAddr = GDB_SearchMemory(&found, ctx, addr, len, patternStart, patternLen); diff --git a/thermosphere/src/gdb/net.c b/thermosphere/src/gdb/net.c index 5553c08ad..d22f66515 100644 --- a/thermosphere/src/gdb/net.c +++ b/thermosphere/src/gdb/net.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "../pattern_utils.h" u8 GDB_ComputeChecksum(const char *packetData, size_t len) @@ -236,7 +237,7 @@ int GDB_ReceivePacket(GDBContext *ctx) } // Set helper attributes, change '#' to NUL - ctx->commandEnd = delimPos; + ctx->commandEnd = ctx->buffer + delimPos; ctx->buffer[delimPos] = '\0'; return (int)(delimPos + 2); diff --git a/thermosphere/src/gdb/query.c b/thermosphere/src/gdb/query.c index 26ee915f4..09f18861a 100644 --- a/thermosphere/src/gdb/query.c +++ b/thermosphere/src/gdb/query.c @@ -5,6 +5,8 @@ * SPDX-License-Identifier: (MIT OR GPL-2.0-or-later) */ +#include + #include "../utils.h" #include "query.h" @@ -36,7 +38,6 @@ static const struct { GDB_QUERY_HANDLER_LIST_ITEM(sThreadInfo, READ), GDB_QUERY_HANDLER_LIST_ITEM(ThreadEvents, WRITE), GDB_QUERY_HANDLER_LIST_ITEM(ThreadExtraInfo, READ), - GDB_QUERY_HANDLER_LIST_ITEM(GetTLSAddr, READ), GDB_QUERY_HANDLER_LIST_ITEM_3("C", CurrentThreadId, READ), GDB_QUERY_HANDLER_LIST_ITEM_3("Search", SearchMemory, READ), GDB_QUERY_HANDLER_LIST_ITEM(Rcmd, READ), diff --git a/thermosphere/src/gdb/query.h b/thermosphere/src/gdb/query.h index a828b023d..adfcd681e 100644 --- a/thermosphere/src/gdb/query.h +++ b/thermosphere/src/gdb/query.h @@ -15,4 +15,3 @@ int GDB_HandleWriteQuery(GDBContext *ctx); GDB_DECLARE_QUERY_HANDLER(Supported); GDB_DECLARE_QUERY_HANDLER(StartNoAckMode); GDB_DECLARE_QUERY_HANDLER(Attached); -GDB_DECLARE_QUERY_HANDLER(CatchSyscalls); diff --git a/thermosphere/src/gdb/thread.c b/thermosphere/src/gdb/thread.c index a0915f6da..9c90b0f71 100644 --- a/thermosphere/src/gdb/thread.c +++ b/thermosphere/src/gdb/thread.c @@ -6,6 +6,7 @@ */ #include +#include #include "thread.h" #include "net.h" @@ -75,7 +76,7 @@ GDB_DECLARE_QUERY_HANDLER(fThreadInfo) u32 coreMask = ctx->attachedCoreList; FOREACH_BIT (tmp, coreId, coreMask) { - n += sprintf(buf + n, "%x,", 1 + coreId); + n += sprintf(buf + n, "%lx,", 1 + coreId); } // Remove trailing comma diff --git a/thermosphere/src/gdb/verbose.c b/thermosphere/src/gdb/verbose.c index 56e3408d0..753cfa072 100644 --- a/thermosphere/src/gdb/verbose.c +++ b/thermosphere/src/gdb/verbose.c @@ -18,7 +18,9 @@ static const struct { } gdbVerboseCommandHandlers[] = { { "Cont?", '\0', GDB_VERBOSE_HANDLER(ContinueSupported) }, { "Cont", ';', GDB_VERBOSE_HANDLER(Continue) }, + { "CtrlC", '\0', GDB_VERBOSE_HANDLER(CtrlC) }, { "MustReplyEmpty", '\0', GDB_HANDLER(Unsupported) }, + { "Stopped", '\0', GDB_VERBOSE_HANDLER(Stopped) }, }; GDB_DECLARE_HANDLER(VerboseCommand) diff --git a/thermosphere/src/gdb/xfer.c b/thermosphere/src/gdb/xfer.c index b9d374d01..53a725450 100644 --- a/thermosphere/src/gdb/xfer.c +++ b/thermosphere/src/gdb/xfer.c @@ -121,7 +121,7 @@ GDB_DECLARE_QUERY_HANDLER(Xfer) bool write; const char *pos; if (strcmp(opStart, "read") == 0) { - unsigned int lst[2]; + unsigned long lst[2]; if(GDB_ParseHexIntegerList(lst, offStart, 2, 0) == NULL) { return GDB_ReplyErrno(ctx, EILSEQ); }