diff options
Diffstat (limited to 'src/corelib/global/qlogging.cpp')
-rw-r--r-- | src/corelib/global/qlogging.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 94ec78f382..16755e6e21 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -862,7 +862,7 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info) if (info.isEmpty()) return info; - int pos; + qsizetype pos; // Skip trailing [with XXX] for templates (gcc), but make // sure to not affect Objective-C message names. @@ -892,6 +892,12 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info) // Don't know how to parse this function name return info; } + if (info.indexOf('>', pos) != -1 + || info.indexOf(':', pos) != -1) { + // that wasn't the function argument list. + pos = info.size(); + break; + } // find the beginning of the argument list --pos; @@ -909,7 +915,7 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info) info.truncate(++pos); if (info.at(pos - 1) == ')') { - if (info.indexOf(operator_call) == pos - (int)strlen(operator_call)) + if (info.indexOf(operator_call) == pos - qsizetype(strlen(operator_call))) break; // this function returns a pointer to a function @@ -932,19 +938,19 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info) if (pos > -1) { switch (info.at(pos)) { case ')': - if (info.indexOf(operator_call) == pos - (int)strlen(operator_call) + 1) + if (info.indexOf(operator_call) == pos - qsizetype(strlen(operator_call)) + 1) pos -= 2; break; case '<': - if (info.indexOf(operator_lessThan) == pos - (int)strlen(operator_lessThan) + 1) + if (info.indexOf(operator_lessThan) == pos - qsizetype(strlen(operator_lessThan)) + 1) --pos; break; case '>': - if (info.indexOf(operator_greaterThan) == pos - (int)strlen(operator_greaterThan) + 1) + if (info.indexOf(operator_greaterThan) == pos - qsizetype(strlen(operator_greaterThan)) + 1) --pos; break; case '=': { - int operatorLength = (int)strlen(operator_lessThanEqual); + auto operatorLength = qsizetype(strlen(operator_lessThanEqual)); if (info.indexOf(operator_lessThanEqual) == pos - operatorLength + 1) pos -= 2; else if (info.indexOf(operator_greaterThanEqual) == pos - operatorLength + 1) @@ -988,7 +994,7 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info) break; // find the matching close - int end = pos; + qsizetype end = pos; templatecount = 1; --pos; while (pos && templatecount) { @@ -1151,9 +1157,9 @@ void QMessagePattern::setPattern(const QString &pattern) tokens[i] = qthreadptrTokenC; else if (lexeme.startsWith(QLatin1StringView(timeTokenC))) { tokens[i] = timeTokenC; - int spaceIdx = lexeme.indexOf(QChar::fromLatin1(' ')); + qsizetype spaceIdx = lexeme.indexOf(QChar::fromLatin1(' ')); if (spaceIdx > 0) - timeArgs.append(lexeme.mid(spaceIdx + 1, lexeme.length() - spaceIdx - 2)); + timeArgs.append(lexeme.mid(spaceIdx + 1, lexeme.size() - spaceIdx - 2)); else timeArgs.append(QString()); } else if (lexeme.startsWith(QLatin1StringView(backtraceTokenC))) { @@ -1209,11 +1215,8 @@ void QMessagePattern::setPattern(const QString &pattern) .arg(lexeme); } } else { - char *literal = new char[lexeme.size() + 1]; - strncpy(literal, lexeme.toLatin1().constData(), lexeme.size()); - literal[lexeme.size()] = '\0'; - literalsVar.emplace_back(literal); - tokens[i] = literal; + using UP = std::unique_ptr<char[]>; + tokens[i] = literalsVar.emplace_back(UP(qstrdup(lexeme.toLatin1().constData()))).get(); } } if (nestedIfError) @@ -1302,7 +1305,7 @@ static QStringList backtraceFramesForLogMessage(int frameCount) // use dladdr() instead of backtrace_symbols() QString cachedLibrary; const char *cachedFname = nullptr; - auto decodeFrame = [&](const void *addr) -> DecodedFrame { + auto decodeFrame = [&](void *addr) -> DecodedFrame { Dl_info info; if (!dladdr(addr, &info)) return {}; @@ -2040,9 +2043,12 @@ void qErrnoWarning(int code, const char *msg, ...) \row \li \c{%{backtrace [depth=N] [separator="..."]}} \li A backtrace with the number of frames specified by the optional \c depth parameter (defaults to 5), and separated by the optional \c separator parameter (defaults to "|"). + This expansion is available only on some platforms (currently only platfoms using glibc). Names are only known for exported functions. If you want to see the name of every function - in your application, use \c{QMAKE_LFLAGS += -rdynamic}. + in your application, make sure your application is compiled and linked with \c{-rdynamic}, + or an equivalent of it. + When reading backtraces, take into account that frames might be missing due to inlining or tail call optimization. \endtable |