diff --git a/src/plugins/debugger/debuggeritem.cpp b/src/plugins/debugger/debuggeritem.cpp index 2e689ae9d3d..85206926fb8 100644 --- a/src/plugins/debugger/debuggeritem.cpp +++ b/src/plugins/debugger/debuggeritem.cpp @@ -144,8 +144,6 @@ 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,10 +165,12 @@ void DebuggerItem::reinitializeFromFile(const Environment &sysEnv, QString *erro return; } + Environment env = sysEnv.size() == 0 ? Environment::systemEnvironment() : sysEnv; // Prevent calling lldb on Windows because the lldb from the llvm package is linked against // python but does not contain a python dll. + const bool isAndroidNdkLldb = DebuggerItem::addAndroidLldbPythonEnv(m_command, env); if (HostOsInfo::isWindowsHost() && m_command.fileName().startsWith("lldb") - && !isAndroid) { + && !isAndroidNdkLldb) { QString errorMessage; m_version = winGetDLLVersion(WinDLLFileVersion, m_command.absoluteFilePath().path(), @@ -180,16 +180,6 @@ 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(env); proc.setCommand({m_command, {version}}); @@ -275,6 +265,22 @@ void DebuggerItem::reinitializeFromFile(const Environment &sysEnv, QString *erro m_engineType = NoEngineType; } +bool DebuggerItem::addAndroidLldbPythonEnv(const Utils::FilePath &lldbCmd, Utils::Environment &env) +{ + if (lldbCmd.baseName().contains("lldb") && + (lldbCmd.path().contains("/ndk/") || lldbCmd.path().contains("/ndk-bundle/"))) { + const FilePath pythonDir = lldbCmd.parentDir().parentDir().pathAppended("python3"); + const FilePath pythonBinDir = + HostOsInfo::isAnyUnixHost() ? pythonDir.pathAppended("bin") : pythonDir; + if (pythonBinDir.exists()) { + env.set("PYTHONHOME", pythonDir.path()); + env.prependOrSetPath(pythonBinDir.path()); + return true; + } + } + return false; +} + QString DebuggerItem::engineTypeName() const { switch (m_engineType) { diff --git a/src/plugins/debugger/debuggeritem.h b/src/plugins/debugger/debuggeritem.h index 12bc903bdd0..f8d5e602ded 100644 --- a/src/plugins/debugger/debuggeritem.h +++ b/src/plugins/debugger/debuggeritem.h @@ -107,6 +107,8 @@ public: QString detectionSource() const { return m_detectionSource; } void setDetectionSource(const QString &source) { m_detectionSource = source; } + static bool addAndroidLldbPythonEnv(const Utils::FilePath &lldbCmd, Utils::Environment &env); + private: DebuggerItem(const QVariant &id); void initMacroExpander(); diff --git a/src/plugins/debugger/lldb/lldbengine.cpp b/src/plugins/debugger/lldb/lldbengine.cpp index ad2f4f2974e..49124aca320 100644 --- a/src/plugins/debugger/lldb/lldbengine.cpp +++ b/src/plugins/debugger/lldb/lldbengine.cpp @@ -204,18 +204,6 @@ static QString adapterStartFailed() return LldbEngine::tr("Adapter start failed."); } -static void addAndroidPythonDir(const FilePath &lldbCmd, Environment &env) -{ - if (!lldbCmd.path().contains("/ndk/") && !lldbCmd.path().contains("/ndk-bundle/")) - return; - - FilePath androidPythonDir = lldbCmd.parentDir().parentDir().pathAppended("python3"); - if (HostOsInfo::isAnyUnixHost()) - androidPythonDir = androidPythonDir.pathAppended("bin"); - if (androidPythonDir.exists()) - env.prependOrSetPath(androidPythonDir.path()); -} - void LldbEngine::setupEngine() { QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state()); @@ -225,7 +213,7 @@ void LldbEngine::setupEngine() showMessage("STARTING LLDB: " + lldbCmd.toUserOutput()); Environment environment = runParameters().debugger.environment; environment.appendOrSet("PYTHONUNBUFFERED", "1"); // avoid flushing problem on macOS - addAndroidPythonDir(lldbCmd, environment); + DebuggerItem::addAndroidLldbPythonEnv(lldbCmd, environment); m_lldbProc.setEnvironment(environment); if (runParameters().debugger.workingDirectory.isDir())