From 138b45f8bd90ba31d7449458a3daf20c6c4d9b28 Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 10 Apr 2021 21:56:25 +0100 Subject: [PATCH] Small tweaks to port number extract in GDB RSP debug server. Also included port and address configuration in template config file --- resources/bloom.template.json | 4 +++- src/DebugServers/GdbRsp/GdbRspDebugServer.cpp | 12 ++++++++---- src/DebugServers/GdbRsp/GdbRspDebugServer.hpp | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/resources/bloom.template.json b/resources/bloom.template.json index 3cba6321..fa0a4899 100644 --- a/resources/bloom.template.json +++ b/resources/bloom.template.json @@ -9,7 +9,9 @@ }, "debugServer": { - "name": "avr-gdb-rsp" + "name": "avr-gdb-rsp", + "ipAddress": "127.0.0.1", + "port": "1442" } } }, diff --git a/src/DebugServers/GdbRsp/GdbRspDebugServer.cpp b/src/DebugServers/GdbRsp/GdbRspDebugServer.cpp index 9410b0f9..74d4ffeb 100644 --- a/src/DebugServers/GdbRsp/GdbRspDebugServer.cpp +++ b/src/DebugServers/GdbRsp/GdbRspDebugServer.cpp @@ -15,14 +15,17 @@ using namespace Exceptions; void GdbRspDebugServer::init() { auto ipAddress = this->debugServerConfig.jsonObject.find("ipAddress")->toString().toStdString(); - auto port = static_cast(this->debugServerConfig.jsonObject.find("port")->toInt()); + auto configPortJsonValue = this->debugServerConfig.jsonObject.find("port"); + auto configPortValue = configPortJsonValue->isString() + ? static_cast(configPortJsonValue->toString().toInt(nullptr, 10)) + : static_cast(configPortJsonValue->toInt()); if (!ipAddress.empty()) { this->listeningAddress = ipAddress; } - if (port > 0) { - this->listeningPortNumber = port; + if (configPortValue > 0) { + this->listeningPortNumber = configPortValue; } this->socketAddress.sin_family = AF_INET; @@ -55,7 +58,8 @@ void GdbRspDebugServer::init() { sizeof(this->socketAddress) ) < 0 ) { - throw Exception("Failed to bind address."); + throw Exception("Failed to bind address. The selected port number (" + + std::to_string(this->listeningPortNumber) + ") may be in use."); } this->serverSocketFileDescriptor = socketFileDescriptor; diff --git a/src/DebugServers/GdbRsp/GdbRspDebugServer.hpp b/src/DebugServers/GdbRsp/GdbRspDebugServer.hpp index b518bdca..a6b3edb0 100644 --- a/src/DebugServers/GdbRsp/GdbRspDebugServer.hpp +++ b/src/DebugServers/GdbRsp/GdbRspDebugServer.hpp @@ -45,7 +45,7 @@ namespace Bloom::DebugServers::Gdb * 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 = 1055; + std::uint16_t listeningPortNumber = 1442; /** * The address for the GDB server to listen on.