Launching the Debugger

To start an application from an open project under the control of a debugger, press the Debug button in the lower left corner of the main view, or press F5.

Qt Creator checks whether the compiled program is up-to-date, and rebuilds and deploys it if the Always build project before deploying it and Always deploy before running options are selected in the Build and Run options.

The debugger then takes over and starts the program with suitable parameters.

Note: Starting a C++ program in the debugger can take a long time, typically in the range of several seconds to minutes if complex features are used.

Launching the Debugger in Different Modes

The debugger plugin can run the native debuggers in various operating modes depending on where and how the debugged process is started and run. Some of the modes are only available for a particular operating system or platform.

In general, the F5 and the Debug button are set up in a way to start the operating mode that is commonly used in a given context. So if the current project is set up as a C++ application using the MinGW toolchain targeting desktop Windows, the GDB engine will be started in Start Internal mode. If the current project is a QML application using C++ plugins, a "mixed" QML/C++ engine will be started, with the C++ parts being handled by GDB and GDB server remote debugging.

Change the run configuration parameters (such as Run in Terminal) in the run settings of the project, or select options from the Debug > Start Debugging menu to select other modes of operation.

The debugger can run in the following modes:

  • Start Internal to debug applications developed inside Qt Creator such as a Qt based GUI application.
  • Start External to start and debug processes without a proper Qt Creator project setup, either locally or on a remote machine.
  • Attach to debug processes already started and running outside Qt Creator, either locally or on a remote machine.
  • Core to debug crashed processes on Unix.
  • Post-mortem to debug crashed processes on Windows.

Launching in Start Internal Mode

Start Internal mode is the default start mode for most projects, including all projects using a desktop Qt version and plain C++ projects.

If you need a console window to operate your application, for example because it accepts console input from the user, go to Projects > Run Settings and select the Run in terminal check box.

To launch the debugger in Start Internal mode, click the Start Debugging button for the active project.

You can specify breakpoints before or after launching the debugger. For more information, see Setting Breakpoints.

Launching in Start External Mode

To run any executable already present on your local or a remote machine without using a project, select Debug > Start Debugging > Start and Debug External Application.

Launching in Attach Mode

To attach the debugger to an application already running on your local or a remote machine, select Debug > Start Debugging > Attach to Running Application, and then select a process by its name or process ID to attach to.

While this mode does not strictly require a project to be opened in Qt Creator, it is beneficial to have open one, as it makes setting breakpoints and stepping through the code easier.

You can specify breakpoints before or after attaching the debugger to the application. For more information, see Setting Breakpoints.

Launching in Core Mode

The Core mode is used to inspect core files (crash dumps) that are generated from crashed processes on Linux and Unix systems if the system is set up to allow this.

To enable the dumping of core files on a Unix system, enter the following command in the shell from which the application will be launched:

ulimit -c unlimited

To launch the debugger in the core mode, select Debug > Start Debugging > Load Core File.

Also in this mode, using a properly configured project containing the sources of the crashed program is not strictly necessary, but helpful.

Launching in Post-Mortem Mode

The post-mortem mode is available only on Windows, if you have installed the debugging tools for Windows.

The Qt Creator installation program asks you whether you want to register Qt Creator as a post-mortem debugger. To change the setting, select Tools > Options > Debugger > General > Use Qt Creator for post-mortem debugging.

You can launch the debugger in the post-mortem mode if an application crashes on Windows. Click the Debug in Qt Creator button in the error message that is displayed by the Windows operating system.

Remote Debugging

Qt Creator provides very easy access to remote debugging.

In general, the remote debugging setup consist of a probe running on the remote machine and a counterpart running on the host side. The probe is either integrated into the running process (e.g. for QML debugging) or runs a separate process (e.g. when using GDB server on embedded Linux). The host side typically consists of Qt Creator itself, often with the help of an external process, such as GDB or CDB.

While this setup might look daunting, it is mostly invisible to the user of Qt Creator. To start debugging on a remote target with the necessary helper processes running, select the corresponding kit in Projects > Build & Run, and then select a function to start remote debugging in the Debug > Start Debugging menu.

Special use cases, such as attaching to a running process on the target, might still require manual setup.

Using GDB

When debugging on a target supported by GDB server, a local GDB process talks to a GDB server running on the remote machine that controls the process to be debugged.

The GDB server process is started on the remote machines by passing a port number and the executable:

gdbserver :1234 <executable>

It then typically responds:

Process bin/qtcreator created; pid = 5159
Listening on port 1234

On the local machine that runs Qt Creator:

  1. Select Debug > Start Debugging > Attach to Running Debug Server.
  2. In the Host and port field, enter the name of the remote machine and the port number to use.
  3. Select OK to start debugging.

Using CDB

In remote mode, the local CDB process talks to a CDB process that runs on the remote machine. The process is started with special command line options that switch it into server mode. The remote CDB process must load the Qt Creator CDB extension library that is shipped with Qt Creator:

  1. Install the Debugging Tools for Windows on the remote machine. The installation folder contains the CDB command line executable (cdb.exe).
  2. Copy the Qt Creator CDB extension library from the Qt installation directory to the a new folder on the remote machine (32 or 64 bit version depending on the version of the Debugging Tools for Windows used):
    • \lib\qtcreatorcdbext32\qtcreatorcdbext.dll (32 bit)
    • \lib\qtcreatorcdbext64\qtcreatorcdbext.dll (64 bit)
  3. Set the _NT_DEBUGGER_EXTENSION_PATH environment variable to point to that folder.
  4. To use TCP/IP as communication protocol, launch remote CDB as follows:
    cdb.exe -server tcp:port=1234 <executable>
  5. On the local machine running Qt Creator, select Debug > Start Debugging > Attach to Remote CDB Session.
  6. In the Connection field enter the connection parameters. For example, for TCP/IP:

    If you chose some other protocol, specify one of the alternative formats:

  7. Click OK to start debugging.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.