Replaced SetProgramCounterOnTarget event with TC command

This commit is contained in:
Nav
2022-04-30 23:10:07 +01:00
parent acc96fd6d1
commit 7c4e39dd03
10 changed files with 60 additions and 86 deletions

View File

@@ -29,8 +29,6 @@ namespace Bloom::Events
TARGET_EXECUTION_RESUMED,
TARGET_EXECUTION_STOPPED,
MEMORY_WRITTEN_TO_TARGET,
SET_PROGRAM_COUNTER_ON_TARGET,
PROGRAM_COUNTER_SET_ON_TARGET,
EXTRACT_TARGET_DESCRIPTOR,
TARGET_DESCRIPTOR_EXTRACTED,
INSIGHT_THREAD_STATE_CHANGED,

View File

@@ -16,8 +16,6 @@
#include "TargetExecutionResumed.hpp"
#include "TargetExecutionStopped.hpp"
#include "MemoryWrittenToTarget.hpp"
#include "SetProgramCounterOnTarget.hpp"
#include "ProgramCounterSetOnTarget.hpp"
#include "ExtractTargetDescriptor.hpp"
#include "TargetDescriptorExtracted.hpp"
#include "InsightThreadStateChanged.hpp"

View File

@@ -1,23 +0,0 @@
#pragma once
#include <string>
#include "Event.hpp"
namespace Bloom::Events
{
class ProgramCounterSetOnTarget: public Event
{
public:
static constexpr EventType type = EventType::PROGRAM_COUNTER_SET_ON_TARGET;
static inline const std::string name = "ProgramCounterSetOnTarget";
[[nodiscard]] EventType getType() const override {
return ProgramCounterSetOnTarget::type;
}
[[nodiscard]] std::string getName() const override {
return ProgramCounterSetOnTarget::name;
}
};
}

View File

@@ -1,28 +0,0 @@
#pragma once
#include <cstdint>
#include <string>
#include "Event.hpp"
#include "ProgramCounterSetOnTarget.hpp"
namespace Bloom::Events
{
class SetProgramCounterOnTarget: public Event
{
public:
using TargetControllerResponseType = ProgramCounterSetOnTarget;
static constexpr EventType type = EventType::SET_PROGRAM_COUNTER_ON_TARGET;
static inline const std::string name = "SetProgramCounterOnTarget";
std::uint32_t address = 0;
[[nodiscard]] EventType getType() const override {
return SetProgramCounterOnTarget::type;
}
[[nodiscard]] std::string getName() const override {
return SetProgramCounterOnTarget::name;
}
};
}

View File

@@ -19,5 +19,6 @@ namespace Bloom::TargetController::Commands
WRITE_TARGET_MEMORY,
SET_BREAKPOINT,
REMOVE_BREAKPOINT,
SET_PROGRAM_COUNTER,
};
}

View File

