From 9f598d5ee9819971613c27705bce39e505705903 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sun, 13 Jul 2014 13:07:40 +0200 Subject: Logging: support %{backtrace} in QT_MESSAGE_PATTERN On supported platform, allow to show a backtrace by using %{backtrace} or %{backtrace depth=N separator="|"} [ChangeLog][QtCore][Logging] QT_MESSAGE_PATTERN can include a backtrace using %{backtrace} Change-Id: Ib00418c070d3bd6fe846dc04bf69fa91ba64f9cd Reviewed-by: Kai Koehne --- tests/auto/corelib/global/qlogging/app/app.pro | 3 ++ tests/auto/corelib/global/qlogging/app/main.cpp | 31 ++++++++++++++++++ .../auto/corelib/global/qlogging/tst_qlogging.cpp | 37 ++++++++++++++++++---- 3 files changed, 64 insertions(+), 7 deletions(-) (limited to 'tests/auto/corelib/global') diff --git a/tests/auto/corelib/global/qlogging/app/app.pro b/tests/auto/corelib/global/qlogging/app/app.pro index 24ac571bac..b11e792a4c 100644 --- a/tests/auto/corelib/global/qlogging/app/app.pro +++ b/tests/auto/corelib/global/qlogging/app/app.pro @@ -10,3 +10,6 @@ CONFIG += console SOURCES += main.cpp DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 + +gcc:!mingw: QMAKE_LFLAGS += -rdynamic + diff --git a/tests/auto/corelib/global/qlogging/app/main.cpp b/tests/auto/corelib/global/qlogging/app/main.cpp index 621059caad..e190a48873 100644 --- a/tests/auto/corelib/global/qlogging/app/main.cpp +++ b/tests/auto/corelib/global/qlogging/app/main.cpp @@ -42,11 +42,37 @@ #include #include +#ifdef Q_CC_GNU +#define NEVER_INLINE __attribute__((__noinline__)) +#else +#define NEVER_INLINE +#endif + struct T { T() { qDebug("static constructor"); } ~T() { qDebug("static destructor"); } } t; +class MyClass : public QObject +{ + Q_OBJECT +public slots: + virtual NEVER_INLINE QString mySlot1(); +private: + virtual NEVER_INLINE void myFunction(int a); +}; + +QString MyClass::mySlot1() +{ + myFunction(34); + return QString(); +} + +void MyClass::myFunction(int a) +{ + qDebug() << "from_a_function" << a; +} + int main(int argc, char **argv) { QCoreApplication app(argc, argv); @@ -65,5 +91,10 @@ int main(int argc, char **argv) qDebug("qDebug2"); + MyClass cl; + QMetaObject::invokeMethod(&cl, "mySlot1"); + return 0; } + +#include "main.moc" diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp index 3c1a26c629..a8027a4157 100644 --- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Olivier Goffart ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -650,14 +651,15 @@ void tst_qmessagehandler::qMessagePattern_data() // %{file} is tricky because of shadow builds QTest::newRow("basic") << "%{type} %{appname} %{line} %{function} %{message}" << true << (QList() - << "debug 46 T::T static constructor" + << "debug 52 T::T static constructor" // we can't be sure whether the QT_MESSAGE_PATTERN is already destructed << "static destructor" - << "debug tst_qlogging 57 main qDebug" - << "warning tst_qlogging 58 main qWarning" - << "critical tst_qlogging 59 main qCritical" - << "warning tst_qlogging 62 main qDebug with category" - << "debug tst_qlogging 66 main qDebug2"); + << "debug tst_qlogging 73 MyClass::myFunction from_a_function 34" + << "debug tst_qlogging 83 main qDebug" + << "warning tst_qlogging 84 main qWarning" + << "critical tst_qlogging 85 main qCritical" + << "warning tst_qlogging 88 main qDebug with category" + << "debug tst_qlogging 92 main qDebug2"); QTest::newRow("invalid") << "PREFIX: %{unknown} %{message}" << false << (QList() @@ -701,6 +703,23 @@ void tst_qmessagehandler::qMessagePattern_data() QTest::newRow("time") << "<%{time}>%{message}" << true << (QList() << "< "); +#ifdef __GLIBC__ +#ifdef QT_NAMESPACE +#define QT_NAMESPACE_STR QT_STRINGIFY(QT_NAMESPACE::) +#else +#define QT_NAMESPACE_STR "" +#endif + +#ifndef QT_NO_DEBUG + QTest::newRow("backtrace") << "[%{backtrace}] %{message}" << true << (QList() + // MyClass::qt_static_metacall is explicitly marked as hidden in the Q_OBJECT macro + << "[MyClass::myFunction|MyClass::mySlot1|?app?|" QT_NAMESPACE_STR "QMetaMethod::invoke|" QT_NAMESPACE_STR "QMetaObject::invokeMethod] from_a_function 34"); +#endif + + QTest::newRow("backtrace depth,separator") << "[%{backtrace depth=2 separator=\"\n\"}] %{message}" << true << (QList() + << "[MyClass::myFunction\nMyClass::mySlot1] from_a_function 34"); +#endif + } @@ -734,7 +753,11 @@ void tst_qmessagehandler::qMessagePattern() QCOMPARE(!output.contains("QT_MESSAGE_PATTERN"), valid); foreach (const QByteArray &e, expected) { - QVERIFY(output.contains(e)); + if (!output.contains(e)) { + qDebug() << output; + qDebug() << "expected: " << e; + QVERIFY(output.contains(e)); + } } #endif } -- cgit v1.2.3