Tidying
This commit is contained in:
@@ -29,7 +29,7 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
|
||||
|
||||
ContinueExecution(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {
|
||||
init();
|
||||
};
|
||||
}
|
||||
|
||||
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
|
||||
class InterruptExecution: public CommandPacket
|
||||
{
|
||||
public:
|
||||
InterruptExecution(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {};
|
||||
InterruptExecution(std::vector<unsigned char> rawPacket): CommandPacket(rawPacket) {}
|
||||
|
||||
virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override;
|
||||
};
|
||||
|
||||
@@ -202,7 +202,6 @@ std::vector<std::unique_ptr<CommandPacket>> Connection::readPackets() {
|
||||
} catch (const Exception& exception) {
|
||||
Logger::error("Failed to parse GDB packet - " + exception.getMessage());
|
||||
this->write({'-'});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -354,7 +354,7 @@ void EdbgAvr8Interface::activatePhysical(bool applyExternalReset) {
|
||||
return this->activatePhysical(true);
|
||||
|
||||
} else {
|
||||
throw Exception("Activate physical interface command failed");
|
||||
throw Avr8CommandFailure("Activate physical interface command failed", response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -204,8 +204,8 @@ void InsightWindow::deactivate() {
|
||||
}
|
||||
|
||||
this->ioUnavailableWidget->setText(
|
||||
"Insight deactivated - Bloom has been disconnected from the target.\n"
|
||||
"Bloom will attempt to reconnect upon the start of a debug session."
|
||||
"Insight deactivated - Bloom has been disconnected from the target.\n\n"
|
||||
"Bloom will attempt to reconnect upon the start of a new debug session."
|
||||
);
|
||||
this->ioUnavailableWidget->show();
|
||||
|
||||
|
||||
@@ -7,31 +7,6 @@
|
||||
|
||||
using namespace Bloom;
|
||||
|
||||
void SignalHandler::run() {
|
||||
try {
|
||||
this->startup();
|
||||
auto signalSet = this->getRegisteredSignalSet();
|
||||
int signalNumber = 0;
|
||||
|
||||
Logger::debug("SignalHandler ready");
|
||||
while(Thread::getThreadState() == ThreadState::READY) {
|
||||
if (sigwait(&signalSet, &signalNumber) == 0) {
|
||||
Logger::debug("SIGNAL " + std::to_string(signalNumber) + " received");
|
||||
if (this->handlersMappedBySignalNum.contains(signalNumber)) {
|
||||
// We have a registered handler for this signal.
|
||||
this->handlersMappedBySignalNum.at(signalNumber)();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (std::exception& exception) {
|
||||
Logger::error("SignalHandler fatal error: " + std::string(exception.what()));
|
||||
}
|
||||
|
||||
Logger::debug("SignalHandler shutting down");
|
||||
Thread::setThreadState(ThreadState::STOPPED);
|
||||
}
|
||||
|
||||
void SignalHandler::startup() {
|
||||
this->setName("SH");
|
||||
Thread::setThreadState(ThreadState::STARTING);
|
||||
@@ -57,6 +32,31 @@ void SignalHandler::startup() {
|
||||
}
|
||||
}
|
||||
|
||||
void SignalHandler::run() {
|
||||
try {
|
||||
this->startup();
|
||||
auto signalSet = this->getRegisteredSignalSet();
|
||||
int signalNumber = 0;
|
||||
|
||||
Logger::debug("SignalHandler ready");
|
||||
while(Thread::getThreadState() == ThreadState::READY) {
|
||||
if (sigwait(&signalSet, &signalNumber) == 0) {
|
||||
Logger::debug("SIGNAL " + std::to_string(signalNumber) + " received");
|
||||
if (this->handlersMappedBySignalNum.contains(signalNumber)) {
|
||||
// We have a registered handler for this signal.
|
||||
this->handlersMappedBySignalNum.at(signalNumber)();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (std::exception& exception) {
|
||||
Logger::error("SignalHandler fatal error: " + std::string(exception.what()));
|
||||
}
|
||||
|
||||
Logger::info("Shutting down SignalHandler");
|
||||
Thread::setThreadState(ThreadState::STOPPED);
|
||||
}
|
||||
|
||||
sigset_t SignalHandler::getRegisteredSignalSet() const {
|
||||
sigset_t set = {};
|
||||
if (sigfillset(&set) == -1) {
|
||||
|
||||
@@ -18,6 +18,17 @@ namespace Bloom
|
||||
*/
|
||||
std::map<int, std::function<void()>> handlersMappedBySignalNum;
|
||||
|
||||
/**
|
||||
* We keep record of the number of shutdown signals received. See definition of triggerApplicationShutdown()
|
||||
* for more on this.
|
||||
*/
|
||||
int shutdownSignalsReceived = 0;
|
||||
|
||||
/**
|
||||
* Initiates the SignalHandler thread.
|
||||
*/
|
||||
void startup();
|
||||
|
||||
/**
|
||||
* Fetches all signals currently of interest to the application.
|
||||
*
|
||||
@@ -28,10 +39,12 @@ namespace Bloom
|
||||
sigset_t getRegisteredSignalSet() const;
|
||||
|
||||
/**
|
||||
* We keep record of the number of shutdown signals received. See definition of triggerApplicationShutdown()
|
||||
* for more on this.
|
||||
* Handler for SIGINT, SIGTERM, etc signals.
|
||||
*
|
||||
* Will trigger a ShutdownApplication event to kick-off a clean shutdown or it will terminate the
|
||||
* program immediately if numerous SIGINT signals have been received.
|
||||
*/
|
||||
int shutdownSignalsReceived = 0;
|
||||
void triggerApplicationShutdown();
|
||||
|
||||
public:
|
||||
SignalHandler(EventManager& eventManager): eventManager(eventManager) {};
|
||||
@@ -41,24 +54,11 @@ namespace Bloom
|
||||
*/
|
||||
void run();
|
||||
|
||||
/**
|
||||
* Initiates the SignalHandler thread.
|
||||
*/
|
||||
void startup();
|
||||
|
||||
/**
|
||||
* Triggers the shutdown of the SignalHandler thread.
|
||||
*/
|
||||
void triggerShutdown() {
|
||||
this->setThreadState(ThreadState::SHUTDOWN_INITIATED);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handler for SIGINT, SIGTERM, etc signals.
|
||||
*
|
||||
* Will trigger a ShutdownApplication event to kick-off a clean shutdown or it will terminate the
|
||||
* program immediately if numerous SIGINT signals have been received.
|
||||
*/
|
||||
void triggerApplicationShutdown();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ void TargetController::shutdown() {
|
||||
try {
|
||||
Logger::info("Shutting down TargetController");
|
||||
this->eventManager.deregisterListener(this->eventListener->getId());
|
||||
this->releaseResources();
|
||||
this->releaseHardware();
|
||||
|
||||
} catch (const std::exception& exception) {
|
||||
Logger::error("Failed to properly shutdown TargetController. Error: " + std::string(exception.what()));
|
||||
@@ -140,7 +140,7 @@ void TargetController::suspend() {
|
||||
Logger::debug("Suspending TargetController");
|
||||
|
||||
try {
|
||||
this->releaseResources();
|
||||
this->releaseHardware();
|
||||
|
||||
} catch (const std::exception& exception) {
|
||||
Logger::error("Failed to release connected debug tool and target resources. Error: "
|
||||
@@ -175,7 +175,7 @@ void TargetController::suspend() {
|
||||
}
|
||||
|
||||
void TargetController::resume() {
|
||||
this->acquireResources();
|
||||
this->acquireHardware();
|
||||
|
||||
this->eventListener->registerCallbackForEventType<Events::DebugSessionFinished>(
|
||||
std::bind(&TargetController::onDebugSessionFinishedEvent, this, std::placeholders::_1)
|
||||
@@ -248,7 +248,7 @@ void TargetController::resume() {
|
||||
}
|
||||
}
|
||||
|
||||
void TargetController::acquireResources() {
|
||||
void TargetController::acquireHardware() {
|
||||
auto debugToolName = this->environmentConfig.debugToolConfig.name;
|
||||
auto targetName = this->environmentConfig.targetConfig.name;
|
||||
|
||||
@@ -311,7 +311,7 @@ void TargetController::acquireResources() {
|
||||
Logger::info("Target name: " + this->target->getName());
|
||||
}
|
||||
|
||||
void TargetController::releaseResources() {
|
||||
void TargetController::releaseHardware() {
|
||||
auto target = this->getTarget();
|
||||
auto debugTool = this->getDebugTool();
|
||||
|
||||
@@ -360,7 +360,7 @@ void TargetController::emitErrorEvent(int correlationId) {
|
||||
this->eventManager.triggerEvent(errorEvent);
|
||||
}
|
||||
|
||||
void TargetController::onShutdownTargetControllerEvent(EventPointer<Events::ShutdownTargetController> event) {
|
||||
void TargetController::onShutdownTargetControllerEvent(EventPointer<Events::ShutdownTargetController>) {
|
||||
this->shutdown();
|
||||
}
|
||||
|
||||
|
||||
@@ -183,19 +183,33 @@ namespace Bloom
|
||||
/**
|
||||
* Exit point - must be called before the TargetController thread is terminated.
|
||||
*
|
||||
* Handles deactivating the target among other clean-up related things.
|
||||
* Handles releasing the hardware among other clean-up related things.
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* Establishes a connection with the debug tool and target. Prepares the hardware for a debug session.
|
||||
*/
|
||||
void acquireHardware();
|
||||
|
||||
/**
|
||||
* Attempts to gracefully disconnect from the debug tool and the target. All control of the debug tool and
|
||||
* target will cease.
|
||||
*/
|
||||
void releaseHardware();
|
||||
|
||||
/**
|
||||
* Puts the TargetController into the suspended state.
|
||||
*
|
||||
* In this state, the hardware is released and the TargetController will only handle a subset of events.
|
||||
*/
|
||||
void suspend();
|
||||
|
||||
/**
|
||||
* Wakes the TargetController from the suspended state.
|
||||
*/
|
||||
void resume();
|
||||
|
||||
void acquireResources();
|
||||
|
||||
void releaseResources();
|
||||
|
||||
/**
|
||||
* Should fire any events queued on the target.
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ TargetControllerState TargetControllerConsole::getTargetControllerState() {
|
||||
|
||||
if (!responseEvent.has_value()
|
||||
|| !std::holds_alternative<EventPointer<Events::TargetControllerStateReported>>(responseEvent.value())
|
||||
) {
|
||||
) {
|
||||
throw Exception("Unexpected response from TargetController");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user