forked from qt-creator/qt-creator
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:
@@ -66,10 +66,11 @@ const char DEBUGGER_INFORMATION_WORKINGDIRECTORY[] = "WorkingDirectory";
|
||||
|
||||
//! Return the configuration of gdb as a list of --key=value
|
||||
//! \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
|
||||
Utils::SynchronousProcess gdbConfigurationCall;
|
||||
gdbConfigurationCall.setEnvironment(sysEnv);
|
||||
Utils::SynchronousProcessResponse output =
|
||||
gdbConfigurationCall.runBlocking({command, {"--configuration"}});
|
||||
return output.allOutput();
|
||||
@@ -148,7 +149,7 @@ static bool isUVisionExecutable(const QFileInfo &fileInfo)
|
||||
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
|
||||
// happy with both -version and --version. So use the "working" -version
|
||||
@@ -184,6 +185,7 @@ void DebuggerItem::reinitializeFromFile()
|
||||
}
|
||||
|
||||
SynchronousProcess proc;
|
||||
proc.setEnvironment(sysEnv);
|
||||
SynchronousProcessResponse response = proc.runBlocking({m_command, {version}});
|
||||
if (response.result != SynchronousProcessResponse::Finished) {
|
||||
m_engineType = NoEngineType;
|
||||
@@ -207,7 +209,7 @@ void DebuggerItem::reinitializeFromFile()
|
||||
const bool unableToFindAVersion = (0 == version);
|
||||
const bool gdbSupportsConfigurationFlag = (version >= 70700);
|
||||
if (gdbSupportsConfigurationFlag || unableToFindAVersion) {
|
||||
const auto gdbConfiguration = getConfigurationOfGdbCommand(m_command);
|
||||
const auto gdbConfiguration = getConfigurationOfGdbCommand(m_command, sysEnv);
|
||||
const auto gdbTargetAbiString =
|
||||
extractGdbTargetAbiStringFromGdbOutput(gdbConfiguration);
|
||||
if (!gdbTargetAbiString.isEmpty()) {
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include <projectexplorer/abi.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/environment.h>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QList>
|
||||
@@ -97,7 +98,7 @@ public:
|
||||
bool operator==(const DebuggerItem &other) const;
|
||||
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; }
|
||||
void setWorkingDirectory(const Utils::FilePath &workingPath) { m_workingDirectory = workingPath; }
|
||||
|
@@ -67,6 +67,10 @@ const QLatin1String QNXVersionKey("QNXVersion");
|
||||
// For backward compatibility
|
||||
const QLatin1String SdpEnvFileKey("NDKEnvFile");
|
||||
|
||||
const QLatin1String QNXConfiguration("QNX_CONFIGURATION");
|
||||
const QLatin1String QNXTarget("QNX_TARGET");
|
||||
const QLatin1String QNXHost("QNX_HOST");
|
||||
|
||||
QnxConfiguration::QnxConfiguration() = default;
|
||||
|
||||
QnxConfiguration::QnxConfiguration(const FilePath &sdpEnvFile)
|
||||
@@ -251,9 +255,11 @@ void QnxConfiguration::createTools(const Target &target)
|
||||
|
||||
QVariant QnxConfiguration::createDebugger(const Target &target)
|
||||
{
|
||||
Utils::Environment sysEnv = Utils::Environment::systemEnvironment();
|
||||
setQnxValuesToEnvironment(sysEnv);
|
||||
Debugger::DebuggerItem debugger;
|
||||
debugger.setCommand(target.m_debuggerPath);
|
||||
debugger.reinitializeFromFile();
|
||||
debugger.reinitializeFromFile(sysEnv);
|
||||
debugger.setAutoDetected(true);
|
||||
debugger.setUnexpandedDisplayName(
|
||||
QCoreApplication::translate(
|
||||
@@ -376,11 +382,11 @@ void QnxConfiguration::setDefaultConfiguration(const Utils::FilePath &envScript)
|
||||
m_envFile = envScript;
|
||||
m_qnxEnv = QnxUtils::qnxEnvironmentFromEnvFile(m_envFile.toString());
|
||||
foreach (const EnvironmentItem &item, m_qnxEnv) {
|
||||
if (item.name == QLatin1String("QNX_CONFIGURATION"))
|
||||
if (item.name == QNXConfiguration)
|
||||
m_qnxConfiguration = FilePath::fromString(item.value);
|
||||
else if (item.name == QLatin1String("QNX_TARGET"))
|
||||
else if (item.name == QNXTarget)
|
||||
m_qnxTarget = FilePath::fromString(item.value);
|
||||
else if (item.name == QLatin1String("QNX_HOST"))
|
||||
else if (item.name == QNXHost)
|
||||
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 FilePath &path) const
|
||||
{
|
||||
@@ -423,12 +436,14 @@ void QnxConfiguration::assignDebuggersToTargets()
|
||||
QStringList debuggerNames = hostUsrBinDir.entryList(
|
||||
QStringList(HostOsInfo::withExecutableSuffix(QLatin1String("nto*-gdb"))),
|
||||
QDir::Files);
|
||||
Utils::Environment sysEnv = Utils::Environment::systemEnvironment();
|
||||
setQnxValuesToEnvironment(sysEnv);
|
||||
foreach (const QString &debuggerName, debuggerNames) {
|
||||
const FilePath debuggerPath = FilePath::fromString(hostUsrBinDir.path())
|
||||
.pathAppended(debuggerName);
|
||||
DebuggerItem item;
|
||||
item.setCommand(debuggerPath);
|
||||
item.reinitializeFromFile();
|
||||
item.reinitializeFromFile(sysEnv);
|
||||
bool found = false;
|
||||
foreach (const Abi &abi, item.abis()) {
|
||||
for (Target &target : m_targets) {
|
||||
|
@@ -90,6 +90,8 @@ private:
|
||||
|
||||
void setDefaultConfiguration(const Utils::FilePath &envScript);
|
||||
|
||||
void setQnxValuesToEnvironment(Utils::Environment &env);
|
||||
|
||||
QString m_configName;
|
||||
|
||||
Utils::FilePath m_envFile;
|
||||
|
Reference in New Issue
Block a user