This commit is contained in:
Nav
2021-05-31 00:03:57 +01:00
parent f7944ac6b4
commit 08914372b9
11 changed files with 93 additions and 77 deletions

View File

@@ -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)

View File

@@ -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;
};

View File

@@ -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;
};

View File

@@ -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({'-'});
}
}

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -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) {

View File

@@ -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();
};
}

View File

@@ -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();
}

View File

@@ -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.
*/

View File

@@ -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");
}