DebuggerItem: Pass environment to debugger probing

QNX 7.1.0 requires that the QNX specific environment variables are
present at the time of running the gdb executable.

Without this the QNX Device configuration fails with the:
"Configuration already exists or is invalid"

Change-Id: I1cb8da58247247ac8248cb613f73e2e28d350e9e
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Cristian Adam
2021-05-07 14:03:48 +02:00
parent 1e80ed9b78
commit ee33fd6409
4 changed files with 29 additions and 9 deletions

View File

@@ -66,10 +66,11 @@ const char DEBUGGER_INFORMATION_WORKINGDIRECTORY[] = "WorkingDirectory";
//! Return the configuration of gdb as a list of --key=value //! Return the configuration of gdb as a list of --key=value
//! \note That the list will also contain some output not in this format. //! \note That the list will also contain some output not in this format.
static QString getConfigurationOfGdbCommand(const FilePath &command) static QString getConfigurationOfGdbCommand(const FilePath &command, const Utils::Environment &sysEnv)
{ {
// run gdb with the --configuration opion // run gdb with the --configuration opion
Utils::SynchronousProcess gdbConfigurationCall; Utils::SynchronousProcess gdbConfigurationCall;
gdbConfigurationCall.setEnvironment(sysEnv);
Utils::SynchronousProcessResponse output = Utils::SynchronousProcessResponse output =
gdbConfigurationCall.runBlocking({command, {"--configuration"}}); gdbConfigurationCall.runBlocking({command, {"--configuration"}});
return output.allOutput(); return output.allOutput();
@@ -148,7 +149,7 @@ static bool isUVisionExecutable(const QFileInfo &fileInfo)
return baseName == "UV4"; return baseName == "UV4";
} }
void DebuggerItem::reinitializeFromFile() void DebuggerItem::reinitializeFromFile(const Utils::Environment &sysEnv)
{ {
// CDB only understands the single-dash -version, whereas GDB and LLDB are // CDB only understands the single-dash -version, whereas GDB and LLDB are
// happy with both -version and --version. So use the "working" -version // happy with both -version and --version. So use the "working" -version
@@ -184,6 +185,7 @@ void DebuggerItem::reinitializeFromFile()
} }
SynchronousProcess proc; SynchronousProcess proc;
proc.setEnvironment(sysEnv);
SynchronousProcessResponse response = proc.runBlocking({m_command, {version}}); SynchronousProcessResponse response = proc.runBlocking({m_command, {version}});
if (response.result != SynchronousProcessResponse::Finished) { if (response.result != SynchronousProcessResponse::Finished) {
m_engineType = NoEngineType; m_engineType = NoEngineType;
@@ -207,7 +209,7 @@ void DebuggerItem::reinitializeFromFile()
const bool unableToFindAVersion = (0 == version); const bool unableToFindAVersion = (0 == version);
const bool gdbSupportsConfigurationFlag = (version >= 70700); const bool gdbSupportsConfigurationFlag = (version >= 70700);
if (gdbSupportsConfigurationFlag || unableToFindAVersion) { if (gdbSupportsConfigurationFlag || unableToFindAVersion) {
const auto gdbConfiguration = getConfigurationOfGdbCommand(m_command); const auto gdbConfiguration = getConfigurationOfGdbCommand(m_command, sysEnv);
const auto gdbTargetAbiString = const auto gdbTargetAbiString =
extractGdbTargetAbiStringFromGdbOutput(gdbConfiguration); extractGdbTargetAbiStringFromGdbOutput(gdbConfiguration);
if (!gdbTargetAbiString.isEmpty()) { if (!gdbTargetAbiString.isEmpty()) {

View File

@@ -31,6 +31,7 @@
#include <projectexplorer/abi.h> #include <projectexplorer/abi.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/environment.h>
#include <QDateTime> #include <QDateTime>
#include <QList> #include <QList>
@@ -97,7 +98,7 @@ public:
bool operator==(const DebuggerItem &other) const; bool operator==(const DebuggerItem &other) const;
bool operator!=(const DebuggerItem &other) const { return !operator==(other); } bool operator!=(const DebuggerItem &other) const { return !operator==(other); }
void reinitializeFromFile(); void reinitializeFromFile(const Utils::Environment &sysEnv = Utils::Environment::systemEnvironment());
Utils::FilePath workingDirectory() const { return m_workingDirectory; } Utils::FilePath workingDirectory() const { return m_workingDirectory; }
void setWorkingDirectory(const Utils::FilePath &workingPath) { m_workingDirectory = workingPath; } void setWorkingDirectory(const Utils::FilePath &workingPath) { m_workingDirectory = workingPath; }

View File

@@ -67,6 +67,10 @@ const QLatin1String QNXVersionKey("QNXVersion");
// For backward compatibility // For backward compatibility
const QLatin1String SdpEnvFileKey("NDKEnvFile"); const QLatin1String SdpEnvFileKey("NDKEnvFile");
const QLatin1String QNXConfiguration("QNX_CONFIGURATION");
const QLatin1String QNXTarget("QNX_TARGET");
const QLatin1String QNXHost("QNX_HOST");
QnxConfiguration::QnxConfiguration() = default; QnxConfiguration::QnxConfiguration() = default;
QnxConfiguration::QnxConfiguration(const FilePath &sdpEnvFile) QnxConfiguration::QnxConfiguration(const FilePath &sdpEnvFile)
@@ -251,9 +255,11 @@ void QnxConfiguration::createTools(const Target &target)
QVariant QnxConfiguration::createDebugger(const Target &target) QVariant QnxConfiguration::createDebugger(const Target &target)
{ {
Utils::Environment sysEnv = Utils::Environment::systemEnvironment();
setQnxValuesToEnvironment(sysEnv);
Debugger::DebuggerItem debugger; Debugger::DebuggerItem debugger;
debugger.setCommand(target.m_debuggerPath); debugger.setCommand(target.m_debuggerPath);
debugger.reinitializeFromFile(); debugger.reinitializeFromFile(sysEnv);
debugger.setAutoDetected(true); debugger.setAutoDetected(true);
debugger.setUnexpandedDisplayName( debugger.setUnexpandedDisplayName(
QCoreApplication::translate( QCoreApplication::translate(
@@ -376,11 +382,11 @@ void QnxConfiguration::setDefaultConfiguration(const Utils::FilePath &envScript)
m_envFile = envScript; m_envFile = envScript;
m_qnxEnv = QnxUtils::qnxEnvironmentFromEnvFile(m_envFile.toString()); m_qnxEnv = QnxUtils::qnxEnvironmentFromEnvFile(m_envFile.toString());
foreach (const EnvironmentItem &item, m_qnxEnv) { foreach (const EnvironmentItem &item, m_qnxEnv) {
if (item.name == QLatin1String("QNX_CONFIGURATION")) if (item.name == QNXConfiguration)
m_qnxConfiguration = FilePath::fromString(item.value); m_qnxConfiguration = FilePath::fromString(item.value);
else if (item.name == QLatin1String("QNX_TARGET")) else if (item.name == QNXTarget)
m_qnxTarget = FilePath::fromString(item.value); m_qnxTarget = FilePath::fromString(item.value);
else if (item.name == QLatin1String("QNX_HOST")) else if (item.name == QNXHost)
m_qnxHost = FilePath::fromString(item.value); m_qnxHost = FilePath::fromString(item.value);
} }
@@ -401,6 +407,13 @@ void QnxConfiguration::setDefaultConfiguration(const Utils::FilePath &envScript)
}); });
} }
void QnxConfiguration::setQnxValuesToEnvironment(Utils::Environment &env)
{
env.set(QNXConfiguration, m_qnxConfiguration.toString());
env.set(QNXTarget, m_qnxTarget.toString());
env.set(QNXHost, m_qnxHost.toString());
}
const QnxConfiguration::Target *QnxConfiguration::findTargetByDebuggerPath( const QnxConfiguration::Target *QnxConfiguration::findTargetByDebuggerPath(
const FilePath &path) const const FilePath &path) const
{ {
@@ -423,12 +436,14 @@ void QnxConfiguration::assignDebuggersToTargets()
QStringList debuggerNames = hostUsrBinDir.entryList( QStringList debuggerNames = hostUsrBinDir.entryList(
QStringList(HostOsInfo::withExecutableSuffix(QLatin1String("nto*-gdb"))), QStringList(HostOsInfo::withExecutableSuffix(QLatin1String("nto*-gdb"))),
QDir::Files); QDir::Files);
Utils::Environment sysEnv = Utils::Environment::systemEnvironment();
setQnxValuesToEnvironment(sysEnv);
foreach (const QString &debuggerName, debuggerNames) { foreach (const QString &debuggerName, debuggerNames) {
const FilePath debuggerPath = FilePath::fromString(hostUsrBinDir.path()) const FilePath debuggerPath = FilePath::fromString(hostUsrBinDir.path())
.pathAppended(debuggerName); .pathAppended(debuggerName);
DebuggerItem item; DebuggerItem item;
item.setCommand(debuggerPath); item.setCommand(debuggerPath);
item.reinitializeFromFile(); item.reinitializeFromFile(sysEnv);
bool found = false; bool found = false;
foreach (const Abi &abi, item.abis()) { foreach (const Abi &abi, item.abis()) {
for (Target &target : m_targets) { for (Target &target : m_targets) {

View File

@@ -90,6 +90,8 @@ private:
void setDefaultConfiguration(const Utils::FilePath &envScript); void setDefaultConfiguration(const Utils::FilePath &envScript);
void setQnxValuesToEnvironment(Utils::Environment &env);
QString m_configName; QString m_configName;
Utils::FilePath m_envFile; Utils::FilePath m_envFile;