From 50b23958046a617c9182f4f44fa09b310449b24e Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 8 Nov 2021 11:44:10 +0100 Subject: [PATCH] Debugger: Fix running android lldb ..when gathering version information. Change-Id: I99d69de661edad856fe66a045e8e2ee03036dd2c Reviewed-by: Alessandro Portale --- src/plugins/debugger/debuggeritem.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/plugins/debugger/debuggeritem.cpp b/src/plugins/debugger/debuggeritem.cpp index 2f71c8606bf..2e689ae9d3d 100644 --- a/src/plugins/debugger/debuggeritem.cpp +++ b/src/plugins/debugger/debuggeritem.cpp @@ -144,6 +144,8 @@ void DebuggerItem::createId() void DebuggerItem::reinitializeFromFile(const Environment &sysEnv, QString *error) { + const bool isAndroid = m_command.path().contains("/ndk/") + || m_command.path().contains("/ndk-bundle/"); // CDB only understands the single-dash -version, whereas GDB and LLDB are // happy with both -version and --version. So use the "working" -version // except for the experimental LLDB-MI which insists on --version. @@ -167,7 +169,8 @@ void DebuggerItem::reinitializeFromFile(const Environment &sysEnv, QString *erro // Prevent calling lldb on Windows because the lldb from the llvm package is linked against // python but does not contain a python dll. - if (HostOsInfo::isWindowsHost() && m_command.fileName().startsWith("lldb")) { + if (HostOsInfo::isWindowsHost() && m_command.fileName().startsWith("lldb") + && !isAndroid) { QString errorMessage; m_version = winGetDLLVersion(WinDLLFileVersion, m_command.absoluteFilePath().path(), @@ -177,8 +180,18 @@ void DebuggerItem::reinitializeFromFile(const Environment &sysEnv, QString *erro return; } + Environment env = sysEnv.toProcessEnvironment().isEmpty() ? Environment::systemEnvironment() + : sysEnv; + if (isAndroid && m_command.fileName().startsWith("lldb")) { + FilePath pythonPath = m_command.parentDir().parentDir().pathAppended("python3"); + if (HostOsInfo::isAnyUnixHost()) + pythonPath = pythonPath.pathAppended("bin"); + if (pythonPath.exists()) + env.prependOrSetPath(pythonPath.toUserOutput()); + } + QtcProcess proc; - proc.setEnvironment(sysEnv); + proc.setEnvironment(env); proc.setCommand({m_command, {version}}); proc.runBlocking(); const QString output = proc.allOutput().trimmed();