In previous articles, I was not able to use Qt’s debug package provided by Ubuntu. Now, I will explain how to use them.
Our simple application:
C++
1
2
3
4
5
6
7
// main.cpp
#include <QtCore/QString>
intmain(){
QStrings="1234567";
inti=s.indexOf('3');
returni!=2;
}
Our *.pro file, you should enable the debug build:
1
2
3
4
5
6
# DebugQt.pro
TARGET = DebugQt
TEMPLATE = app
SOURCES += main.cpp
QT -= gui
CONFIG += console debug_and_release
1. Build your debug version of application:
1
2
# qmake-qt4
# make debug
2. Install Qt’s debug package:
1
# sudo apt-get install libqt4-debug
3. Install the Qt source:
1
# sudo apt-get source libqt4-debug
Now you can start debugging your application. Since Qt’s debug symbols are installed in /usr/lib, It does not follow the GDB’s global debug directory described here. We should tell GDB to load these symbols manually:
We set a breakpoint at the beginning of main function to load all shared libraries. Next, we will load symbols for libQtCore.so.4. The symbol will be loaded in the start address of it (0xb7652510):