diff --git a/resources/gdbHelpMonitorInfo.txt b/resources/gdbHelpMonitorInfo.txt new file mode 100644 index 00000000..42083e88 --- /dev/null +++ b/resources/gdbHelpMonitorInfo.txt @@ -0,0 +1,7 @@ +Supported Bloom commands: + + help Displays this help text. + version Outputs Bloom's version information. + version machine Outputs Bloom's version information in JSON format. + + reset Resets the target and holds it in a stopped state. diff --git a/src/DebugServer/CMakeLists.txt b/src/DebugServer/CMakeLists.txt index a9a8bbf9..ccac480c 100755 --- a/src/DebugServer/CMakeLists.txt +++ b/src/DebugServer/CMakeLists.txt @@ -19,6 +19,7 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/RemoveBreakpoint.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/Monitor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/ResetTarget.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/HelpMonitorInfo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/BloomVersion.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/BloomVersionMachine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/ResponsePackets/SupportedFeaturesResponse.cpp diff --git a/src/DebugServer/Gdb/CommandPackets/HelpMonitorInfo.cpp b/src/DebugServer/Gdb/CommandPackets/HelpMonitorInfo.cpp new file mode 100644 index 00000000..c4f0243b --- /dev/null +++ b/src/DebugServer/Gdb/CommandPackets/HelpMonitorInfo.cpp @@ -0,0 +1,51 @@ +#include "HelpMonitorInfo.hpp" + +#include +#include + +#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp" +#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp" + +#include "src/Helpers/Paths.hpp" +#include "src/Logger/Logger.hpp" +#include "src/Exceptions/Exception.hpp" + +namespace Bloom::DebugServer::Gdb::CommandPackets +{ + using TargetController::TargetControllerConsole; + + using ResponsePackets::ErrorResponsePacket; + using ResponsePackets::ResponsePacket; + + using Exceptions::Exception; + + HelpMonitorInfo::HelpMonitorInfo(Monitor&& monitorPacket) + : Monitor(std::move(monitorPacket)) + {} + + void HelpMonitorInfo::handle(DebugSession& debugSession, TargetControllerConsole&) { + Logger::debug("Handling HelpMonitorInfo packet"); + + try { + // The file gdbHelpMonitorInfo.txt is included in the binary image as a resource. See src/resource.qrc + auto helpFile = QFile( + QString::fromStdString(Paths::compiledResourcesPath() + "/resources/gdbHelpMonitorInfo.txt") + ); + + if (!helpFile.open(QIODevice::ReadOnly)) { + throw Exception( + "Failed to open GDB monitor info help file - please report this issue at " + Paths::homeDomainName() + + "/report-issue" + ); + } + + debugSession.connection.writePacket( + ResponsePacket(Packet::toHex("\n" + QTextStream(&helpFile).readAll().toUtf8().toStdString() + "\n")) + ); + + } catch (const Exception& exception) { + Logger::error(exception.getMessage()); + debugSession.connection.writePacket(ErrorResponsePacket()); + } + } +} diff --git a/src/DebugServer/Gdb/CommandPackets/HelpMonitorInfo.hpp b/src/DebugServer/Gdb/CommandPackets/HelpMonitorInfo.hpp new file mode 100644 index 00000000..4cf8ecd9 --- /dev/null +++ b/src/DebugServer/Gdb/CommandPackets/HelpMonitorInfo.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "Monitor.hpp" + +namespace Bloom::DebugServer::Gdb::CommandPackets +{ + /** + * The HelpMonitorInfo class implements a structure for the "monitor help" GDB command. + * + * We just respond with some help info on the available "monitor" commands. + */ + class HelpMonitorInfo: public Monitor + { + public: + explicit HelpMonitorInfo(Monitor&& monitorPacket); + + void handle( + DebugSession& debugSession, + TargetController::TargetControllerConsole& targetControllerConsole + ) override; + }; +} diff --git a/src/DebugServer/Gdb/GdbRspDebugServer.cpp b/src/DebugServer/Gdb/GdbRspDebugServer.cpp index c5bef2f3..66317857 100644 --- a/src/DebugServer/Gdb/GdbRspDebugServer.cpp +++ b/src/DebugServer/Gdb/GdbRspDebugServer.cpp @@ -26,6 +26,7 @@ #include "CommandPackets/RemoveBreakpoint.hpp" #include "CommandPackets/Monitor.hpp" #include "CommandPackets/ResetTarget.hpp" +#include "CommandPackets/HelpMonitorInfo.hpp" #include "CommandPackets/BloomVersion.hpp" #include "CommandPackets/BloomVersionMachine.hpp" @@ -296,6 +297,10 @@ namespace Bloom::DebugServer::Gdb // This is a monitor packet auto monitorCommand = std::make_unique(rawPacket); + if (monitorCommand->command == "help") { + return std::make_unique(std::move(*(monitorCommand.get()))); + } + if (monitorCommand->command == "version") { return std::make_unique(std::move(*(monitorCommand.get()))); } diff --git a/src/resources.qrc b/src/resources.qrc index 29eccaec..1917ecac 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -13,6 +13,9 @@ ../resources/help.txt + + ../resources/gdbHelpMonitorInfo.txt + ../resources/bloom.template.json