View Full Version : How to debug random crashes?

21st November 2011, 11:24
My current application ALMOST works. I seem to get random crashes. The application just dies. Sometimes after a few seconds, sometimes after 30 minutes. I have no clue why.

I use Ubuntu 11.10 and qt-creator but I have no idea on how to debug this problem.

Can anyone help me with detailed debug instructions? I guess my first option is to get a core dump?
Perhaps this is something for the wiki? I will try to update this page http://www.qtcentre.org/wiki/index.php?title=Debuging with advices and help written here.

21st November 2011, 11:39
instead of running it stand alone. run it in debug mode and leave it running inside qt-creator(debbuger).

21st November 2011, 12:13
I changed to debug mode, started debugger and it said in the application output window:
&"warning: GDB: Failed to set controlling terminal: Invalid argument\n"

The application starts and after a while a dialog pops up and says:
"The inferior stopped because it received a signal from the Operating System

Signal Name: SIGSEGV
Signal Meaning: Segmentation fault"

In one of the debug windows I see

0 DBusMenuExporter::setStatus(QString const&) /usr/lib/x86_64-linux-gnu/libdbusmenu-qt.so.2 0 0x7fffe2718210
1 AppMenuPlatformMenuBar::setAltPressed(bool) /usr/lib/x86_64-linux-gnu/qt4/plugins/menubar/libappmenu-qt.so 0 0x7fffe294836e
2 AppMenuPlatformMenuBar::menuBarEventFilter(QObject *, QEvent*) /usr/lib/x86_64-linux-gnu/qt4/plugins/menubar/libappmenu-qt.so 0 0x7fffe2948783
3 QMenuBar::eventFilter(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0 0x7ffff773c1cd
4 QCoreApplicationPrivate::sendThroughObjectEventFil ters(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6dc8c88
5 QApplicationPrivate::notify_helper(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0 0x7ffff72f93ef
6 QApplication::notify(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0 0x7ffff72fe985
7 QCoreApplication::notifyInternal(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6dc8afc
8 ?? /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0 0x7ffff732c8e9
9 QApplication::notify(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0 0x7ffff72ffb12
10 QCoreApplication::notifyInternal(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6dc8afc
11 ?? /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0 0x7ffff739cf99
12 ?? /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0 0x7ffff739d40b
13 QApplication::x11ProcessEvent(_XEvent*) /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0 0x7ffff7378347
14 ?? /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0 0x7ffff73a1412
15 g_main_context_dispatch /lib/x86_64-linux-gnu/libglib-2.0.so.0 0 0x7ffff5a82a5d
16 ?? /lib/x86_64-linux-gnu/libglib-2.0.so.0 0 0x7ffff5a83258
17 g_main_context_iteration /lib/x86_64-linux-gnu/libglib-2.0.so.0 0 0x7ffff5a83429
18 QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6df3ed6
19 ?? /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0 0x7ffff73a107e
20 QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6dc7cf2
21 QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6dc7ef7
22 QCoreApplication::exec() /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6dcc789
23 main 0 0x405089

Sorry for the formatting :(

21st November 2011, 13:08
Now you see a call stack.
If your bug is not very fishy, just click first entry in call stack which is pointing to your code. At this point you can try check variables of your program and see if some values are wrong.

21st November 2011, 15:12
Well, I've clicked all 23 entries above but all I see is assembler code. So I did a rebuild-all and now I got nr 23 to point to
the line return a.exec(); in the default main function

int main(int argc, char *argv[])
QApplication a(argc, argv);
MainWindow w;

return a.exec();

That doesn't sound very helpful to me. Is the system trying to send some kind of signal to my application that I can't handle?
On the first line I see
0 DBusMenuExporter::setStatus(QString const&) /usr/lib/x86_64-linux-gnu/libdbusmenu-qt.so.2 0 0x7fffe2718210

and I have not done any thing knowingly to include any DBus in my application. Any more suggestions?

Btw. the code is here
(sorry for the poor quality of the code I haven't been using Qt for a long time now)

21st November 2011, 22:25
I did some googling on the DBus error and found some ubuntu related issue in programs that don't have a Menubar.
I added one and the program has not crashed, yet! :-)