Using Visual Studio to debug MinGW applications

This tutorial shows how to build and debug a simple MinGW-based application using VisualGDB.

Before you begin, please download and install VisualGDB.

  1. To create your first project, select File->New->Project in Visual Studio and then choose VisualGDB -> MinGW/Cygwin Project Wizard:Please avoid spaces in directory names, as GDB does not support it.
  2. Once VisualGDB wizard is started, “Create a new project -> Application” and pick the build subsystem type. VisualGDB supports both GNU Make and CMake for MinGW projects. In this tutorial we will show the simpler GNU Make option, so select it in the “Build the project using” field:
  3. On the next page of the wizard select the toolchain that will be used to build the project. If you haven’t installed the MinGW toolchain yet, VisualGDB can install it for you automatically:
  4. Press “Finish” to generate the project. VisualGDB will created a sample source file, a generic Makefile and a file containing all GNU Make flags. Press Ctrl-Shift-Build to build the generated project:The generated makefile will disable optimization for the Debug configuration and set it to maximum for Release. To change this behavior, you can modify the flags.mak file.
  5. Now we will show how to add new sources to the project. Right-click in Solution Explorer and select Add->New Item:
  6. Add a new source file and try building the project. Note how VisualGDB has automatically updated the Makefile to reflect the changes:
  7. Now we will show how to use the create-from-use feature of the Advanced Clang IntelliSense. Modify the main() function to call another non-existing function as shown below, then press Ctrl-. and click on “Create function/method stub”:
  8. VisualGDB will automatically detect the types of the arguments and suggest creating a new method. Add a basic body to the function and press Ctrl-Enter to generate it:
  9. Call the function from main() and use the CodeJumps link on NewFunction() to explore the call tree:
  10. Now we will show how to use C++17 features with MinGW projects. Open VisualGDB Project Properties and add “-std=c+=17” to CXXFLAGS:
  11. Replace NewFunction() with a function adding its arguments using the C++17 pack folding syntax:
    template <typename ...Args> void NewFunction(Args ...args)
    {
    	cout << (args + ... + 0) << endl;
    }

    Then call the new function from main():

  12. Build the project, set a breakpoint after the call to NewFunction() and start debugging it. Observe how the correct sum of the arguments is printed to the console: