From f33ad9d6548d4544ad2ea6229b47093efa9ea0ef Mon Sep 17 00:00:00 2001 From: Murray Read Date: Mon, 26 Mar 2012 14:02:10 +0100 Subject: Give QThread threads better names on Symbian QThread sets the name of a Symbian thread that it creates. This name can appear in a number of debugging scenarios, and it can give useful information. However the existing name set by QThread has not been informative. This change improves the amount of information in the thread name. Threads are now named as: __v=_ The class name and vptr can be used to identify the QThread subclass type. In the case of a QThread subclass that generates a .moc file, the class name will be the true class name. However for other cases, eg where QThread is used directly, or is subclassed without a QOBJECT declaration, the name may simply be "QThread", and the vptr field might then be more informative. This change also allows the use of RTTI to get the true class name, through a rebuild of Qt, defining the macro name QT_USE_RTTI_IN_THREAD_CLASSNAME. This is not enabled by default, as there may be Symbian cases where RTTI does not work. Task-number: QTBUG-24950 Change-Id: Ifae9c6cb64638e95a01d34e421aa36f6fd0e7444 Reviewed-by: Shane Kearns Reviewed-by: Gareth Stockwell --- src/corelib/thread/qthread_symbian.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/corelib/thread/qthread_symbian.cpp b/src/corelib/thread/qthread_symbian.cpp index fd551ff..0cddb68 100644 --- a/src/corelib/thread/qthread_symbian.cpp +++ b/src/corelib/thread/qthread_symbian.cpp @@ -53,6 +53,11 @@ #include #include +// This can be manually enabled if debugging thread problems +#ifdef QT_USE_RTTI_IN_THREAD_CLASSNAME +#include +#endif + // You only find these enumerations on Symbian^3 onwards, so we need to provide our own // to remain compatible with older releases. They won't be called by pre-Sym^3 SDKs. @@ -520,17 +525,23 @@ void QThread::start(Priority priority) d->stackSize = 0x14000; // Maximum stack size on Symbian. int code = KErrAlreadyExists; - QString objName = objectName(); - TPtrC objNamePtr(qt_QString2TPtrC(objName)); + QString className(QLatin1String(metaObject()->className())); +#ifdef QT_USE_RTTI_IN_THREAD_CLASSNAME + // use RTTI, if enabled, to get a more accurate className. This must be manually enabled. + const char* rttiName = typeid(*this).name(); + if (rttiName) + className = QLatin1String(rttiName); +#endif + QString threadNameBase = QString(QLatin1String("%1_%2_v=0x%3_")).arg(objectName()).arg(className).arg(*(uint*)this,8,16,QLatin1Char('0')); + TPtrC threadNameBasePtr(qt_QString2TPtrC(threadNameBase)); TName name; - objNamePtr.Set(objNamePtr.Left(qMin(objNamePtr.Length(), name.MaxLength() - 16))); + threadNameBasePtr.Set(threadNameBasePtr.Left(qMin(threadNameBasePtr.Length(), name.MaxLength() - 8))); const int MaxRetries = 10; for (int i=0; idata->symbian_thread_handle.Create(name, (TThreadFunction) QThreadPrivate::start, d->stackSize, NULL, this); } -- cgit v0.12