Replaced ResumeTargetExecution event with TC command

This commit is contained in:
Nav
2022-04-19 21:12:59 +01:00
parent fa4f5e3427
commit 5da06f22d1
8 changed files with 58 additions and 69 deletions

View File

@@ -15,7 +15,6 @@ namespace Bloom::Events
enum class EventType: std::uint8_t
{
GENERIC,
RESUME_TARGET_EXECUTION,
RESET_TARGET,
DEBUG_SESSION_STARTED,
DEBUG_SESSION_FINISHED,

View File

@@ -3,7 +3,6 @@
#include <memory>
#include "Event.hpp"
#include "ResumeTargetExecution.hpp"
#include "ResetTarget.hpp"
#include "DebugSessionStarted.hpp"
#include "DebugSessionFinished.hpp"

View File

@@ -1,31 +0,0 @@
#pragma once
#include <cstdint>
#include <string>
#include "Event.hpp"
#include "TargetExecutionResumed.hpp"
namespace Bloom::Events
{
class ResumeTargetExecution: public Event
{
public:
using TargetControllerResponseType = TargetExecutionResumed;
static constexpr EventType type = EventType::RESUME_TARGET_EXECUTION;
static inline const std::string name = "ResumeTargetExecutionEvent";
std::optional<std::uint32_t> fromProgramCounter;
ResumeTargetExecution() = default;
explicit ResumeTargetExecution(std::uint32_t fromProgramCounter): fromProgramCounter(fromProgramCounter) {};
[[nodiscard]] EventType getType() const override {
return ResumeTargetExecution::type;
}
[[nodiscard]] std::string getName() const override {
return ResumeTargetExecution::name;
}
};
}

View File

@@ -8,5 +8,6 @@ namespace Bloom::TargetController::Commands
{
GENERIC,
STOP_TARGET_EXECUTION,
RESUME_TARGET_EXECUTION,
};
}

View File

@@ -0,0 +1,24 @@
#pragma once
#include "Command.hpp"
namespace Bloom::TargetController::Commands
{
class ResumeTargetExecution: public Command
{
public:
static constexpr CommandType type = CommandType::RESUME_TARGET_EXECUTION;
static inline const std::string name = "ResumeTargetExecution";
std::optional<std::uint32_t> fromProgramCounter;
ResumeTargetExecution() = default;
explicit ResumeTargetExecution(std::uint32_t fromProgramCounter)
: fromProgramCounter(fromProgramCounter)
{};
[[nodiscard]] CommandType getType() const override {
return ResumeTargetExecution::type;
}
};
}

View File

