From eab46ab1b6665998ba448a05b8b20eae7e7d7575 Mon Sep 17 00:00:00 2001
From: TuxSH <1922548+TuxSH@users.noreply.github.com>
Date: Sat, 8 Feb 2020 01:57:36 +0000
Subject: [PATCH] thermosphere: C++ify gdb/verbose
---
thermosphere/src/gdb/hvisor_gdb_vebose.cpp | 62 ++++++++++++++++++++++
thermosphere/src/gdb/hvisor_gdb_xfer.cpp | 4 +-
thermosphere/src/gdb/verbose.c | 61 ---------------------
thermosphere/src/gdb/verbose.h | 13 -----
thermosphere/src/gdb/xfer.h | 11 ----
5 files changed, 64 insertions(+), 87 deletions(-)
create mode 100644 thermosphere/src/gdb/hvisor_gdb_vebose.cpp
delete mode 100644 thermosphere/src/gdb/verbose.c
delete mode 100644 thermosphere/src/gdb/verbose.h
delete mode 100644 thermosphere/src/gdb/xfer.h
diff --git a/thermosphere/src/gdb/hvisor_gdb_vebose.cpp b/thermosphere/src/gdb/hvisor_gdb_vebose.cpp
new file mode 100644
index 000000000..0d283ca9b
--- /dev/null
+++ b/thermosphere/src/gdb/hvisor_gdb_vebose.cpp
@@ -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 .
+ */
+
+/*
+* 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");
+ }
+
+}
diff --git a/thermosphere/src/gdb/hvisor_gdb_xfer.cpp b/thermosphere/src/gdb/hvisor_gdb_xfer.cpp
index 9e83bdb31..2c6866d08 100644
--- a/thermosphere/src/gdb/hvisor_gdb_xfer.cpp
+++ b/thermosphere/src/gdb/hvisor_gdb_xfer.cpp
@@ -134,10 +134,10 @@ namespace ams::hvisor::gdb {
// Run command
if (cmd == "features") {
- return HandleXferFeatures(isWrite, annex, off, len);
+ return GDB_XFER_HANDLER(Features)(isWrite, annex, off, len);
} else {
return HandleUnsupported();
}
}
-}
\ No newline at end of file
+}
diff --git a/thermosphere/src/gdb/verbose.c b/thermosphere/src/gdb/verbose.c
deleted file mode 100644
index 753cfa072..000000000
--- a/thermosphere/src/gdb/verbose.c
+++ /dev/null
@@ -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
-
-#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));
-}
diff --git a/thermosphere/src/gdb/verbose.h b/thermosphere/src/gdb/verbose.h
deleted file mode 100644
index 67b85f914..000000000
--- a/thermosphere/src/gdb/verbose.h
+++ /dev/null
@@ -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);
diff --git a/thermosphere/src/gdb/xfer.h b/thermosphere/src/gdb/xfer.h
deleted file mode 100644
index 901f9b35c..000000000
--- a/thermosphere/src/gdb/xfer.h
+++ /dev/null
@@ -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"
-