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
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
namespace DebugServer::Gdb
|
2022-03-24 19:07:28 +00:00
|
|
|
{
|
2022-05-14 22:38:49 +01:00
|
|
|
DebugSession::DebugSession(
|
|
|
|
|
Connection&& connection,
|
|
|
|
|
const std::set<std::pair<Feature, std::optional<std::string>>>& supportedFeatures,
|
2023-04-01 14:30:33 +01:00
|
|
|
const TargetDescriptor& targetDescriptor,
|
|
|
|
|
const GdbDebugServerConfig& serverConfig
|
2022-05-14 22:38:49 +01:00
|
|
|
)
|
2022-03-28 01:04:14 +01:00
|
|
|
: connection(std::move(connection))
|
2022-05-14 22:38:49 +01:00
|
|
|
, supportedFeatures(supportedFeatures)
|
2022-05-04 19:49:18 +01:00
|
|
|
, gdbTargetDescriptor(targetDescriptor)
|
2023-04-01 14:30:33 +01:00
|
|
|
, serverConfig(serverConfig)
|
2022-05-14 22:38:49 +01:00
|
|
|
{
|
|
|
|
|
this->supportedFeatures.insert({
|
2022-11-16 23:50:28 +00:00
|
|
|
Feature::PACKET_SIZE, std::to_string(Connection::ABSOLUTE_MAXIMUM_PACKET_READ_SIZE)
|
2022-05-14 22:38:49 +01:00
|
|
|
});
|
2022-03-24 19:07:28 +00:00
|
|
|
|
2022-08-13 03:06:30 +01:00
|
|
|
EventManager::triggerEvent(std::make_shared<Events::DebugSessionStarted>());
|
|
|
|
|
}
|
2022-03-29 14:54:49 +01:00
|
|
|
|
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
|
|
|
}
|
2023-09-10 22:27:10 +01:00
|
|
|
|
|
|
|
|
void DebugSession::setInternalBreakpoint(
|
|
|
|
|
const Targets::TargetBreakpoint& breakpoint,
|
|
|
|
|
Services::TargetControllerService& targetControllerService
|
|
|
|
|
) {
|
|
|
|
|
if (this->internalBreakpointAddresses.contains(breakpoint.address)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!this->externalBreakpointAddresses.contains(breakpoint.address)) {
|
|
|
|
|
targetControllerService.setBreakpoint(breakpoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->internalBreakpointAddresses.insert(breakpoint.address);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebugSession::removeInternalBreakpoint(
|
|
|
|
|
const Targets::TargetBreakpoint& breakpoint,
|
|
|
|
|
Services::TargetControllerService& targetControllerService
|
|
|
|
|
) {
|
|
|
|
|
if (!this->internalBreakpointAddresses.contains(breakpoint.address)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!this->externalBreakpointAddresses.contains(breakpoint.address)) {
|
|
|
|
|
targetControllerService.removeBreakpoint(breakpoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->internalBreakpointAddresses.erase(breakpoint.address);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebugSession::setExternalBreakpoint(
|
|
|
|
|
const Targets::TargetBreakpoint& breakpoint,
|
|
|
|
|
Services::TargetControllerService& targetControllerService
|
|
|
|
|
) {
|
|
|
|
|
if (this->externalBreakpointAddresses.contains(breakpoint.address)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!this->internalBreakpointAddresses.contains(breakpoint.address)) {
|
|
|
|
|
targetControllerService.setBreakpoint(breakpoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->externalBreakpointAddresses.insert(breakpoint.address);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebugSession::removeExternalBreakpoint(
|
|
|
|
|
const Targets::TargetBreakpoint& breakpoint,
|
|
|
|
|
Services::TargetControllerService& targetControllerService
|
|
|
|
|
) {
|
|
|
|
|
if (!this->externalBreakpointAddresses.contains(breakpoint.address)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!this->internalBreakpointAddresses.contains(breakpoint.address)) {
|
|
|
|
|
targetControllerService.removeBreakpoint(breakpoint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->externalBreakpointAddresses.erase(breakpoint.address);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebugSession::startRangeSteppingSession(
|
|
|
|
|
RangeSteppingSession&& session,
|
|
|
|
|
Services::TargetControllerService& targetControllerService
|
|
|
|
|
) {
|
|
|
|
|
for (const auto& interceptAddress : session.interceptedAddresses) {
|
|
|
|
|
this->setInternalBreakpoint(Targets::TargetBreakpoint(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) {
|
|
|
|
|
this->removeInternalBreakpoint(Targets::TargetBreakpoint(interceptAddress), targetControllerService);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->activeRangeSteppingSession.reset();
|
|
|
|
|
}
|
2022-03-24 19:07:28 +00:00
|
|
|
}
|