Files
BloomPatched/src/DebugServer/Gdb/DebugSession.cpp

127 lines
4.5 KiB
C++
Raw Normal View History

2022-03-24 19:07:28 +00:00
#include "DebugSession.hpp"
2022-08-13 03:06:30 +01:00
#include "src/EventManager/EventManager.hpp"
2022-03-24 19:07:28 +00:00
namespace DebugServer::Gdb
2022-03-24 19:07:28 +00:00
{
DebugSession::DebugSession(
Connection&& connection,
const std::set<std::pair<Feature, std::optional<std::string>>>& supportedFeatures,
const GdbDebugServerConfig& serverConfig
)
: connection(std::move(connection))
, supportedFeatures(supportedFeatures)
, serverConfig(serverConfig)
{
this->supportedFeatures.emplace(
Feature::PACKET_SIZE,
std::to_string(Connection::ABSOLUTE_MAXIMUM_PACKET_READ_SIZE)
);
2022-03-24 19:07:28 +00:00
2022-08-13 03:06:30 +01:00
EventManager::triggerEvent(std::make_shared<Events::DebugSessionStarted>());
}
2022-08-13 03:06:30 +01:00
DebugSession::~DebugSession() {
EventManager::triggerEvent(std::make_shared<Events::DebugSessionFinished>());
2022-03-24 19:07:28 +00:00
}
void DebugSession::setInternalBreakpoint(
2023-09-20 23:37:54 +01:00
Targets::TargetMemoryAddress address,
Services::TargetControllerService& targetControllerService
) {
2023-09-20 23:37:54 +01:00
if (this->internalBreakpointsByAddress.contains(address)) {
return;
}
2023-09-20 23:37:54 +01:00
const auto externalBreakpointIt = this->externalBreakpointsByAddress.find(address);
if (externalBreakpointIt != this->externalBreakpointsByAddress.end()) {
// We already have an external breakpoint at this address
this->internalBreakpointsByAddress.emplace(address, externalBreakpointIt->second);
2023-09-20 23:37:54 +01:00
return;
}
this->internalBreakpointsByAddress.emplace(
address,
targetControllerService.setBreakpoint(address, Targets::TargetBreakpoint::Type::HARDWARE)
2023-09-20 23:37:54 +01:00
);
}
void DebugSession::removeInternalBreakpoint(
2023-09-20 23:37:54 +01:00
Targets::TargetMemoryAddress address,
Services::TargetControllerService& targetControllerService
) {
2023-09-20 23:37:54 +01:00
const auto breakpointIt = this->internalBreakpointsByAddress.find(address);
if (breakpointIt == this->internalBreakpointsByAddress.end()) {
return;
}
2023-09-20 23:37:54 +01:00
if (!this->externalBreakpointsByAddress.contains(address)) {
targetControllerService.removeBreakpoint(breakpointIt->second);
}
2023-09-20 23:37:54 +01:00
this->internalBreakpointsByAddress.erase(breakpointIt);
}
void DebugSession::setExternalBreakpoint(
2023-09-20 23:37:54 +01:00
Targets::TargetMemoryAddress address,
Services::TargetControllerService& targetControllerService
) {
2023-09-20 23:37:54 +01:00
if (this->externalBreakpointsByAddress.contains(address)) {
return;
}
2023-09-20 23:37:54 +01:00
const auto internalBreakpointIt = this->internalBreakpointsByAddress.find(address);
if (internalBreakpointIt != this->internalBreakpointsByAddress.end()) {
// We already have an internal breakpoint at this address
this->externalBreakpointsByAddress.emplace(address, internalBreakpointIt->second);
2023-09-20 23:37:54 +01:00
return;
}
this->externalBreakpointsByAddress.emplace(
address,
targetControllerService.setBreakpoint(address, Targets::TargetBreakpoint::Type::HARDWARE)
2023-09-20 23:37:54 +01:00
);
}
void DebugSession::removeExternalBreakpoint(
2023-09-20 23:37:54 +01:00
Targets::TargetMemoryAddress address,
Services::TargetControllerService& targetControllerService
) {
2023-09-20 23:37:54 +01:00
const auto breakpointIt = this->externalBreakpointsByAddress.find(address);
if (breakpointIt == this->externalBreakpointsByAddress.end()) {
return;
}
2023-09-20 23:37:54 +01:00
if (!this->internalBreakpointsByAddress.contains(address)) {
targetControllerService.removeBreakpoint(breakpointIt->second);
}
2023-09-20 23:37:54 +01:00
this->externalBreakpointsByAddress.erase(breakpointIt);
}
void DebugSession::startRangeSteppingSession(
RangeSteppingSession&& session,
Services::TargetControllerService& targetControllerService
) {
for (const auto& interceptAddress : session.interceptedAddresses) {
2023-09-20 23:37:54 +01:00
this->setInternalBreakpoint(interceptAddress, targetControllerService);
}
this->activeRangeSteppingSession = std::move(session);
}
void DebugSession::terminateRangeSteppingSession(Services::TargetControllerService& targetControllerService) {
if (!this->activeRangeSteppingSession.has_value()) {
return;
}
// Clear all intercepting breakpoints
for (const auto& interceptAddress : this->activeRangeSteppingSession->interceptedAddresses) {
2023-09-20 23:37:54 +01:00
this->removeInternalBreakpoint(interceptAddress, targetControllerService);
}
this->activeRangeSteppingSession.reset();
}
2022-03-24 19:07:28 +00:00
}