From fdf383cf37add455797ca5c2365ea9f23a285f82 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Fri, 6 Mar 2020 13:47:08 +0300 Subject: [PATCH] BareMetal: Choose peripheral description file on debug provider page ... instead of device page. Reason is that a path to the peripheral description file comes from the inside of the provider for some providers (e.g. for the UVSC provider at parsing the selected "Software Device Pack" file). This complicates a code for assigning of the selected peripheral description file path to the device configuration page. So, it is makes sense to make it possible to choose a peripheral description file from the debug server provider page. In this case we will pass a path to the selected peripheral description file via the runnable's extra data variable. Tested with STM32 NUCLEO-F767ZI board on Windows. Change-Id: Iec4d738dd236449969fd669e7fbe58da3a660938 Reviewed-by: hjk --- .../baremetaldeviceconfigurationwidget.cpp | 22 --------- .../baremetaldeviceconfigurationwidget.h | 4 -- .../debugservers/gdb/gdbserverprovider.cpp | 48 ++++++++++++++++++- .../debugservers/gdb/gdbserverprovider.h | 8 ++++ src/plugins/debugger/debuggerconstants.h | 3 ++ .../debugger/peripheralregisterhandler.cpp | 15 +++--- .../projectexplorer/devicesupport/idevice.cpp | 15 ------ .../projectexplorer/devicesupport/idevice.h | 3 -- 8 files changed, 64 insertions(+), 54 deletions(-) diff --git a/src/plugins/baremetal/baremetaldeviceconfigurationwidget.cpp b/src/plugins/baremetal/baremetaldeviceconfigurationwidget.cpp index b1288aa1fad..e20e89bc824 100644 --- a/src/plugins/baremetal/baremetaldeviceconfigurationwidget.cpp +++ b/src/plugins/baremetal/baremetaldeviceconfigurationwidget.cpp @@ -28,9 +28,7 @@ #include "baremetaldeviceconfigurationwidget.h" #include "debugserverproviderchooser.h" -#include "idebugserverprovider.h" -#include #include #include @@ -57,19 +55,6 @@ BareMetalDeviceConfigurationWidget::BareMetalDeviceConfigurationWidget( connect(m_debugServerProviderChooser, &DebugServerProviderChooser::providerChanged, this, &BareMetalDeviceConfigurationWidget::debugServerProviderChanged); - - m_peripheralDescriptionFileChooser = new Utils::PathChooser(this); - m_peripheralDescriptionFileChooser->setExpectedKind(Utils::PathChooser::File); - m_peripheralDescriptionFileChooser->setPromptDialogFilter( - tr("Peripheral description files (*.svd)")); - m_peripheralDescriptionFileChooser->setPromptDialogTitle( - tr("Select Peripheral Description File")); - m_peripheralDescriptionFileChooser->setPath(dev->peripheralDescriptionFilePath()); - formLayout->addRow(tr("Peripheral description file:"), - m_peripheralDescriptionFileChooser); - - connect(m_peripheralDescriptionFileChooser, &Utils::PathChooser::pathChanged, - this, &BareMetalDeviceConfigurationWidget::peripheralDescriptionFileChanged); } void BareMetalDeviceConfigurationWidget::debugServerProviderChanged() @@ -79,13 +64,6 @@ void BareMetalDeviceConfigurationWidget::debugServerProviderChanged() dev->setDebugServerProviderId(m_debugServerProviderChooser->currentProviderId()); } -void BareMetalDeviceConfigurationWidget::peripheralDescriptionFileChanged() -{ - const auto dev = qSharedPointerCast(device()); - QTC_ASSERT(dev, return); - dev->setPeripheralDescriptionFilePath(m_peripheralDescriptionFileChooser->path()); -} - void BareMetalDeviceConfigurationWidget::updateDeviceFromUi() { debugServerProviderChanged(); diff --git a/src/plugins/baremetal/baremetaldeviceconfigurationwidget.h b/src/plugins/baremetal/baremetaldeviceconfigurationwidget.h index 0bc07f5235f..b94ced03abd 100644 --- a/src/plugins/baremetal/baremetaldeviceconfigurationwidget.h +++ b/src/plugins/baremetal/baremetaldeviceconfigurationwidget.h @@ -28,8 +28,6 @@ #include -namespace Utils { class PathChooser; } - namespace BareMetal { namespace Internal { @@ -47,11 +45,9 @@ public: private: void debugServerProviderChanged(); - void peripheralDescriptionFileChanged(); void updateDeviceFromUi() final; DebugServerProviderChooser *m_debugServerProviderChooser = nullptr; - Utils::PathChooser *m_peripheralDescriptionFileChooser = nullptr; }; } // namespace Internal diff --git a/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.cpp b/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.cpp index 98456644b74..4e4e73a90c6 100644 --- a/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.cpp +++ b/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.cpp @@ -33,6 +33,7 @@ #include #include +#include #include @@ -49,6 +50,7 @@ namespace BareMetal { namespace Internal { const char startupModeKeyC[] = "BareMetal.GdbServerProvider.Mode"; +const char peripheralDescriptionFileKeyC[] = "BareMetal.GdbServerProvider.PeripheralDescriptionFile"; const char initCommandsKeyC[] = "BareMetal.GdbServerProvider.InitCommands"; const char resetCommandsKeyC[] = "BareMetal.GdbServerProvider.ResetCommands"; const char useExtendedRemoteKeyC[] = "BareMetal.GdbServerProvider.UseExtendedRemote"; @@ -64,6 +66,7 @@ GdbServerProvider::GdbServerProvider(const QString &id) GdbServerProvider::GdbServerProvider(const GdbServerProvider &other) : IDebugServerProvider(other.id()) , m_startupMode(other.m_startupMode) + , m_peripheralDescriptionFile(other.m_peripheralDescriptionFile) , m_initCommands(other.m_initCommands) , m_resetCommands(other.m_resetCommands) , m_useExtendedRemote(other.useExtendedRemote()) @@ -76,11 +79,21 @@ GdbServerProvider::StartupMode GdbServerProvider::startupMode() const return m_startupMode; } +Utils::FilePath GdbServerProvider::peripheralDescriptionFile() const +{ + return m_peripheralDescriptionFile; +} + void GdbServerProvider::setStartupMode(StartupMode m) { m_startupMode = m; } +void GdbServerProvider::setPeripheralDescriptionFile(const FilePath &file) +{ + m_peripheralDescriptionFile = file; +} + QString GdbServerProvider::initCommands() const { return m_initCommands; @@ -123,6 +136,7 @@ bool GdbServerProvider::operator==(const IDebugServerProvider &other) const const auto p = static_cast(&other); return m_startupMode == p->m_startupMode + && m_peripheralDescriptionFile == p->m_peripheralDescriptionFile && m_initCommands == p->m_initCommands && m_resetCommands == p->m_resetCommands && m_useExtendedRemote == p->m_useExtendedRemote; @@ -132,6 +146,7 @@ QVariantMap GdbServerProvider::toMap() const { QVariantMap data = IDebugServerProvider::toMap(); data.insert(startupModeKeyC, m_startupMode); + data.insert(peripheralDescriptionFileKeyC, m_peripheralDescriptionFile.toVariant()); data.insert(initCommandsKeyC, m_initCommands); data.insert(resetCommandsKeyC, m_resetCommands); data.insert(useExtendedRemoteKeyC, m_useExtendedRemote); @@ -166,6 +181,8 @@ bool GdbServerProvider::aboutToRun(DebuggerRunTool *runTool, Runnable inferior; inferior.executable = bin; + inferior.extraData.insert(Debugger::Constants::kPeripheralDescriptionFile, + m_peripheralDescriptionFile.toVariant()); if (const auto argAspect = runControl->aspect()) inferior.commandLineArguments = argAspect->arguments(runControl->macroExpander()); runTool->setInferior(inferior); @@ -197,6 +214,7 @@ bool GdbServerProvider::fromMap(const QVariantMap &data) return false; m_startupMode = static_cast(data.value(startupModeKeyC).toInt()); + m_peripheralDescriptionFile = FilePath::fromVariant(data.value(peripheralDescriptionFileKeyC)); m_initCommands = data.value(initCommandsKeyC).toString(); m_resetCommands = data.value(resetCommandsKeyC).toString(); m_useExtendedRemote = data.value(useExtendedRemoteKeyC).toBool(); @@ -214,17 +232,31 @@ GdbServerProviderConfigWidget::GdbServerProviderConfigWidget( "of the GDB server provider.")); m_mainLayout->addRow(tr("Startup mode:"), m_startupModeComboBox); + m_peripheralDescriptionFileChooser = new Utils::PathChooser(this); + m_peripheralDescriptionFileChooser->setExpectedKind(Utils::PathChooser::File); + m_peripheralDescriptionFileChooser->setPromptDialogFilter( + tr("Peripheral description files (*.svd)")); + m_peripheralDescriptionFileChooser->setPromptDialogTitle( + tr("Select Peripheral Description File")); + m_mainLayout->addRow(tr("Peripheral description file:"), + m_peripheralDescriptionFileChooser); + populateStartupModes(); setFromProvider(); connect(m_startupModeComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, &GdbServerProviderConfigWidget::dirty); + + connect(m_peripheralDescriptionFileChooser, &Utils::PathChooser::pathChanged, + this, &GdbServerProviderConfigWidget::dirty); } void GdbServerProviderConfigWidget::apply() { - static_cast(m_provider)->setStartupMode(startupMode()); + const auto p = static_cast(m_provider); + p->setStartupMode(startupMode()); + p->setPeripheralDescriptionFile(peripheralDescriptionFile()); IDebugServerProviderConfigWidget::apply(); } @@ -277,9 +309,21 @@ void GdbServerProviderConfigWidget::populateStartupModes() m_startupModeComboBox->addItem(startupModeName(mode), mode); } +Utils::FilePath GdbServerProviderConfigWidget::peripheralDescriptionFile() const +{ + return m_peripheralDescriptionFileChooser->fileName(); +} + +void GdbServerProviderConfigWidget::setPeripheralDescriptionFile(const Utils::FilePath &file) +{ + m_peripheralDescriptionFileChooser->setFileName(file); +} + void GdbServerProviderConfigWidget::setFromProvider() { - setStartupMode(static_cast(m_provider)->startupMode()); + const auto p = static_cast(m_provider); + setStartupMode(p->startupMode()); + setPeripheralDescriptionFile(p->peripheralDescriptionFile()); } QString GdbServerProviderConfigWidget::defaultInitCommandsTooltip() diff --git a/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.h b/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.h index 259cd246ca6..a8351939210 100644 --- a/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.h +++ b/src/plugins/baremetal/debugservers/gdb/gdbserverprovider.h @@ -35,6 +35,8 @@ QT_BEGIN_NAMESPACE class QComboBox; QT_END_NAMESPACE +namespace Utils { class PathChooser; } + namespace BareMetal { namespace Internal { @@ -51,6 +53,7 @@ public: }; StartupMode startupMode() const; + Utils::FilePath peripheralDescriptionFile() const; QString initCommands() const; QString resetCommands() const; bool useExtendedRemote() const; @@ -74,6 +77,7 @@ protected: explicit GdbServerProvider(const GdbServerProvider &other); void setStartupMode(StartupMode); + void setPeripheralDescriptionFile(const Utils::FilePath &file); void setInitCommands(const QString &); void setResetCommands(const QString &); void setUseExtendedRemote(bool); @@ -81,6 +85,7 @@ protected: bool fromMap(const QVariantMap &data) override; StartupMode m_startupMode = StartupOnNetwork; + Utils::FilePath m_peripheralDescriptionFile; QString m_initCommands; QString m_resetCommands; bool m_useExtendedRemote = false; @@ -104,12 +109,15 @@ protected: GdbServerProvider::StartupMode startupMode() const; void setStartupMode(GdbServerProvider::StartupMode mode); void populateStartupModes(); + Utils::FilePath peripheralDescriptionFile() const; + void setPeripheralDescriptionFile(const Utils::FilePath &file); void setFromProvider(); static QString defaultInitCommandsTooltip(); static QString defaultResetCommandsTooltip(); QComboBox *m_startupModeComboBox = nullptr; + Utils::PathChooser *m_peripheralDescriptionFileChooser = nullptr; }; // GdbServerProviderRunner diff --git a/src/plugins/debugger/debuggerconstants.h b/src/plugins/debugger/debuggerconstants.h index f06b5258960..912e2096690 100644 --- a/src/plugins/debugger/debuggerconstants.h +++ b/src/plugins/debugger/debuggerconstants.h @@ -36,6 +36,9 @@ const char MODE_DEBUG[] = "Mode.Debug"; // Debug mode context const char C_DEBUGMODE[] = "Debugger.DebugMode"; +// Common debugger constants. +const char kPeripheralDescriptionFile[] = "PeripheralDescriptionFile"; + // UVSC-specific debugger constants. const char kUVisionProjectFilePath[] = "UVisionProjectFilePath"; const char kUVisionOptionsFilePath[] = "UVisionOptionsFilePath"; diff --git a/src/plugins/debugger/peripheralregisterhandler.cpp b/src/plugins/debugger/peripheralregisterhandler.cpp index fa9427a6e2a..beb5aa107b3 100644 --- a/src/plugins/debugger/peripheralregisterhandler.cpp +++ b/src/plugins/debugger/peripheralregisterhandler.cpp @@ -682,9 +682,9 @@ static void handleGroup(QXmlStreamReader &in, PeripheralRegisterGroups &groups) groups.push_back(group); } -static PeripheralRegisterGroups availablePeripheralRegisterGroups(const QString &filePath) +static PeripheralRegisterGroups availablePeripheralRegisterGroups(const FilePath &filePath) { - QFile f(filePath); + QFile f(filePath.toString()); if (!f.open(QIODevice::ReadOnly)) return {}; @@ -716,14 +716,13 @@ void PeripheralRegisterHandler::updateRegisterGroups() { clear(); - const auto dev = m_engine->device(); - QTC_ASSERT(dev, return); + const DebuggerRunParameters &rp = m_engine->runParameters(); + const FilePath peripheralDescriptionFile = FilePath::fromVariant( + rp.inferior.extraData.value(Debugger::Constants::kPeripheralDescriptionFile)); - const QString filePath = dev->peripheralDescriptionFilePath(); - if (filePath.isEmpty()) + if (!peripheralDescriptionFile.exists()) return; - - m_peripheralRegisterGroups = availablePeripheralRegisterGroups(filePath); + m_peripheralRegisterGroups = availablePeripheralRegisterGroups(peripheralDescriptionFile); } void PeripheralRegisterHandler::updateRegister(quint64 address, quint64 value) diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp index c74c87cc3e6..b1685a2791a 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp @@ -124,7 +124,6 @@ const char TimeoutKey[] = "Timeout"; const char HostKeyCheckingKey[] = "HostKeyChecking"; const char DebugServerKey[] = "DebugServerKey"; -const char PeripheralDescriptionFileKey[] = "PeripheralDescriptionFileKey"; const char QmlsceneKey[] = "QmlsceneKey"; using AuthType = QSsh::SshConnectionParameters::AuthenticationType; @@ -152,7 +151,6 @@ public: QSsh::SshConnectionParameters sshParameters; Utils::PortList freePorts; QString debugServerPath; - QString peripheralDescriptionFilePath; QString qmlsceneCommand; QList deviceIcons; @@ -392,7 +390,6 @@ void IDevice::fromMap(const QVariantMap &map) d->version = map.value(QLatin1String(VersionKey), 0).toInt(); d->debugServerPath = map.value(QLatin1String(DebugServerKey)).toString(); - d->peripheralDescriptionFilePath = map.value(QLatin1String(PeripheralDescriptionFileKey)).toString(); d->qmlsceneCommand = map.value(QLatin1String(QmlsceneKey)).toString(); d->extraData = map.value(ExtraDataKey).toMap(); } @@ -424,7 +421,6 @@ QVariantMap IDevice::toMap() const map.insert(QLatin1String(VersionKey), d->version); map.insert(QLatin1String(DebugServerKey), d->debugServerPath); - map.insert(QLatin1String(PeripheralDescriptionFileKey), d->peripheralDescriptionFilePath); map.insert(QLatin1String(QmlsceneKey), d->qmlsceneCommand); map.insert(ExtraDataKey, d->extraData); @@ -508,17 +504,6 @@ void IDevice::setDebugServerPath(const QString &path) d->debugServerPath = path; } - -QString IDevice::peripheralDescriptionFilePath() const -{ - return d->peripheralDescriptionFilePath; -} - -void IDevice::setPeripheralDescriptionFilePath(const QString &path) -{ - d->peripheralDescriptionFilePath = path; -} - QString IDevice::qmlsceneCommand() const { return d->qmlsceneCommand; diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h index 37403e8b82f..9a59f106722 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.h +++ b/src/plugins/projectexplorer/devicesupport/idevice.h @@ -210,9 +210,6 @@ public: QString debugServerPath() const; void setDebugServerPath(const QString &path); - QString peripheralDescriptionFilePath() const; - void setPeripheralDescriptionFilePath(const QString &path); - QString qmlsceneCommand() const; void setQmlsceneCommand(const QString &path);