支持的調試器
windows系統下主要的調試器:
- CDB ,只能調試用戶程序,只有控制台界面,以命令行形式工作
- NTSD, 只能調試用戶程序,只有控制台界面,以命令行形式工作
- KD,主要用於內核調試,有時候也用於用戶態調試,只有控制台界面,以命令行形式工作
- WinDbg,在用戶態、內核態下都能夠發揮調試功能,采用了可視化的用戶界面
Platform | Compiler | Native Debugger |
---|---|---|
Linux | GCC/ICC | GDB, LLDB (experimental) |
Unix | GCC/ICC | GDB |
macOS | GCC/Clang | LLDB,FSF GDB(experimental) |
Windows/MinGW | GCC | GDB |
Windows/MSVC | Microsoft Visual C++ Compiler | Debugging Tools for Windows/CDB |
在qt的官方文檔上,寫明了各個平台上的qtcreator支持的編譯器以及對應調試器。如windows平台上面MinGW版本的qtcreator就支持GDB調試器。而MSVC版本的qtcreator默認是沒有調試器的,需要自己去安裝並設置好調試器(CDB)。
下載和安裝
下載地址:https://msdn.microsoft.com/zh-cn/library/windows/hardware/ff551063
安裝分為在線安裝和離線安裝,離線安裝可以先選擇將安裝包下載下來,然后再安裝。獨立安裝只選擇Debugging Tools for Windows
即可。
QtCreator中配置CDB
方式一: 手動配置
- 打開
Tools
>Options
>Debugger
>CDB Paths
- 在Symbol Paths面板中, 選擇
Insert
- Select the directory where you want to store the cached information. Use a subfolder in a temporary directory, such as
C:\temp\symbolcache
. - Select
OK
.
方式二:重啟QtCreator,自動檢測,然后手動選擇調試器
調試實踐
可以很清晰的看到變量的值變化,可以單步調試,打斷點等等。
擴展
qt內存泄露檢查:
- Linux ,Mac OS X : Valgrind
- Windows: Visual Leak Detector for Visual C++ 2008-2015 (VLD, Open-source)
參考
https://wiki.qt.io/Profiling_and_Memory_Checking_Tools
http://www.voidcn.com/blog/u011012932/article/p-6231451.html
https://msdn.microsoft.com/zh-cn/library/windows/hardware/hh406277
https://doc.qt.io/qtcreator/creator-debugger-engines.html
http://blog.csdn.net/FreeApe/article/details/52976704