How to Configure Cdb in Qt Creator

How to configure CDB in Qt Creator?

I was having the same problems too, and finally figured out how to solve this. Styne666 gave me a hint. Do the following:

  1. Tools
  2. Options...
  3. Build & Run
  4. Tool Chains
  5. Use the "Clone" button to make a copy of each of the auto-detected MSVC items
  6. In each of the cloned items, you can specify the debugger in the "Debugger" field (e.g. C:\Program Files\Windows Kits\8.0\Debuggers\x64\cdb.exe)
  7. After this everything seems to work...

I should further mention that if you are running a 64-bit version of Windows and a 32-bit version of Qt Creator like I am, you need to make sure that you are pointing to the 32-bit versions of cdb (of which there are x86 and x64 target versions). So for the 32-bit target builds I run this:

C:\Program Files (x86)\Windows Kits\8.0\Debuggers\x86\cdb.exe

And for x64 builds I run this:

C:\Program Files (x86)\Windows Kits\8.0\Debuggers\x64\cdb.exe

The tricky part is that it is somewhat difficult to get Microsoft to install the 32-bit version of the debugging tools on your 64-bit machine. A co-worker tried to do so recently and said that he needed to install the Windows 8 tools in order to have the option to do that - the Windows 7 versions would not let you.

MSVC QT Creator - How to setup CDB correctly?

The anwser is kind of silly, when you install QT creator you need to create at least one project first without anything setup. If you import a project without doing this first everything will fail. So the exact steps I took to get this to work are....

1) I installed VS 2010

2) Update VS 2010 to SP1

3) Update Windows and .NET

4) uninstall 2010 C++ redistributables 1.4 or newer

5) install Windows debugging tools and SDK for Windows 7

6) install QT libs

7) install QT creator

8) create C++ code snippet project

9) setup Compiler and Debbuger with CDB 64 bit

The 64 Bit CDB works in 32 bit mode as well.

How to get Qt Creator to work with CDB?

Since your Qt is compiled with MSVC the best option is indeed CDB (for GDB you would need, for example, a MinGW compiled version).

Debugging should be out of the box. One first point I could think is whether for some reason Qt Creator doesn't see your debugging tools for Windows. Have you made sure that the path (and the version) for it is correctly specified in the CDB options page?

Also, have you considered switching to Qt Creator 2.1 (it has a lot of improvements in the area)? Or even better, a self-compiled version of the 2.2 branch, which includes a total refactoring of the CDB engine.

How to write debugging helper for cdb in qt creator?

Since Qt Creator 4.3 you can use exactly the same debugging helpers for GDB and CDB (and LLDB). The syntax has changed slightly compared to 4.2 but porting should be straightforward. It was mentioned in the release blog.

Debugging in QtCreator using MSVC2017 compiler

What I discuss here is getting QtCreator working with the Visual Studio 2017 (MSVC2017) compiler--including debugging! A default installation of MSVC2017 and Qt 5.10 will allow you to compile and run code, but you won't get debugging support by default. I will show the steps necessary to get everything installed (including debugging support) for the following reference system:

Reference System

  • Windows 7 SP1 x64 (works exactly the same with Win10, also)
  • Visual Studio 2017 (version 15.5.1)
  • Qt 5.10.0
  • Qt Creator 4.5.0 (MSVC 2015, 64-bit)
  • Debugging Tools for Windows (CDB.exe), which does NOT ship with Visual Studio 2017

    • via Windows 10 SDK
  • Targeting Windows Desktop 64-bit applications

I've tested these steps on both Windows 10 and Windows 7 (x64) and it seems to be working. Note that the version of QtCreator that comes bundled with the Qt installer is the 32 bit version, and it won't work out of the box if you're trying to do debugging using MSVC. This is documented, but not step-by-step (see QtCreator Windows Debugging and QtCreator Debugger Engines), and not everything is in one place, so I'm going to provide simple instructions here on how to get things working for the reference system I describe above.

Prerequisites

  • Windows 7 x64, or Windows 10
  • Visual Studio 2017 (tested with version 15.5.1)

Assuming you have Win7/Win10 and MSVC2017 installed, let's get started!

Download Qt

  • Download the file qt-opensource-windows-x86-5.10.0.exe from the Qt Official Release Archive
  • Install with the option "msvc2017 64-bit" checked.

    • all of the other check boxes are not necessary for the configuration described here

Qt 5.10 Setup

Install the Windows SDK for Windows 10
- https://developer.microsoft.com/en-us/windows/downloads/sdk-archive

Windows 10 SDK

  • select "Debugging Tools for Windows" and uncheck everything else

