From 88aec120753768959cac7977d802c04dc2c6e526 Mon Sep 17 00:00:00 2001 From: Rafael Roquetto Date: Fri, 4 Mar 2022 14:08:32 +1000 Subject: [PATCH] QNX: Fix debugger detection The QNX gdb binary requires the QNX_TARGET env variable to be set even for codepaths that do not make use of it, namely, when invoking gdb with the --version or --configuration parameters to detect the ABI. Failure to set this variable causes gdb to fail with "QNX environment not set!" instead. This patch works around that by setting a phony QNX_TARGET variable in these occasions. Change-Id: I9f2638c422eb56516b87dde049186579d238de5c Reviewed-by: hjk Reviewed-by: James McDonnell --- src/plugins/debugger/debuggeritem.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/plugins/debugger/debuggeritem.cpp b/src/plugins/debugger/debuggeritem.cpp index 5d27bba2a8b..bdc46cb71e1 100644 --- a/src/plugins/debugger/debuggeritem.cpp +++ b/src/plugins/debugger/debuggeritem.cpp @@ -180,6 +180,12 @@ void DebuggerItem::reinitializeFromFile(const Environment &sysEnv, QString *erro return; } + // QNX gdb unconditionally checks whether the QNX_TARGET env variable is + // set and bails otherwise, even when it is not used by the specific + // codepath triggered by the --version and --configuration arguments. The + // hack below tricks it into giving us the information we want. + env.set("QNX_TARGET", QString()); + QtcProcess proc; proc.setEnvironment(env); proc.setCommand({m_command, {version}}); @@ -208,9 +214,18 @@ void DebuggerItem::reinitializeFromFile(const Environment &sysEnv, QString *erro const bool unableToFindAVersion = (0 == version); const bool gdbSupportsConfigurationFlag = (version >= 70700); if (gdbSupportsConfigurationFlag || unableToFindAVersion) { - const QString gdbConfiguration = getGdbConfiguration(m_command, sysEnv); + + auto gdbConfiguration = [this, &output, &sysEnv]() { + if (!output.contains("qnx")) + return getGdbConfiguration(m_command, sysEnv); + + Environment env = sysEnv; + env.set("QNX_TARGET", QString()); + return getGdbConfiguration(m_command, env); + }; + const QString gdbTargetAbiString = - extractGdbTargetAbiStringFromGdbOutput(gdbConfiguration); + extractGdbTargetAbiStringFromGdbOutput(gdbConfiguration()); if (!gdbTargetAbiString.isEmpty()) { m_abis.append(Abi::abiFromTargetTriplet(gdbTargetAbiString)); return;