How to debug in Qt Creator/MSVC2017?

If you use Qt Creator/Mingw(the Qt Creator installation package contains Mingw so you do not need to install Mingw separately), you will have no problem debugging your application. Qt Creator can detect the Mingw debugger(GDB) correctly. But if you use Qt Creator/MSVC, you will be left enough problems towards setting up the debugger successfully. It took me quite a long time to install Visual Studio and Qt5.12, and just found I can not even debug a program:

“Unable to create a debugging engine”

This is the error message showed in Qt Creator when I try to debug. Before that, I have built the debug version of the program successfully. In the “projects” tab of the current project, I clicked the “Manage Kits…” button, which showed me a list of auto-detected kits. But only the “Desktop Qt 5.12.1 Mingw 64-bit” kit is in normal status, the other kits all have an exclamation mark before them. But I’ve installed visual studio 2017 without a problem. Why the MSVC kits are not working properly?  In the compiler tab on the same dialog, I can see all Microsoft Visual C++ Compilers are detected and listed. In fact, a complete kit includes not only the compiler, but also the Qt version and the debugger. In the debugger tab, only GDB is auto-detected, MSVC debuggers are missing, which is the reason for the exclamation mark before the MSVC kits.

It turns out the Microsoft Visual Studio installer does  not install the debuggers. You need to install the MSVC debuggers(CDB) separately. You know, big companies like to create troubles for their users. This is one of their ways to make money.

To install MSVC debuggers(CDB), you need to download an installer on this web page. This little Windows SDK installer behaviors weirdly. It will let you specify a download directory and select the features you want to download(you only need to select the “Debugging Tools for Windows”), then download the packages to the directory, then finish! It won’t install the downloaded packages actually. You need to go to the download directory,e.g., D:\Windows Kits\10\WindowsSDK\Installers\, click and run the packages (X64 Debuggers And Tools-x64_en-us.msi,X86 Debuggers And Tools-x86_en-us.msi) manually. The two msi packages also behavior weirdly. They do not allow you to choose the target installation directory. In fact, they install the debuggers in D:\Windows Kits\10\Debuggers\x64 and D:\Windows Kits\10\Debuggers\x86 silently.  The two directories now contain the x64 version and the x86 version of the same set of debuggers, respectively. I do not know how they know the location of the Windows Kits. I do not know the Windows Kits directory, either. It must be created during  my installing Visual Studio 2017. But I do not remember MSVC2017 installer let me choose this directory. MSVC installer only let me choose where to install, and I chose to install MSVC in D:\programming\Microsoft Visual Studio. The wiseacre must determine to install Windows Kits under the root directory of the partition that MSVC is installed. It is very annoying that MSVC installer scatters the files everywhere. Besides the Visual Studio directory you select and the Windows Kits directory, you can also find parts of the Windows SDK are installed in C:\Program Files (x86)\Microsoft SDKs. And there is another Windows Kits in C:\Program Files (x86)\Windows Kits(but is an old version 8.1). I bet if something is wrong with Windows SDK, you can not locate the exact problematic file.

Ok, we have installed the Windows debuggers(CDB). If you re-open your project in Qt creator now, you will find two new debuggers (D:\Windows Kits\10\Debuggers\x86\cdb.exe,D:\Windows Kits\10\Debuggers\x64\cdb.exe) are auto-detected in the Debuggers tab, and the exclamation marks before the kit Desktop Qt 5.12.1 MSVC2017 64bit and Desktop Qt 5.12.1 MSVC2017 32bit disappear. Now you can use CDB to debug your program happily.

Posted in

Leave a Reply