Search code examples
cmakevalgrinddebug-build

Cmake flags for debugging don't seem to be useful in valgrind?


Ok, so I have this Qt application I'm attempting to debug; upon running valgrind on it and redirecting output to a file, I see many some 'definitely lost' blocks that look something like this, which make me sad:

==24357== 24 bytes in 1 blocks are definitely lost in loss record 150 of 508
==24357==    at 0x4C2C56F: malloc (vg_replace_malloc.c:267)
==24357==    by 0x76ED3CA: FcPatternCreate (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
==24357==    by 0x76EB3CD: FcFontRenderPrepare (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
==24357==    by 0x76EB66C: FcFontMatch (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
==24357==    by 0x57163D7: QFontDatabase::load(QFontPrivate const*, int) (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
==24357==    by 0x56F3586: QFontPrivate::engineForScript(int) const (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
==24357==    by 0x5728482: ??? (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
==24357==    by 0x573B73D: QTextLine::layout_helper(int) (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
==24357==    by 0x573D5A4: QTextLayout::endLayout() (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
==24357==    by 0x58F33CE: QLineControl::updateDisplayText(bool) (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
==24357==    by 0x58F36C6: QLineControl::init(QString const&) (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
==24357==    by 0x58EC720: ??? (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)

I'm not very good with valgrind, but as far as I can tell, this trace doesn't come back to my source files, right? In fact, nowhere in the full valgrind report (with the -v switch) do my source files appear, except for in main() where I declare the QApplication.

Then can I assume I'm not compiling my project with CMake correctly? Hopefully that's the problem, because the valgrind report doesn't seem too helpful to me right now..

Now then, in my CmakeLists.txt, I'm (attempting) to compile the project with debug flags like so:

 set(CMAKE_CXX_FLAGS_DEBUG "-g3 -ggdb -O0")

is this a proper way of doing this?

Am I doing something wrong here?

Thanks, and sorry for such a long question! :/


Solution

  • The usual procedure is to set CMAKE_BUILD_TYPE variable to Debug, Release, or etc. during configuration stage. This can be achieved by using -D flag for command-line cmake tool, or by modifying appropriate field in GUI.

    If you wish to pass extra flags to the compiler, just set CMAKE_CXX_FLAGS the same way as you set CMAKE_BUILD_TYPE.

    As you see, this doesn't invovles modifying any of CMakeLists.txt files, but CMakeCache.txt in your build dir.