diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2016-04-29 16:52:58 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2016-05-11 10:04:38 +0000 |
commit | ddefe062c73e35def585f8fc6c90a4f18e47c0f4 (patch) | |
tree | 03c3aecc501c03b92e259fe0ae1c4d472033b7e5 /src/plugins/debugger | |
parent | 1a248b1b932e2c7c42e25993d921e78c52aa4bcf (diff) | |
download | qt-creator-ddefe062c73e35def585f8fc6c90a4f18e47c0f4.tar.gz |
Fix up QProcess::waitForFinished()
waitForFinish returns false if the process is no longer running at
the time of the call. Handle that throughout the codebase.
Change-Id: Ia7194095454e82efbd4eb88f2d55926bdd09e094
Reviewed-by: hjk <hjk@theqtcompany.com>
Diffstat (limited to 'src/plugins/debugger')
-rw-r--r-- | src/plugins/debugger/debuggeritem.cpp | 41 | ||||
-rw-r--r-- | src/plugins/debugger/debuggeritemmanager.cpp | 25 | ||||
-rw-r--r-- | src/plugins/debugger/debuggersourcepathmappingwidget.cpp | 2 | ||||
-rw-r--r-- | src/plugins/debugger/gdb/coregdbadapter.cpp | 15 |
4 files changed, 43 insertions, 40 deletions
diff --git a/src/plugins/debugger/debuggeritem.cpp b/src/plugins/debugger/debuggeritem.cpp index ec6ac3d799..986a9cb30f 100644 --- a/src/plugins/debugger/debuggeritem.cpp +++ b/src/plugins/debugger/debuggeritem.cpp @@ -35,6 +35,7 @@ #include <utils/hostosinfo.h> #include <utils/macroexpander.h> #include <utils/qtcassert.h> +#include <utils/synchronousprocess.h> #include <QFileInfo> #include <QProcess> @@ -117,66 +118,66 @@ void DebuggerItem::reinitializeFromFile() if (fileInfo.baseName().toLower().contains(QLatin1String("lldb-mi"))) version = "--version"; - QProcess proc; - proc.start(m_command.toString(), QStringList({ QLatin1String(version) })); - if (!proc.waitForStarted() || !proc.waitForFinished()) { + SynchronousProcess proc; + SynchronousProcessResponse response + = proc.run(m_command.toString(), QStringList({ QLatin1String(version) })); + if (response.result != SynchronousProcessResponse::Finished) { m_engineType = NoEngineType; return; } m_abis.clear(); - QByteArray ba = proc.readAll(); - if (ba.contains("gdb")) { + const QString output = response.allOutput(); + if (output.contains("gdb")) { m_engineType = GdbEngineType; const char needle[] = "This GDB was configured as \""; // E.g. "--host=i686-pc-linux-gnu --target=arm-unknown-nto-qnx6.5.0". // or "i686-linux-gnu" - int pos1 = ba.indexOf(needle); + int pos1 = output.indexOf(needle); if (pos1 != -1) { pos1 += int(strlen(needle)); - int pos2 = ba.indexOf('"', pos1 + 1); - QByteArray target = ba.mid(pos1, pos2 - pos1); + int pos2 = output.indexOf('"', pos1 + 1); + QString target = output.mid(pos1, pos2 - pos1); int pos3 = target.indexOf("--target="); if (pos3 >= 0) target = target.mid(pos3 + 9); - m_abis.append(Abi::abiFromTargetTriplet(QString::fromLatin1(target))); + m_abis.append(Abi::abiFromTargetTriplet(target)); } else { // Fallback. m_abis = Abi::abisOfBinary(m_command); // FIXME: Wrong. } // Version - QString all = QString::fromUtf8(ba); bool isMacGdb, isQnxGdb; int version = 0, buildVersion = 0; - Debugger::Internal::extractGdbVersion(all, + Debugger::Internal::extractGdbVersion(output, &version, &buildVersion, &isMacGdb, &isQnxGdb); if (version) m_version = QString::fromLatin1("%1.%2.%3") .arg(version / 10000).arg((version / 100) % 100).arg(version % 100); return; } - if (ba.startsWith("lldb") || ba.startsWith("LLDB")) { + if (output.startsWith("lldb") || output.startsWith("LLDB")) { m_engineType = LldbEngineType; m_abis = Abi::abisOfBinary(m_command); // Version - if (ba.startsWith(("lldb version "))) { // Linux typically. + if (output.startsWith(("lldb version "))) { // Linux typically. int pos1 = int(strlen("lldb version ")); - int pos2 = ba.indexOf(' ', pos1); - m_version = QString::fromLatin1(ba.mid(pos1, pos2 - pos1)); - } else if (ba.startsWith("lldb-") || ba.startsWith("LLDB-")) { // Mac typically. - m_version = QString::fromLatin1(ba.mid(5)); + int pos2 = output.indexOf(' ', pos1); + m_version = output.mid(pos1, pos2 - pos1); + } else if (output.startsWith("lldb-") || output.startsWith("LLDB-")) { // Mac typically. + m_version = output.mid(5); } return; } - if (ba.startsWith("cdb")) { + if (output.startsWith("cdb")) { // "cdb version 6.2.9200.16384" m_engineType = CdbEngineType; m_abis = Abi::abisOfBinary(m_command); - m_version = QString::fromLatin1(ba).section(QLatin1Char(' '), 2); + m_version = output.section(QLatin1Char(' '), 2); return; } - if (ba.startsWith("Python")) { + if (output.startsWith("Python")) { m_engineType = PdbEngineType; return; } diff --git a/src/plugins/debugger/debuggeritemmanager.cpp b/src/plugins/debugger/debuggeritemmanager.cpp index e5716e4a15..c02a87f9c2 100644 --- a/src/plugins/debugger/debuggeritemmanager.cpp +++ b/src/plugins/debugger/debuggeritemmanager.cpp @@ -33,12 +33,12 @@ #include <utils/fileutils.h> #include <utils/persistentsettings.h> #include <utils/qtcassert.h> +#include <utils/synchronousprocess.h> #include <utils/hostosinfo.h> #include <QDebug> #include <QDir> #include <QFileInfo> -#include <QProcess> using namespace Core; using namespace ProjectExplorer; @@ -225,17 +225,18 @@ void DebuggerItemManager::autoDetectGdbOrLldbDebuggers() FileNameList suspects; if (HostOsInfo::isMacHost()) { - QProcess lldbInfo; - lldbInfo.start(QLatin1String("xcrun"), QStringList() << QLatin1String("--find") - << QLatin1String("lldb")); - if (!lldbInfo.waitForFinished(2000)) { - lldbInfo.kill(); - lldbInfo.waitForFinished(); - } else { - QByteArray lPath = lldbInfo.readAll(); - const QFileInfo fi(QString::fromLocal8Bit(lPath.data(), lPath.size() -1)); - if (fi.exists() && fi.isExecutable() && !fi.isDir()) - suspects.append(FileName::fromString(fi.absoluteFilePath())); + SynchronousProcess lldbInfo; + lldbInfo.setTimeoutS(2); + SynchronousProcessResponse response + = lldbInfo.run(QLatin1String("xcrun"), QStringList() << QLatin1String("--find") + << QLatin1String("lldb")); + if (response.result == Utils::SynchronousProcessResponse::Finished) { + QString lPath = response.allOutput(); + if (!lPath.isEmpty()) { + const QFileInfo fi(lPath); + if (fi.exists() && fi.isExecutable() && !fi.isDir()) + suspects.append(FileName::fromString(fi.absoluteFilePath())); + } } } diff --git a/src/plugins/debugger/debuggersourcepathmappingwidget.cpp b/src/plugins/debugger/debuggersourcepathmappingwidget.cpp index 4769eecf3a..11319c47c9 100644 --- a/src/plugins/debugger/debuggersourcepathmappingwidget.cpp +++ b/src/plugins/debugger/debuggersourcepathmappingwidget.cpp @@ -415,7 +415,7 @@ static QString findQtInstallPath(const FileName &qmakePath) return QString(); } proc.closeWriteChannel(); - if (!proc.waitForFinished()) { + if (!proc.waitForFinished() && proc.state() == QProcess::Running) { SynchronousProcess::stopProcess(proc); qWarning("%s: Timeout running '%s'.", Q_FUNC_INFO, qPrintable(qmakePath.toString())); return QString(); diff --git a/src/plugins/debugger/gdb/coregdbadapter.cpp b/src/plugins/debugger/gdb/coregdbadapter.cpp index d946efbe4a..109592bd62 100644 --- a/src/plugins/debugger/gdb/coregdbadapter.cpp +++ b/src/plugins/debugger/gdb/coregdbadapter.cpp @@ -34,6 +34,7 @@ #include <utils/fileutils.h> #include <utils/qtcassert.h> +#include <utils/synchronousprocess.h> #include <QDir> #include <QTemporaryFile> @@ -135,23 +136,23 @@ GdbCoreEngine::readExecutableNameFromCore(const QString &debuggerCommand, const args.append(QLatin1String("-c")); args.append(coreFile); - QProcess proc; + SynchronousProcess proc; QStringList envLang = QProcess::systemEnvironment(); Utils::Environment::setupEnglishOutput(&envLang); proc.setEnvironment(envLang); - proc.start(debuggerCommand, args); + SynchronousProcessResponse response = proc.run(debuggerCommand, args); - if (proc.waitForFinished()) { - QByteArray ba = proc.readAllStandardOutput(); + if (response.result == SynchronousProcessResponse::Finished) { + QString output = response.stdOut; // Core was generated by `/data/dev/creator-2.6/bin/qtcreator'. // Program terminated with signal 11, Segmentation fault. - int pos1 = ba.indexOf("Core was generated by"); + int pos1 = output.indexOf("Core was generated by"); if (pos1 != -1) { pos1 += 23; - int pos2 = ba.indexOf('\'', pos1); + int pos2 = output.indexOf('\'', pos1); if (pos2 != -1) { cinfo.isCore = true; - cinfo.rawStringFromCore = QString::fromLocal8Bit(ba.mid(pos1, pos2 - pos1)); + cinfo.rawStringFromCore = output.mid(pos1, pos2 - pos1); cinfo.foundExecutableName = findExecutableFromName(cinfo.rawStringFromCore, coreFile); } } |