Windows 10 SDK feature selection

  • The web installer will download the selected component and create a folder called "Windows Kits."
  • Install these two files (the x86 version is optional):

    • Windows Kits\10\WindowsSDK\Installers\X64 Debuggers And Tools-x64_en-us.msi
    • Windows Kits\10\WindowsSDK\Installers\X86 Debuggers And Tools-x86_en-us.msi

Win SDK debugger installers

Install the 64-bit STAND-ALONE installer for QtCreator

NOTE: if you install QtCreator AFTER installing the Windows debugging tools, QtCreator will automatically detect the location of the debuggers, saving you the hassle when creating the kits. If you have already installed QtCreator, don't worry, configuring the kits in QtCreator is shown below.

  • Download "Qt Creator 4.5.0 for Windows 64-bit"

Sample Image

  • this version seems to have the option to select "CDB Debugger Support" (not found when installing the full Qt package that has Qt Creator bundled in)

Qt Creator 4.5.0 (64-bit) setup

Configure Kits in QtCreator

In QtCreator parlance or terminology, a "Kit" is a combination of debugger + compiler + Qt version + others. (In this sense, the word "Kit" does not mean the same thing as it does for "Windows Kits" when we installed the debugger above; this is an unfortunate name collision.) Set up a "QtCreator Kit" by selecting Tools -> Options -> Build & Run. I like to start on the far right tab and work to the left, ending on "Kits." The reason for this is that all of the tabs (1,2,3) below need to be configured in order to make a complete Kit.

QtCreator kit configuration order

Configure Debuggers in QtCreator

  • Set the path to C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\cdb.exe and give it a name like "Window Kit 10 cdb x64".

Debugger Tab in QtCreator

  • Set up the compiler. Make sure "Microsoft Visual C++ Compiler 15.0 (amd64)" is in the list. Note that QtCreator will auto-detected these locations if you've installed things to the default paths. Add the path to the compiler if it isn't listed.

  • Note that for Visual Studio 2017 x64 bit, you want the "amd64" version, which is the 64-bit compiler. In case you are wondering why there are so many compilers listed--they are "cross-compilers." That means they target different architectures, so for example, the "x86_amd64" is a 32-bit process that creates a 64-bit application; you would use this version if you were developing 64-bit code on a 32-bit computer (hence the term cross-compiling). Since this tutorial assumes you're running on a 64-bit OS, use the amd64 version. (The "x86_amd64" cross-compiler will also generate 64-bit code.) When I first saw the huge list of compiler selections in QtCreator, I didn't know which one to pick. Now you know, too! See When compiling x64 code, what's the difference between "x86_amd64" and "amd64"?.

cpp-64-bit-compiler

Now configure the Kit

  1. Click Add.
  2. Name - Give the name of the Kit; this will be the configuration you use when compiling your application.
  3. Compiler - Select the "Microsoft Visual C++ Compiler 15.0 (amd64)" for C and C++.
  4. Debugger - Select "Windows Kit 10 cdb x64" that we configured on the "Debuggers" tab
  5. Qt version - Select "Qt 5.10.0 (msvc2017_64). It is important to compile with the same bit-ness as the Qt libraries that you will link against.
  6. Click Apply.

Kit Setup in Qt Creator

Verify debugging works

Let's have some fun and write a 64-bit program, and then debug it. A good test is to allocate lots of memory (typical 32-bit Windows processes are limited to 2GB, see How much memory can a 32 bit process access on a 64 bit operating system? ). Allocating, say, 32GB of RAM should be a positive indicator that we are indeed compiling a 64-bit application. Here is a screen shot of QtCreator debugging a 64-bit Windows test program:

Debugging 64-bit code in Qt Creator

Note that I'm using the MSVC2017 64-bit compiler and the CDB.exe debugger mentioned above.

#include <QCoreApplication>
#include <cassert>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

int intSize = sizeof(int);
assert(intSize == 4);

int intPtrSize = sizeof(int*);
assert(intPtrSize == 8);

constexpr size_t giga = 1000 * 1000 * 1000;

size_t _32gigs = 32 * giga / intSize;
int* gigaChunk = new int[_32gigs];
assert(gigaChunk != nullptr);

return a.exec();
}

How to change debugger in QT Creator?

That kit was installed by the installer, which explicitly set that particular debugger. Those settings can not get changed via the UI! If there is something wrong there, then the Qt installer needs to be fixed.

Of course you can clone the kit and edit the cloned kit to your liking.

If you feel like wielding your text editor, then you can of course also change the settings that the installer wrote for Creator. They are stored in a file called profiles.xml somewhere in the "share" folder of your Qt Creator installation.



Related Topics



Leave a reply



Submit