[trunk] we need a Qt message handler to catch crashes originating from Q_ASSERT more quickly

• Feb 2, 2012 - 15:59
Type
Functional
Severity
S4 - Minor
Status
closed
Project

I am developing on Windows, so I don't know whether this is such an issue on other platforms.

When the application fails due to a Q_ASSERT, for example doing a QList::last on an empty list, the debugger belonging to the Qt IDE doesn't catch the crash. Countless hours can be wasted to find the cause.

With the enclosed patch, a handler is installed in debug mode which allows to set a breakpoint and catch the crash in no time.

Attachment Size
musescore.cpp_.patch 1.28 KB

Comments

On linux there is no problem. The qt messages appear on the connected terminal as expected. There is a default message handler in qt which should exactly do what the handler in your patch does. So the question is: why does it not work on windows?

It's not about printing the message, it's about catching the abort with a breakpoint!

I did research it. Previously Q_ASSERT would break into the debugger. Now not any more. So to find the location where the Q_ASSERT is triggered can waste hours (like I did last night).

Following the suggestion in http://developer.qt.nokia.com/forums/viewthread/13148 I created the message handler so we can set a breakpoint, like the comment suggests.

This is an essential improvement to help the developers finding crashes.

I'll give you an example. Take a look at http://musescore.org/en/node/11904.

The application causes a crash in a Q_ASSERT which prints a message and then aborts without going into the debugger. So without my message handler it takes hours to find. With the message handler, you can set a breakpoint just before the abort and catch the crash.
NOT FOUND: 01

Attachment Size
14748.jpg 146.74 KB

Further reading:
https://bugreports.qt-project.org/browse/QTCREATORBUG-6203:
If somewhere in the code a Q_ASSERT() evaluates false, the application is stopped with an info, where the Q_ASSERT() is and what expression evaluates false. If the application was run with a debugger, debugger is also stopped. If the developer wants to inspect a call stack, he must call qInstallMsgHandler() with a new MsgHandler, set a breakpoint in it and reproduce the bug.

Title [trunk] we need a QT message handler to catch crashes originating from Q_ASSERT more quickly [trunk] we need a Qt message handler to catch crashes originating from Q_ASSERT more quickly

Updated patch. Made the function static and changed its name.

Attachment Size
musescore.cpp-2.patch 1.29 KB
Status (old) patch (ready to commit) fixed

The patch has been applied and the message handler (mscoreMessageHandler) can be found just before main() in musescore.cpp.

Note that the code is conditionally compiled only under Windows:
#if defined(QT_DEBUG) && defined(Q_WS_WIN)

This may be a disadvantage for developers on other platforms. Developers on Mac and Linux who want to try it need to remove the && defined(Q_WS_WIN).

Lately I've noticed that some patches are being applied with no mention in the appropriate issue as to when or in what revision. This patch was quietly installed in trunk update 5290.