Replaced StepTargetExecution event with TC command
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -15,5 +15,6 @@ namespace Bloom::TargetController::Commands
|
||||
WRITE_TARGET_REGISTERS,
|
||||
READ_TARGET_MEMORY,
|
||||
GET_TARGET_STATE,
|
||||
STEP_TARGET_EXECUTION,
|
||||
};
|
||||
}
|
||||
|
||||
30
src/TargetController/Commands/StepTargetExecution.hpp
Normal file
30
src/TargetController/Commands/StepTargetExecution.hpp
Normal 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;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user