简体   繁体   English

让 Qt 调试器工作 (GDB)

[英]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.我目前正在 Windows 7 上构建,并试图让我的调试器逐步执行我的代码。 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.问题是,虽然我将构建配置设置为调试,并将我的CONFIG变量设置为在我的 QMake 文件中调试,但它仍然不起作用。

Here is my QMake file:这是我的 QMake 文件:

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).请注意,它实际上是用 C 编写并按原样编译的(所有文件都是本机 C 代码,使用 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).每次我谷歌时,我都会找到一些关于“添加调试符号”的东西,这在 Linux 中很容易做到,但在 Qt Creator 中,它似乎是正确完成的 PITA(除非我只是遗漏了一些完全简单的东西)。

Faced the similar problem on Linux (Fedora 16) using Qt Creator 2.5.0使用 Qt Creator 2.5.0 在 Linux (Fedora 16) 上遇到类似问题

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.原来 gdb 在我的主目录中启动,无法(我不知道为什么)加载正在调试的库的调试符号。 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.每当我强制 gdb 从放置库二进制文件的目录启动时(在 Qt Creator 中,它是通过工具->选项->调试器->附加启动命令中的附加调试器启动命令完成的:只需将“cd”设置为目录二进制文件)一切正常。

One more solution is to set the environment variable LD_LIBRARY_PATH to contain full path to the directory with binary.另一种解决方案是将环境变量 LD_LIBRARY_PATH 设置为包含二进制目录的完整路径。 In Qt Creator it is done in Project->Run Settings->Run Environment.在 Qt Creator 中,它是在项目->运行设置->运行环境中完成的。

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".为了检查调试符号是否已正确加载,请通过 Window->Views->Debugger Log 打开 gdb log 并键入命令“info shared”。

This worked for me under Linux, and I'm not sure if it'll work under Windows but here it goes anyway:这在 Linux 下对我有用,我不确定它是否可以在 Windows 下工作,但无论如何它都可以:

in the .pro file, I added the line:在 .pro 文件中,我添加了以下行:

CONFIG += debug

This enabled debugging within the QT system.这启用了 QT 系统内的调试。 Then i added the following:然后我添加了以下内容:

QMAKE_CXXFLAGS += -O0 -g -ggdb

The -ggdb is for the gdb support. -ggdb 用于 gdb 支持。 And the O (letter O) 0 (number zero) to be no optimisation - to prevent the compiler from optimising out variables.并且 O(字母 O)0(数字零)没有优化 - 以防止编译器优化出变量。 This gives me the backtraces i need with all the symbols when debugging under Linux.这为我提供了在 Linux 下调试时所需的所有符号的回溯。 This is a fairly standard debugging compiling option across the board with gdb.这是一个相当标准的 gdb 调试编译选项。 But it may already be covered by the debug option in CONFIG.但它可能已经被 CONFIG 中的调试选项覆盖。

Under Linux i rebuilt the project too:在 Linux 下,我也重建了项目:

make clean
make

But for Windows, if you're using Visual Studio, you might need to do a rebuild.但是对于 Windows,如果您使用的是 Visual Studio,则可能需要进行重建。 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.我知道您使用的是 Windows,如果它也可以在 Windows 下运行,那么尝试这些东西可能是值得的。 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.但是,即使它在 Windows 下不起作用,对于在 Linux 下搜索如何执行此操作的人来说也可能很有用,所以我认为这是一个有效的答案,即使它可能没有专门回答这个特定问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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