[SOLVED] QFileDialog/QDir/QDebug segmentation fault
-
I'm at a loss for words with this one...
I can't repro in a minimal example, so it's just specific to my project, though I am not sure in what way.
I am using 32-bit Qt5.1.0 on Fedora 19 64-bit.I am simply calling a function
@void tmp_test(void)
{
XXX
}@Where XXX is one of the following:
These snippets work fine:
@ QDir *test_dir = new QDir;
QString test_str;
test_str = QFileDialog::getExistingDirectory();
qDebug() << test_str;
test_dir->setPath(test_str);@@ QString test_str;
test_str = QFileDialog::getExistingDirectory();
qDebug() << test_str;@@ QString test_str;
test_str = QFileDialog::getExistingDirectory();
bool test_bool = test_str.isEmpty();
if (test_bool)
qDebug() << test_str;@The following all lead to a segmentation fault:
@ QDir *test_dir = new QDir;
QString test_str;
test_str = QFileDialog::getExistingDirectory();
/qDebug() << test_str;/
test_dir->setPath(test_str);@@ QDir test_dir;
QString test_str;
test_str = QFileDialog::getExistingDirectory();
qDebug() << test_str;
test_dir.setPath(test_str);@@ QString test_str;
test_str = QFileDialog::getExistingDirectory();@@ QString test_str;
test_str = QFileDialog::getExistingDirectory();
bool test_bool = test_str.isEmpty();
if (!test_bool)
test_str.chop(1);@The flow is either a QAction or a QPushButton, which when pressed calls the above function to grab a directory. This happens in multiple places in the program It occurs at the getExistingDirectory() line, and as soon as the window opens.
This is the bt from gdb after the sef-fault http://pastebin.com/yArrFvDd
Any ideas? Thanks.
-
-
The bug is somewhere else in your code. Anywhere else. You likely have some memory corruption going on (double-frees, writing to invalid pointers, writing past variable/array limits on the stack...). This doesn't always cause a segfault right away (see heisenbug). At some point though, this corrupted memory is hit again, somewhere in another portion of code. A clear sign of this is something like
@qDebug() << "test: " << test_str;@
showing the bug and
@qDebug() << test_str;@
not showing it. This obviously changed the portion of memory that gets involved and thus causes or doesn't cause the bug to surface.Use "Valgrind":http://www.valgrind.org/ to (hopefully) find the source of your problem.
The hardest thing will be to convince yourself that you've actually found and fixed the bug. Because as you see, anything you do, may make the bug seemingly disappear – just to have it surface in two months again in a completely different situation.
-
Thanks for the reply DerManu.
I usually keep a keen eye out for memory errors, and I've used Valgrind before to track them down with this project, I removed all the ones that came from my source files awhile back.
I compiled with '-g' and ran Valgrind again. There are no frames listed that start with one of my files (they are all pre-pended with drgui).
I ran Valgrind with 'valgrind --leak-check=full --show-reachable=yes --log-file=./a.out ../DR_install/ext/bin32/drgui'There are a lot of errors, though I'm not sure if they come from my code or not. My files aren't listed in the callstacks, but I'm told that the Qt devs take memory errors seriously, so I don't think it would be from them either.
You can see the report "here":http://pastebin.com/sHtDrM8g.Does anything jump out at you?
-
I suggest you run valgrind from within QtCreator. This will automatically exclude warnings that don't originate from your application, but Qt itself or any lower libraries (e.g. GTK, STL or whatever). The warnings that come up from external libs may be real memory errors but it's also possible that they are false positives (i.e. the developers do something tricky or something outside the control/sight of valgrind).
-
One way to create a minimal example (and/or to track down the source of memory corruption) is to gradually cut out parts of your code and see if it still crashes each time.
How are you calling tmp_test()? (As a direct function call in main()? From within a slot? etc.)
[quote author="clarkb7" date="1375736191"]I'm told that the Qt devs take memory errors seriously, so I don't think it would be from them either.[/quote]With a library as large as Qt, it's nigh impossible to keep things 100% bug-free :) Don't rule out a Qt bug yet -- do keep investigating.
I've found what I believe is a segfault-causing bug in Qt, when opening dialogs in a specific way: https://bugreports.qt-project.org/browse/QTBUG-32821
-
I figured it out :)
The segmentation faults were coming from a stack-boundary mismatch between my drgui app and the Qt libs.
DynamoRIO defines the flag -mpreferred-stack-boundary=2, while my Qt uses the default of 4.Changing CMAKE_CXX_FLAGS for just the drgui part resolved the problem.
Thanks for your help and hints DerManu and JKSH!