mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-01-03 11:11:14 +00:00
thermosphere: C++ify gdb/verbose
This commit is contained in:
parent
192d2db4a9
commit
eab46ab1b6
5 changed files with 64 additions and 87 deletions
62
thermosphere/src/gdb/hvisor_gdb_vebose.cpp
Normal file
62
thermosphere/src/gdb/hvisor_gdb_vebose.cpp
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019-2020 Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Luma3DS.
|
||||||
|
* Copyright (C) 2016-2019 Aurora Wright, TuxSH
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: (MIT OR GPL-2.0-or-later)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "hvisor_gdb_defines_internal.hpp"
|
||||||
|
#include "hvisor_gdb_packet_data.hpp"
|
||||||
|
|
||||||
|
namespace ams::hvisor::gdb {
|
||||||
|
|
||||||
|
GDB_DEFINE_HANDLER(VerboseCommand)
|
||||||
|
{
|
||||||
|
// Extract name
|
||||||
|
char delim = ':';
|
||||||
|
|
||||||
|
size_t delimPos = m_commandData.find_first_of(";:");
|
||||||
|
std::string_view cmdName = m_commandData;
|
||||||
|
if (delimPos != std::string_view::npos) {
|
||||||
|
delim = m_commandData[delimPos];
|
||||||
|
cmdName.remove_suffix(cmdName.size() - delimPos);
|
||||||
|
m_commandData.remove_prefix(delimPos + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmdName == "Cont?") {
|
||||||
|
GDB_VERBOSE_HANDLER(ContinueSupported)();
|
||||||
|
} else if (cmdName == "Cont") {
|
||||||
|
GDB_VERBOSE_HANDLER(Continue)();
|
||||||
|
} else if (cmdName == "CtrlC") {
|
||||||
|
GDB_VERBOSE_HANDLER(CtrlC)();
|
||||||
|
} else if (cmdName == "MustReplyEmpty") {
|
||||||
|
return HandleUnsupported();
|
||||||
|
} else if (cmdName == "Stopped") {
|
||||||
|
return GDB_VERBOSE_HANDLER(Stopped)();
|
||||||
|
} else {
|
||||||
|
return HandleUnsupported(); // No handler found!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GDB_DEFINE_VERBOSE_HANDLER(ContinueSupported)
|
||||||
|
{
|
||||||
|
return SendPacket("vCont;c;C;s;S;t;r");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -134,10 +134,10 @@ namespace ams::hvisor::gdb {
|
||||||
|
|
||||||
// Run command
|
// Run command
|
||||||
if (cmd == "features") {
|
if (cmd == "features") {
|
||||||
return HandleXferFeatures(isWrite, annex, off, len);
|
return GDB_XFER_HANDLER(Features)(isWrite, annex, off, len);
|
||||||
} else {
|
} else {
|
||||||
return HandleUnsupported();
|
return HandleUnsupported();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of Luma3DS.
|
|
||||||
* Copyright (C) 2016-2019 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: (MIT OR GPL-2.0-or-later)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "verbose.h"
|
|
||||||
#include "net.h"
|
|
||||||
#include "debug.h"
|
|
||||||
|
|
||||||
static const struct {
|
|
||||||
const char *name;
|
|
||||||
char trailingCharacter;
|
|
||||||
GDBCommandHandler handler;
|
|
||||||
} 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)
|
|
||||||
{
|
|
||||||
char *nameBegin = ctx->commandData; // w/o leading 'v'
|
|
||||||
if (*nameBegin == 0) {
|
|
||||||
return GDB_ReplyErrno(ctx, EILSEQ);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *nameEnd;
|
|
||||||
char *vData = NULL;
|
|
||||||
|
|
||||||
for (nameEnd = nameBegin; *nameEnd != 0 && *nameEnd != ';' && *nameEnd != ':'; nameEnd++);
|
|
||||||
char oldNameEnd = *nameEnd;
|
|
||||||
if (*nameEnd != 0) {
|
|
||||||
*nameEnd = 0;
|
|
||||||
vData = nameEnd + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(gdbVerboseCommandHandlers) / sizeof(gdbVerboseCommandHandlers[0]); i++) {
|
|
||||||
if (strcmp(gdbVerboseCommandHandlers[i].name, nameBegin) == 0) {
|
|
||||||
ctx->commandData = vData;
|
|
||||||
if (oldNameEnd == gdbVerboseCommandHandlers[i].trailingCharacter) {
|
|
||||||
return gdbVerboseCommandHandlers[i].handler(ctx);
|
|
||||||
} else {
|
|
||||||
return GDB_ReplyErrno(ctx, EILSEQ);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return GDB_HandleUnsupported(ctx); // No handler found!
|
|
||||||
}
|
|
||||||
|
|
||||||
GDB_DECLARE_VERBOSE_HANDLER(ContinueSupported)
|
|
||||||
{
|
|
||||||
const char *supported = "vCont;c;C;s;S;t;r";
|
|
||||||
return GDB_SendPacket(ctx, supported, strlen(supported));
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of Luma3DS.
|
|
||||||
* Copyright (C) 2016-2019 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: (MIT OR GPL-2.0-or-later)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "context.h"
|
|
||||||
|
|
||||||
GDB_DECLARE_HANDLER(VerboseCommand);
|
|
||||||
GDB_DECLARE_VERBOSE_HANDLER(ContinueSupported);
|
|
|
@ -1,11 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of Luma3DS.
|
|
||||||
* Copyright (C) 2016-2019 Aurora Wright, TuxSH
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: (MIT OR GPL-2.0-or-later)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "context.h"
|
|
||||||
|
|
Loading…
Reference in a new issue