diff options
Diffstat (limited to 'src/corelib/global')
-rw-r--r-- | src/corelib/global/qglobal.h | 9 | ||||
-rw-r--r-- | src/corelib/global/qlogging.cpp | 140 | ||||
-rw-r--r-- | src/corelib/global/qnamespace.h | 3 | ||||
-rw-r--r-- | src/corelib/global/qnamespace.qdoc | 11 | ||||
-rw-r--r-- | src/corelib/global/qprocessordetection.h | 2 |
5 files changed, 108 insertions, 57 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 38ced26ea4..78b7cec915 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -61,6 +61,9 @@ #include <QtCore/qfeatures.h> #endif +// The QT_SUPPORTS macro is deprecated. Don't use it in new code. +// Instead, use #ifdef/ndef QT_NO_feature. +// ### Qt6: remove macro #ifdef _MSC_VER # define QT_SUPPORTS(FEATURE) (!defined QT_NO_##FEATURE) #else @@ -920,6 +923,8 @@ QT_WARNING_DISABLE_MSVC(4530) /* C++ exception handler used, but unwind semantic # endif #endif +#ifndef QT_NO_FOREACH + template <typename T> class QForeachContainer { QForeachContainer &operator=(const QForeachContainer &) Q_DECL_EQ_DELETE; @@ -945,11 +950,15 @@ for (QForeachContainer<typename QtPrivate::remove_reference<decltype(container)> ++_container_.i, _container_.control ^= 1) \ for (variable = *_container_.i; _container_.control; _container_.control = 0) +#endif // QT_NO_FOREACH + #define Q_FOREVER for(;;) #ifndef QT_NO_KEYWORDS +# ifndef QT_NO_FOREACH # ifndef foreach # define foreach Q_FOREACH # endif +# endif // QT_NO_FOREACH # ifndef forever # define forever Q_FOREVER # endif diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 6dc453009b..0fe095b8d3 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -54,6 +54,7 @@ #include "qthread.h" #include "private/qloggingregistry_p.h" #include "private/qcoreapplication_p.h" +#include "private/qsimd_p.h" #endif #ifdef Q_OS_WIN #include <qt_windows.h> @@ -1193,6 +1194,89 @@ void QMessagePattern::setPattern(const QString &pattern) memcpy(literals, literalsVar.constData(), literalsVar.size() * sizeof(const char*)); } +#if defined(QLOGGING_HAVE_BACKTRACE) && !defined(QT_BOOTSTRAPPED) +// make sure the function has "Message" in the name so the function is removed + +#if (defined(Q_CC_GNU) && defined(QT_COMPILER_SUPPORTS_SIMD_ALWAYS)) || QT_HAS_ATTRIBUTE(optimize) +// force skipping the frame pointer, to save the backtrace() function some work +__attribute__((optimize("omit-frame-pointer"))) +#endif +static QStringList backtraceFramesForLogMessage(int frameCount) +{ + QStringList result; + if (frameCount == 0) + return result; + + // The results of backtrace_symbols looks like this: + // /lib/libc.so.6(__libc_start_main+0xf3) [0x4a937413] + // The offset and function name are optional. + // This regexp tries to extract the library name (without the path) and the function name. + // This code is protected by QMessagePattern::mutex so it is thread safe on all compilers + static QRegularExpression rx(QStringLiteral("^(?:[^(]*/)?([^(/]+)\\(([^+]*)(?:[\\+[a-f0-9x]*)?\\) \\[[a-f0-9x]*\\]$"), + QRegularExpression::OptimizeOnFirstUsageOption); + + QVarLengthArray<void*, 32> buffer(7 + frameCount); + int n = backtrace(buffer.data(), buffer.size()); + if (n > 0) { + int numberPrinted = 0; + for (int i = 0; i < n && numberPrinted < frameCount; ++i) { + QScopedPointer<char*, QScopedPointerPodDeleter> strings(backtrace_symbols(buffer.data() + i, 1)); + QString trace = QString::fromLatin1(strings.data()[0]); + QRegularExpressionMatch m = rx.match(trace); + if (m.hasMatch()) { + QString library = m.captured(1); + QString function = m.captured(2); + + // skip the trace from QtCore that are because of the qDebug itself + if (!numberPrinted && library.contains(QLatin1String("Qt5Core")) + && (function.isEmpty() || function.contains(QLatin1String("Message"), Qt::CaseInsensitive) + || function.contains(QLatin1String("QDebug")))) { + continue; + } + + if (function.startsWith(QLatin1String("_Z"))) { + QScopedPointer<char, QScopedPointerPodDeleter> demangled( + abi::__cxa_demangle(function.toUtf8(), 0, 0, 0)); + if (demangled) + function = QString::fromUtf8(qCleanupFuncinfo(demangled.data())); + } + + if (function.isEmpty()) { + result.append(QLatin1Char('?') + library + QLatin1Char('?')); + } else { + result.append(function); + } + } else { + if (numberPrinted == 0) { + // innermost, unknown frames are usually the logging framework itself + continue; + } + result.append(QStringLiteral("???")); + } + numberPrinted++; + } + } + return result; +} + +static QString formatBacktraceForLogMessage(const QMessagePattern::BacktraceParams backtraceParams, + const char *function) +{ + QString backtraceSeparator = backtraceParams.backtraceSeparator; + int backtraceDepth = backtraceParams.backtraceDepth; + + QStringList frames = backtraceFramesForLogMessage(backtraceDepth); + if (frames.isEmpty()) + return QString(); + + // if the first frame is unknown, replace it with the context function + if (function && frames.at(0).startsWith(QLatin1Char('?'))) + frames[0] = QString::fromUtf8(qCleanupFuncinfo(function)); + + return frames.join(backtraceSeparator); +} +#endif // QLOGGING_HAVE_BACKTRACE && !QT_BOOTSTRAPPED + #if defined(QT_USE_SLOG2) #ifndef QT_LOG_CODE #define QT_LOG_CODE 9000 @@ -1336,62 +1420,8 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con #ifdef QLOGGING_HAVE_BACKTRACE } else if (token == backtraceTokenC) { QMessagePattern::BacktraceParams backtraceParams = pattern->backtraceArgs.at(backtraceArgsIdx); - QString backtraceSeparator = backtraceParams.backtraceSeparator; - int backtraceDepth = backtraceParams.backtraceDepth; backtraceArgsIdx++; - QVarLengthArray<void*, 32> buffer(7 + backtraceDepth); - int n = backtrace(buffer.data(), buffer.size()); - if (n > 0) { - int numberPrinted = 0; - for (int i = 0; i < n && numberPrinted < backtraceDepth; ++i) { - QScopedPointer<char*, QScopedPointerPodDeleter> strings(backtrace_symbols(buffer.data() + i, 1)); - QString trace = QString::fromLatin1(strings.data()[0]); - // The results of backtrace_symbols looks like this: - // /lib/libc.so.6(__libc_start_main+0xf3) [0x4a937413] - // The offset and function name are optional. - // This regexp tries to extract the librry name (without the path) and the function name. - // This code is protected by QMessagePattern::mutex so it is thread safe on all compilers - static QRegularExpression rx(QStringLiteral("^(?:[^(]*/)?([^(/]+)\\(([^+]*)(?:[\\+[a-f0-9x]*)?\\) \\[[a-f0-9x]*\\]$"), - QRegularExpression::OptimizeOnFirstUsageOption); - - QRegularExpressionMatch m = rx.match(trace); - if (m.hasMatch()) { - // skip the trace from QtCore that are because of the qDebug itself - QString library = m.captured(1); - QString function = m.captured(2); - if (!numberPrinted && library.contains(QLatin1String("Qt5Core")) - && (function.isEmpty() || function.contains(QLatin1String("Message"), Qt::CaseInsensitive) - || function.contains(QLatin1String("QDebug")))) { - continue; - } - - if (function.startsWith(QLatin1String("_Z"))) { - QScopedPointer<char, QScopedPointerPodDeleter> demangled( - abi::__cxa_demangle(function.toUtf8(), 0, 0, 0)); - if (demangled) - function = QString::fromUtf8(qCleanupFuncinfo(demangled.data())); - } - - if (numberPrinted > 0) - message.append(backtraceSeparator); - - if (function.isEmpty()) { - if (numberPrinted == 0 && context.function) - message += QString::fromUtf8(qCleanupFuncinfo(context.function)); - else - message += QLatin1Char('?') + library + QLatin1Char('?'); - } else { - message += function; - } - - } else { - if (numberPrinted == 0) - continue; - message += backtraceSeparator + QLatin1String("???"); - } - numberPrinted++; - } - } + message.append(formatBacktraceForLogMessage(backtraceParams, context.function)); #endif } else if (token == timeTokenC) { QString timeFormat = pattern->timeArgs.at(timeArgsIdx); diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 06b0f824f6..edb568a2d6 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -503,7 +503,8 @@ public: AA_UseStyleSheetPropagationInWidgetStyles = 22, // ### Qt 6: remove me AA_DontUseNativeDialogs = 23, AA_SynthesizeMouseForUnhandledTabletEvents = 24, - AA_DontCheckOpenGLContextThreadAffinity = 25, + AA_CompressHighFrequencyEvents = 25, + AA_DontCheckOpenGLContextThreadAffinity = 26, // Add new attributes before this line AA_AttributeCount diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 9878ce046a..d8a0acabf1 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -239,6 +239,17 @@ to mouse events instead. This attribute is enabled by default. This value has been added in Qt 5.7. + \value AA_CompressHighFrequencyEvents Enables compression of certain frequent events. + On the X11 windowing system, the default value is true, which means that + QEvent::MouseMove, QEvent::TouchUpdate, and changes in window size and + position will be combined whenever they occur more frequently than the + application handles them, so that they don't accumulate and overwhelm the + application later. On other platforms, the default is false. + (In the future, the compression feature may be implemented across platforms.) + You can test the attribute to see whether compression is enabled. + If your application needs to handle all events with no compression, + you can unset this attribute. This value has been added in Qt 5.7. + \value AA_DontCheckOpenGLContextThreadAffinity When making a context current using QOpenGLContext, do not check that the \l{QObject#Thread Affinity}{QObject thread affinity} diff --git a/src/corelib/global/qprocessordetection.h b/src/corelib/global/qprocessordetection.h index ee94720e7a..6ecd41bc30 100644 --- a/src/corelib/global/qprocessordetection.h +++ b/src/corelib/global/qprocessordetection.h @@ -107,7 +107,7 @@ # define Q_PROCESSOR_ARM __TARGET_ARCH_ARM # elif defined(_M_ARM) && _M_ARM > 1 # define Q_PROCESSOR_ARM _M_ARM -# elif defined(__ARM64_ARCH_8__) +# elif defined(__ARM64_ARCH_8__) || defined(__aarch64__) # define Q_PROCESSOR_ARM 8 # elif defined(__ARM_ARCH_7__) \ || defined(__ARM_ARCH_7A__) \ |