From 9034c6ade6b44345bfb774c4a377e88b604aee8e Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Wed, 3 Jul 2019 13:02:51 +0200 Subject: [PATCH] Utils: Add logging category to SynchronousProcess This helps to debug e.g. runGcc(), which is used for detecting predefined macros or header paths for the code model. The log gives also a (limited) overview of the (blocking) processes that are run on Qt Creator start up. The produced command line is copy-pastable. The generated output looks like this: qtc.utils.synchronousprocess: Starting blocking: /usr/bin/x86_64-linux-gnu-gcc-8 -dumpmachine qtc.utils.synchronousprocess: SynchronousProcessResponse: result=0 ex=0 17 bytes stdout, stderr="" qtc.utils.synchronousprocess: Starting blocking: /usr/lib/icecc/bin/clang++ -x c++ -E -dM - qtc.utils.synchronousprocess: SynchronousProcessResponse: result=1 ex=115 0 bytes stdout, stderr="ICECC[9867] 2019-07-03 13:00:35: couldn't find any clang++\nICECC[9867] 2019-07-03 13:00:35: could not find clang++ in PATH.\n" "The command \"/usr/lib/icecc/bin/clang++\" terminated with exit code 115." Change-Id: I9bc7b24121801b0c98c52416848734d850aa9f4d Reviewed-by: Christian Kandeler --- src/libs/utils/synchronousprocess.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/libs/utils/synchronousprocess.cpp b/src/libs/utils/synchronousprocess.cpp index bfb9d0d2964..70e65fc8c9f 100644 --- a/src/libs/utils/synchronousprocess.cpp +++ b/src/libs/utils/synchronousprocess.cpp @@ -24,15 +24,18 @@ ****************************************************************************/ #include "synchronousprocess.h" -#include "qtcassert.h" +#include "executeondestruction.h" #include "hostosinfo.h" +#include "qtcassert.h" +#include "qtcprocess.h" #include -#include -#include #include +#include #include +#include #include +#include #include @@ -81,6 +84,8 @@ enum { defaultMaxHangTimerCount = 10 }; namespace Utils { +Q_LOGGING_CATEGORY(processLog, "qtc.utils.synchronousprocess", QtWarningMsg); + // A special QProcess derivative allowing for terminal control. class TerminalControllingProcess : public QProcess { public: @@ -445,8 +450,11 @@ SynchronousProcessResponse SynchronousProcess::run(const QString &binary, const QStringList &args, const QByteArray &writeData) { - if (debug) - qDebug() << '>' << Q_FUNC_INFO << binary << args; + qCDebug(processLog).noquote() << "Starting:" + << QtcProcess::joinArgs(QStringList(binary) + args); + ExecuteOnDestruction logResult([this] { + qCDebug(processLog) << d->m_result; + }); d->clearForRun(); @@ -492,13 +500,17 @@ SynchronousProcessResponse SynchronousProcess::run(const QString &binary, QApplication::restoreOverrideCursor(); } - if (debug) - qDebug() << '<' << Q_FUNC_INFO << binary << d->m_result; return d->m_result; } SynchronousProcessResponse SynchronousProcess::runBlocking(const QString &binary, const QStringList &args) { + qCDebug(processLog).noquote() << "Starting blocking:" + << QtcProcess::joinArgs(QStringList(binary) + args); + ExecuteOnDestruction logResult([this] { + qCDebug(processLog) << d->m_result; + }); + d->clearForRun(); // On Windows, start failure is triggered immediately if the