如何使QT的Release模式可调试(Windows)

时间:2024-03-21 13:26:47

如何使QT的Release模式可调试(Windows)


如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033

目录

环境:
QT版本:5.6.2
开发环境:VS2013
系统版本:windows 7 64bit


前言

我们很多情况下是需要在Release模式下调试QT程序的,如联合dmp文件输出崩溃信息辅助定位问题、引用第三方库没有Debug版本但是有需要单步调试程序等等。
本文将介绍QT如何在Release模式下调试程序。

1.PDB简介

PDB(Program Database,程序数据库)文件保存调试和项目状态信息,允许增量链接程序的Debug配置。使用/ ZI或/ Zi(用于C / C ++)构建时,将创建PDB文件。
每次创建OBJ文件时,C / C ++编译器都会将调试信息合并到VCx0.PDB中。插入的信息包括类型信息,但不包括诸如功能定义之类的符号信息。因此,即使每个源文件都包含公共头文件(如<windows.h>),这些头文件中的typedef也只存储一次,而不是存储在每个OBJ文件中。
链接器创建project.PDB,其中包含项目的EXE文件的调试信息。 project.PDB文件包含完整的调试信息,包括函数原型,而不仅仅是VCx0.PDB中的类型信息。两个PDB文件都允许增量更新。链接器还将.pdb文件的路径嵌入到它创建的.exe或.dll文件中。

MSDN原文:
A program database (PDB) file holds debugging and project state information that allows incremental linking of a Debug configuration of your program. A PDB file is created when you build with /ZI or /Zi (for C/C++).
In Visual C++, the /Fd option names the PDB file created by the compiler. When you create a project in Visual Studio using wizards, the /Fd option is set to create a PDB named project.PDB.
If you build your C/C++ application using a makefile, and you specify /ZI or /Zi without /Fd, you end up with two PDB files:
VCx0.PDB, where x represents the version of Visual C++, for example VC100.PDB. This file stores all debugging information for the individual OBJ files and resides in the same directory as the project makefile.
project.PDB This file stores all debug information for the.exe file. For C/C++, it resides in the \debug subdirectory.
Each time it creates an OBJ file, the C/C++ compiler merges debug information into VCx0.PDB. The inserted information includes type information but does not include symbol information such as function definitions. So, even if every source file includes common header files such as <windows.h>, the typedefs from those headers are stored only once, rather than being in every OBJ file.
The linker creates project.PDB, which contains debug information for the project’s EXE file. The project.PDB file contains full debug information, including function prototypes, not just the type information found in VCx0.PDB. Both PDB files allow incremental updates. The linker also embeds the path to the .pdb file in the .exe or .dll file that it creates.
The Visual Studio debugger uses the path to the PDB in the EXE or DLL file to find the project.PDB file. If the debugger cannot find the PDB file at that location or if the path is invalid (for example, if the project was moved to another computer), the debugger searches the path containing the EXE, the symbol paths specified in the Options dialog box (Debugging folder, Symbols node). If the debugger cannot find a .PDB file, a Find Symbols dialog box appears, which allows you to search for symbols or to add additional locations to the search path.

2.QT中设置Release模式可调试

2.1 全局设置

目录:Qt5.6.2\5.6\msvc2013\mkspecs\common
文件:msvc-desktop.conf

QMAKE_CFLAGS_RELEASE     = -O2 -MD -Zi
QMAKE_LFLAGS_RELEASE     = /INCREMENTAL:NO /DEBUG

2.2 项目设置

在pro文件中加入

QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO
QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO

注意:
如果项目中有多个pro文件,如一个主程序+多个lib的方式,需要给每一个需要调试的pro都加入上面的配置。

3.结果

重新启动QT Creator获取重新编译后,会发现
a.程序产生了*.pdb文件
b.release版本可以和Debug一样调试了


Reference:

  1. MSDN : Program Database Files (C++)

觉得文章对你有帮助,可以用微信扫描二维码捐赠给博主,谢谢!
如何使QT的Release模式可调试(Windows)
如需转载请标明出处:http://blog.csdn.net/itas109
QQ技术交流群:129518033