diff --git a/src/plugins/baremetal/CMakeLists.txt b/src/plugins/baremetal/CMakeLists.txt index 0a811d37b9b..65312e55b13 100644 --- a/src/plugins/baremetal/CMakeLists.txt +++ b/src/plugins/baremetal/CMakeLists.txt @@ -12,18 +12,19 @@ add_qtc_plugin(BareMetal baremetaldeviceconfigurationwizardpages.cpp baremetaldeviceconfigurationwizardpages.h baremetalplugin.cpp baremetalplugin.h baremetalrunconfiguration.cpp baremetalrunconfiguration.h - defaultgdbserverprovider.cpp defaultgdbserverprovider.h - gdbserverprovider.cpp gdbserverprovider.h - gdbserverproviderchooser.cpp gdbserverproviderchooser.h - gdbserverprovidermanager.cpp gdbserverprovidermanager.h - gdbserverproviderprocess.cpp gdbserverproviderprocess.h - gdbserverproviderssettingspage.cpp gdbserverproviderssettingspage.h + debugserverproviderchooser.cpp debugserverproviderchooser.h + debugserverprovidermanager.cpp debugserverprovidermanager.h + debugserverproviderssettingspage.cpp debugserverproviderssettingspage.h + debugservers/gdb/defaultgdbserverprovider.cpp debugservers/gdb/defaultgdbserverprovider.h + debugservers/gdb/gdbserverprovider.cpp debugservers/gdb/gdbserverprovider.h + debugservers/gdb/gdbserverproviderprocess.cpp debugservers/gdb/gdbserverproviderprocess.h + debugservers/gdb/openocdgdbserverprovider.cpp debugservers/gdb/openocdgdbserverprovider.h + debugservers/gdb/stlinkutilgdbserverprovider.cpp debugservers/gdb/stlinkutilgdbserverprovider.h iarewparser.cpp iarewparser.h iarewtoolchain.cpp iarewtoolchain.h + idebugserverprovider.cpp idebugserverprovider.h keilparser.cpp keilparser.h keiltoolchain.cpp keiltoolchain.h sdccparser.cpp sdccparser.h sdcctoolchain.cpp sdcctoolchain.h - openocdgdbserverprovider.cpp openocdgdbserverprovider.h - stlinkutilgdbserverprovider.cpp stlinkutilgdbserverprovider.h ) diff --git a/src/plugins/baremetal/baremetal.pro b/src/plugins/baremetal/baremetal.pro index 76cd5ac3082..d88a4bc40b2 100644 --- a/src/plugins/baremetal/baremetal.pro +++ b/src/plugins/baremetal/baremetal.pro @@ -1,54 +1,51 @@ QT += network include(../../qtcreatorplugin.pri) +# GDB debug servers +include(debugservers/gdb/gdbservers.pri) + # BareMetal files -SOURCES += baremetalplugin.cpp \ +SOURCES += \ baremetalcustomrunconfiguration.cpp\ - baremetaldevice.cpp \ - baremetalrunconfiguration.cpp \ - baremetaldeviceconfigurationwizardpages.cpp \ - baremetaldeviceconfigurationwizard.cpp \ - baremetaldeviceconfigurationwidget.cpp \ baremetaldebugsupport.cpp \ - gdbserverproviderprocess.cpp \ - gdbserverproviderssettingspage.cpp \ - gdbserverprovider.cpp \ - gdbserverproviderchooser.cpp \ - gdbserverprovidermanager.cpp \ - openocdgdbserverprovider.cpp \ - defaultgdbserverprovider.cpp \ - stlinkutilgdbserverprovider.cpp \ - iarewtoolchain.cpp \ - keiltoolchain.cpp \ - sdcctoolchain.cpp \ + baremetaldevice.cpp \ + baremetaldeviceconfigurationwidget.cpp \ + baremetaldeviceconfigurationwizard.cpp \ + baremetaldeviceconfigurationwizardpages.cpp \ + baremetalplugin.cpp \ + baremetalrunconfiguration.cpp \ + debugserverproviderchooser.cpp \ + debugserverprovidermanager.cpp \ + debugserverproviderssettingspage.cpp \ iarewparser.cpp \ + iarewtoolchain.cpp \ + idebugserverprovider.cpp \ keilparser.cpp \ + keiltoolchain.cpp \ sdccparser.cpp \ + sdcctoolchain.cpp -HEADERS += baremetalplugin.h \ +HEADERS += \ baremetalconstants.h \ baremetalcustomrunconfiguration.h \ + baremetaldebugsupport.h \ baremetaldevice.h \ - baremetalrunconfiguration.h \ baremetaldeviceconfigurationwidget.h \ baremetaldeviceconfigurationwizard.h \ baremetaldeviceconfigurationwizardpages.h \ - baremetaldebugsupport.h \ - gdbserverproviderprocess.h \ - gdbserverproviderssettingspage.h \ - gdbserverprovider.h \ - gdbserverproviderchooser.h \ - gdbserverprovidermanager.h \ - openocdgdbserverprovider.h \ - defaultgdbserverprovider.h \ - stlinkutilgdbserverprovider.h \ - iarewtoolchain.h \ - keiltoolchain.h \ - sdcctoolchain.h \ + baremetalplugin.h \ + baremetalrunconfiguration.h \ + debugserverproviderchooser.h \ + debugserverprovidermanager.h \ + debugserverproviderssettingspage.h \ iarewparser.h \ + iarewtoolchain.h \ + idebugserverprovider.h \ keilparser.h \ + keiltoolchain.h \ sdccparser.h \ + sdcctoolchain.h RESOURCES += \ baremetal.qrc diff --git a/src/plugins/baremetal/baremetal.qbs b/src/plugins/baremetal/baremetal.qbs index b50db5769eb..1d32ca881ce 100644 --- a/src/plugins/baremetal/baremetal.qbs +++ b/src/plugins/baremetal/baremetal.qbs @@ -12,30 +12,41 @@ QtcPlugin { Depends { name: "ProjectExplorer" } Depends { name: "TextEditor" } - files: [ - "baremetal.qrc", - "baremetalconstants.h", - "baremetalcustomrunconfiguration.cpp", "baremetalcustomrunconfiguration.h", - "baremetaldevice.cpp", "baremetaldevice.h", - "baremetaldeviceconfigurationwidget.cpp", "baremetaldeviceconfigurationwidget.h", - "baremetaldeviceconfigurationwizard.cpp", "baremetaldeviceconfigurationwizard.h", - "baremetaldeviceconfigurationwizardpages.cpp", "baremetaldeviceconfigurationwizardpages.h", - "baremetalplugin.cpp", "baremetalplugin.h", - "baremetalrunconfiguration.cpp", "baremetalrunconfiguration.h", - "baremetaldebugsupport.cpp", "baremetaldebugsupport.h", - "gdbserverproviderprocess.cpp", "gdbserverproviderprocess.h", - "gdbserverproviderssettingspage.cpp", "gdbserverproviderssettingspage.h", - "gdbserverprovider.cpp", "gdbserverprovider.h", - "gdbserverproviderchooser.cpp", "gdbserverproviderchooser.h", - "gdbserverprovidermanager.cpp", "gdbserverprovidermanager.h", - "openocdgdbserverprovider.cpp", "openocdgdbserverprovider.h", - "defaultgdbserverprovider.cpp", "defaultgdbserverprovider.h", - "stlinkutilgdbserverprovider.cpp", "stlinkutilgdbserverprovider.h", - "iarewtoolchain.cpp", "iarewtoolchain.h", - "keiltoolchain.cpp", "keiltoolchain.h", - "sdcctoolchain.cpp", "sdcctoolchain.h", - "iarewparser.cpp", "iarewparser.h", - "keilparser.cpp", "keilparser.h", - "sdccparser.cpp", "sdccparser.h", - ] + Group { + name: "General" + files: [ + "baremetal.qrc", + "baremetalconstants.h", + "baremetalcustomrunconfiguration.cpp", "baremetalcustomrunconfiguration.h", + "baremetaldebugsupport.cpp", "baremetaldebugsupport.h", + "baremetaldevice.cpp", "baremetaldevice.h", + "baremetaldeviceconfigurationwidget.cpp", "baremetaldeviceconfigurationwidget.h", + "baremetaldeviceconfigurationwizard.cpp", "baremetaldeviceconfigurationwizard.h", + "baremetaldeviceconfigurationwizardpages.cpp", "baremetaldeviceconfigurationwizardpages.h", + "baremetalplugin.cpp", "baremetalplugin.h", + "baremetalrunconfiguration.cpp", "baremetalrunconfiguration.h", + "debugserverproviderchooser.cpp", "debugserverproviderchooser.h", + "debugserverprovidermanager.cpp", "debugserverprovidermanager.h", + "debugserverproviderssettingspage.cpp", "debugserverproviderssettingspage.h", + "iarewparser.cpp", "iarewparser.h", + "iarewtoolchain.cpp", "iarewtoolchain.h", + "idebugserverprovider.cpp", "idebugserverprovider.h", + "keilparser.cpp", "keilparser.h", + "keiltoolchain.cpp", "keiltoolchain.h", + "sdccparser.cpp", "sdccparser.h", + "sdcctoolchain.cpp", "sdcctoolchain.h", + ] + } + + Group { + name: "GDB Servers" + prefix: "debugservers/gdb/" + files: [ + "defaultgdbserverprovider.cpp", "defaultgdbserverprovider.h", + "gdbserverprovider.cpp", "gdbserverprovider.h", + "gdbserverproviderprocess.cpp", "gdbserverproviderprocess.h", + "openocdgdbserverprovider.cpp", "openocdgdbserverprovider.h", + "stlinkutilgdbserverprovider.cpp", "stlinkutilgdbserverprovider.h", + ] + } } diff --git a/src/plugins/baremetal/baremetaldebugsupport.cpp b/src/plugins/baremetal/baremetaldebugsupport.cpp index a8f20e197a2..b5a839ac84b 100644 --- a/src/plugins/baremetal/baremetaldebugsupport.cpp +++ b/src/plugins/baremetal/baremetaldebugsupport.cpp @@ -26,8 +26,10 @@ #include "baremetaldebugsupport.h" #include "baremetaldevice.h" -#include "gdbserverprovider.h" -#include "gdbserverprovidermanager.h" +#include "debugserverprovidermanager.h" +#include "idebugserverprovider.h" + +#include "debugservers/gdb/gdbserverprovider.h" #include #include @@ -54,18 +56,6 @@ namespace Internal { // BareMetalDebugSupport -class BareMetalGdbServer : public SimpleTargetRunner -{ -public: - BareMetalGdbServer(RunControl *runControl, const Runnable &runnable) - : SimpleTargetRunner(runControl) - { - setId("BareMetalGdbServer"); - // Baremetal's GDB servers are launched on the host, not on the target. - setStarter([this, runnable] { doStart(runnable, {}); }); - } -}; - BareMetalDebugSupport::BareMetalDebugSupport(RunControl *runControl) : Debugger::DebuggerRunTool(runControl) { @@ -75,42 +65,48 @@ BareMetalDebugSupport::BareMetalDebugSupport(RunControl *runControl) return; } - const QString providerId = dev->gdbServerProviderId(); - const GdbServerProvider *p = GdbServerProviderManager::findProvider(providerId); + const QString providerId = dev->debugServerProviderId(); + const IDebugServerProvider *p = DebugServerProviderManager::findProvider(providerId); if (!p) { - reportFailure(tr("No GDB server provider found for %1").arg(providerId)); + reportFailure(tr("No debug server provider found for %1").arg(providerId)); return; } - if (p->startupMode() == GdbServerProvider::StartupOnNetwork) { - Runnable r; - r.setCommandLine(p->command()); - // Command arguments are in host OS style as the bare metal's GDB servers are launched - // on the host, not on that target. - auto gdbServer = new BareMetalGdbServer(runControl, r); - addStartDependency(gdbServer); - } + addTargetRunnerForProvider(p, runControl); } void BareMetalDebugSupport::start() { + const auto dev = qSharedPointerCast(device()); + QTC_ASSERT(dev, reportFailure(); return); + const IDebugServerProvider *p = DebugServerProviderManager::findProvider( + dev->debugServerProviderId()); + QTC_ASSERT(p, reportFailure(); return); + + if (aboutToStart(p)) + DebuggerRunTool::start(); +} + +bool BareMetalDebugSupport::aboutToStart(const IDebugServerProvider *provider) +{ + if (provider->engineType() != Debugger::GdbEngineType) + return true; + const auto exeAspect = runControl()->aspect(); - QTC_ASSERT(exeAspect, reportFailure(); return); + QTC_ASSERT(exeAspect, reportFailure(); return false); const FilePath bin = exeAspect->executable(); if (bin.isEmpty()) { reportFailure(tr("Cannot debug: Local executable is not set.")); - return; + return false; } if (!bin.exists()) { - reportFailure(tr("Cannot debug: Could not find executable for \"%1\".").arg(bin.toString())); - return; + reportFailure(tr("Cannot debug: Could not find executable for \"%1\".") + .arg(bin.toString())); + return false; } - const auto dev = qSharedPointerCast(device()); - QTC_ASSERT(dev, reportFailure(); return); - const GdbServerProvider *p = GdbServerProviderManager::findProvider(dev->gdbServerProviderId()); - QTC_ASSERT(p, reportFailure(); return); + const auto gdbProvider = static_cast(provider); Runnable inferior; inferior.executable = bin; @@ -119,13 +115,28 @@ void BareMetalDebugSupport::start() setInferior(inferior); setSymbolFile(bin); setStartMode(AttachToRemoteServer); - setCommandsAfterConnect(p->initCommands()); // .. and here? - setCommandsForReset(p->resetCommands()); - setRemoteChannel(p->channelString()); + setCommandsAfterConnect(gdbProvider->initCommands()); // .. and here? + setCommandsForReset(gdbProvider->resetCommands()); + setRemoteChannel(gdbProvider->channelString()); setUseContinueInsteadOfRun(true); - setUseExtendedRemote(p->useExtendedRemote()); + setUseExtendedRemote(gdbProvider->useExtendedRemote()); + return true; +} - DebuggerRunTool::start(); +void BareMetalDebugSupport::addTargetRunnerForProvider(const IDebugServerProvider *provider, + ProjectExplorer::RunControl *runControl) +{ + if (provider->engineType() != Debugger::GdbEngineType) + return; + const auto gdbProvider = static_cast(provider); + if (gdbProvider->startupMode() == GdbServerProvider::StartupOnNetwork) { + Runnable r; + r.setCommandLine(gdbProvider->command()); + // Command arguments are in host OS style as the bare metal's GDB servers are launched + // on the host, not on that target. + const auto gdbServer = new GdbServerProviderRunner(runControl, r); + addStartDependency(gdbServer); + } } } // namespace Internal diff --git a/src/plugins/baremetal/baremetaldebugsupport.h b/src/plugins/baremetal/baremetaldebugsupport.h index cfc31017fb3..8e52fbf0a6d 100644 --- a/src/plugins/baremetal/baremetaldebugsupport.h +++ b/src/plugins/baremetal/baremetaldebugsupport.h @@ -27,9 +27,15 @@ #include +namespace ProjectExplorer { +class RunControl; +} + namespace BareMetal { namespace Internal { +class IDebugServerProvider; + // BareMetalDebugSupport class BareMetalDebugSupport final : public Debugger::DebuggerRunTool @@ -41,6 +47,9 @@ public: private: void start() final; + bool aboutToStart(const IDebugServerProvider *provider); + void addTargetRunnerForProvider(const IDebugServerProvider *provider, + ProjectExplorer::RunControl *runControl); }; } // namespace Internal diff --git a/src/plugins/baremetal/baremetaldevice.cpp b/src/plugins/baremetal/baremetaldevice.cpp index d9901ccc584..846c6519f0b 100644 --- a/src/plugins/baremetal/baremetaldevice.cpp +++ b/src/plugins/baremetal/baremetaldevice.cpp @@ -28,11 +28,11 @@ #include "baremetaldevice.h" #include "baremetaldeviceconfigurationwidget.h" #include "baremetaldeviceconfigurationwizard.h" +#include "debugserverprovidermanager.h" -#include "defaultgdbserverprovider.h" - -#include "gdbserverprovidermanager.h" -#include "gdbserverproviderprocess.h" +// GDB server providers. +#include "debugservers/gdb/defaultgdbserverprovider.h" +#include "debugservers/gdb/gdbserverproviderprocess.h" #include @@ -46,63 +46,72 @@ using namespace ProjectExplorer; namespace BareMetal { namespace Internal { -const char gdbServerProviderIdKeyC[] = "GdbServerProviderId"; +const char debugServerProviderIdKeyC[] = "IDebugServerProviderId"; // BareMetalDevice BareMetalDevice::BareMetalDevice() { - setDisplayType(QCoreApplication::translate("BareMetal::Internal::BareMetalDevice", "Bare Metal")); + setDisplayType(QCoreApplication::translate("BareMetal::Internal::BareMetalDevice", + "Bare Metal")); setDefaultDisplayName(defaultDisplayName()); setOsType(Utils::OsTypeOther); } BareMetalDevice::~BareMetalDevice() { - if (GdbServerProvider *provider = GdbServerProviderManager::findProvider(m_gdbServerProviderId)) + if (IDebugServerProvider *provider = DebugServerProviderManager::findProvider( + m_debugServerProviderId)) provider->unregisterDevice(this); } QString BareMetalDevice::defaultDisplayName() { - return QCoreApplication::translate("BareMetal::Internal::BareMetalDevice", "Bare Metal Device"); + return QCoreApplication::translate("BareMetal::Internal::BareMetalDevice", + "Bare Metal Device"); } -QString BareMetalDevice::gdbServerProviderId() const +QString BareMetalDevice::debugServerProviderId() const { - return m_gdbServerProviderId; + return m_debugServerProviderId; } -void BareMetalDevice::setGdbServerProviderId(const QString &id) +void BareMetalDevice::setDebugServerProviderId(const QString &id) { - if (id == m_gdbServerProviderId) + if (id == m_debugServerProviderId) return; - if (GdbServerProvider *currentProvider = GdbServerProviderManager::findProvider(m_gdbServerProviderId)) + if (IDebugServerProvider *currentProvider = + DebugServerProviderManager::findProvider(m_debugServerProviderId)) currentProvider->unregisterDevice(this); - m_gdbServerProviderId = id; - if (GdbServerProvider *provider = GdbServerProviderManager::findProvider(id)) { + m_debugServerProviderId = id; + if (IDebugServerProvider *provider = DebugServerProviderManager::findProvider(id)) { setChannelByServerProvider(provider); provider->registerDevice(this); } } -void BareMetalDevice::unregisterProvider(GdbServerProvider *provider) +void BareMetalDevice::unregisterDebugServerProvider(IDebugServerProvider *provider) { - if (provider->id() == m_gdbServerProviderId) - m_gdbServerProviderId.clear(); + if (provider->id() == m_debugServerProviderId) + m_debugServerProviderId.clear(); } -void BareMetalDevice::providerUpdated(GdbServerProvider *provider) +void BareMetalDevice::debugServerProviderUpdated(IDebugServerProvider *provider) { - GdbServerProvider *myProvider = GdbServerProviderManager::findProvider(m_gdbServerProviderId); + IDebugServerProvider *myProvider = DebugServerProviderManager::findProvider( + m_debugServerProviderId); if (provider == myProvider) setChannelByServerProvider(provider); } -void BareMetalDevice::setChannelByServerProvider(GdbServerProvider *provider) +void BareMetalDevice::setChannelByServerProvider(IDebugServerProvider *provider) { QTC_ASSERT(provider, return); - const QString channel = provider->channelString(); + if (provider->engineType() != Debugger::GdbEngineType) + return; + + const auto gdbProvider = static_cast(provider); + const QString channel = gdbProvider->channelString(); const int colon = channel.indexOf(QLatin1Char(':')); if (colon < 0) return; @@ -115,29 +124,30 @@ void BareMetalDevice::setChannelByServerProvider(GdbServerProvider *provider) void BareMetalDevice::fromMap(const QVariantMap &map) { IDevice::fromMap(map); - QString gdbServerProvider = map.value(QLatin1String(gdbServerProviderIdKeyC)).toString(); - if (gdbServerProvider.isEmpty()) { + QString providerId = map.value(QLatin1String(debugServerProviderIdKeyC)).toString(); + if (providerId.isEmpty()) { const QString name = displayName(); - if (GdbServerProvider *provider = GdbServerProviderManager::findByDisplayName(name)) { - gdbServerProvider = provider->id(); + if (IDebugServerProvider *provider = + DebugServerProviderManager::findByDisplayName(name)) { + providerId = provider->id(); } else { const QSsh::SshConnectionParameters sshParams = sshParameters(); const auto newProvider = new DefaultGdbServerProvider; newProvider->setChannel(sshParams.url); newProvider->setDisplayName(name); - if (GdbServerProviderManager::registerProvider(newProvider)) - gdbServerProvider = newProvider->id(); + if (DebugServerProviderManager::registerProvider(newProvider)) + providerId = newProvider->id(); else delete newProvider; } } - setGdbServerProviderId(gdbServerProvider); + setDebugServerProviderId(providerId); } QVariantMap BareMetalDevice::toMap() const { QVariantMap map = IDevice::toMap(); - map.insert(QLatin1String(gdbServerProviderIdKeyC), gdbServerProviderId()); + map.insert(QLatin1String(debugServerProviderIdKeyC), debugServerProviderId()); return map; } @@ -151,9 +161,26 @@ IDeviceWidget *BareMetalDevice::createWidget() return new BareMetalDeviceConfigurationWidget(sharedFromThis()); } +bool BareMetalDevice::canCreateProcess() const +{ + if (IDebugServerProvider *provider = DebugServerProviderManager::findProvider( + m_debugServerProviderId)) { + if (provider->engineType() == Debugger::GdbEngineType) + return true; + } + + return false; +} + DeviceProcess *BareMetalDevice::createProcess(QObject *parent) const { - return new GdbServerProviderProcess(sharedFromThis(), parent); + if (IDebugServerProvider *provider = DebugServerProviderManager::findProvider( + m_debugServerProviderId)) { + if (provider->engineType() == Debugger::GdbEngineType) + return new GdbServerProviderProcess(sharedFromThis(), parent); + } + + return nullptr; } // Factory diff --git a/src/plugins/baremetal/baremetaldevice.h b/src/plugins/baremetal/baremetaldevice.h index eda3f957f21..a7850c5d350 100644 --- a/src/plugins/baremetal/baremetaldevice.h +++ b/src/plugins/baremetal/baremetaldevice.h @@ -32,7 +32,7 @@ namespace BareMetal { namespace Internal { -class GdbServerProvider; +class IDebugServerProvider; // BareMetalDevice @@ -51,13 +51,13 @@ public: ProjectExplorer::DeviceProcessSignalOperation::Ptr signalOperation() const final; - bool canCreateProcess() const final { return true; } + bool canCreateProcess() const final; ProjectExplorer::DeviceProcess *createProcess(QObject *parent) const final; - QString gdbServerProviderId() const; - void setGdbServerProviderId(const QString &id); - void unregisterProvider(GdbServerProvider *provider); - void providerUpdated(GdbServerProvider *provider); + QString debugServerProviderId() const; + void setDebugServerProviderId(const QString &id); + void unregisterDebugServerProvider(IDebugServerProvider *provider); + void debugServerProviderUpdated(IDebugServerProvider *provider); void fromMap(const QVariantMap &map) final; QVariantMap toMap() const final; @@ -65,8 +65,10 @@ public: private: BareMetalDevice(); - void setChannelByServerProvider(GdbServerProvider *provider); - QString m_gdbServerProviderId; + // Only for GDB servers! + void setChannelByServerProvider(IDebugServerProvider *provider); + + QString m_debugServerProviderId; }; // BareMetalDeviceFactory diff --git a/src/plugins/baremetal/baremetaldeviceconfigurationwidget.cpp b/src/plugins/baremetal/baremetaldeviceconfigurationwidget.cpp index 26257ef128c..b1288aa1fad 100644 --- a/src/plugins/baremetal/baremetaldeviceconfigurationwidget.cpp +++ b/src/plugins/baremetal/baremetaldeviceconfigurationwidget.cpp @@ -27,8 +27,8 @@ #include "baremetaldevice.h" #include "baremetaldeviceconfigurationwidget.h" -#include "gdbserverprovider.h" -#include "gdbserverproviderchooser.h" +#include "debugserverproviderchooser.h" +#include "idebugserverprovider.h" #include #include @@ -50,13 +50,13 @@ BareMetalDeviceConfigurationWidget::BareMetalDeviceConfigurationWidget( const auto formLayout = new QFormLayout(this); formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); - m_gdbServerProviderChooser = new GdbServerProviderChooser(true, this); - m_gdbServerProviderChooser->populate(); - m_gdbServerProviderChooser->setCurrentProviderId(dev->gdbServerProviderId()); - formLayout->addRow(tr("GDB server provider:"), m_gdbServerProviderChooser); + m_debugServerProviderChooser = new DebugServerProviderChooser(true, this); + m_debugServerProviderChooser->populate(); + m_debugServerProviderChooser->setCurrentProviderId(dev->debugServerProviderId()); + formLayout->addRow(tr("Debug server provider:"), m_debugServerProviderChooser); - connect(m_gdbServerProviderChooser, &GdbServerProviderChooser::providerChanged, - this, &BareMetalDeviceConfigurationWidget::gdbServerProviderChanged); + connect(m_debugServerProviderChooser, &DebugServerProviderChooser::providerChanged, + this, &BareMetalDeviceConfigurationWidget::debugServerProviderChanged); m_peripheralDescriptionFileChooser = new Utils::PathChooser(this); m_peripheralDescriptionFileChooser->setExpectedKind(Utils::PathChooser::File); @@ -72,11 +72,11 @@ BareMetalDeviceConfigurationWidget::BareMetalDeviceConfigurationWidget( this, &BareMetalDeviceConfigurationWidget::peripheralDescriptionFileChanged); } -void BareMetalDeviceConfigurationWidget::gdbServerProviderChanged() +void BareMetalDeviceConfigurationWidget::debugServerProviderChanged() { const auto dev = qSharedPointerCast(device()); QTC_ASSERT(dev, return); - dev->setGdbServerProviderId(m_gdbServerProviderChooser->currentProviderId()); + dev->setDebugServerProviderId(m_debugServerProviderChooser->currentProviderId()); } void BareMetalDeviceConfigurationWidget::peripheralDescriptionFileChanged() @@ -88,7 +88,7 @@ void BareMetalDeviceConfigurationWidget::peripheralDescriptionFileChanged() void BareMetalDeviceConfigurationWidget::updateDeviceFromUi() { - gdbServerProviderChanged(); + debugServerProviderChanged(); } } // namespace Internal diff --git a/src/plugins/baremetal/baremetaldeviceconfigurationwidget.h b/src/plugins/baremetal/baremetaldeviceconfigurationwidget.h index abf0c3f3e1d..0bc07f5235f 100644 --- a/src/plugins/baremetal/baremetaldeviceconfigurationwidget.h +++ b/src/plugins/baremetal/baremetaldeviceconfigurationwidget.h @@ -33,7 +33,7 @@ namespace Utils { class PathChooser; } namespace BareMetal { namespace Internal { -class GdbServerProviderChooser; +class DebugServerProviderChooser; // BareMetalDeviceConfigurationWidget @@ -46,11 +46,11 @@ public: explicit BareMetalDeviceConfigurationWidget(const ProjectExplorer::IDevice::Ptr &deviceConfig); private: - void gdbServerProviderChanged(); + void debugServerProviderChanged(); void peripheralDescriptionFileChanged(); void updateDeviceFromUi() final; - GdbServerProviderChooser *m_gdbServerProviderChooser = nullptr; + DebugServerProviderChooser *m_debugServerProviderChooser = nullptr; Utils::PathChooser *m_peripheralDescriptionFileChooser = nullptr; }; diff --git a/src/plugins/baremetal/baremetaldeviceconfigurationwizard.cpp b/src/plugins/baremetal/baremetaldeviceconfigurationwizard.cpp index 7a4b05928b0..1912a3e059d 100644 --- a/src/plugins/baremetal/baremetaldeviceconfigurationwizard.cpp +++ b/src/plugins/baremetal/baremetaldeviceconfigurationwizard.cpp @@ -52,7 +52,7 @@ ProjectExplorer::IDevice::Ptr BareMetalDeviceConfigurationWizard::device() const dev->setDisplayName(m_setupPage->configurationName()); dev->setType(Constants::BareMetalOsType); dev->setMachineType(ProjectExplorer::IDevice::Hardware); - dev->setGdbServerProviderId(m_setupPage->gdbServerProviderId()); + dev->setDebugServerProviderId(m_setupPage->debugServerProviderId()); return dev; } diff --git a/src/plugins/baremetal/baremetaldeviceconfigurationwizardpages.cpp b/src/plugins/baremetal/baremetaldeviceconfigurationwizardpages.cpp index 53634ec2391..d3216e0bb64 100644 --- a/src/plugins/baremetal/baremetaldeviceconfigurationwizardpages.cpp +++ b/src/plugins/baremetal/baremetaldeviceconfigurationwizardpages.cpp @@ -27,7 +27,7 @@ #include "baremetaldevice.h" #include "baremetaldeviceconfigurationwizardpages.h" -#include "gdbserverproviderchooser.h" +#include "debugserverproviderchooser.h" #include #include @@ -44,19 +44,19 @@ BareMetalDeviceConfigurationWizardSetupPage::BareMetalDeviceConfigurationWizardS QWidget *parent) : QWizardPage(parent) { - setTitle(tr("Set up GDB Server or Hardware Debugger")); + setTitle(tr("Set up Debug Server or Hardware Debugger")); const auto formLayout = new QFormLayout(this); formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); m_nameLineEdit = new QLineEdit(this); formLayout->addRow(tr("Name:"), m_nameLineEdit); - m_gdbServerProviderChooser = new GdbServerProviderChooser(false, this); - m_gdbServerProviderChooser->populate(); - formLayout->addRow(tr("GDB server provider:"), m_gdbServerProviderChooser); + m_debugServerProviderChooser = new DebugServerProviderChooser(false, this); + m_debugServerProviderChooser->populate(); + formLayout->addRow(tr("Debug server provider:"), m_debugServerProviderChooser); connect(m_nameLineEdit, &QLineEdit::textChanged, this, &BareMetalDeviceConfigurationWizardSetupPage::completeChanged); - connect(m_gdbServerProviderChooser, &GdbServerProviderChooser::providerChanged, + connect(m_debugServerProviderChooser, &DebugServerProviderChooser::providerChanged, this, &QWizardPage::completeChanged); } @@ -75,9 +75,9 @@ QString BareMetalDeviceConfigurationWizardSetupPage::configurationName() const return m_nameLineEdit->text().trimmed(); } -QString BareMetalDeviceConfigurationWizardSetupPage::gdbServerProviderId() const +QString BareMetalDeviceConfigurationWizardSetupPage::debugServerProviderId() const { - return m_gdbServerProviderChooser->currentProviderId(); + return m_debugServerProviderChooser->currentProviderId(); } } // namespace Internal diff --git a/src/plugins/baremetal/baremetaldeviceconfigurationwizardpages.h b/src/plugins/baremetal/baremetaldeviceconfigurationwizardpages.h index 05f16ba290e..1b6d0e0fcf1 100644 --- a/src/plugins/baremetal/baremetaldeviceconfigurationwizardpages.h +++ b/src/plugins/baremetal/baremetaldeviceconfigurationwizardpages.h @@ -35,7 +35,7 @@ QT_END_NAMESPACE namespace BareMetal { namespace Internal { -class GdbServerProviderChooser; +class DebugServerProviderChooser; // BareMetalDeviceConfigurationWizardSetupPage @@ -49,11 +49,11 @@ public: void initializePage() final; bool isComplete() const final; QString configurationName() const; - QString gdbServerProviderId() const; + QString debugServerProviderId() const; private: QLineEdit *m_nameLineEdit = nullptr; - GdbServerProviderChooser *m_gdbServerProviderChooser = nullptr; + DebugServerProviderChooser *m_debugServerProviderChooser = nullptr; }; } // namespace Internal diff --git a/src/plugins/baremetal/baremetalplugin.cpp b/src/plugins/baremetal/baremetalplugin.cpp index fa43b9d97f5..1848724d548 100644 --- a/src/plugins/baremetal/baremetalplugin.cpp +++ b/src/plugins/baremetal/baremetalplugin.cpp @@ -31,8 +31,8 @@ #include "baremetalplugin.h" #include "baremetalrunconfiguration.h" -#include "gdbserverprovidermanager.h" -#include "gdbserverproviderssettingspage.h" +#include "debugserverprovidermanager.h" +#include "debugserverproviderssettingspage.h" #include "iarewtoolchain.h" #include "keiltoolchain.h" @@ -76,8 +76,8 @@ public: BareMetalDeviceFactory deviceFactory; BareMetalRunConfigurationFactory runConfigurationFactory; BareMetalCustomRunConfigurationFactory customRunConfigurationFactory; - GdbServerProvidersSettingsPage gdbServerProviderSettinsPage; - GdbServerProviderManager gdbServerProviderManager; + DebugServerProvidersSettingsPage debugServerProviderSettinsPage; + DebugServerProviderManager debugServerProviderManager; BareMetalDeployConfigurationFactory deployConfigurationFactory; RunWorkerFactory runWorkerFactory{ @@ -105,7 +105,7 @@ bool BareMetalPlugin::initialize(const QStringList &arguments, QString *errorStr void BareMetalPlugin::extensionsInitialized() { - GdbServerProviderManager::instance()->restoreProviders(); + DebugServerProviderManager::instance()->restoreProviders(); } } // namespace Internal diff --git a/src/plugins/baremetal/gdbserverproviderchooser.cpp b/src/plugins/baremetal/debugserverproviderchooser.cpp similarity index 73% rename from src/plugins/baremetal/gdbserverproviderchooser.cpp rename to src/plugins/baremetal/debugserverproviderchooser.cpp index 768c2d205f7..de1f5c845d9 100644 --- a/src/plugins/baremetal/gdbserverproviderchooser.cpp +++ b/src/plugins/baremetal/debugserverproviderchooser.cpp @@ -25,9 +25,9 @@ #include "baremetalconstants.h" -#include "gdbserverprovider.h" -#include "gdbserverproviderchooser.h" -#include "gdbserverprovidermanager.h" +#include "debugserverproviderchooser.h" +#include "debugserverprovidermanager.h" +#include "idebugserverprovider.h" #include @@ -39,9 +39,9 @@ namespace BareMetal { namespace Internal { -// GdbServerProviderChooser +// DebugServerProviderChooser -GdbServerProviderChooser::GdbServerProviderChooser( +DebugServerProviderChooser::DebugServerProviderChooser( bool useManageButton, QWidget *parent) : QWidget(parent) { @@ -58,20 +58,20 @@ GdbServerProviderChooser::GdbServerProviderChooser( setFocusProxy(m_manageButton); connect(m_chooser, QOverload::of(&QComboBox::currentIndexChanged), - this, &GdbServerProviderChooser::currentIndexChanged); + this, &DebugServerProviderChooser::currentIndexChanged); connect(m_manageButton, &QAbstractButton::clicked, - this, &GdbServerProviderChooser::manageButtonClicked); - connect(GdbServerProviderManager::instance(), &GdbServerProviderManager::providersChanged, - this, &GdbServerProviderChooser::populate); + this, &DebugServerProviderChooser::manageButtonClicked); + connect(DebugServerProviderManager::instance(), &DebugServerProviderManager::providersChanged, + this, &DebugServerProviderChooser::populate); } -QString GdbServerProviderChooser::currentProviderId() const +QString DebugServerProviderChooser::currentProviderId() const { const int idx = m_chooser->currentIndex(); return qvariant_cast(m_chooser->itemData(idx)); } -void GdbServerProviderChooser::setCurrentProviderId(const QString &id) +void DebugServerProviderChooser::setCurrentProviderId(const QString &id) { for (int i = 0; i < m_chooser->count(); ++i) { if (id != qvariant_cast(m_chooser->itemData(i))) @@ -80,34 +80,34 @@ void GdbServerProviderChooser::setCurrentProviderId(const QString &id) } } -void GdbServerProviderChooser::manageButtonClicked() +void DebugServerProviderChooser::manageButtonClicked() { Core::ICore::showOptionsDialog(Constants::GDB_PROVIDERS_SETTINGS_ID, this); } -void GdbServerProviderChooser::currentIndexChanged(int index) +void DebugServerProviderChooser::currentIndexChanged(int index) { Q_UNUSED(index) emit providerChanged(); } -bool GdbServerProviderChooser::providerMatches(const GdbServerProvider *provider) const +bool DebugServerProviderChooser::providerMatches(const IDebugServerProvider *provider) const { return provider->isValid(); } -QString GdbServerProviderChooser::providerText(const GdbServerProvider *provider) const +QString DebugServerProviderChooser::providerText(const IDebugServerProvider *provider) const { return provider->displayName(); } -void GdbServerProviderChooser::populate() +void DebugServerProviderChooser::populate() { const QSignalBlocker blocker(m_chooser); m_chooser->clear(); m_chooser->addItem(tr("None")); - for (const GdbServerProvider *p : GdbServerProviderManager::providers()) { + for (const IDebugServerProvider *p : DebugServerProviderManager::providers()) { if (!providerMatches(p)) continue; m_chooser->addItem(providerText(p), QVariant::fromValue(p->id())); diff --git a/src/plugins/baremetal/gdbserverproviderchooser.h b/src/plugins/baremetal/debugserverproviderchooser.h similarity index 86% rename from src/plugins/baremetal/gdbserverproviderchooser.h rename to src/plugins/baremetal/debugserverproviderchooser.h index a53f228a0c0..16ce4e94b83 100644 --- a/src/plugins/baremetal/gdbserverproviderchooser.h +++ b/src/plugins/baremetal/debugserverproviderchooser.h @@ -37,16 +37,16 @@ namespace Core { class Id; } namespace BareMetal { namespace Internal { -class GdbServerProvider; +class IDebugServerProvider; -// GdbServerProviderChooser +// DebugServerProviderChooser -class GdbServerProviderChooser final : public QWidget +class DebugServerProviderChooser final : public QWidget { Q_OBJECT public: - explicit GdbServerProviderChooser( + explicit DebugServerProviderChooser( bool useManageButton = true, QWidget *parent = nullptr); QString currentProviderId() const; @@ -59,8 +59,8 @@ signals: private: void currentIndexChanged(int index); void manageButtonClicked(); - bool providerMatches(const GdbServerProvider *) const; - QString providerText(const GdbServerProvider *) const; + bool providerMatches(const IDebugServerProvider *) const; + QString providerText(const IDebugServerProvider *) const; QComboBox *m_chooser = nullptr; QPushButton *m_manageButton = nullptr; diff --git a/src/plugins/baremetal/gdbserverprovidermanager.cpp b/src/plugins/baremetal/debugserverprovidermanager.cpp similarity index 65% rename from src/plugins/baremetal/gdbserverprovidermanager.cpp rename to src/plugins/baremetal/debugserverprovidermanager.cpp index cd4f199508f..19b0704e1ce 100644 --- a/src/plugins/baremetal/gdbserverprovidermanager.cpp +++ b/src/plugins/baremetal/debugserverprovidermanager.cpp @@ -23,12 +23,13 @@ ** ****************************************************************************/ -#include "gdbserverprovider.h" -#include "gdbserverprovidermanager.h" +#include "debugserverprovidermanager.h" +#include "idebugserverprovider.h" -#include "defaultgdbserverprovider.h" -#include "openocdgdbserverprovider.h" -#include "stlinkutilgdbserverprovider.h" +// GDB debug servers. +#include "debugservers/gdb/defaultgdbserverprovider.h" +#include "debugservers/gdb/openocdgdbserverprovider.h" +#include "debugservers/gdb/stlinkutilgdbserverprovider.h" #include @@ -43,16 +44,16 @@ namespace BareMetal { namespace Internal { -const char dataKeyC[] = "GdbServerProvider."; -const char countKeyC[] = "GdbServerProvider.Count"; +const char dataKeyC[] = "DebugServerProvider."; +const char countKeyC[] = "DebugServerProvider.Count"; const char fileVersionKeyC[] = "Version"; -const char fileNameKeyC[] = "/gdbserverproviders.xml"; +const char fileNameKeyC[] = "/debugserverproviders.xml"; -static GdbServerProviderManager *m_instance = nullptr; +static DebugServerProviderManager *m_instance = nullptr; -// GdbServerProviderManager +// DebugServerProviderManager -GdbServerProviderManager::GdbServerProviderManager() +DebugServerProviderManager::DebugServerProviderManager() : m_configFile(Utils::FilePath::fromString(Core::ICore::userResourcePath() + fileNameKeyC)) , m_factories({new DefaultGdbServerProviderFactory, new OpenOcdGdbServerProviderFactory, @@ -60,20 +61,20 @@ GdbServerProviderManager::GdbServerProviderManager() { m_instance = this; m_writer = new Utils::PersistentSettingsWriter( - m_configFile, QLatin1String("QtCreatorGdbServerProviders")); + m_configFile, QLatin1String("QtCreatorDebugServerProviders")); connect(Core::ICore::instance(), &Core::ICore::saveSettingsRequested, - this, &GdbServerProviderManager::saveProviders); + this, &DebugServerProviderManager::saveProviders); - connect(this, &GdbServerProviderManager::providerAdded, - this, &GdbServerProviderManager::providersChanged); - connect(this, &GdbServerProviderManager::providerRemoved, - this, &GdbServerProviderManager::providersChanged); - connect(this, &GdbServerProviderManager::providerUpdated, - this, &GdbServerProviderManager::providersChanged); + connect(this, &DebugServerProviderManager::providerAdded, + this, &DebugServerProviderManager::providersChanged); + connect(this, &DebugServerProviderManager::providerRemoved, + this, &DebugServerProviderManager::providersChanged); + connect(this, &DebugServerProviderManager::providerUpdated, + this, &DebugServerProviderManager::providersChanged); } -GdbServerProviderManager::~GdbServerProviderManager() +DebugServerProviderManager::~DebugServerProviderManager() { qDeleteAll(m_providers); m_providers.clear(); @@ -82,12 +83,12 @@ GdbServerProviderManager::~GdbServerProviderManager() m_instance = nullptr; } -GdbServerProviderManager *GdbServerProviderManager::instance() +DebugServerProviderManager *DebugServerProviderManager::instance() { return m_instance; } -void GdbServerProviderManager::restoreProviders() +void DebugServerProviderManager::restoreProviders() { Utils::PersistentSettingsReader reader; if (!reader.load(m_configFile)) @@ -106,9 +107,9 @@ void GdbServerProviderManager::restoreProviders() const QVariantMap map = data.value(key).toMap(); bool restored = false; - for (GdbServerProviderFactory *f : qAsConst(m_factories)) { + for (IDebugServerProviderFactory *f : qAsConst(m_factories)) { if (f->canRestore(map)) { - if (GdbServerProvider *p = f->restore(map)) { + if (IDebugServerProvider *p = f->restore(map)) { registerProvider(p); restored = true; break; @@ -117,20 +118,20 @@ void GdbServerProviderManager::restoreProviders() } if (!restored) qWarning("Warning: Unable to restore provider '%s' stored in %s.", - qPrintable(GdbServerProviderFactory::idFromMap(map)), + qPrintable(IDebugServerProviderFactory::idFromMap(map)), qPrintable(m_configFile.toUserOutput())); } emit providersLoaded(); } -void GdbServerProviderManager::saveProviders() +void DebugServerProviderManager::saveProviders() { QVariantMap data; data.insert(QLatin1String(fileVersionKeyC), 1); int count = 0; - for (const GdbServerProvider *p : qAsConst(m_providers)) { + for (const IDebugServerProvider *p : qAsConst(m_providers)) { if (p->isValid()) { const QVariantMap tmp = p->toMap(); if (tmp.isEmpty()) @@ -144,45 +145,45 @@ void GdbServerProviderManager::saveProviders() m_writer->save(data, Core::ICore::mainWindow()); } -QList GdbServerProviderManager::providers() +QList DebugServerProviderManager::providers() { return m_instance->m_providers; } -QList GdbServerProviderManager::factories() +QList DebugServerProviderManager::factories() { return m_instance->m_factories; } -GdbServerProvider *GdbServerProviderManager::findProvider(const QString &id) +IDebugServerProvider *DebugServerProviderManager::findProvider(const QString &id) { if (id.isEmpty() || !m_instance) return nullptr; - return Utils::findOrDefault(m_instance->m_providers, Utils::equal(&GdbServerProvider::id, id)); + return Utils::findOrDefault(m_instance->m_providers, Utils::equal(&IDebugServerProvider::id, id)); } -GdbServerProvider *GdbServerProviderManager::findByDisplayName(const QString &displayName) +IDebugServerProvider *DebugServerProviderManager::findByDisplayName(const QString &displayName) { if (displayName.isEmpty()) return nullptr; return Utils::findOrDefault(m_instance->m_providers, - Utils::equal(&GdbServerProvider::displayName, displayName)); + Utils::equal(&IDebugServerProvider::displayName, displayName)); } -void GdbServerProviderManager::notifyAboutUpdate(GdbServerProvider *provider) +void DebugServerProviderManager::notifyAboutUpdate(IDebugServerProvider *provider) { if (!provider || !m_instance->m_providers.contains(provider)) return; emit m_instance->providerUpdated(provider); } -bool GdbServerProviderManager::registerProvider(GdbServerProvider *provider) +bool DebugServerProviderManager::registerProvider(IDebugServerProvider *provider) { if (!provider || m_instance->m_providers.contains(provider)) return true; - for (const GdbServerProvider *current : qAsConst(m_instance->m_providers)) { + for (const IDebugServerProvider *current : qAsConst(m_instance->m_providers)) { if (*provider == *current) return false; QTC_ASSERT(current->id() != provider->id(), return false); @@ -193,7 +194,7 @@ bool GdbServerProviderManager::registerProvider(GdbServerProvider *provider) return true; } -void GdbServerProviderManager::deregisterProvider(GdbServerProvider *provider) +void DebugServerProviderManager::deregisterProvider(IDebugServerProvider *provider) { if (!provider || !m_instance->m_providers.contains(provider)) return; diff --git a/src/plugins/baremetal/gdbserverprovidermanager.h b/src/plugins/baremetal/debugserverprovidermanager.h similarity index 64% rename from src/plugins/baremetal/gdbserverprovidermanager.h rename to src/plugins/baremetal/debugserverprovidermanager.h index 64bd6df409d..e677c60f644 100644 --- a/src/plugins/baremetal/gdbserverprovidermanager.h +++ b/src/plugins/baremetal/debugserverprovidermanager.h @@ -37,48 +37,48 @@ namespace Internal { class BareMetalPlugin; class BareMetalPluginPrivate; -class GdbServerProvider; -class GdbServerProviderFactory; +class IDebugServerProvider; +class IDebugServerProviderFactory; -// GdbServerProviderManager +// DebugServerProviderManager -class GdbServerProviderManager final : public QObject +class DebugServerProviderManager final : public QObject { Q_OBJECT public: - static GdbServerProviderManager *instance(); - ~GdbServerProviderManager() final; + static DebugServerProviderManager *instance(); + ~DebugServerProviderManager() final; - static QList providers(); - static QList factories(); - static GdbServerProvider *findProvider(const QString &id); - static GdbServerProvider *findByDisplayName(const QString &displayName); - static bool registerProvider(GdbServerProvider *); - static void deregisterProvider(GdbServerProvider *); + static QList providers(); + static QList factories(); + static IDebugServerProvider *findProvider(const QString &id); + static IDebugServerProvider *findByDisplayName(const QString &displayName); + static bool registerProvider(IDebugServerProvider *provider); + static void deregisterProvider(IDebugServerProvider *provider); signals: - void providerAdded(GdbServerProvider *); - void providerRemoved(GdbServerProvider *); - void providerUpdated(GdbServerProvider *); + void providerAdded(IDebugServerProvider *provider); + void providerRemoved(IDebugServerProvider *provider); + void providerUpdated(IDebugServerProvider *provider); void providersChanged(); void providersLoaded(); private: void saveProviders(); - GdbServerProviderManager(); + DebugServerProviderManager(); void restoreProviders(); - static void notifyAboutUpdate(GdbServerProvider *); + static void notifyAboutUpdate(IDebugServerProvider *provider); Utils::PersistentSettingsWriter *m_writer = nullptr; - QList m_providers; + QList m_providers; const Utils::FilePath m_configFile; - const QList m_factories; + const QList m_factories; friend class BareMetalPlugin; // for restoreProviders friend class BareMetalPluginPrivate; // for constructor - friend class GdbServerProvider; + friend class IDebugServerProvider; }; } // namespace Internal diff --git a/src/plugins/baremetal/gdbserverproviderssettingspage.cpp b/src/plugins/baremetal/debugserverproviderssettingspage.cpp similarity index 63% rename from src/plugins/baremetal/gdbserverproviderssettingspage.cpp rename to src/plugins/baremetal/debugserverproviderssettingspage.cpp index fb78ef713ef..a1d2980f8c3 100644 --- a/src/plugins/baremetal/gdbserverproviderssettingspage.cpp +++ b/src/plugins/baremetal/debugserverproviderssettingspage.cpp @@ -25,9 +25,9 @@ #include "baremetalconstants.h" -#include "gdbserverprovider.h" -#include "gdbserverprovidermanager.h" -#include "gdbserverproviderssettingspage.h" +#include "debugserverprovidermanager.h" +#include "debugserverproviderssettingspage.h" +#include "idebugserverprovider.h" #include #include @@ -56,12 +56,12 @@ using namespace Utils; namespace BareMetal { namespace Internal { -// GdbServerProviderNode +// DebugServerProviderNode -class GdbServerProviderNode final : public TreeItem +class DebugServerProviderNode final : public TreeItem { public: - explicit GdbServerProviderNode(GdbServerProvider *provider, bool changed = false) + explicit DebugServerProviderNode(IDebugServerProvider *provider, bool changed = false) : provider(provider), changed(changed) { } @@ -83,54 +83,54 @@ public: return {}; } - GdbServerProvider *provider = nullptr; - GdbServerProviderConfigWidget *widget = nullptr; + IDebugServerProvider *provider = nullptr; + IDebugServerProviderConfigWidget *widget = nullptr; bool changed = false; }; -// GdbServerProviderModel +// DebugServerProviderModel -GdbServerProviderModel::GdbServerProviderModel() +DebugServerProviderModel::DebugServerProviderModel() { setHeader({tr("Name"), tr("Type")}); - const GdbServerProviderManager *manager = GdbServerProviderManager::instance(); + const DebugServerProviderManager *manager = DebugServerProviderManager::instance(); - connect(manager, &GdbServerProviderManager::providerAdded, - this, &GdbServerProviderModel::addProvider); - connect(manager, &GdbServerProviderManager::providerRemoved, - this, &GdbServerProviderModel::removeProvider); + connect(manager, &DebugServerProviderManager::providerAdded, + this, &DebugServerProviderModel::addProvider); + connect(manager, &DebugServerProviderManager::providerRemoved, + this, &DebugServerProviderModel::removeProvider); - for (GdbServerProvider *p : GdbServerProviderManager::providers()) + for (IDebugServerProvider *p : DebugServerProviderManager::providers()) addProvider(p); } -GdbServerProvider *GdbServerProviderModel::provider(const QModelIndex &index) const +IDebugServerProvider *DebugServerProviderModel::provider(const QModelIndex &index) const { - if (const GdbServerProviderNode *node = nodeForIndex(index)) + if (const DebugServerProviderNode *node = nodeForIndex(index)) return node->provider; return nullptr; } -GdbServerProviderNode *GdbServerProviderModel::nodeForIndex(const QModelIndex &index) const +DebugServerProviderNode *DebugServerProviderModel::nodeForIndex(const QModelIndex &index) const { if (!index.isValid()) return nullptr; - return static_cast(itemForIndex(index)); + return static_cast(itemForIndex(index)); } -void GdbServerProviderModel::apply() +void DebugServerProviderModel::apply() { // Remove unused providers - for (GdbServerProvider *provider : qAsConst(m_providersToRemove)) - GdbServerProviderManager::deregisterProvider(provider); + for (IDebugServerProvider *provider : qAsConst(m_providersToRemove)) + DebugServerProviderManager::deregisterProvider(provider); QTC_ASSERT(m_providersToRemove.isEmpty(), m_providersToRemove.clear()); // Update providers for (TreeItem *item : *rootItem()) { - const auto n = static_cast(item); + const auto n = static_cast(item); if (!n->changed) continue; @@ -144,8 +144,8 @@ void GdbServerProviderModel::apply() // Add new (and already updated) providers QStringList skippedProviders; - for (GdbServerProvider *provider: qAsConst(m_providersToAdd)) { - if (!GdbServerProviderManager::registerProvider(provider)) + for (IDebugServerProvider *provider: qAsConst(m_providersToAdd)) { + if (!DebugServerProviderManager::registerProvider(provider)) skippedProviders << provider->displayName(); } @@ -161,24 +161,24 @@ void GdbServerProviderModel::apply() } } -GdbServerProviderNode *GdbServerProviderModel::findNode(const GdbServerProvider *provider) const +DebugServerProviderNode *DebugServerProviderModel::findNode(const IDebugServerProvider *provider) const { auto test = [provider](TreeItem *item) { - return static_cast(item)->provider == provider; + return static_cast(item)->provider == provider; }; - return static_cast(Utils::findOrDefault(*rootItem(), test)); + return static_cast(Utils::findOrDefault(*rootItem(), test)); } -QModelIndex GdbServerProviderModel::indexForProvider(GdbServerProvider *provider) const +QModelIndex DebugServerProviderModel::indexForProvider(IDebugServerProvider *provider) const { - const GdbServerProviderNode *n = findNode(provider); + const DebugServerProviderNode *n = findNode(provider); return n ? indexForItem(n) : QModelIndex(); } -void GdbServerProviderModel::markForRemoval(GdbServerProvider *provider) +void DebugServerProviderModel::markForRemoval(IDebugServerProvider *provider) { - GdbServerProviderNode *n = findNode(provider); + DebugServerProviderNode *n = findNode(provider); QTC_ASSERT(n, return); destroyItem(n); @@ -190,26 +190,26 @@ void GdbServerProviderModel::markForRemoval(GdbServerProvider *provider) } } -void GdbServerProviderModel::markForAddition(GdbServerProvider *provider) +void DebugServerProviderModel::markForAddition(IDebugServerProvider *provider) { - GdbServerProviderNode *n = createNode(provider, true); + DebugServerProviderNode *n = createNode(provider, true); rootItem()->appendChild(n); m_providersToAdd.append(provider); } -GdbServerProviderNode *GdbServerProviderModel::createNode( - GdbServerProvider *provider, bool changed) +DebugServerProviderNode *DebugServerProviderModel::createNode( + IDebugServerProvider *provider, bool changed) { - const auto node = new GdbServerProviderNode(provider, changed); + const auto node = new DebugServerProviderNode(provider, changed); node->widget = provider->configurationWidget(); - connect(node->widget, &GdbServerProviderConfigWidget::dirty, this, [node] { + connect(node->widget, &IDebugServerProviderConfigWidget::dirty, this, [node] { node->changed = true; node->update(); }); return node; } -void GdbServerProviderModel::addProvider(GdbServerProvider *provider) +void DebugServerProviderModel::addProvider(IDebugServerProvider *provider) { if (findNode(provider)) m_providersToAdd.removeOne(provider); @@ -219,34 +219,34 @@ void GdbServerProviderModel::addProvider(GdbServerProvider *provider) emit providerStateChanged(); } -void GdbServerProviderModel::removeProvider(GdbServerProvider *provider) +void DebugServerProviderModel::removeProvider(IDebugServerProvider *provider) { m_providersToRemove.removeAll(provider); - if (GdbServerProviderNode *n = findNode(provider)) + if (DebugServerProviderNode *n = findNode(provider)) destroyItem(n); emit providerStateChanged(); } -// GdbServerProvidersSettingsWidget +// DebugServerProvidersSettingsWidget -class GdbServerProvidersSettingsWidget final : public QWidget +class DebugServerProvidersSettingsWidget final : public QWidget { - Q_DECLARE_TR_FUNCTIONS(BareMetal::Internal::GdbServerProvidersSettingsPage) + Q_DECLARE_TR_FUNCTIONS(BareMetal::Internal::DebugServerProvidersSettingsPage) public: - explicit GdbServerProvidersSettingsWidget(GdbServerProvidersSettingsPage *page); + explicit DebugServerProvidersSettingsWidget(DebugServerProvidersSettingsPage *page); void providerSelectionChanged(); void removeProvider(); void updateState(); - void createProvider(GdbServerProviderFactory *f); + void createProvider(IDebugServerProviderFactory *f); QModelIndex currentIndex() const; public: - GdbServerProvidersSettingsPage *m_page = nullptr; - GdbServerProviderModel m_model; + DebugServerProvidersSettingsPage *m_page = nullptr; + DebugServerProviderModel m_model; QItemSelectionModel *m_selectionModel = nullptr; QTreeView *m_providerView = nullptr; Utils::DetailsWidget *m_container = nullptr; @@ -255,8 +255,8 @@ public: QPushButton *m_delButton = nullptr; }; -GdbServerProvidersSettingsWidget::GdbServerProvidersSettingsWidget - (GdbServerProvidersSettingsPage *page) +DebugServerProvidersSettingsWidget::DebugServerProvidersSettingsWidget + (DebugServerProvidersSettingsPage *page) : m_page(page) { m_providerView = new QTreeView(this); @@ -289,14 +289,14 @@ GdbServerProvidersSettingsWidget::GdbServerProvidersSettingsWidget horizontalLayout->addLayout(verticalLayout); horizontalLayout->addWidget(m_container); - const auto groupBox = new QGroupBox(tr("GDB Server Providers"), this); + const auto groupBox = new QGroupBox(tr("Debug Server Providers"), this); groupBox->setLayout(horizontalLayout); const auto topLayout = new QVBoxLayout(this); topLayout->addWidget(groupBox); - connect(&m_model, &GdbServerProviderModel::providerStateChanged, - this, &GdbServerProvidersSettingsWidget::updateState); + connect(&m_model, &DebugServerProviderModel::providerStateChanged, + this, &DebugServerProvidersSettingsWidget::updateState); m_providerView->setModel(&m_model); @@ -308,15 +308,15 @@ GdbServerProvidersSettingsWidget::GdbServerProvidersSettingsWidget m_selectionModel = m_providerView->selectionModel(); connect(m_selectionModel, &QItemSelectionModel::selectionChanged, - this, &GdbServerProvidersSettingsWidget::providerSelectionChanged); + this, &DebugServerProvidersSettingsWidget::providerSelectionChanged); - connect(GdbServerProviderManager::instance(), &GdbServerProviderManager::providersChanged, - this, &GdbServerProvidersSettingsWidget::providerSelectionChanged); + connect(DebugServerProviderManager::instance(), &DebugServerProviderManager::providersChanged, + this, &DebugServerProvidersSettingsWidget::providerSelectionChanged); // Set up add menu: const auto addMenu = new QMenu(m_addButton); - for (const auto f : GdbServerProviderManager::factories()) { + for (const auto f : DebugServerProviderManager::factories()) { const auto action = new QAction(addMenu); action->setText(f->displayName()); connect(action, &QAction::triggered, this, [this, f] { createProvider(f); }); @@ -328,12 +328,12 @@ GdbServerProvidersSettingsWidget::GdbServerProvidersSettingsWidget m_addButton->setMenu(addMenu); connect(m_delButton, &QPushButton::clicked, - this, &GdbServerProvidersSettingsWidget::removeProvider); + this, &DebugServerProvidersSettingsWidget::removeProvider); updateState(); } -void GdbServerProvidersSettingsWidget::providerSelectionChanged() +void DebugServerProvidersSettingsWidget::providerSelectionChanged() { if (!m_container) return; @@ -342,18 +342,18 @@ void GdbServerProvidersSettingsWidget::providerSelectionChanged() if (w) w->setVisible(false); - const GdbServerProviderNode *node = m_model.nodeForIndex(current); + const DebugServerProviderNode *node = m_model.nodeForIndex(current); w = node ? node->widget : nullptr; m_container->setWidget(w); m_container->setVisible(w != nullptr); updateState(); } -void GdbServerProvidersSettingsWidget::createProvider(GdbServerProviderFactory *f) +void DebugServerProvidersSettingsWidget::createProvider(IDebugServerProviderFactory *f) { - GdbServerProvider *provider = nullptr; + IDebugServerProvider *provider = nullptr; if (!f) { - const GdbServerProvider *old = m_model.provider(currentIndex()); + const IDebugServerProvider *old = m_model.provider(currentIndex()); if (!old) return; provider = old->clone(); @@ -372,20 +372,20 @@ void GdbServerProvidersSettingsWidget::createProvider(GdbServerProviderFactory * | QItemSelectionModel::Rows); } -void GdbServerProvidersSettingsWidget::removeProvider() +void DebugServerProvidersSettingsWidget::removeProvider() { - if (GdbServerProvider *p = m_model.provider(currentIndex())) + if (IDebugServerProvider *p = m_model.provider(currentIndex())) m_model.markForRemoval(p); } -void GdbServerProvidersSettingsWidget::updateState() +void DebugServerProvidersSettingsWidget::updateState() { if (!m_cloneButton) return; bool canCopy = false; bool canDelete = false; - if (const GdbServerProvider *p = m_model.provider(currentIndex())) { + if (const IDebugServerProvider *p = m_model.provider(currentIndex())) { canCopy = p->isValid(); canDelete = true; } @@ -394,7 +394,7 @@ void GdbServerProvidersSettingsWidget::updateState() m_delButton->setEnabled(canDelete); } -QModelIndex GdbServerProvidersSettingsWidget::currentIndex() const +QModelIndex DebugServerProvidersSettingsWidget::currentIndex() const { if (!m_selectionModel) return {}; @@ -406,31 +406,31 @@ QModelIndex GdbServerProvidersSettingsWidget::currentIndex() const } -GdbServerProvidersSettingsPage::GdbServerProvidersSettingsPage() +DebugServerProvidersSettingsPage::DebugServerProvidersSettingsPage() { setId(Constants::GDB_PROVIDERS_SETTINGS_ID); setDisplayName(tr("Bare Metal")); setCategory(ProjectExplorer::Constants::DEVICE_SETTINGS_CATEGORY); } -QWidget *GdbServerProvidersSettingsPage::widget() +QWidget *DebugServerProvidersSettingsPage::widget() { if (!m_configWidget) - m_configWidget = new GdbServerProvidersSettingsWidget(this); + m_configWidget = new DebugServerProvidersSettingsWidget(this); return m_configWidget; } -void GdbServerProvidersSettingsPage::apply() +void DebugServerProvidersSettingsPage::apply() { if (m_configWidget) m_configWidget->m_model.apply(); } -void GdbServerProvidersSettingsPage::finish() +void DebugServerProvidersSettingsPage::finish() { if (m_configWidget) - disconnect(GdbServerProviderManager::instance(), &GdbServerProviderManager::providersChanged, - m_configWidget, &GdbServerProvidersSettingsWidget::providerSelectionChanged); + disconnect(DebugServerProviderManager::instance(), &DebugServerProviderManager::providersChanged, + m_configWidget, &DebugServerProvidersSettingsWidget::providerSelectionChanged); delete m_configWidget; m_configWidget = nullptr; diff --git a/src/plugins/baremetal/gdbserverproviderssettingspage.h b/src/plugins/baremetal/debugserverproviderssettingspage.h similarity index 57% rename from src/plugins/baremetal/gdbserverproviderssettingspage.h rename to src/plugins/baremetal/debugserverproviderssettingspage.h index c41389b3078..576f3480fc9 100644 --- a/src/plugins/baremetal/gdbserverproviderssettingspage.h +++ b/src/plugins/baremetal/debugserverproviderssettingspage.h @@ -40,61 +40,61 @@ namespace Utils { class DetailsWidget; } namespace BareMetal { namespace Internal { -class GdbServerProvider; -class GdbServerProviderConfigWidget; -class GdbServerProviderFactory; -class GdbServerProviderNode; -class GdbServerProvidersSettingsWidget; +class DebugServerProviderNode; +class DebugServerProvidersSettingsWidget; +class IDebugServerProvider; +class IDebugServerProviderConfigWidget; +class IDebugServerProviderFactory; -// GdbServerProviderModel +// DebugServerProviderModel -class GdbServerProviderModel final - : public Utils::TreeModel, GdbServerProviderNode> +class DebugServerProviderModel final + : public Utils::TreeModel, DebugServerProviderNode> { Q_OBJECT public: - explicit GdbServerProviderModel(); + explicit DebugServerProviderModel(); - GdbServerProvider *provider(const QModelIndex &) const; - GdbServerProviderConfigWidget *widget(const QModelIndex &) const; - GdbServerProviderNode *nodeForIndex(const QModelIndex &index) const; - QModelIndex indexForProvider(GdbServerProvider *provider) const; + IDebugServerProvider *provider(const QModelIndex &) const; + IDebugServerProviderConfigWidget *widget(const QModelIndex &) const; + DebugServerProviderNode *nodeForIndex(const QModelIndex &index) const; + QModelIndex indexForProvider(IDebugServerProvider *provider) const; void apply(); - void markForRemoval(GdbServerProvider *); - void markForAddition(GdbServerProvider *); + void markForRemoval(IDebugServerProvider *); + void markForAddition(IDebugServerProvider *); signals: void providerStateChanged(); private: - void addProvider(GdbServerProvider *); - void removeProvider(GdbServerProvider *); + void addProvider(IDebugServerProvider *); + void removeProvider(IDebugServerProvider *); - GdbServerProviderNode *findNode(const GdbServerProvider *provider) const; - GdbServerProviderNode *createNode(GdbServerProvider *, bool changed); + DebugServerProviderNode *findNode(const IDebugServerProvider *provider) const; + DebugServerProviderNode *createNode(IDebugServerProvider *, bool changed); - QList m_providersToAdd; - QList m_providersToRemove; + QList m_providersToAdd; + QList m_providersToRemove; }; -// GdbServerProvidersSettingsPage +// DebugServerProvidersSettingsPage -class GdbServerProvidersSettingsPage final : public Core::IOptionsPage +class DebugServerProvidersSettingsPage final : public Core::IOptionsPage { Q_OBJECT public: - GdbServerProvidersSettingsPage(); + DebugServerProvidersSettingsPage(); private: QWidget *widget() final; void apply() final; void finish() final; - GdbServerProvidersSettingsWidget *m_configWidget = nullptr; + DebugServerProvidersSettingsWidget *m_configWidget = nullptr; }; } // namespace Internal diff --git a/src/plugins/baremetal/defaultgdbserverprovider.cpp b/src/plugins/baremetal/debugservers/gdb/defaultgdbserverprovider.cpp similarity index 92% rename from src/plugins/baremetal/defaultgdbserverprovider.cpp rename to src/plugins/baremetal/debugservers/gdb/defaultgdbserverprovider.cpp index 189e64524b0..9605ae166bd 100644 --- a/src/plugins/baremetal/defaultgdbserverprovider.cpp +++ b/src/plugins/baremetal/debugservers/gdb/defaultgdbserverprovider.cpp @@ -23,14 +23,15 @@ ** ****************************************************************************/ -#include "baremetalconstants.h" #include "defaultgdbserverprovider.h" -#include "gdbserverprovidermanager.h" -#include +#include +#include #include +#include + #include #include #include @@ -126,25 +127,27 @@ DefaultGdbServerProviderConfigWidget::DefaultGdbServerProviderConfigWidget( this, &GdbServerProviderConfigWidget::dirty); } -void DefaultGdbServerProviderConfigWidget::applyImpl() +void DefaultGdbServerProviderConfigWidget::apply() { - auto p = static_cast(provider()); + const auto p = static_cast(m_provider); Q_ASSERT(p); p->setChannel(m_hostWidget->channel()); p->setUseExtendedRemote(m_useExtendedRemoteCheckBox->isChecked()); p->setInitCommands(m_initCommandsTextEdit->toPlainText()); p->setResetCommands(m_resetCommandsTextEdit->toPlainText()); + IDebugServerProviderConfigWidget::apply(); } -void DefaultGdbServerProviderConfigWidget::discardImpl() +void DefaultGdbServerProviderConfigWidget::discard() { setFromProvider(); + IDebugServerProviderConfigWidget::discard(); } void DefaultGdbServerProviderConfigWidget::setFromProvider() { - const auto p = static_cast(provider()); + const auto p = static_cast(m_provider); Q_ASSERT(p); const QSignalBlocker blocker(this); diff --git a/src/plugins/baremetal/defaultgdbserverprovider.h b/src/plugins/baremetal/debugservers/gdb/defaultgdbserverprovider.h similarity index 85% rename from src/plugins/baremetal/defaultgdbserverprovider.h rename to src/plugins/baremetal/debugservers/gdb/defaultgdbserverprovider.h index 8beb9b7b770..ef385af8630 100644 --- a/src/plugins/baremetal/defaultgdbserverprovider.h +++ b/src/plugins/baremetal/debugservers/gdb/defaultgdbserverprovider.h @@ -27,12 +27,14 @@ #include "gdbserverprovider.h" +QT_BEGIN_NAMESPACE +class QCheckBox; +class QPlainTextEdit; +QT_END_NAMESPACE + namespace BareMetal { namespace Internal { -class DefaultGdbServerProviderConfigWidget; -class DefaultGdbServerProviderFactory; - // DefaultGdbServerProvider class DefaultGdbServerProvider final : public GdbServerProvider @@ -51,7 +53,8 @@ private: // DefaultGdbServerProviderFactory -class DefaultGdbServerProviderFactory final : public GdbServerProviderFactory +class DefaultGdbServerProviderFactory final + : public IDebugServerProviderFactory { Q_OBJECT @@ -66,16 +69,18 @@ public: // DefaultGdbServerProviderConfigWidget -class DefaultGdbServerProviderConfigWidget final : public GdbServerProviderConfigWidget +class DefaultGdbServerProviderConfigWidget final + : public GdbServerProviderConfigWidget { Q_OBJECT public: - explicit DefaultGdbServerProviderConfigWidget(DefaultGdbServerProvider *); + explicit DefaultGdbServerProviderConfigWidget( + DefaultGdbServerProvider *provider); private: - void applyImpl() final; - void discardImpl() final; + void apply() final; + void discard() final; void setFromProvider(); diff --git a/src/plugins/baremetal/gdbserverprovider.cpp b/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.cpp similarity index 58% rename from src/plugins/baremetal/gdbserverprovider.cpp rename to src/plugins/baremetal/debugservers/gdb/gdbserverprovider.cpp index a916146c385..837f02d1ee0 100644 --- a/src/plugins/baremetal/gdbserverprovider.cpp +++ b/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.cpp @@ -23,27 +23,22 @@ ** ****************************************************************************/ -#include "baremetaldevice.h" #include "gdbserverprovider.h" -#include "gdbserverprovidermanager.h" + +#include +#include #include #include #include -#include #include -#include #include -#include #include -#include namespace BareMetal { namespace Internal { -const char idKeyC[] = "BareMetal.GdbServerProvider.Id"; -const char displayNameKeyC[] = "BareMetal.GdbServerProvider.DisplayName"; const char startupModeKeyC[] = "BareMetal.GdbServerProvider.Mode"; const char initCommandsKeyC[] = "BareMetal.GdbServerProvider.InitCommands"; const char resetCommandsKeyC[] = "BareMetal.GdbServerProvider.ResetCommands"; @@ -52,58 +47,20 @@ const char useExtendedRemoteKeyC[] = "BareMetal.GdbServerProvider.UseExtendedRem const char hostKeySuffixC[] = ".Host"; const char portKeySuffixC[] = ".Port"; -static QString createId(const QString &id) -{ - QString newId = id.left(id.indexOf(QLatin1Char(':'))); - newId.append(QLatin1Char(':') + QUuid::createUuid().toString()); - return newId; -} - // GdbServerProvider GdbServerProvider::GdbServerProvider(const QString &id) - : m_id(createId(id)) + : IDebugServerProvider(id) { } GdbServerProvider::GdbServerProvider(const GdbServerProvider &other) - : m_id(createId(other.m_id)) + : IDebugServerProvider(other.id()) , m_startupMode(other.m_startupMode) , m_initCommands(other.m_initCommands) , m_resetCommands(other.m_resetCommands) , m_useExtendedRemote(other.useExtendedRemote()) { - m_displayName = QCoreApplication::translate( - "BareMetal::GdbServerProvider", "Clone of %1") - .arg(other.displayName()); -} - -GdbServerProvider::~GdbServerProvider() -{ - const QSet devices = m_devices; - for (BareMetalDevice *device : devices) - device->unregisterProvider(this); -} - -QString GdbServerProvider::displayName() const -{ - if (m_displayName.isEmpty()) - return typeDisplayName(); - return m_displayName; -} - -void GdbServerProvider::setDisplayName(const QString &name) -{ - if (m_displayName == name) - return; - - m_displayName = name; - providerUpdated(); -} - -QString GdbServerProvider::id() const -{ - return m_id; } GdbServerProvider::StartupMode GdbServerProvider::startupMode() const @@ -131,11 +88,6 @@ bool GdbServerProvider::useExtendedRemote() const return m_useExtendedRemote; } -QString GdbServerProvider::typeDisplayName() const -{ - return m_typeDisplayName; -} - void GdbServerProvider::setUseExtendedRemote(bool useExtendedRemote) { m_useExtendedRemote = useExtendedRemote; @@ -172,21 +124,17 @@ Utils::CommandLine GdbServerProvider::command() const return {}; } -bool GdbServerProvider::operator==(const GdbServerProvider &other) const +bool GdbServerProvider::operator==(const IDebugServerProvider &other) const { - if (this == &other) - return true; + if (!IDebugServerProvider::operator==(other)) + return false; - const QString thisId = id().left(id().indexOf(QLatin1Char(':'))); - const QString otherId = other.id().left(other.id().indexOf(QLatin1Char(':'))); - - // We ignore displayname - return thisId == otherId - && m_channel == other.m_channel - && m_startupMode == other.m_startupMode - && m_initCommands == other.m_initCommands - && m_resetCommands == other.m_resetCommands - && m_useExtendedRemote == other.m_useExtendedRemote; + const auto p = static_cast(&other); + return m_channel == p->m_channel + && m_startupMode == p->m_startupMode + && m_initCommands == p->m_initCommands + && m_resetCommands == p->m_resetCommands + && m_useExtendedRemote == p->m_useExtendedRemote; } QString GdbServerProvider::channelString() const @@ -199,16 +147,14 @@ QString GdbServerProvider::channelString() const QVariantMap GdbServerProvider::toMap() const { - return { - {QLatin1String(idKeyC), m_id}, - {QLatin1String(displayNameKeyC), m_displayName}, - {QLatin1String(startupModeKeyC), m_startupMode}, - {QLatin1String(initCommandsKeyC), m_initCommands}, - {QLatin1String(resetCommandsKeyC), m_resetCommands}, - {QLatin1String(useExtendedRemoteKeyC), m_useExtendedRemote}, - {m_settingsBase + hostKeySuffixC, m_channel.host()}, - {m_settingsBase + portKeySuffixC, m_channel.port()}, - }; + QVariantMap data = IDebugServerProvider::toMap(); + data.insert(startupModeKeyC, m_startupMode); + data.insert(initCommandsKeyC, m_initCommands); + data.insert(resetCommandsKeyC, m_resetCommands); + data.insert(useExtendedRemoteKeyC, m_useExtendedRemote); + data.insert(m_settingsBase + hostKeySuffixC, m_channel.host()); + data.insert(m_settingsBase + portKeySuffixC, m_channel.port()); + return data; } bool GdbServerProvider::isValid() const @@ -221,94 +167,31 @@ bool GdbServerProvider::canStartupMode(StartupMode m) const return m == NoStartup; } -void GdbServerProvider::registerDevice(BareMetalDevice *device) -{ - m_devices.insert(device); -} - -void GdbServerProvider::unregisterDevice(BareMetalDevice *device) -{ - m_devices.remove(device); -} - -void GdbServerProvider::providerUpdated() -{ - GdbServerProviderManager::notifyAboutUpdate(this); - for (BareMetalDevice *device : qAsConst(m_devices)) - device->providerUpdated(this); -} - bool GdbServerProvider::fromMap(const QVariantMap &data) { - m_id = data.value(QLatin1String(idKeyC)).toString(); - m_displayName = data.value(QLatin1String(displayNameKeyC)).toString(); - m_startupMode = static_cast(data.value(QLatin1String(startupModeKeyC)).toInt()); - m_initCommands = data.value(QLatin1String(initCommandsKeyC)).toString(); - m_resetCommands = data.value(QLatin1String(resetCommandsKeyC)).toString(); - m_useExtendedRemote = data.value(QLatin1String(useExtendedRemoteKeyC)).toBool(); + if (!IDebugServerProvider::fromMap(data)) + return false; + + m_startupMode = static_cast(data.value(startupModeKeyC).toInt()); + m_initCommands = data.value(initCommandsKeyC).toString(); + m_resetCommands = data.value(resetCommandsKeyC).toString(); + m_useExtendedRemote = data.value(useExtendedRemoteKeyC).toBool(); m_channel.setHost(data.value(m_settingsBase + hostKeySuffixC).toString()); m_channel.setPort(data.value(m_settingsBase + portKeySuffixC).toInt()); - return true; } -void GdbServerProvider::setTypeDisplayName(const QString &typeDisplayName) -{ - m_typeDisplayName = typeDisplayName; -} - void GdbServerProvider::setSettingsKeyBase(const QString &settingsBase) { m_settingsBase = settingsBase; } -// GdbServerProviderFactory - -QString GdbServerProviderFactory::id() const -{ - return m_id; -} - -void GdbServerProviderFactory::setId(const QString &id) -{ - m_id = id; -} - -QString GdbServerProviderFactory::displayName() const -{ - return m_displayName; -} - -void GdbServerProviderFactory::setDisplayName(const QString &name) -{ - m_displayName = name; -} - -QString GdbServerProviderFactory::idFromMap(const QVariantMap &data) -{ - return data.value(QLatin1String(idKeyC)).toString(); -} - -void GdbServerProviderFactory::idToMap(QVariantMap &data, const QString &id) -{ - data.insert(QLatin1String(idKeyC), id); -} - // GdbServerProviderConfigWidget GdbServerProviderConfigWidget::GdbServerProviderConfigWidget( GdbServerProvider *provider) - : m_provider(provider) + : IDebugServerProviderConfigWidget(provider) { - Q_ASSERT(provider); - - m_mainLayout = new QFormLayout(this); - m_mainLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); - - m_nameLineEdit = new QLineEdit(this); - m_nameLineEdit->setToolTip(tr("Enter the name of the GDB server provider.")); - m_mainLayout->addRow(tr("Name:"), m_nameLineEdit); - m_startupModeComboBox = new QComboBox(this); m_startupModeComboBox->setToolTip(tr("Choose the desired startup mode " "of the GDB server provider.")); @@ -317,8 +200,6 @@ GdbServerProviderConfigWidget::GdbServerProviderConfigWidget( populateStartupModes(); setFromProvider(); - connect(m_nameLineEdit, &QLineEdit::textChanged, - this, &GdbServerProviderConfigWidget::dirty); connect(m_startupModeComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &GdbServerProviderConfigWidget::dirty); @@ -326,30 +207,14 @@ GdbServerProviderConfigWidget::GdbServerProviderConfigWidget( void GdbServerProviderConfigWidget::apply() { - m_provider->setDisplayName(m_nameLineEdit->text()); - m_provider->setStartupMode(startupMode()); - - applyImpl(); + static_cast(m_provider)->setStartupMode(startupMode()); + IDebugServerProviderConfigWidget::apply(); } void GdbServerProviderConfigWidget::discard() { - m_nameLineEdit->setText(m_provider->displayName()); - discardImpl(); -} - -GdbServerProvider *GdbServerProviderConfigWidget::provider() const -{ - return m_provider; -} - -void GdbServerProviderConfigWidget::addErrorLabel() -{ - if (!m_errorLabel) { - m_errorLabel = new QLabel; - m_errorLabel->setVisible(false); - } - m_mainLayout->addRow(m_errorLabel); + setFromProvider(); + IDebugServerProviderConfigWidget::discard(); } GdbServerProvider::StartupMode GdbServerProviderConfigWidget::startupModeFromIndex( @@ -379,7 +244,7 @@ void GdbServerProviderConfigWidget::populateStartupModes() { for (int i = 0; i < GdbServerProvider::StartupModesCount; ++i) { const auto m = static_cast(i); - if (!m_provider->canStartupMode(m)) + if (!static_cast(m_provider)->canStartupMode(m)) continue; const int idx = m_startupModeComboBox->count(); @@ -394,31 +259,9 @@ void GdbServerProviderConfigWidget::populateStartupModes() } } -void GdbServerProviderConfigWidget::setErrorMessage(const QString &m) -{ - QTC_ASSERT(m_errorLabel, return); - if (m.isEmpty()) { - clearErrorMessage(); - } else { - m_errorLabel->setText(m); - m_errorLabel->setStyleSheet(QLatin1String("background-color: \"red\"")); - m_errorLabel->setVisible(true); - } -} - -void GdbServerProviderConfigWidget::clearErrorMessage() -{ - QTC_ASSERT(m_errorLabel, return); - m_errorLabel->clear(); - m_errorLabel->setStyleSheet(QString()); - m_errorLabel->setVisible(false); -} - void GdbServerProviderConfigWidget::setFromProvider() { - const QSignalBlocker blocker(this); - m_nameLineEdit->setText(m_provider->displayName()); - setStartupMode(m_provider->startupMode()); + setStartupMode(static_cast(m_provider)->startupMode()); } QString GdbServerProviderConfigWidget::defaultInitCommandsTooltip() @@ -435,6 +278,17 @@ QString GdbServerProviderConfigWidget::defaultResetCommandsTooltip() "The MCU should be halted after these commands."); } +// GdbServerProviderRunner + +GdbServerProviderRunner::GdbServerProviderRunner(ProjectExplorer::RunControl *runControl, + const ProjectExplorer::Runnable &runnable) + : SimpleTargetRunner(runControl) +{ + setId("BareMetalGdbServer"); + // Baremetal's GDB servers are launched on the host, not on the target. + setStarter([this, runnable] { doStart(runnable, {}); }); +} + // HostWidget HostWidget::HostWidget(QWidget *parent) diff --git a/src/plugins/baremetal/gdbserverprovider.h b/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.h similarity index 59% rename from src/plugins/baremetal/gdbserverprovider.h rename to src/plugins/baremetal/debugservers/gdb/gdbserverprovider.h index 5a6bc246a56..14e7048816b 100644 --- a/src/plugins/baremetal/gdbserverprovider.h +++ b/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.h @@ -25,33 +25,23 @@ #pragma once -#include -#include -#include -#include +#include + +#include #include QT_BEGIN_NAMESPACE -class QCheckBox; class QComboBox; -class QFormLayout; -class QLabel; -class QLineEdit; -class QPlainTextEdit; class QSpinBox; QT_END_NAMESPACE namespace BareMetal { namespace Internal { -class BareMetalDevice; -class GdbServerProviderConfigWidget; -class GdbServerProviderManager; - // GdbServerProvider -class GdbServerProvider +class GdbServerProvider : public IDebugServerProvider { public: enum StartupMode { @@ -61,137 +51,81 @@ public: StartupModesCount }; - virtual ~GdbServerProvider(); - - QString displayName() const; - void setDisplayName(const QString &name); - - QString id() const; - StartupMode startupMode() const; QString initCommands() const; QString resetCommands() const; bool useExtendedRemote() const; - QString typeDisplayName() const; - virtual bool operator==(const GdbServerProvider &) const; - - virtual GdbServerProviderConfigWidget *configurationWidget() = 0; + bool operator==(const IDebugServerProvider &other) const override; virtual QString channelString() const; - virtual GdbServerProvider *clone() const = 0; - virtual QVariantMap toMap() const; + QVariantMap toMap() const override; virtual Utils::CommandLine command() const; - virtual bool isValid() const; + bool isValid() const override; + Debugger::DebuggerEngineType engineType() const final { + return Debugger::DebuggerEngineType::GdbEngineType; } virtual bool canStartupMode(StartupMode) const; - void registerDevice(BareMetalDevice *); - void unregisterDevice(BareMetalDevice *); - QUrl channel() const; void setChannel(const QUrl &channelString); void setDefaultChannel(const QString &host, int port); protected: explicit GdbServerProvider(const QString &id); - explicit GdbServerProvider(const GdbServerProvider &); + explicit GdbServerProvider(const GdbServerProvider &other); void setStartupMode(StartupMode); void setInitCommands(const QString &); void setResetCommands(const QString &); void setUseExtendedRemote(bool); void setSettingsKeyBase(const QString &settingsBase); - void setTypeDisplayName(const QString &typeDisplayName); - void providerUpdated(); + bool fromMap(const QVariantMap &data) override; - virtual bool fromMap(const QVariantMap &data); - -private: - QString m_id; QString m_settingsBase; - mutable QString m_displayName; - QString m_typeDisplayName; QUrl m_channel; StartupMode m_startupMode = NoStartup; QString m_initCommands; QString m_resetCommands; - QSet m_devices; bool m_useExtendedRemote = false; friend class GdbServerProviderConfigWidget; }; -// GdbServerProviderFactory - -class GdbServerProviderFactory : public QObject -{ - Q_OBJECT - -public: - QString id() const; - QString displayName() const; - - virtual GdbServerProvider *create() = 0; - - virtual bool canRestore(const QVariantMap &data) const = 0; - virtual GdbServerProvider *restore(const QVariantMap &data) = 0; - - static QString idFromMap(const QVariantMap &data); - static void idToMap(QVariantMap &data, const QString &id); - -protected: - void setId(const QString &id); - void setDisplayName(const QString &name); - -private: - QString m_displayName; - QString m_id; -}; - // GdbServerProviderConfigWidget -class GdbServerProviderConfigWidget : public QWidget +class GdbServerProviderConfigWidget : public IDebugServerProviderConfigWidget { Q_OBJECT public: - explicit GdbServerProviderConfigWidget(GdbServerProvider *); - GdbServerProvider *provider() const; - void apply(); - void discard(); - -signals: - void dirty(); + explicit GdbServerProviderConfigWidget(GdbServerProvider *provider); + void apply() override; + void discard() override; protected: - virtual void applyImpl() = 0; - virtual void discardImpl() = 0; - - void setErrorMessage(const QString &); - void clearErrorMessage(); - void addErrorLabel(); - GdbServerProvider::StartupMode startupModeFromIndex(int idx) const; GdbServerProvider::StartupMode startupMode() const; void setStartupMode(GdbServerProvider::StartupMode mode); void populateStartupModes(); + void setFromProvider(); static QString defaultInitCommandsTooltip(); static QString defaultResetCommandsTooltip(); - QFormLayout *m_mainLayout = nullptr; - QLineEdit *m_nameLineEdit = nullptr; QComboBox *m_startupModeComboBox = nullptr; +}; -private: - void setFromProvider(); +// GdbServerProviderRunner - GdbServerProvider *m_provider = nullptr; - QLabel *m_errorLabel = nullptr; +class GdbServerProviderRunner final : public ProjectExplorer::SimpleTargetRunner +{ +public: + explicit GdbServerProviderRunner(ProjectExplorer::RunControl *runControl, + const ProjectExplorer::Runnable &runnable); }; // HostWidget @@ -209,7 +143,7 @@ public: signals: void dataChanged(); -private: +protected: QLineEdit *m_hostLineEdit = nullptr; QSpinBox *m_portSpinBox = nullptr; }; diff --git a/src/plugins/baremetal/gdbserverproviderprocess.cpp b/src/plugins/baremetal/debugservers/gdb/gdbserverproviderprocess.cpp similarity index 100% rename from src/plugins/baremetal/gdbserverproviderprocess.cpp rename to src/plugins/baremetal/debugservers/gdb/gdbserverproviderprocess.cpp diff --git a/src/plugins/baremetal/gdbserverproviderprocess.h b/src/plugins/baremetal/debugservers/gdb/gdbserverproviderprocess.h similarity index 100% rename from src/plugins/baremetal/gdbserverproviderprocess.h rename to src/plugins/baremetal/debugservers/gdb/gdbserverproviderprocess.h diff --git a/src/plugins/baremetal/debugservers/gdb/gdbservers.pri b/src/plugins/baremetal/debugservers/gdb/gdbservers.pri new file mode 100644 index 00000000000..f43b4a92fb8 --- /dev/null +++ b/src/plugins/baremetal/debugservers/gdb/gdbservers.pri @@ -0,0 +1,13 @@ +HEADERS += \ + $$PWD/defaultgdbserverprovider.h \ + $$PWD/gdbserverprovider.h \ + $$PWD/gdbserverproviderprocess.h \ + $$PWD/openocdgdbserverprovider.h \ + $$PWD/stlinkutilgdbserverprovider.h \ + +SOURCES += \ + $$PWD/defaultgdbserverprovider.cpp \ + $$PWD/gdbserverprovider.cpp \ + $$PWD/gdbserverproviderprocess.cpp \ + $$PWD/openocdgdbserverprovider.cpp \ + $$PWD/stlinkutilgdbserverprovider.cpp \ diff --git a/src/plugins/baremetal/openocdgdbserverprovider.cpp b/src/plugins/baremetal/debugservers/gdb/openocdgdbserverprovider.cpp similarity index 90% rename from src/plugins/baremetal/openocdgdbserverprovider.cpp rename to src/plugins/baremetal/debugservers/gdb/openocdgdbserverprovider.cpp index 04b1b88cc53..0374c46d5dc 100644 --- a/src/plugins/baremetal/openocdgdbserverprovider.cpp +++ b/src/plugins/baremetal/debugservers/gdb/openocdgdbserverprovider.cpp @@ -23,20 +23,19 @@ ** ****************************************************************************/ -#include "baremetalconstants.h" - -#include "gdbserverprovidermanager.h" #include "openocdgdbserverprovider.h" +#include +#include + +#include + #include #include #include #include -#include - #include -#include #include #include #include @@ -158,10 +157,10 @@ GdbServerProvider *OpenOcdGdbServerProvider::clone() const QVariantMap OpenOcdGdbServerProvider::toMap() const { QVariantMap data = GdbServerProvider::toMap(); - data.insert(QLatin1String(executableFileKeyC), m_executableFile.toVariant()); - data.insert(QLatin1String(rootScriptsDirKeyC), m_rootScriptsDir); - data.insert(QLatin1String(configurationFileKeyC), m_configurationFile); - data.insert(QLatin1String(additionalArgumentsKeyC), m_additionalArguments); + data.insert(executableFileKeyC, m_executableFile.toVariant()); + data.insert(rootScriptsDirKeyC, m_rootScriptsDir); + data.insert(configurationFileKeyC, m_configurationFile); + data.insert(additionalArgumentsKeyC, m_additionalArguments); return data; } @@ -170,14 +169,14 @@ bool OpenOcdGdbServerProvider::fromMap(const QVariantMap &data) if (!GdbServerProvider::fromMap(data)) return false; - m_executableFile = FilePath::fromVariant(data.value(QLatin1String(executableFileKeyC))); - m_rootScriptsDir = data.value(QLatin1String(rootScriptsDirKeyC)).toString(); - m_configurationFile = data.value(QLatin1String(configurationFileKeyC)).toString(); - m_additionalArguments = data.value(QLatin1String(additionalArgumentsKeyC)).toString(); + m_executableFile = FilePath::fromVariant(data.value(executableFileKeyC)); + m_rootScriptsDir = data.value(rootScriptsDirKeyC).toString(); + m_configurationFile = data.value(configurationFileKeyC).toString(); + m_additionalArguments = data.value(additionalArgumentsKeyC).toString(); return true; } -bool OpenOcdGdbServerProvider::operator==(const GdbServerProvider &other) const +bool OpenOcdGdbServerProvider::operator==(const IDebugServerProvider &other) const { if (!GdbServerProvider::operator==(other)) return false; @@ -227,10 +226,10 @@ GdbServerProvider *OpenOcdGdbServerProviderFactory::restore(const QVariantMap &d // OpenOcdGdbServerProviderConfigWidget OpenOcdGdbServerProviderConfigWidget::OpenOcdGdbServerProviderConfigWidget( - OpenOcdGdbServerProvider *p) - : GdbServerProviderConfigWidget(p) + OpenOcdGdbServerProvider *provider) + : GdbServerProviderConfigWidget(provider) { - Q_ASSERT(p); + Q_ASSERT(provider); m_hostWidget = new HostWidget(this); m_mainLayout->addRow(tr("Host:"), m_hostWidget); @@ -285,6 +284,27 @@ OpenOcdGdbServerProviderConfigWidget::OpenOcdGdbServerProviderConfigWidget( this, &OpenOcdGdbServerProviderConfigWidget::startupModeChanged); } +void OpenOcdGdbServerProviderConfigWidget::apply() +{ + const auto p = static_cast(m_provider); + Q_ASSERT(p); + + p->setChannel(m_hostWidget->channel()); + p->m_executableFile = m_executableFileChooser->fileName(); + p->m_rootScriptsDir = m_rootScriptsDirChooser->fileName().toString(); + p->m_configurationFile = m_configurationFileChooser->fileName().toString(); + p->m_additionalArguments = m_additionalArgumentsLineEdit->text(); + p->setInitCommands(m_initCommandsTextEdit->toPlainText()); + p->setResetCommands(m_resetCommandsTextEdit->toPlainText()); + GdbServerProviderConfigWidget::apply(); +} + +void OpenOcdGdbServerProviderConfigWidget::discard() +{ + setFromProvider(); + GdbServerProviderConfigWidget::discard(); +} + void OpenOcdGdbServerProviderConfigWidget::startupModeChanged() { const GdbServerProvider::StartupMode m = startupMode(); @@ -302,28 +322,9 @@ void OpenOcdGdbServerProviderConfigWidget::startupModeChanged() m_mainLayout->labelForField(m_hostWidget)->setVisible(isNetwork); } -void OpenOcdGdbServerProviderConfigWidget::applyImpl() -{ - const auto p = static_cast(provider()); - Q_ASSERT(p); - - p->setChannel(m_hostWidget->channel()); - p->m_executableFile = m_executableFileChooser->fileName(); - p->m_rootScriptsDir = m_rootScriptsDirChooser->fileName().toString(); - p->m_configurationFile = m_configurationFileChooser->fileName().toString(); - p->m_additionalArguments = m_additionalArgumentsLineEdit->text(); - p->setInitCommands(m_initCommandsTextEdit->toPlainText()); - p->setResetCommands(m_resetCommandsTextEdit->toPlainText()); -} - -void OpenOcdGdbServerProviderConfigWidget::discardImpl() -{ - setFromProvider(); -} - void OpenOcdGdbServerProviderConfigWidget::setFromProvider() { - const auto p = static_cast(provider()); + const auto p = static_cast(m_provider); Q_ASSERT(p); const QSignalBlocker blocker(this); diff --git a/src/plugins/baremetal/openocdgdbserverprovider.h b/src/plugins/baremetal/debugservers/gdb/openocdgdbserverprovider.h similarity index 85% rename from src/plugins/baremetal/openocdgdbserverprovider.h rename to src/plugins/baremetal/debugservers/gdb/openocdgdbserverprovider.h index ceb5329c372..fb494a30adf 100644 --- a/src/plugins/baremetal/openocdgdbserverprovider.h +++ b/src/plugins/baremetal/debugservers/gdb/openocdgdbserverprovider.h @@ -27,14 +27,15 @@ #include "gdbserverprovider.h" +QT_BEGIN_NAMESPACE +class QPlainTextEdit; +QT_END_NAMESPACE + namespace Utils { class PathChooser; } namespace BareMetal { namespace Internal { -class OpenOcdGdbServerProviderConfigWidget; -class OpenOcdGdbServerProviderFactory; - // OpenOcdGdbServerProvider class OpenOcdGdbServerProvider final : public GdbServerProvider @@ -43,7 +44,7 @@ public: QVariantMap toMap() const final; bool fromMap(const QVariantMap &data) final; - bool operator==(const GdbServerProvider &) const final; + bool operator==(const IDebugServerProvider &other) const final; GdbServerProviderConfigWidget *configurationWidget() final; GdbServerProvider *clone() const final; @@ -53,6 +54,7 @@ public: bool canStartupMode(StartupMode mode) const final; bool isValid() const final; + bool hasProcess() const final { return true; } private: explicit OpenOcdGdbServerProvider(); @@ -71,7 +73,8 @@ private: // OpenOcdGdbServerProviderFactory -class OpenOcdGdbServerProviderFactory final : public GdbServerProviderFactory +class OpenOcdGdbServerProviderFactory final + : public IDebugServerProviderFactory { Q_OBJECT @@ -82,25 +85,24 @@ public: bool canRestore(const QVariantMap &data) const final; GdbServerProvider *restore(const QVariantMap &data) final; - - GdbServerProviderConfigWidget *configurationWidget(GdbServerProvider *); }; // OpenOcdGdbServerProviderConfigWidget -class OpenOcdGdbServerProviderConfigWidget final : public GdbServerProviderConfigWidget +class OpenOcdGdbServerProviderConfigWidget final + : public GdbServerProviderConfigWidget { Q_OBJECT public: - explicit OpenOcdGdbServerProviderConfigWidget(OpenOcdGdbServerProvider *); + explicit OpenOcdGdbServerProviderConfigWidget( + OpenOcdGdbServerProvider *provider); private: + void apply() final; + void discard() final; + void startupModeChanged(); - - void applyImpl() final; - void discardImpl() final; - void setFromProvider(); HostWidget *m_hostWidget = nullptr; diff --git a/src/plugins/baremetal/stlinkutilgdbserverprovider.cpp b/src/plugins/baremetal/debugservers/gdb/stlinkutilgdbserverprovider.cpp similarity index 91% rename from src/plugins/baremetal/stlinkutilgdbserverprovider.cpp rename to src/plugins/baremetal/debugservers/gdb/stlinkutilgdbserverprovider.cpp index 35e83322e38..3591ddb2fd7 100644 --- a/src/plugins/baremetal/stlinkutilgdbserverprovider.cpp +++ b/src/plugins/baremetal/debugservers/gdb/stlinkutilgdbserverprovider.cpp @@ -23,22 +23,20 @@ ** ****************************************************************************/ -#include "baremetalconstants.h" - -#include "gdbserverprovidermanager.h" #include "stlinkutilgdbserverprovider.h" +#include +#include + +#include + #include #include #include -#include - #include #include -#include #include -#include #include #include @@ -152,11 +150,11 @@ GdbServerProvider *StLinkUtilGdbServerProvider::clone() const QVariantMap StLinkUtilGdbServerProvider::toMap() const { QVariantMap data = GdbServerProvider::toMap(); - data.insert(QLatin1String(executableFileKeyC), m_executableFile.toVariant()); - data.insert(QLatin1String(verboseLevelKeyC), m_verboseLevel); - data.insert(QLatin1String(extendedModeKeyC), m_extendedMode); - data.insert(QLatin1String(resetBoardKeyC), m_resetBoard); - data.insert(QLatin1String(transportLayerKeyC), m_transport); + data.insert(executableFileKeyC, m_executableFile.toVariant()); + data.insert(verboseLevelKeyC, m_verboseLevel); + data.insert(extendedModeKeyC, m_extendedMode); + data.insert(resetBoardKeyC, m_resetBoard); + data.insert(transportLayerKeyC, m_transport); return data; } @@ -165,16 +163,16 @@ bool StLinkUtilGdbServerProvider::fromMap(const QVariantMap &data) if (!GdbServerProvider::fromMap(data)) return false; - m_executableFile = FilePath::fromVariant(data.value(QLatin1String(executableFileKeyC))); - m_verboseLevel = data.value(QLatin1String(verboseLevelKeyC)).toInt(); - m_extendedMode = data.value(QLatin1String(extendedModeKeyC)).toBool(); - m_resetBoard = data.value(QLatin1String(resetBoardKeyC)).toBool(); + m_executableFile = FilePath::fromVariant(data.value(executableFileKeyC)); + m_verboseLevel = data.value(verboseLevelKeyC).toInt(); + m_extendedMode = data.value(extendedModeKeyC).toBool(); + m_resetBoard = data.value(resetBoardKeyC).toBool(); m_transport = static_cast( - data.value(QLatin1String(transportLayerKeyC)).toInt()); + data.value(transportLayerKeyC).toInt()); return true; } -bool StLinkUtilGdbServerProvider::operator==(const GdbServerProvider &other) const +bool StLinkUtilGdbServerProvider::operator==(const IDebugServerProvider &other) const { if (!GdbServerProvider::operator==(other)) return false; @@ -296,25 +294,9 @@ StLinkUtilGdbServerProviderConfigWidget::StLinkUtilGdbServerProviderConfigWidget this, &StLinkUtilGdbServerProviderConfigWidget::startupModeChanged); } -void StLinkUtilGdbServerProviderConfigWidget::startupModeChanged() +void StLinkUtilGdbServerProviderConfigWidget::apply() { - const GdbServerProvider::StartupMode m = startupMode(); - const bool isStartup = m != GdbServerProvider::NoStartup; - m_executableFileChooser->setVisible(isStartup); - m_mainLayout->labelForField(m_executableFileChooser)->setVisible(isStartup); - m_verboseLevelSpinBox->setVisible(isStartup); - m_mainLayout->labelForField(m_verboseLevelSpinBox)->setVisible(isStartup); - m_extendedModeCheckBox->setVisible(isStartup); - m_mainLayout->labelForField(m_extendedModeCheckBox)->setVisible(isStartup); - m_resetBoardCheckBox->setVisible(isStartup); - m_mainLayout->labelForField(m_resetBoardCheckBox)->setVisible(isStartup); - m_transportLayerComboBox->setVisible(isStartup); - m_mainLayout->labelForField(m_transportLayerComboBox)->setVisible(isStartup); -} - -void StLinkUtilGdbServerProviderConfigWidget::applyImpl() -{ - const auto p = static_cast(provider()); + const auto p = static_cast(m_provider); Q_ASSERT(p); p->setChannel(m_hostWidget->channel()); @@ -325,11 +307,13 @@ void StLinkUtilGdbServerProviderConfigWidget::applyImpl() p->m_transport = transportLayer(); p->setInitCommands(m_initCommandsTextEdit->toPlainText()); p->setResetCommands(m_resetCommandsTextEdit->toPlainText()); + GdbServerProviderConfigWidget::apply(); } -void StLinkUtilGdbServerProviderConfigWidget::discardImpl() +void StLinkUtilGdbServerProviderConfigWidget::discard() { setFromProvider(); + GdbServerProviderConfigWidget::discard(); } StLinkUtilGdbServerProvider::TransportLayer @@ -357,6 +341,22 @@ void StLinkUtilGdbServerProviderConfigWidget::setTransportLayer( } } +void StLinkUtilGdbServerProviderConfigWidget::startupModeChanged() +{ + const GdbServerProvider::StartupMode m = startupMode(); + const bool isStartup = m != GdbServerProvider::NoStartup; + m_executableFileChooser->setVisible(isStartup); + m_mainLayout->labelForField(m_executableFileChooser)->setVisible(isStartup); + m_verboseLevelSpinBox->setVisible(isStartup); + m_mainLayout->labelForField(m_verboseLevelSpinBox)->setVisible(isStartup); + m_extendedModeCheckBox->setVisible(isStartup); + m_mainLayout->labelForField(m_extendedModeCheckBox)->setVisible(isStartup); + m_resetBoardCheckBox->setVisible(isStartup); + m_mainLayout->labelForField(m_resetBoardCheckBox)->setVisible(isStartup); + m_transportLayerComboBox->setVisible(isStartup); + m_mainLayout->labelForField(m_transportLayerComboBox)->setVisible(isStartup); +} + void StLinkUtilGdbServerProviderConfigWidget::populateTransportLayers() { m_transportLayerComboBox->insertItem( @@ -369,7 +369,7 @@ void StLinkUtilGdbServerProviderConfigWidget::populateTransportLayers() void StLinkUtilGdbServerProviderConfigWidget::setFromProvider() { - const auto p = static_cast(provider()); + const auto p = static_cast(m_provider); Q_ASSERT(p); const QSignalBlocker blocker(this); diff --git a/src/plugins/baremetal/stlinkutilgdbserverprovider.h b/src/plugins/baremetal/debugservers/gdb/stlinkutilgdbserverprovider.h similarity index 89% rename from src/plugins/baremetal/stlinkutilgdbserverprovider.h rename to src/plugins/baremetal/debugservers/gdb/stlinkutilgdbserverprovider.h index 5416cb5b8b8..aad6e6e31dc 100644 --- a/src/plugins/baremetal/stlinkutilgdbserverprovider.h +++ b/src/plugins/baremetal/debugservers/gdb/stlinkutilgdbserverprovider.h @@ -29,6 +29,7 @@ QT_BEGIN_NAMESPACE class QCheckBox; +class QPlainTextEdit; QT_END_NAMESPACE namespace Utils { class PathChooser; } @@ -36,9 +37,6 @@ namespace Utils { class PathChooser; } namespace BareMetal { namespace Internal { -class StLinkUtilGdbServerProviderConfigWidget; -class StLinkUtilGdbServerProviderFactory; - // StLinkUtilGdbServerProvider class StLinkUtilGdbServerProvider final : public GdbServerProvider @@ -49,7 +47,7 @@ public: QVariantMap toMap() const final; bool fromMap(const QVariantMap &data) final; - bool operator==(const GdbServerProvider &) const final; + bool operator==(const IDebugServerProvider &other) const final; GdbServerProviderConfigWidget *configurationWidget() final; GdbServerProvider *clone() const final; @@ -59,6 +57,7 @@ public: bool canStartupMode(StartupMode mode) const final; bool isValid() const final; + bool hasProcess() const final { return true; } private: explicit StLinkUtilGdbServerProvider(); @@ -79,7 +78,8 @@ private: // StLinkUtilGdbServerProviderFactory -class StLinkUtilGdbServerProviderFactory final : public GdbServerProviderFactory +class StLinkUtilGdbServerProviderFactory final + : public IDebugServerProviderFactory { Q_OBJECT @@ -90,8 +90,6 @@ public: bool canRestore(const QVariantMap &data) const final; GdbServerProvider *restore(const QVariantMap &data) final; - - GdbServerProviderConfigWidget *configurationWidget(GdbServerProvider *); }; // StLinkUtilGdbServerProviderConfigWidget @@ -102,18 +100,18 @@ class StLinkUtilGdbServerProviderConfigWidget final Q_OBJECT public: - explicit StLinkUtilGdbServerProviderConfigWidget(StLinkUtilGdbServerProvider *); + explicit StLinkUtilGdbServerProviderConfigWidget( + StLinkUtilGdbServerProvider *provider); private: - void startupModeChanged(); - - void applyImpl() final; - void discardImpl() final; + void apply() final; + void discard() final; StLinkUtilGdbServerProvider::TransportLayer transportLayerFromIndex(int idx) const; StLinkUtilGdbServerProvider::TransportLayer transportLayer() const; void setTransportLayer(StLinkUtilGdbServerProvider::TransportLayer); + void startupModeChanged(); void populateTransportLayers(); void setFromProvider(); diff --git a/src/plugins/baremetal/idebugserverprovider.cpp b/src/plugins/baremetal/idebugserverprovider.cpp new file mode 100644 index 00000000000..ba9140a47f6 --- /dev/null +++ b/src/plugins/baremetal/idebugserverprovider.cpp @@ -0,0 +1,248 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Denis Shienkov +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "baremetaldevice.h" +#include "debugserverprovidermanager.h" +#include "idebugserverprovider.h" + +#include +#include + +#include +#include +#include +#include +#include + +namespace BareMetal { +namespace Internal { + +const char idKeyC[] = "BareMetal.IDebugServerProvider.Id"; +const char displayNameKeyC[] = "BareMetal.IDebugServerProvider.DisplayName"; + +static QString createId(const QString &id) +{ + QString newId = id.left(id.indexOf(QLatin1Char(':'))); + newId.append(QLatin1Char(':') + QUuid::createUuid().toString()); + return newId; +} + +// IDebugServerProvider + +IDebugServerProvider::IDebugServerProvider(const QString &id) + : m_id(createId(id)) +{ +} + +IDebugServerProvider::IDebugServerProvider(const IDebugServerProvider &provider) + : m_id(createId(provider.m_id)) +{ + m_displayName = QCoreApplication::translate( + "BareMetal::IDebugServerProvider", "Clone of %1") + .arg(provider.displayName()); +} + +IDebugServerProvider::~IDebugServerProvider() +{ + const QSet devices = m_devices; + for (BareMetalDevice *device : devices) + device->unregisterDebugServerProvider(this); +} + +QString IDebugServerProvider::displayName() const +{ + if (m_displayName.isEmpty()) + return typeDisplayName(); + return m_displayName; +} + +void IDebugServerProvider::setDisplayName(const QString &name) +{ + if (m_displayName == name) + return; + + m_displayName = name; + providerUpdated(); +} + +QString IDebugServerProvider::id() const +{ + return m_id; +} + +QString IDebugServerProvider::typeDisplayName() const +{ + return m_typeDisplayName; +} + +bool IDebugServerProvider::operator==(const IDebugServerProvider &other) const +{ + if (this == &other) + return true; + + const QString thisId = id().left(id().indexOf(QLatin1Char(':'))); + const QString otherId = other.id().left(other.id().indexOf(QLatin1Char(':'))); + + // We ignore displayname + return thisId == otherId; +} + +QVariantMap IDebugServerProvider::toMap() const +{ + return { + {QLatin1String(idKeyC), m_id}, + {QLatin1String(displayNameKeyC), m_displayName}, + }; +} + +void IDebugServerProvider::registerDevice(BareMetalDevice *device) +{ + m_devices.insert(device); +} + +void IDebugServerProvider::unregisterDevice(BareMetalDevice *device) +{ + m_devices.remove(device); +} + +void IDebugServerProvider::providerUpdated() +{ + DebugServerProviderManager::notifyAboutUpdate(this); + for (BareMetalDevice *device : qAsConst(m_devices)) + device->debugServerProviderUpdated(this); +} + +bool IDebugServerProvider::fromMap(const QVariantMap &data) +{ + m_id = data.value(QLatin1String(idKeyC)).toString(); + m_displayName = data.value(QLatin1String(displayNameKeyC)).toString(); + return true; +} + +void IDebugServerProvider::setTypeDisplayName(const QString &typeDisplayName) +{ + m_typeDisplayName = typeDisplayName; +} + +// IDebugServerProviderFactory + +QString IDebugServerProviderFactory::id() const +{ + return m_id; +} + +void IDebugServerProviderFactory::setId(const QString &id) +{ + m_id = id; +} + +QString IDebugServerProviderFactory::displayName() const +{ + return m_displayName; +} + +void IDebugServerProviderFactory::setDisplayName(const QString &name) +{ + m_displayName = name; +} + +QString IDebugServerProviderFactory::idFromMap(const QVariantMap &data) +{ + return data.value(QLatin1String(idKeyC)).toString(); +} + +void IDebugServerProviderFactory::idToMap(QVariantMap &data, const QString &id) +{ + data.insert(QLatin1String(idKeyC), id); +} + +// IDebugServerProviderConfigWidget + +IDebugServerProviderConfigWidget::IDebugServerProviderConfigWidget( + IDebugServerProvider *provider) + : m_provider(provider) +{ + Q_ASSERT(provider); + + m_mainLayout = new QFormLayout(this); + m_mainLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); + + m_nameLineEdit = new QLineEdit(this); + m_nameLineEdit->setToolTip(tr("Enter the name of the debugger server provider.")); + m_mainLayout->addRow(tr("Name:"), m_nameLineEdit); + + setFromProvider(); + + connect(m_nameLineEdit, &QLineEdit::textChanged, + this, &IDebugServerProviderConfigWidget::dirty); +} + +void IDebugServerProviderConfigWidget::apply() +{ + m_provider->setDisplayName(m_nameLineEdit->text()); +} + +void IDebugServerProviderConfigWidget::discard() +{ + setFromProvider(); +} + +void IDebugServerProviderConfigWidget::addErrorLabel() +{ + if (!m_errorLabel) { + m_errorLabel = new QLabel; + m_errorLabel->setVisible(false); + } + m_mainLayout->addRow(m_errorLabel); +} + +void IDebugServerProviderConfigWidget::setErrorMessage(const QString &m) +{ + QTC_ASSERT(m_errorLabel, return); + if (m.isEmpty()) { + clearErrorMessage(); + } else { + m_errorLabel->setText(m); + m_errorLabel->setStyleSheet(QLatin1String("background-color: \"red\"")); + m_errorLabel->setVisible(true); + } +} + +void IDebugServerProviderConfigWidget::clearErrorMessage() +{ + QTC_ASSERT(m_errorLabel, return); + m_errorLabel->clear(); + m_errorLabel->setStyleSheet(QString()); + m_errorLabel->setVisible(false); +} + +void IDebugServerProviderConfigWidget::setFromProvider() +{ + const QSignalBlocker blocker(this); + m_nameLineEdit->setText(m_provider->displayName()); +} + +} // namespace Internal +} // namespace BareMetal diff --git a/src/plugins/baremetal/idebugserverprovider.h b/src/plugins/baremetal/idebugserverprovider.h new file mode 100644 index 00000000000..a27f796aa2e --- /dev/null +++ b/src/plugins/baremetal/idebugserverprovider.h @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Denis Shienkov +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include +#include +#include +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QFormLayout; +class QLabel; +class QLineEdit; +QT_END_NAMESPACE + +namespace BareMetal { +namespace Internal { + +class BareMetalDevice; +class IDebugServerProviderConfigWidget; + +// IDebugServerProvider + +class IDebugServerProvider +{ +public: + virtual ~IDebugServerProvider(); + + QString displayName() const; + void setDisplayName(const QString &name); + + QString id() const; + + QString typeDisplayName() const; + + virtual bool operator==(const IDebugServerProvider &other) const; + + virtual IDebugServerProviderConfigWidget *configurationWidget() = 0; + + virtual IDebugServerProvider *clone() const = 0; + + virtual QVariantMap toMap() const; + + virtual bool isValid() const = 0; + virtual bool hasProcess() const { return false; } + virtual Debugger::DebuggerEngineType engineType() const = 0; + + void registerDevice(BareMetalDevice *device); + void unregisterDevice(BareMetalDevice *device); + +protected: + explicit IDebugServerProvider(const QString &id); + explicit IDebugServerProvider(const IDebugServerProvider &provider); + + void setTypeDisplayName(const QString &typeDisplayName); + + void providerUpdated(); + + virtual bool fromMap(const QVariantMap &data); + + QString m_id; + mutable QString m_displayName; + QString m_typeDisplayName; + QSet m_devices; + + friend class IDebugServerProviderConfigWidget; +}; + +// IDebugServerProviderFactory + +class IDebugServerProviderFactory : public QObject +{ + Q_OBJECT + +public: + QString id() const; + QString displayName() const; + + virtual IDebugServerProvider *create() = 0; + + virtual bool canRestore(const QVariantMap &data) const = 0; + virtual IDebugServerProvider *restore(const QVariantMap &data) = 0; + + static QString idFromMap(const QVariantMap &data); + static void idToMap(QVariantMap &data, const QString &id); + +protected: + void setId(const QString &id); + void setDisplayName(const QString &name); + +private: + QString m_displayName; + QString m_id; +}; + +// IDebugServerProviderConfigWidget + +class IDebugServerProviderConfigWidget : public QWidget +{ + Q_OBJECT + +public: + explicit IDebugServerProviderConfigWidget(IDebugServerProvider *provider); + + virtual void apply(); + virtual void discard(); + +signals: + void dirty(); + +protected: + void setErrorMessage(const QString &); + void clearErrorMessage(); + void addErrorLabel(); + void setFromProvider(); + + IDebugServerProvider *m_provider = nullptr; + QFormLayout *m_mainLayout = nullptr; + QLineEdit *m_nameLineEdit = nullptr; + QLabel *m_errorLabel = nullptr; +}; + +} // namespace Internal +} // namespace BareMetal