@@ -0,0 +1,32 @@
#pragma once
#include <cstdint>
#include "Command.hpp"
#include "src/Targets/TargetBreakpoint.hpp"
namespace Bloom::TargetController::Commands
{
class SetProgramCounter: public Command
{
public:
static constexpr CommandType type = CommandType::SET_PROGRAM_COUNTER;
static inline const std::string name = "SetProgramCounter";
std::uint32_t address = 0;
SetProgramCounter() = default;
explicit SetProgramCounter(std::uint32_t address)
: address(address)
{};
[[nodiscard]] CommandType getType() const override {
return SetProgramCounter::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -33,6 +33,7 @@ namespace Bloom::TargetController
using Commands::StepTargetExecution;
using Commands::SetBreakpoint;
using Commands::RemoveBreakpoint;
using Commands::SetProgramCounter;
using Responses::Response;
using Responses::TargetRegistersRead;
@@ -397,10 +398,10 @@ namespace Bloom::TargetController
this->deregisterCommandHandler(StepTargetExecution::type);
this->deregisterCommandHandler(SetBreakpoint::type);
this->deregisterCommandHandler(RemoveBreakpoint::type);
this->deregisterCommandHandler(SetProgramCounter::type);
this->eventListener->deregisterCallbacksForEventType<Events::DebugSessionFinished>();
this->eventListener->deregisterCallbacksForEventType<Events::ExtractTargetDescriptor>();
this->eventListener->deregisterCallbacksForEventType<Events::SetProgramCounterOnTarget>();
this->eventListener->deregisterCallbacksForEventType<Events::InsightThreadStateChanged>();
this->eventListener->deregisterCallbacksForEventType<Events::RetrieveTargetPinStates>();
this->eventListener->deregisterCallbacksForEventType<Events::SetTargetPinState>();
@@ -465,6 +466,10 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::handleRemoveBreakpoint, this, std::placeholders::_1)
);
this->registerCommandHandler<SetProgramCounter>(
std::bind(&TargetControllerComponent::handleSetProgramCounter, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::DebugSessionFinished>(
std::bind(&TargetControllerComponent::onDebugSessionFinishedEvent, this, std::placeholders::_1)
);
@@ -473,10 +478,6 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::onExtractTargetDescriptor, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::SetProgramCounterOnTarget>(
std::bind(&TargetControllerComponent::onSetProgramCounterEvent, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::RetrieveTargetPinStates>(
std::bind(&TargetControllerComponent::onRetrieveTargetPinStatesEvent, this, std::placeholders::_1)
);
@@ -871,24 +872,9 @@ namespace Bloom::TargetController
return std::make_unique<Response>();
}
void TargetControllerComponent::onSetProgramCounterEvent(const Events::SetProgramCounterOnTarget& event) {
try {
if (this->target->getState() != TargetState::STOPPED) {
throw TargetOperationFailure(
"Invalid target state - target must be stopped before the program counter can be updated"
);
}
this->target->setProgramCounter(event.address);
auto programCounterSetEvent = std::make_shared<Events::ProgramCounterSetOnTarget>();
programCounterSetEvent->correlationId = event.id;
EventManager::triggerEvent(programCounterSetEvent);
} catch (const TargetOperationFailure& exception) {
Logger::error("Failed to set program counter on target - " + exception.getMessage());
this->emitErrorEvent(event.id, exception.getMessage());
}
std::unique_ptr<Response> TargetControllerComponent::handleSetProgramCounter(SetProgramCounter& command) {
this->target->setProgramCounter(command.address);
return std::make_unique<Response>();
}
void TargetControllerComponent::onRetrieveTargetPinStatesEvent(const Events::RetrieveTargetPinStates& event) {

View File

@@ -29,6 +29,7 @@
#include "Commands/StepTargetExecution.hpp"
#include "Commands/SetBreakpoint.hpp"
#include "Commands/RemoveBreakpoint.hpp"
#include "Commands/SetProgramCounter.hpp"
// Responses
#include "Responses/Response.hpp"
@@ -310,14 +311,7 @@ namespace Bloom::TargetController
std::unique_ptr<Responses::Response> handleStepTargetExecution(Commands::StepTargetExecution& command);
std::unique_ptr<Responses::Response> handleSetBreakpoint(Commands::SetBreakpoint& command);
std::unique_ptr<Responses::Response> handleRemoveBreakpoint(Commands::RemoveBreakpoint& command);
/**
* Will update the program counter value on the target. On success, a ProgramCounterSetOnTarget event is
* emitted.
*
* @param event
*/
void onSetProgramCounterEvent(const Events::SetProgramCounterOnTarget& event);
std::unique_ptr<Responses::Response> handleSetProgramCounter(Commands::SetProgramCounter& command);
/**
* Will attempt to obtain the pin states from the target. Will emit a TargetPinStatesRetrieved event on success.

View File

@@ -16,6 +16,7 @@
#include "Commands/StepTargetExecution.hpp"
#include "Commands/SetBreakpoint.hpp"
#include "Commands/RemoveBreakpoint.hpp"
#include "Commands/SetProgramCounter.hpp"
#include "src/Logger/Logger.hpp"
@@ -36,6 +37,7 @@ namespace Bloom::TargetController
using Commands::StepTargetExecution;
using Commands::SetBreakpoint;
using Commands::RemoveBreakpoint;
using Commands::SetProgramCounter;
TargetControllerConsole::TargetControllerConsole(EventListener& eventListener)
: eventListener(eventListener)
@@ -156,6 +158,13 @@ namespace Bloom::TargetController
);
}
void TargetControllerConsole::setProgramCounter(std::uint32_t address) {
this->commandManager.sendCommandAndWaitForResponse(
std::make_unique<SetProgramCounter>(address),
this->defaultTimeout
);
}
Targets::TargetPinStateMappingType TargetControllerConsole::getPinStates(int variantId) {
auto requestEvent = std::make_shared<RetrieveTargetPinStates>();
requestEvent->variantId = variantId;

View File

@@ -144,6 +144,13 @@ namespace Bloom::TargetController
*/
void removeBreakpoint(Targets::TargetBreakpoint breakpoint);
/**
* Sets the target's program counter to the given address.
*
* @param address
*/
void setProgramCounter(std::uint32_t address);
/**
* Retrieves the pin states for a particular target variant.
*