2022-02-05 15:32:08 +00:00
|
|
|
#include "StepExecution.hpp"
|
|
|
|
|
|
2022-03-31 21:52:46 +01:00
|
|
|
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
#include "src/Services/StringService.hpp"
|
2022-03-24 19:17:41 +00:00
|
|
|
#include "src/Logger/Logger.hpp"
|
|
|
|
|
#include "src/Exceptions/Exception.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
namespace DebugServer::Gdb::CommandPackets
|
2022-02-05 15:32:08 +00:00
|
|
|
{
|
2022-12-26 21:27:19 +00:00
|
|
|
using Services::TargetControllerService;
|
2022-04-09 15:57:24 +01:00
|
|
|
|
2022-03-24 19:17:41 +00:00
|
|
|
using ResponsePackets::ErrorResponsePacket;
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
using ::Exceptions::Exception;
|
2021-10-06 21:12:31 +01:00
|
|
|
|
2022-10-01 21:01:37 +01:00
|
|
|
StepExecution::StepExecution(const RawPacket& rawPacket)
|
2022-04-03 17:25:21 +01:00
|
|
|
: CommandPacket(rawPacket)
|
|
|
|
|
{
|
2023-04-01 12:37:59 +01:00
|
|
|
if (this->data.size() > 2) {
|
2023-09-21 00:40:30 +01:00
|
|
|
this->fromAddress = static_cast<Targets::TargetMemoryAddress>(
|
2024-07-23 21:14:22 +01:00
|
|
|
Services::StringService::toUint32(std::string{this->data.begin() + 2, this->data.end()}, 16)
|
2022-02-05 15:32:08 +00:00
|
|
|
);
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
2022-03-24 19:17:41 +00:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
void StepExecution::handle(
|
|
|
|
|
DebugSession& debugSession,
|
|
|
|
|
const TargetDescriptor& gdbTargetDescriptor,
|
|
|
|
|
const Targets::TargetDescriptor&,
|
|
|
|
|
TargetControllerService& targetControllerService
|
|
|
|
|
) {
|
2023-05-07 20:17:33 +01:00
|
|
|
Logger::info("Handling StepExecution packet");
|
2022-03-24 19:17:41 +00:00
|
|
|
|
|
|
|
|
try {
|
2024-07-23 21:14:22 +01:00
|
|
|
const auto atomicSession = targetControllerService.makeAtomicSession();
|
|
|
|
|
if (this->fromAddress.has_value()) {
|
|
|
|
|
targetControllerService.setProgramCounter(*(this->fromAddress));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
targetControllerService.stepTargetExecution();
|
2022-03-24 19:17:41 +00:00
|
|
|
debugSession.waitingForBreak = true;
|
|
|
|
|
|
|
|
|
|
} catch (const Exception& exception) {
|
|
|
|
|
Logger::error("Failed to step execution on target - " + exception.getMessage());
|
2024-07-23 21:14:22 +01:00
|
|
|
debugSession.connection.writePacket(ErrorResponsePacket{});
|
2022-03-24 19:17:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|