Applied new GdbDebugServerConfig object to GDB Debug Server implementation

This commit is contained in:
Nav
2022-03-19 15:16:59 +00:00
parent 18f08d8faa
commit e65f89caf1
2 changed files with 17 additions and 33 deletions

View File

@@ -285,27 +285,21 @@ namespace Bloom::DebugServers::Gdb
} }
void GdbRspDebugServer::init() { void GdbRspDebugServer::init() {
auto ipAddress = this->debugServerConfig.jsonObject.find("ipAddress")->toString().toStdString(); this->debugServerConfig = GdbDebugServerConfig(DebugServer::debugServerConfig);
auto configPortJsonValue = this->debugServerConfig.jsonObject.find("port");
auto configPortValue = configPortJsonValue->isString()
? static_cast<std::uint16_t>(configPortJsonValue->toString().toInt(nullptr, 10))
: static_cast<std::uint16_t>(configPortJsonValue->toInt());
if (!ipAddress.empty()) {
this->listeningAddress = ipAddress;
}
if (configPortValue > 0) {
this->listeningPortNumber = configPortValue;
}
this->socketAddress.sin_family = AF_INET; this->socketAddress.sin_family = AF_INET;
this->socketAddress.sin_port = htons(this->listeningPortNumber); this->socketAddress.sin_port = htons(this->debugServerConfig->listeningPortNumber);
if (::inet_pton(AF_INET, this->listeningAddress.c_str(), &(this->socketAddress.sin_addr)) == 0) { if (::inet_pton(
AF_INET,
this->debugServerConfig->listeningAddress.c_str(),
&(this->socketAddress.sin_addr)
) == 0
) {
// Invalid IP address // Invalid IP address
throw InvalidConfig( throw InvalidConfig(
"Invalid IP address provided in config file: (\"" + this->listeningAddress + "\")" "Invalid IP address provided in config file: (\"" + this->debugServerConfig->listeningAddress
+ "\")"
); );
} }
@@ -333,7 +327,7 @@ namespace Bloom::DebugServers::Gdb
) < 0 ) < 0
) { ) {
throw Exception("Failed to bind address. The selected port number (" throw Exception("Failed to bind address. The selected port number ("
+ std::to_string(this->listeningPortNumber) + ") may be in use."); + std::to_string(this->debugServerConfig->listeningPortNumber) + ") may be in use.");
} }
this->serverSocketFileDescriptor = socketFileDescriptor; this->serverSocketFileDescriptor = socketFileDescriptor;
@@ -357,8 +351,8 @@ namespace Bloom::DebugServers::Gdb
} }
} }
Logger::info("GDB RSP address: " + this->listeningAddress); Logger::info("GDB RSP address: " + this->debugServerConfig->listeningAddress);
Logger::info("GDB RSP port: " + std::to_string(this->listeningPortNumber)); Logger::info("GDB RSP port: " + std::to_string(this->debugServerConfig->listeningPortNumber));
this->eventListener->registerCallbackForEventType<Events::TargetControllerStateReported>( this->eventListener->registerCallbackForEventType<Events::TargetControllerStateReported>(
std::bind(&GdbRspDebugServer::onTargetControllerStateReported, this, std::placeholders::_1) std::bind(&GdbRspDebugServer::onTargetControllerStateReported, this, std::placeholders::_1)

View File

@@ -7,6 +7,9 @@
#include <cstdint> #include <cstdint>
#include "../DebugServer.hpp" #include "../DebugServer.hpp"
#include "GdbDebugServerConfig.hpp"
#include "Connection.hpp" #include "Connection.hpp"
#include "Signal.hpp" #include "Signal.hpp"
#include "RegisterDescriptor.hpp" #include "RegisterDescriptor.hpp"
@@ -127,20 +130,7 @@ namespace Bloom::DebugServers::Gdb
virtual void handleGdbPacket(CommandPackets::InterruptExecution& packet); virtual void handleGdbPacket(CommandPackets::InterruptExecution& packet);
protected: protected:
/** std::optional<GdbDebugServerConfig> debugServerConfig;
* The port number for the GDB server to listen on.
*
* This will be pulled from the user's project configuration, if set. Otherwise it will default to whatever is
* set here.
*/
std::uint16_t listeningPortNumber = 1442;
/**
* The address for the GDB server to listen on.
*
* Like the port number, this can also be pulled from the user's project configuration.
*/
std::string listeningAddress = "127.0.0.1";
/** /**
* Listening socket address * Listening socket address