Archive for June, 2014

Qt5 Pretty Printers for GDB

4th June 2014

If you’ve ever debugged a Qt program in GDB and been frustrated when attempting to print a QString gives you an unhelpful result like

$1 = {d = 0x6e7c40}

then kde-dev-scripts has some useful tools for you. For some time now, there has been the kde-devel-gdb script, which you can include in your ~/.gdbinit. This gives you commands like “printq4string” and “printq5string” which will dump the actual string contents of a QString.

However, GDB 7 has the ability to add pretty-printers written in Python. This means that you can control how a value is output when you use “print” and when backtraces are printed. So “print someQString” will actually write out the string for you.

The gdb directory of kde-dev-scripts now has some of these pretty-printers for Qt5. Currently, it covers most of the main value classes and collection classes in QtCore (QByteArray, QString, QStringList, QList, QMap, etc). QHash and QSet are the most notable ones that are missing.

To use these pretty-printers, you either need to source the “” file in your GDB session, or use the “” script to generate files that will allow GDB to auto-load the printers when it loads the Qt5 libraries.

I plan to eventually submit these to Qt, so that pretty-printing of Qt value classes will work out of the box. For now, do let me know if you run into any issues with them (don’t forget to compile your application with debugging symbols!), and feel free to extend what’s there, or use it as a template for some Qt4 pretty-printers.