Stepping into Qt Sources in Qt Creator (In Ubuntu Linux)

Stepping into Qt sources in Qt Creator (in Ubuntu Linux)

Since Qt Creator uses gdb, you need to configure gdb. First thing to do is to install Qt debugging symbols:

apt-get install libqt4-dbg

Or, for Qt5:

apt-get install qtbase5-dbg # For the qtbase package

This will install the debugging symbols for Qt libraries. Older releases of Ubuntu had a silly bug that required additional trick to correct those symbol files, but in the current release it works fine.

This will make gdb step inside Qt methods, but it's no fun without sources. So we need sources which can be installed like this, assuming that the source repository is enabled in the APT:

apt-get source qt4-x11
ln -s qt4-x11-4.7.0 qt # a convenience symlink

Or, for Qt5:

apt-get source qtbase-opensource-src
# Make a link as above, if you wish

This will download the sources, unpack them into the current directory and patch them accordingly, no root privileges needed unless the current dir isn't writeable by the current user.

And the last thing is to inform gdb of the sources location, which is done by putting this in the ~/.gdbinit file:

dir ~/vita/qt/src/corelib
dir ~/vita/qt/src/gui
dir ~/vita/qt/src/network
dir ~/vita/qt/src/sql

Add modules and correct paths as needed. The convenience symlink is very useful here, so we don't have to edit this file each time we upgrade to a new Qt version. We only need to download the new sources, patch them and change the symlink.

Note that even we have installed the debugging symbols, we still use the release build of Qt libraries. This means that the code is highly optimized and will sometimes behave very strange when stepping inside Qt binaries. If it is a problem, then it is necessary to build Qt in debug mode, install it separately (say, in /usr/local/qt4-debug) and tell Qt Creator to use that particular installation.

How to add Qt sources to QtCreator in Ubuntu?

A few minor versions ago, Qt added "Qt debug information files" to the maintenance tool.
They contain the debug information of the libraries.

Which means, if you debug and want to step into human readable Qt library code you have to install them.

Setup of Qt Creator to debug into Qt classes

If you are using a prebuilded version just remap the source code location as described in http://doc.qt.io/qtcreator/creator-debugger-engines.html

Mapping Source Paths

To enable the debugger to step into the code and display the source
code when using a copy of the source tree at a location different from
the one at which the libraries where built, map the source paths to
target paths:

  • Select Tools > Options > Debugger > General > Add.
  • In the Source path field, specify the source path in the debug information of the executable as reported by the debugger.
  • In the Target path field, specify the actual location of the source tree on the local machine.

To get "the source path in the debug information of the executable as reported by the debugger", you can activate the "Use Tooltips in Stack-View when Debugging" option by right-clicking in the Stack View and move the mouse over a specific function call.

Step into Qt Sources from Qt Creator on Windows (NOT built from source)

I opened one of the PDB files - c:\QtSDK\Desktop\Qt\4.8.1\msvc2008\lib\QtCored4.pdb - in a hex editor and found these strings describing file paths there:

c:\iwmake\build_vs2008_opensource_________________PADDING_________________\src\network\vc90.pdb

So I added a mapping using Tools->Options->Debugger->Add Qt Sources:

Sample Image

It's working and I can step into Qt Sources now :)

Keep in mind the path might be different for you, so you'll have to inspect your PDB files to find what to map.

Debug into Qt sources

Of course! But you might have to first:

  • go to $QT_HOME/qt

  • run ./configure with the -debug or -debug-and-release flag (many other flags here)

  • run "make"

  • wait a couple of hours while things build


Related Topics



Leave a reply



Submit