简体   繁体   中英

Getting the Qt Debugger to work (GDB)

I'm currently building on Windows 7 and am trying to get my debugger to step through my code. The problem is that, while I have my build configuration set to debug, and my CONFIG variable to set to debug in my QMake file, it still doesn't work.

Here is my QMake file:

TEMPLATE = app
CONFIG += console debug
CONFIG -= qt

QMAKE_CXXFLAGS += -g -gdb

SOURCES += main.c \
    Triangle.c \
    GlutTesting.c

HEADERS += \
    Triangle.h \
    Includes.h \
    GlutTesting.h

LIBS += -lSDL -lopengl32 -lfreeglut

Note that it's actually written in C and compiled as such (all of the files are native C code, compiled with MinGW).

The issue is that everytime I start, even if I set a breakpoint, the code literally just zooms through it to the end of the applications current setting and stops there. It's almost impossible to actually debug my applications now.

What is wrong here? Everytime I Google I just find something about "adding debugging symbols", which is easy to do in Linux, but in Qt Creator it seems quite the PITA to get done properly (unless I'm just missing something totally simple).

Faced the similar problem on Linux (Fedora 16) using Qt Creator 2.5.0

It turned out that gdb started in my home directory and could not (I don't know why) load debugging symbols of a library being debugged. Whenever I force gdb to start from directory where the library binary file is placed (in Qt Creator it is done through additional debugger startup commands in Tools->Options->Debugger->Additional Startup Commands: just make "cd" to the directory with binary file) everything works fine.

One more solution is to set the environment variable LD_LIBRARY_PATH to contain full path to the directory with binary. In Qt Creator it is done in Project->Run Settings->Run Environment.

In order to check that debugging symbols have been loaded properly open gdb log via Window->Views->Debugger Log and type the command "info shared".

This worked for me under Linux, and I'm not sure if it'll work under Windows but here it goes anyway:

in the .pro file, I added the line:

CONFIG += debug

This enabled debugging within the QT system. Then i added the following:

QMAKE_CXXFLAGS += -O0 -g -ggdb

The -ggdb is for the gdb support. And the O (letter O) 0 (number zero) to be no optimisation - to prevent the compiler from optimising out variables. This gives me the backtraces i need with all the symbols when debugging under Linux. This is a fairly standard debugging compiling option across the board with gdb. But it may already be covered by the debug option in CONFIG.

Under Linux i rebuilt the project too:

make clean
make

But for Windows, if you're using Visual Studio, you might need to do a rebuild. I don't know what your compilation toolchain is.

I know you're using Windows, and it might be worth trying these things in case it works under Windows too. However, even if it doesn't work under Windows, it could be useful for someone searching for how to do this under Linux, so I think this is a valid answer, even though it may not specifically answer this particular question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM