BareMetal: Use Utils::CommandLine for gdbserver things

Change-Id: Idf0793636d58b1c6f93a64c94ce5c2b11e4694ce
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2019-06-04 10:17:06 +02:00
parent 8e7138f06a
commit ce59cf6a50
7 changed files with 46 additions and 64 deletions

View File

@@ -72,11 +72,9 @@ BareMetalDebugSupport::BareMetalDebugSupport(RunControl *runControl)
if (p->startupMode() == GdbServerProvider::StartupOnNetwork) {
Runnable r;
r.executable = p->executable();
// We need to wrap the command arguments depending on a host OS,
// as the bare metal's GDB servers are launched on a host,
// but not on a target.
r.commandLineArguments = Utils::QtcProcess::joinArgs(p->arguments(), Utils::HostOsInfo::hostOs());
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.
m_gdbServer = new SimpleTargetRunner(runControl);
m_gdbServer->setRunnable(r);
addStartDependency(m_gdbServer);

View File

@@ -143,12 +143,7 @@ void GdbServerProvider::setResetCommands(const QString &cmds)
m_resetCommands = cmds;
}
QString GdbServerProvider::executable() const
{
return {};
}
QStringList GdbServerProvider::arguments() const
Utils::CommandLine GdbServerProvider::command() const
{
return {};
}

View File

@@ -84,8 +84,7 @@ public:
virtual QVariantMap toMap() const;
virtual QString executable() const;
virtual QStringList arguments() const;
virtual Utils::CommandLine command() const;
virtual bool isValid() const;
virtual bool canStartupMode(StartupMode) const;

View File

@@ -40,7 +40,8 @@
#include <QFormLayout>
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QString>
using namespace Utils;
namespace BareMetal {
namespace Internal {
@@ -92,48 +93,43 @@ QString OpenOcdGdbServerProvider::channel() const
// Just return as "host:port" form.
return m_host + QLatin1Char(':') + QString::number(m_port);
case StartupOnPipe: {
QStringList args;
// In the pipe mode need to add quotes to each item of arguments;
// otherwise running will be stuck.
for (const QString &a : arguments()) {
if (a.startsWith(QLatin1Char('\"')) && a.endsWith(QLatin1Char('\"')))
continue;
args << (QLatin1Char('\"') + a + QLatin1Char('\"'));
CommandLine cmd = command();
QStringList args = {"|", cmd.executable().toString()};
for (const QString &a : QtcProcess::splitArgs(cmd.arguments())) {
if (a.startsWith('\"') && a.endsWith('\"'))
args << a;
else
args << ('\"' + a + '\"');
}
args.prepend(executable());
args.prepend(QLatin1String("|"));
return args.join(QLatin1Char(' '));
return args.join(' ');
}
default: // wrong
return {};
}
}
QString OpenOcdGdbServerProvider::executable() const
CommandLine OpenOcdGdbServerProvider::command() const
{
return m_executableFile;
}
CommandLine cmd{m_executableFile, {}};
QStringList OpenOcdGdbServerProvider::arguments() const
{
QStringList args;
args << QLatin1String("-c");
cmd.addArg("-c");
if (startupMode() == StartupOnPipe)
args << QLatin1String("gdb_port pipe");
cmd.addArg("gdb_port pipe");
else
args << (QLatin1String("gdb_port ") + QString::number(m_port));
cmd.addArg("gdb_port " + QString::number(m_port));
if (!m_rootScriptsDir.isEmpty())
args << QLatin1String("-s") << m_rootScriptsDir;
cmd.addArgs({"-s", m_rootScriptsDir});
if (!m_configurationFile.isEmpty())
args << QLatin1String("-f") << m_configurationFile;
cmd.addArgs({"-f", m_configurationFile});
if (!m_additionalArguments.isEmpty())
args << Utils::QtcProcess::splitArgs(m_additionalArguments);
cmd.addArgs(m_additionalArguments);
return args;
return cmd;
}
bool OpenOcdGdbServerProvider::canStartupMode(StartupMode m) const
@@ -171,7 +167,7 @@ QVariantMap OpenOcdGdbServerProvider::toMap() const
QVariantMap data = GdbServerProvider::toMap();
data.insert(QLatin1String(hostKeyC), m_host);
data.insert(QLatin1String(portKeyC), m_port);
data.insert(QLatin1String(executableFileKeyC), m_executableFile);
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);
@@ -185,7 +181,7 @@ bool OpenOcdGdbServerProvider::fromMap(const QVariantMap &data)
m_host = data.value(QLatin1String(hostKeyC)).toString();
m_port = data.value(QLatin1String(portKeyC)).toInt();
m_executableFile = data.value(QLatin1String(executableFileKeyC)).toString();
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();
@@ -326,7 +322,7 @@ void OpenOcdGdbServerProviderConfigWidget::applyImpl()
p->m_host = m_hostWidget->host();
p->m_port = m_hostWidget->port();
p->m_executableFile = m_executableFileChooser->fileName().toString();
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();
@@ -348,7 +344,7 @@ void OpenOcdGdbServerProviderConfigWidget::setFromProvider()
startupModeChanged();
m_hostWidget->setHost(p->m_host);
m_hostWidget->setPort(p->m_port);
m_executableFileChooser->setFileName(Utils::FilePath::fromString(p->m_executableFile));
m_executableFileChooser->setFileName(p->m_executableFile);
m_rootScriptsDirChooser->setFileName(Utils::FilePath::fromString(p->m_rootScriptsDir));
m_configurationFileChooser->setFileName(Utils::FilePath::fromString(p->m_configurationFile));
m_additionalArgumentsLineEdit->setText(p->m_additionalArguments);

View File

@@ -51,8 +51,7 @@ public:
GdbServerProvider *clone() const final;
QString channel() const final;
QString executable() const final;
QStringList arguments() const final;
Utils::CommandLine command() const final;
bool canStartupMode(StartupMode mode) const final;
bool isValid() const final;
@@ -66,7 +65,7 @@ private:
QString m_host = QLatin1String("localhost");
quint16 m_port = 3333;
QString m_executableFile = QLatin1String("openocd");
Utils::FilePath m_executableFile = Utils::FilePath::fromString("openocd");
QString m_rootScriptsDir;
QString m_configurationFile;
QString m_additionalArguments;

View File

@@ -41,7 +41,8 @@
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QSpinBox>
#include <QString>
using namespace Utils;
namespace BareMetal {
namespace Internal {
@@ -107,26 +108,21 @@ QString StLinkUtilGdbServerProvider::channel() const
}
}
QString StLinkUtilGdbServerProvider::executable() const
CommandLine StLinkUtilGdbServerProvider::command() const
{
return m_executableFile;
}
QStringList StLinkUtilGdbServerProvider::arguments() const
{
QStringList args;
CommandLine cmd{m_executableFile, {}};
if (m_extendedMode)
args << QLatin1String("--multi");
cmd.addArg("--multi");
if (!m_resetBoard)
args << QLatin1String("--no-reset");
cmd.addArg("--no-reset");
args << (QLatin1String("--stlink_version=") + QString::number(m_transport));
args << (QLatin1String("--listen_port=") + QString::number(m_port));
args << (QLatin1String("--verbose=") + QString::number(m_verboseLevel));
cmd.addArg("--stlink_version=" + QString::number(m_transport));
cmd.addArg("--listen_port=" + QString::number(m_port));
cmd.addArg("--verbose=" + QString::number(m_verboseLevel));
return args;
return cmd;
}
bool StLinkUtilGdbServerProvider::canStartupMode(StartupMode m) const
@@ -164,7 +160,7 @@ QVariantMap StLinkUtilGdbServerProvider::toMap() const
QVariantMap data = GdbServerProvider::toMap();
data.insert(QLatin1String(hostKeyC), m_host);
data.insert(QLatin1String(portKeyC), m_port);
data.insert(QLatin1String(executableFileKeyC), m_executableFile);
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);
@@ -179,7 +175,7 @@ bool StLinkUtilGdbServerProvider::fromMap(const QVariantMap &data)
m_host = data.value(QLatin1String(hostKeyC)).toString();
m_port = data.value(QLatin1String(portKeyC)).toInt();
m_executableFile = data.value(QLatin1String(executableFileKeyC)).toString();
m_executableFile = FileName::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();
@@ -335,7 +331,7 @@ void StLinkUtilGdbServerProviderConfigWidget::applyImpl()
p->m_host = m_hostWidget->host();
p->m_port = m_hostWidget->port();
p->m_executableFile = m_executableFileChooser->fileName().toString();
p->m_executableFile = m_executableFileChooser->fileName();
p->m_verboseLevel = m_verboseLevelSpinBox->value();
p->m_extendedMode = m_extendedModeCheckBox->isChecked();
p->m_resetBoard = m_resetBoardCheckBox->isChecked();
@@ -393,7 +389,7 @@ void StLinkUtilGdbServerProviderConfigWidget::setFromProvider()
startupModeChanged();
m_hostWidget->setHost(p->m_host);
m_hostWidget->setPort(p->m_port);
m_executableFileChooser->setFileName(Utils::FilePath::fromString(p->m_executableFile));
m_executableFileChooser->setFileName(p->m_executableFile);
m_verboseLevelSpinBox->setValue(p->m_verboseLevel);
m_extendedModeCheckBox->setChecked(p->m_extendedMode);
m_resetBoardCheckBox->setChecked(p->m_resetBoard);

View File

@@ -56,8 +56,7 @@ public:
GdbServerProvider *clone() const final;
QString channel() const final;
QString executable() const final;
QStringList arguments() const final;
Utils::CommandLine command() const final;
bool canStartupMode(StartupMode mode) const final;
bool isValid() const final;
@@ -71,7 +70,7 @@ private:
QString m_host = QLatin1String("localhost");
quint16 m_port = 4242;
QString m_executableFile = QLatin1String("st-util");
Utils::FilePath m_executableFile = Utils::FilePath::fromString("st-util");
int m_verboseLevel = 0; // 0..99
bool m_extendedMode = false; // Listening for connections after disconnect
bool m_resetBoard = true;