Replaced StepTargetExecution event with TC command

This commit is contained in:
Nav
2022-04-29 22:12:09 +01:00
parent 3fc558f3e8
commit 76e189162e
8 changed files with 56 additions and 69 deletions

View File

@@ -34,7 +34,6 @@ namespace Bloom::Events
REMOVE_BREAKPOINT_ON_TARGET,
BREAKPOINT_SET_ON_TARGET,
BREAKPOINT_REMOVED_ON_TARGET,
STEP_TARGET_EXECUTION,
SET_PROGRAM_COUNTER_ON_TARGET,
PROGRAM_COUNTER_SET_ON_TARGET,
EXTRACT_TARGET_DESCRIPTOR,

View File

@@ -21,7 +21,6 @@
#include "RemoveBreakpointOnTarget.hpp"
#include "BreakpointSetOnTarget.hpp"
#include "BreakpointRemovedOnTarget.hpp"
#include "StepTargetExecution.hpp"
#include "SetProgramCounterOnTarget.hpp"
#include "ProgramCounterSetOnTarget.hpp"
#include "ExtractTargetDescriptor.hpp"

View File

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

View File

@@ -15,5 +15,6 @@ namespace Bloom::TargetController::Commands
WRITE_TARGET_REGISTERS,
READ_TARGET_MEMORY,
GET_TARGET_STATE,
STEP_TARGET_EXECUTION,
};
}

View File

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

View File

@@ -29,6 +29,7 @@ namespace Bloom::TargetController
using Commands::ReadTargetRegisters;
using Commands::WriteTargetRegisters;
using Commands::ReadTargetMemory;
using Commands::StepTargetExecution;
using Responses::Response;
using Responses::TargetRegistersRead;
@@ -388,10 +389,10 @@ namespace Bloom::TargetController
this->deregisterCommandHandler(ReadTargetRegisters::type);
this->deregisterCommandHandler(WriteTargetRegisters::type);
this->deregisterCommandHandler(ReadTargetMemory::type);
this->deregisterCommandHandler(StepTargetExecution::type);
this->eventListener->deregisterCallbacksForEventType<Events::DebugSessionFinished>();
this->eventListener->deregisterCallbacksForEventType<Events::ExtractTargetDescriptor>();
this->eventListener->deregisterCallbacksForEventType<Events::StepTargetExecution>();
this->eventListener->deregisterCallbacksForEventType<Events::WriteMemoryToTarget>();
this->eventListener->deregisterCallbacksForEventType<Events::SetBreakpointOnTarget>();
this->eventListener->deregisterCallbacksForEventType<Events::RemoveBreakpointOnTarget>();
@@ -444,6 +445,10 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::handleReadTargetMemory, this, std::placeholders::_1)
);
this->registerCommandHandler<StepTargetExecution>(
std::bind(&TargetControllerComponent::handleStepTargetExecution, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::DebugSessionFinished>(
std::bind(&TargetControllerComponent::onDebugSessionFinishedEvent, this, std::placeholders::_1)
);
@@ -452,10 +457,6 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::onExtractTargetDescriptor, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::StepTargetExecution>(
std::bind(&TargetControllerComponent::onStepTargetExecutionEvent, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::WriteMemoryToTarget>(
std::bind(&TargetControllerComponent::onWriteMemoryEvent, this, std::placeholders::_1)
);
@@ -798,28 +799,16 @@ namespace Bloom::TargetController
));
}
void TargetControllerComponent::onStepTargetExecutionEvent(const Events::StepTargetExecution& event) {
try {
if (this->target->getState() != TargetState::STOPPED) {
// We can't step the target if it's already running.
throw TargetOperationFailure("Target is already running");
}
if (event.fromProgramCounter.has_value()) {
this->target->setProgramCounter(event.fromProgramCounter.value());
}
this->target->step();
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 step execution on target - " + exception.getMessage());
this->emitErrorEvent(event.id, exception.getMessage());
std::unique_ptr<Response> TargetControllerComponent::handleStepTargetExecution(StepTargetExecution& command) {
if (command.fromProgramCounter.has_value()) {
this->target->setProgramCounter(command.fromProgramCounter.value());
}
this->target->step();
this->lastTargetState = TargetState::RUNNING;
EventManager::triggerEvent(std::make_shared<Events::TargetExecutionResumed>());
return std::make_unique<Response>();
}
void TargetControllerComponent::onWriteMemoryEvent(const Events::WriteMemoryToTarget& event) {

View File

@@ -25,6 +25,7 @@
#include "Commands/ReadTargetRegisters.hpp"
#include "Commands/WriteTargetRegisters.hpp"
#include "Commands/ReadTargetMemory.hpp"
#include "Commands/StepTargetExecution.hpp"
// Responses
#include "Responses/Response.hpp"
@@ -302,13 +303,7 @@ namespace Bloom::TargetController
);
std::unique_ptr<Responses::Response> handleWriteTargetRegisters(Commands::WriteTargetRegisters& command);
std::unique_ptr<Responses::TargetMemoryRead> handleReadTargetMemory(Commands::ReadTargetMemory& command);
/**
* Will attempt to step execution on the target and emit a TargetExecutionResumed event.
*
* @param event
*/
void onStepTargetExecutionEvent(const Events::StepTargetExecution& event);
std::unique_ptr<Responses::Response> handleStepTargetExecution(Commands::StepTargetExecution& command);
/**
* Will attempt to write memory to the target. On success, a MemoryWrittenToTarget event is emitted.

View File

@@ -12,6 +12,7 @@
#include "Commands/ReadTargetRegisters.hpp"
#include "Commands/WriteTargetRegisters.hpp"
#include "Commands/ReadTargetMemory.hpp"
#include "Commands/StepTargetExecution.hpp"
#include "src/Logger/Logger.hpp"
@@ -28,6 +29,7 @@ namespace Bloom::TargetController
using Commands::ReadTargetRegisters;
using Commands::WriteTargetRegisters;
using Commands::ReadTargetMemory;
using Commands::StepTargetExecution;
TargetControllerConsole::TargetControllerConsole(EventListener& eventListener)
: eventListener(eventListener)
@@ -80,13 +82,16 @@ namespace Bloom::TargetController
}
void TargetControllerConsole::stepTargetExecution(std::optional<std::uint32_t> fromAddress) {
auto stepExecutionEvent = std::make_shared<StepTargetExecution>();
auto stepExecutionCommand = std::make_unique<StepTargetExecution>();
if (fromAddress.has_value()) {
stepExecutionEvent->fromProgramCounter = fromAddress.value();
stepExecutionCommand->fromProgramCounter = fromAddress.value();
}
this->triggerTargetControllerEventAndWaitForResponse(stepExecutionEvent);
this->commandManager.sendCommandAndWaitForResponse(
std::move(stepExecutionCommand),
this->defaultTimeout
);
}
TargetRegisters TargetControllerConsole::readRegisters(const TargetRegisterDescriptors& descriptors) {