/* * This file is part of Luma3DS. * Copyright (C) 2016-2019 Aurora Wright, TuxSH * * SPDX-License-Identifier: (MIT OR GPL-2.0-or-later) */ #include #include "remote_command.h" #include "net.h" struct { const char *name; GDBCommandHandler handler; } remoteCommandHandlers[] = { }; static const char *GDB_SkipSpaces(const char *pos) { const char *nextpos; for (nextpos = pos; *nextpos != 0 && ((*nextpos >= 9 && *nextpos <= 13) || *nextpos == ' '); nextpos++); return nextpos; } GDB_DECLARE_QUERY_HANDLER(Rcmd) { char commandData[GDB_BUF_LEN / 2 + 1]; char *endpos; const char *errstr = "Unrecognized command.\n"; size_t len = strlen(ctx->commandData); if(len == 0 || (len % 2) == 1 || GDB_DecodeHex(commandData, ctx->commandData, len / 2) != len / 2) { return GDB_ReplyErrno(ctx, EILSEQ); } commandData[len / 2] = 0; for (endpos = commandData; !(*endpos >= 9 && *endpos <= 13) && *endpos != ' ' && *endpos != 0; endpos++); char *nextpos = (char *)GDB_SkipSpaces(endpos); *endpos = 0; for (size_t i = 0; i < sizeof(remoteCommandHandlers) / sizeof(remoteCommandHandlers[0]); i++) { if (strcmp(commandData, remoteCommandHandlers[i].name) == 0) { ctx->commandData = nextpos; return remoteCommandHandlers[i].handler(ctx); } } return GDB_SendHexPacket(ctx, errstr, strlen(errstr)); }