summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qlogging.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-08-23 10:57:54 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-10-24 04:04:19 -0700
commit232f4f14be2ea95ceb5826ca31fa6fe911abe27f (patch)
tree6ab51284eefd30d93297057652cd58f4b25b8d1b /src/corelib/global/qlogging.cpp
parente85c64bb6d6bd56de9543273d9e92aedca68ca35 (diff)
QMessagePattern: use the system message sinks for parsing errors
Instead of only printing to stderr or the Windows debug buffer. I guess this wasn't done before because the code could recurse back and cause stack overflows. We can do it now without recursion problems. Change-Id: Ifa1111900d6945ea8e05fffd177e14e2f86ae482 Reviewed-by: Kai Köhne <kai.koehne@qt.io>
Diffstat (limited to 'src/corelib/global/qlogging.cpp')
-rw-r--r--src/corelib/global/qlogging.cpp47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 8a7ea6a4bd5..4a31a20cea6 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -168,7 +168,8 @@ Q_NORETURN
#endif
static void qt_message_fatal(QtMsgType, const QMessageLogContext &context, String &&message);
static void qt_message_print(QtMsgType, const QMessageLogContext &context, const QString &message);
-static void qt_message_print(const QString &message);
+static void preformattedMessageHandler(QtMsgType type, const QMessageLogContext &context,
+ const QString &formattedMessage);
static int checked_var_value(const char *varname)
{
@@ -1329,8 +1330,14 @@ void QMessagePattern::setPattern(const QString &pattern)
else if (inIf)
error += "QT_MESSAGE_PATTERN: missing %{endif}\n"_L1;
- if (!error.isEmpty())
- qt_message_print(error);
+ if (!error.isEmpty()) {
+ // remove the last '\n' because the sinks deal with that on their own
+ error.chop(1);
+
+ QMessageLogContext ctx(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE,
+ "QMessagePattern::setPattern", nullptr);
+ preformattedMessageHandler(QtWarningMsg, ctx, error);
+ }
literals.reset(new std::unique_ptr<const char[]>[literalsVar.size() + 1]);
std::move(literalsVar.begin(), literalsVar.end(), &literals[0]);
@@ -1927,6 +1934,18 @@ static constexpr SystemMessageSink systemMessageSink = {
#endif
};
+static void preformattedMessageHandler(QtMsgType type, const QMessageLogContext &context,
+ const QString &formattedMessage)
+{
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_GCC("-Waddress") // "the address of ~~ will never be NULL
+ if (systemMessageSink.sink && systemMessageSink.sink(type, context, formattedMessage))
+ return;
+QT_WARNING_POP
+
+ stderr_message_handler(type, context, formattedMessage);
+}
+
/*!
\internal
*/
@@ -1942,13 +1961,7 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con
return;
}
- QString formattedMessage = qFormatLogMessage(type, context, message);
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_GCC("-Waddress") // "the address of ~~ will never be NULL
- if (systemMessageSink.sink && systemMessageSink.sink(type, context, formattedMessage))
- return;
-QT_WARNING_POP
- stderr_message_handler(type, context, formattedMessage);
+ preformattedMessageHandler(type, context, qFormatLogMessage(type, context, message));
}
#if defined(Q_COMPILER_THREAD_LOCAL)
@@ -1995,20 +2008,8 @@ static void qt_message_print(QtMsgType msgType, const QMessageLogContext &contex
auto msgHandler = messageHandler.loadAcquire();
(msgHandler ? msgHandler : qDefaultMessageHandler)(msgType, context, message);
} else {
- stderr_message_handler(msgType, context, message.toLocal8Bit());
- }
-}
-
-static void qt_message_print(const QString &message)
-{
-#if defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED)
- if (!shouldLogToStderr()) {
- win_outputDebugString_helper(message);
- return;
+ stderr_message_handler(msgType, context, message);
}
-#endif
- fprintf(stderr, "%s", message.toLocal8Bit().constData());
- fflush(stderr);
}
template <typename String>