summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-02-18 11:14:44 -0800
committerThiago Macieira <thiago.macieira@intel.com>2022-03-03 19:05:11 -0800
commitee7166e1761c3b5ca885bab299a7d036e884c2e7 (patch)
treecbafa76ecd9fc41865b325da005c79dd5c4b51ad /src/corelib
parent6358bc9331a961b882173367e9483f4eb4ca4783 (diff)
Logging: remove magic constant from backtrace code
Explain what that number 8 is by way of a comment and a constant. Pick-to: 6.2 6.3 Change-Id: Ic15405335d804bdea761fffd16d4f7567089c575 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qlogging.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index c369259788..11a43f73ef 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -1263,6 +1263,18 @@ void QMessagePattern::setPattern(const QString &pattern)
#if defined(QLOGGING_HAVE_BACKTRACE) && !defined(QT_BOOTSTRAPPED)
// make sure the function has "Message" in the name so the function is removed
+/*
+ A typical backtrace in debug mode looks like:
+ #0 backtraceFramesForLogMessage (frameCount=5) at qlogging.cpp:1296
+ #1 formatBacktraceForLogMessage (backtraceParams=..., function=0x4040b8 "virtual void MyClass::myFunction(int)") at qlogging.cpp:1344
+ #2 qFormatLogMessage (type=QtDebugMsg, context=..., str=...) at qlogging.cpp:1452
+ #3 stderr_message_handler (type=QtDebugMsg, context=..., message=...) at qlogging.cpp:1744
+ #4 qDefaultMessageHandler (type=QtDebugMsg, context=..., message=...) at qlogging.cpp:1795
+ #5 qt_message_print (msgType=QtDebugMsg, context=..., message=...) at qlogging.cpp:1840
+ #6 qt_message_output (msgType=QtDebugMsg, context=..., message=...) at qlogging.cpp:1891
+ #7 QDebug::~QDebug (this=<optimized out>, __in_chrg=<optimized out>) at qdebug.h:111
+*/
+static constexpr int TypicalBacktraceFrameCount = 8;
#if (defined(Q_CC_GNU) || __has_attribute(optimize)) \
&& !defined(Q_CC_INTEL) && !defined(Q_CC_CLANG)
@@ -1282,7 +1294,7 @@ static QStringList backtraceFramesForLogMessage(int frameCount)
// This code is protected by QMessagePattern::mutex so it is thread safe on all compilers
static const QRegularExpression rx(QStringLiteral("^(?:[^(]*/)?([^(/]+)\\(([^+]*)(?:[\\+[a-f0-9x]*)?\\) \\[[a-f0-9x]*\\]$"));
- QVarLengthArray<void *, 32> buffer(8 + frameCount);
+ QVarLengthArray<void *, 32> buffer(TypicalBacktraceFrameCount + frameCount);
int n = backtrace(buffer.data(), buffer.size());
if (n > 0) {
int numberPrinted = 0;