diff options
author | Alessandro Portale <alessandro.portale@qt.io> | 2021-11-08 13:07:00 +0100 |
---|---|---|
committer | Alessandro Portale <alessandro.portale@qt.io> | 2021-11-09 09:35:23 +0000 |
commit | d33cd5194ab6f51ee25836debb5d955400d7d7af (patch) | |
tree | 74cb7ce5f8e4c46de011e080257f97462b31e6dd | |
parent | 1b6d374d62fd3563aadf91e0db1594003f6c29d3 (diff) |
Debugger: Consolidate search code for python-path
Not just to deduplicate/reuse code but also to make make it clear that
different places where lldb is called, the same preparations have to be
done.
Change-Id: I104aca845fd7b42f63443bda2502574f4d28b411
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | src/plugins/debugger/debuggeritem.cpp | 32 | ||||
-rw-r--r-- | src/plugins/debugger/debuggeritem.h | 2 | ||||
-rw-r--r-- | src/plugins/debugger/lldb/lldbengine.cpp | 14 |
3 files changed, 22 insertions, 26 deletions
diff --git a/src/plugins/debugger/debuggeritem.cpp b/src/plugins/debugger/debuggeritem.cpp index 2e689ae9d3..85206926fb 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 12bc903bdd..f8d5e602de 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 ad2f4f2974..49124aca32 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()) |