@@ -23,6 +23,7 @@ namespace Bloom::TargetController
using Commands::Command;
using Commands::CommandIdType;
using Commands::StopTargetExecution;
using Commands::ResumeTargetExecution;
using Responses::Response;
@@ -370,11 +371,11 @@ namespace Bloom::TargetController
}
this->deregisterCommandHandler(StopTargetExecution::type);
this->deregisterCommandHandler(ResumeTargetExecution::type);
this->eventListener->deregisterCallbacksForEventType<Events::DebugSessionFinished>();
this->eventListener->deregisterCallbacksForEventType<Events::ExtractTargetDescriptor>();
this->eventListener->deregisterCallbacksForEventType<Events::StepTargetExecution>();
this->eventListener->deregisterCallbacksForEventType<Events::ResumeTargetExecution>();
this->eventListener->deregisterCallbacksForEventType<Events::RetrieveRegistersFromTarget>();
this->eventListener->deregisterCallbacksForEventType<Events::WriteRegistersToTarget>();
this->eventListener->deregisterCallbacksForEventType<Events::RetrieveMemoryFromTarget>();
@@ -406,6 +407,10 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::handleStopTargetExecution, this, std::placeholders::_1)
);
this->registerCommandHandler<ResumeTargetExecution>(
std::bind(&TargetControllerComponent::handleResumeTargetExecution, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::DebugSessionFinished>(
std::bind(&TargetControllerComponent::onDebugSessionFinishedEvent, this, std::placeholders::_1)
);
@@ -418,10 +423,6 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::onStepTargetExecutionEvent, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::ResumeTargetExecution>(
std::bind(&TargetControllerComponent::onResumeTargetExecutionEvent, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::RetrieveRegistersFromTarget>(
std::bind(&TargetControllerComponent::onReadRegistersEvent, this, std::placeholders::_1)
);
@@ -741,6 +742,23 @@ namespace Bloom::TargetController
return std::make_unique<Response>();
}
std::unique_ptr<Responses::Response> TargetControllerComponent::handleResumeTargetExecution(
ResumeTargetExecution& command
) {
if (this->target->getState() != TargetState::RUNNING) {
if (command.fromProgramCounter.has_value()) {
this->target->setProgramCounter(command.fromProgramCounter.value());
}
this->target->run();
this->lastTargetState = TargetState::RUNNING;
}
EventManager::triggerEvent(std::make_shared<Events::TargetExecutionResumed>());
return std::make_unique<Response>();
}
void TargetControllerComponent::onStepTargetExecutionEvent(const Events::StepTargetExecution& event) {
try {
if (this->target->getState() != TargetState::STOPPED) {
@@ -765,27 +783,6 @@ namespace Bloom::TargetController
}
}
void TargetControllerComponent::onResumeTargetExecutionEvent(const Events::ResumeTargetExecution& event) {
try {
if (this->target->getState() != TargetState::RUNNING) {
if (event.fromProgramCounter.has_value()) {
this->target->setProgramCounter(event.fromProgramCounter.value());
}
this->target->run();
this->lastTargetState = TargetState::RUNNING;
}
auto executionResumedEvent = std::make_shared<Events::TargetExecutionResumed>();
executionResumedEvent->correlationId = event.id;
EventManager::triggerEvent(executionResumedEvent);
} catch (const TargetOperationFailure& exception) {
Logger::error("Failed to resume execution on target - " + exception.getMessage());
this->emitErrorEvent(event.id, exception.getMessage());
}
}
void TargetControllerComponent::onReadRegistersEvent(const Events::RetrieveRegistersFromTarget& event) {
try {
auto registers = this->target->readRegisters(event.descriptors);

View File

@@ -18,6 +18,7 @@
// Commands
#include "Commands/Command.hpp"
#include "Commands/StopTargetExecution.hpp"
#include "Commands/ResumeTargetExecution.hpp"
// Responses
#include "Responses/Response.hpp"
@@ -289,6 +290,7 @@ namespace Bloom::TargetController
void onDebugSessionFinishedEvent(const Events::DebugSessionFinished& event);
std::unique_ptr<Responses::Response> handleStopTargetExecution(Commands::StopTargetExecution& command);
std::unique_ptr<Responses::Response> handleResumeTargetExecution(Commands::ResumeTargetExecution& command);
/**
* Will attempt to step execution on the target and emit a TargetExecutionResumed event.
@@ -297,13 +299,6 @@ namespace Bloom::TargetController
*/
void onStepTargetExecutionEvent(const Events::StepTargetExecution& event);
/**
* Will attempt to resume execution on the target and emit a TargetExecutionResumed event.
*
* @param event
*/
void onResumeTargetExecutionEvent(const Events::ResumeTargetExecution& event);
/**
* Will attempt to read the requested registers and emit a RegistersRetrievedFromTarget event.
*

View File

@@ -4,6 +4,7 @@
// Commands
#include "Commands/StopTargetExecution.hpp"
#include "Commands/ResumeTargetExecution.hpp"
#include "src/Logger/Logger.hpp"
@@ -14,6 +15,7 @@ namespace Bloom::TargetController
using namespace Bloom::Exceptions;
using Commands::StopTargetExecution;
using Commands::ResumeTargetExecution;
TargetControllerConsole::TargetControllerConsole(EventListener& eventListener)
: eventListener(eventListener)
@@ -48,13 +50,16 @@ namespace Bloom::TargetController
}
void TargetControllerConsole::continueTargetExecution(std::optional<std::uint32_t> fromAddress) {
auto resumeExecutionEvent = std::make_shared<ResumeTargetExecution>();
auto resumeExecutionCommand = std::make_unique<ResumeTargetExecution>();
if (fromAddress.has_value()) {
resumeExecutionEvent->fromProgramCounter = fromAddress.value();
resumeExecutionCommand->fromProgramCounter = fromAddress.value();
}
this->triggerTargetControllerEventAndWaitForResponse(resumeExecutionEvent);
this->commandManager.sendCommandAndWaitForResponse(
std::move(resumeExecutionCommand),
this->defaultTimeout
);
}
void TargetControllerConsole::stepTargetExecution(std::optional<std::uint32_t> fromAddress) {