How to use helgrind to debug multithreaded Qt applications
You’ve heard of valgrind before, its default tool (memcheck) is such a life saver, being able to detect memory-related bugs in your code (leaks, double deletions, use of deleted memory, use of uninitialized memory, etc.).
Well, it turns out that valgrind also comes with a tool to detect race conditions between threads, in multithreaded applications. That tool is called helgrind.
In theory, provided that you’re on a Unix platform, using helgrind is as simple as
valgrind --tool=helgrind myapplication
However, if you do just that on a Qt application, you’ll end up digging through lots of false positives, making this a rather painful experience. So I wrote a howto with all the necessary steps to debug Qt4 and Qt5 applications with helgrind.
Currently it’s a little bit involved, you need to compile your own valgrind, your own Qt, patch Qt, set up a suppression file, and define an alias. Don’t worry, it’s all doable 🙂
Over time this will be simpler, after the next release of valgrind and Qt 5 only the last two steps will be necessary.
The full details on how to set up helgrind and Qt are in my helgrind for Qt applications howto.
(I prefer to keep the actual howto as an old-style webpage rather than a blog, to be able to keep updating it as time goes by, and new issues are detected or fixed. Easier than for you to have to read through ten consecutive blogs.)