diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ca820ba..fa09d800 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,18 +48,29 @@ if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") endif() add_executable(Bloom - src/main.cpp src/Generated/resources.cpp - src/ApplicationConfig.cpp - src/Logger/Logger.cpp + + src/main.cpp + src/Application.cpp + src/TargetController/TargetController.cpp + src/DebugServers/DebugServer.cpp + src/Insight/Insight.cpp + src/Insight/InsightWorker.cpp src/SignalHandler/SignalHandler.cpp + + src/EventManager/EventListener.cpp + src/EventManager/EventManager.cpp + src/ApplicationConfig.cpp + src/TargetController/TargetControllerConsole.cpp + src/Logger/Logger.cpp + src/Helpers/Paths.cpp + + src/DebugToolDrivers/USB/UsbDevice.cpp src/DebugToolDrivers/USB/Interface.cpp src/DebugToolDrivers/USB/HID/HidInterface.cpp - src/DebugToolDrivers/Microchip/AtmelICE/AtmelIce.cpp src/DebugToolDrivers/Microchip/PowerDebugger/PowerDebugger.cpp src/DebugToolDrivers/Microchip/MplabSnap/MplabSnap.cpp - src/DebugToolDrivers/Protocols/CMSIS-DAP/Command.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/Response.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/AvrCommand.cpp @@ -71,18 +82,15 @@ add_executable(Bloom src/DebugToolDrivers/Protocols/CMSIS-DAP/CmsisDapInterface.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/EdbgInterface.cpp src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp + src/Targets/Target.cpp src/Targets/Microchip/AVR/AVR8/Avr8.cpp src/Targets/Microchip/AVR/AVR8/Mega/Mega.cpp src/Targets/Microchip/AVR/AVR8/PartDescription/PartDescriptionFile.cpp - src/Application.cpp - src/DebugToolDrivers/USB/UsbDevice.cpp - src/TargetController/TargetController.cpp - src/TargetController/TargetControllerConsole.cpp - src/EventManager/EventListener.cpp - src/EventManager/EventManager.cpp - src/DebugServers/DebugServer.cpp + build/resources/TargetPartDescriptions/AVR/Mapping.json + src/DebugServers/GdbRsp/GdbRspDebugServer.cpp + src/DebugServers/GdbRsp/Connection.cpp src/DebugServers/GdbRsp/CommandPackets/CommandPacket.cpp src/DebugServers/GdbRsp/CommandPackets/CommandPacketFactory.cpp src/DebugServers/GdbRsp/CommandPackets/SupportedFeaturesQuery.cpp @@ -96,24 +104,19 @@ add_executable(Bloom src/DebugServers/GdbRsp/CommandPackets/SetBreakpoint.cpp src/DebugServers/GdbRsp/CommandPackets/RemoveBreakpoint.cpp src/DebugServers/GdbRsp/ResponsePackets/SupportedFeaturesResponse.cpp - src/DebugServers/GdbRsp/Connection.cpp - src/Insight/Insight.cpp - src/Insight/InsightWorker.cpp + src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp src/Insight/UserInterfaces/InsightWindow/TargetWidgets/TargetPackageWidget.hpp src/Insight/UserInterfaces/InsightWindow/TargetWidgets/TargetPinWidget.hpp - src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/DualInlinePackageWidget.cpp src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinWidget.cpp src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinBodyWidget.cpp src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/BodyWidget.cpp - src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/QuadFlatPackageWidget.cpp src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinWidget.cpp src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinBodyWidget.cpp src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/BodyWidget.cpp - build/resources/TargetPartDescriptions/AVR/Mapping.json ) set_target_properties(Bloom PROPERTIES OUTPUT_NAME bloom) diff --git a/src/DebugServers/GdbRsp/CommandPackets/ContinueExecution.hpp b/src/DebugServers/GdbRsp/CommandPackets/ContinueExecution.hpp index ec9478e5..76adcb58 100644 --- a/src/DebugServers/GdbRsp/CommandPackets/ContinueExecution.hpp +++ b/src/DebugServers/GdbRsp/CommandPackets/ContinueExecution.hpp @@ -29,7 +29,7 @@ namespace Bloom::DebugServers::Gdb::CommandPackets ContinueExecution(std::vector rawPacket): CommandPacket(rawPacket) { init(); - }; + } virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override; }; diff --git a/src/DebugServers/GdbRsp/CommandPackets/InterruptExecution.hpp b/src/DebugServers/GdbRsp/CommandPackets/InterruptExecution.hpp index 5f97c55c..f53d8fb8 100644 --- a/src/DebugServers/GdbRsp/CommandPackets/InterruptExecution.hpp +++ b/src/DebugServers/GdbRsp/CommandPackets/InterruptExecution.hpp @@ -15,7 +15,7 @@ namespace Bloom::DebugServers::Gdb::CommandPackets class InterruptExecution: public CommandPacket { public: - InterruptExecution(std::vector rawPacket): CommandPacket(rawPacket) {}; + InterruptExecution(std::vector rawPacket): CommandPacket(rawPacket) {} virtual void dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) override; }; diff --git a/src/DebugServers/GdbRsp/Connection.cpp b/src/DebugServers/GdbRsp/Connection.cpp index e51c3f1d..348059db 100644 --- a/src/DebugServers/GdbRsp/Connection.cpp +++ b/src/DebugServers/GdbRsp/Connection.cpp @@ -202,7 +202,6 @@ std::vector> Connection::readPackets() { } catch (const Exception& exception) { Logger::error("Failed to parse GDB packet - " + exception.getMessage()); this->write({'-'}); - } } diff --git a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp index 7ed971b8..4a350a8f 100644 --- a/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp +++ b/src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/EdbgAvr8Interface.cpp @@ -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); } } diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp index afafc7cf..e76fe130 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp @@ -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(); diff --git a/src/SignalHandler/SignalHandler.cpp b/src/SignalHandler/SignalHandler.cpp index 0dafb663..8197a8d2 100644 --- a/src/SignalHandler/SignalHandler.cpp +++ b/src/SignalHandler/SignalHandler.cpp @@ -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) { diff --git a/src/SignalHandler/SignalHandler.hpp b/src/SignalHandler/SignalHandler.hpp index 96f7db83..abf20213 100644 --- a/src/SignalHandler/SignalHandler.hpp +++ b/src/SignalHandler/SignalHandler.hpp @@ -18,6 +18,17 @@ namespace Bloom */ std::map> 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(); }; } diff --git a/src/TargetController/TargetController.cpp b/src/TargetController/TargetController.cpp index 8349e792..d7ccb2de 100644 --- a/src/TargetController/TargetController.cpp +++ b/src/TargetController/TargetController.cpp @@ -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( 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 event) { +void TargetController::onShutdownTargetControllerEvent(EventPointer) { this->shutdown(); } diff --git a/src/TargetController/TargetController.hpp b/src/TargetController/TargetController.hpp index 1b2a84f5..d1161753 100644 --- a/src/TargetController/TargetController.hpp +++ b/src/TargetController/TargetController.hpp @@ -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. */ diff --git a/src/TargetController/TargetControllerConsole.cpp b/src/TargetController/TargetControllerConsole.cpp index eb79d47d..7b8a228c 100644 --- a/src/TargetController/TargetControllerConsole.cpp +++ b/src/TargetController/TargetControllerConsole.cpp @@ -19,7 +19,7 @@ TargetControllerState TargetControllerConsole::getTargetControllerState() { if (!responseEvent.has_value() || !std::holds_alternative>(responseEvent.value()) - ) { + ) { throw Exception("Unexpected response from TargetController"); }