New clion_adaptation environment config param, to allow for use of Bloom with CLion's new "debug server" functionality

This commit is contained in:
Nav
2025-02-02 15:52:26 +00:00
parent b06e8cc9ad
commit a9c8f24f8b
12 changed files with 69 additions and 152 deletions

View File

@@ -13,8 +13,12 @@ namespace DebugServer
{
using namespace Events;
DebugServerComponent::DebugServerComponent(const DebugServerConfig& debugServerConfig)
: debugServerConfig(debugServerConfig)
DebugServerComponent::DebugServerComponent(
const EnvironmentConfig& environmentConfig,
const DebugServerConfig& debugServerConfig
)
: environmentConfig(environmentConfig)
, debugServerConfig(debugServerConfig)
, targetDescriptor((Services::TargetControllerService()).getTargetDescriptor())
{}
@@ -49,6 +53,7 @@ namespace DebugServer
}
return std::make_unique<DebugServer::Gdb::AvrGdb::AvrGdbRsp>(
this->environmentConfig,
this->debugServerConfig,
this->targetDescriptor,
*(this->eventListener.get()),
@@ -64,6 +69,7 @@ namespace DebugServer
}
return std::make_unique<DebugServer::Gdb::RiscVGdb::RiscVGdbRsp>(
this->environmentConfig,
this->debugServerConfig,
this->targetDescriptor,
*(this->eventListener.get()),

View File

@@ -25,7 +25,10 @@ namespace DebugServer
class DebugServerComponent: public Thread
{
public:
explicit DebugServerComponent(const DebugServerConfig& debugServerConfig);
explicit DebugServerComponent(
const EnvironmentConfig& environmentConfig,
const DebugServerConfig& debugServerConfig
);
/**
* Entry point for the DebugServer. This must called from a dedicated thread.
@@ -44,9 +47,7 @@ namespace DebugServer
*/
EventListenerPointer eventListener = std::make_shared<EventListener>("DebugServerEventListener");
/**
* Project configuration for the debug server (extracted from the user project's bloom.yaml).
*/
EnvironmentConfig environmentConfig;
DebugServerConfig debugServerConfig;
/**

View File

@@ -29,12 +29,14 @@ namespace DebugServer::Gdb::AvrGdb
using Targets::TargetRegisterType;
AvrGdbRsp::AvrGdbRsp(
const EnvironmentConfig& environmentConfig,
const DebugServerConfig& debugServerConfig,
const Targets::TargetDescriptor& targetDescriptor,
EventListener& eventListener,
EventFdNotifier& eventNotifier
)
: GdbRspDebugServer(
environmentConfig,
debugServerConfig,
targetDescriptor,
AvrGdbTargetDescriptor{targetDescriptor},

View File

@@ -14,6 +14,7 @@ namespace DebugServer::Gdb::AvrGdb
{
public:
AvrGdbRsp(
const EnvironmentConfig& environmentConfig,
const DebugServerConfig& debugServerConfig,
const Targets::TargetDescriptor& targetDescriptor,
EventListener& eventListener,

View File

@@ -16,8 +16,9 @@ namespace DebugServer::Gdb::CommandPackets
using ::Exceptions::Exception;
Detach::Detach(const RawPacket& rawPacket)
Detach::Detach(const RawPacket& rawPacket, const EnvironmentConfig& environmentConfig)
: CommandPacket(rawPacket)
, environmentConfig(environmentConfig)
{}
void Detach::handle(
@@ -29,7 +30,14 @@ namespace DebugServer::Gdb::CommandPackets
Logger::info("Handling Detach packet");
try {
if (Services::ProcessService::isManagedByClion()) {
if (this->environmentConfig.clionAdaptation && Services::ProcessService::isManagedByClion()) {
/*
* CLion is about to kill Bloom's process. This is our last chance to detach from the target and
* disconnect from the debug tool, cleanly.
*
* So we have to force the TC to shut down immediately, to prevent CLion from killing Bloom and leaving
* the debug tool and target in an undefined state.
*/
targetControllerService.shutdown();
}

View File

@@ -2,12 +2,14 @@
#include "CommandPacket.hpp"
#include "src/ProjectConfig.hpp"
namespace DebugServer::Gdb::CommandPackets
{
class Detach: public CommandPacket
{
public:
explicit Detach(const RawPacket& rawPacket);
explicit Detach(const RawPacket& rawPacket, const EnvironmentConfig& environmentConfig);
void handle(
DebugSession& debugSession,
@@ -15,5 +17,8 @@ namespace DebugServer::Gdb::CommandPackets
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;
private:
const EnvironmentConfig& environmentConfig;
};
}

View File

@@ -86,13 +86,15 @@ namespace DebugServer::Gdb
{
public:
explicit GdbRspDebugServer(
const EnvironmentConfig& environmentConfig,
const DebugServerConfig& debugServerConfig,
const Targets::TargetDescriptor& targetDescriptor,
GdbTargetDescriptorType&& gdbTargetDescriptor,
EventListener& eventListener,
EventFdNotifier& eventNotifier
)
: debugServerConfig(GdbDebugServerConfig{debugServerConfig})
: environmentConfig(environmentConfig)
, debugServerConfig(GdbDebugServerConfig{debugServerConfig})
, targetDescriptor(targetDescriptor)
, gdbTargetDescriptor(std::move(gdbTargetDescriptor))
, eventListener(eventListener)
@@ -179,9 +181,10 @@ namespace DebugServer::Gdb
std::bind(&GdbRspDebugServer::onTargetStateChanged, this, std::placeholders::_1)
);
if (Services::ProcessService::isManagedByClion()) {
if (this->environmentConfig.clionAdaptation && Services::ProcessService::isManagedByClion()) {
Logger::warning(
"Bloom's process is being managed by CLion - Bloom will automatically shutdown upon detaching from GDB."
"Bloom's process is being managed by CLion - Bloom will automatically shut down upon"
" detaching from GDB."
);
}
}
@@ -286,6 +289,7 @@ namespace DebugServer::Gdb
}
protected:
const EnvironmentConfig& environmentConfig;
GdbDebugServerConfig debugServerConfig;
const Targets::TargetDescriptor& targetDescriptor;
GdbTargetDescriptorType gdbTargetDescriptor;
@@ -434,7 +438,7 @@ namespace DebugServer::Gdb
}
if (rawPacket[1] == 'D') {
return std::make_unique<CommandPackets::Detach>(rawPacket);
return std::make_unique<CommandPackets::Detach>(rawPacket, this->environmentConfig);
}
const auto rawPacketString = std::string{rawPacket.begin() + 1, rawPacket.end()};

View File

@@ -26,12 +26,14 @@ namespace DebugServer::Gdb::RiscVGdb
using Targets::TargetRegisterType;
RiscVGdbRsp::RiscVGdbRsp(
const EnvironmentConfig& environmentConfig,
const DebugServerConfig& debugServerConfig,
const Targets::TargetDescriptor& targetDescriptor,
EventListener& eventListener,
EventFdNotifier& eventNotifier
)
: GdbRspDebugServer(
environmentConfig,
debugServerConfig,
targetDescriptor,
RiscVGdbTargetDescriptor{targetDescriptor},

View File

@@ -17,6 +17,7 @@ namespace DebugServer::Gdb::RiscVGdb
{
public:
RiscVGdbRsp(
const EnvironmentConfig& environmentConfig,
const DebugServerConfig& debugServerConfig,
const Targets::TargetDescriptor& targetDescriptor,
EventListener& eventListener,