Using Visual Studio to debug Cygwin applications

This tutorial shows how to create, build and debug cygwin-based applications with Visual Studio.

Before you begin, please install cygwin and VisualGDB .

  1. Start Visual Studio. Select File->New project->Visual C++->VisualGDB->Visual GDB Project WizardSelect project location and enter a project name. Then click OK.
  2. In the VisualGDB wizard select "A Windows Application":Wizard screenshot Windows application
  3. On the next page select "Create a new project"Wizard screenshot create new application
  4. On the toolchain page select "Cygwin". VisualGDB will detect its location automatically or ask you to enter it in case it cannot be found.Wizard screenshot choose cygwin toolchainIf you want to see or customize the compiler/debugger versions, press the "Setup individual tools" button.
  5. The build settings page allows editing the flags going into the makefile. In our case no changes are needed, press Next.Wizard screenshot build settings page
  6. Next you can customize various debugger settings. In this tutorial we'll accept the default settings and press Next.Wizard screenshot debugger settings
  7. Next page allows you to modify how file names in cygwin error messages will be converted to Win32 paths compatible with Visual Studio. Just click Next to accept the default settings.Wizard screenshot: file mapping settings
  8. On the next page you can customize the include directories used by Visual Studio to suggest function arguments and browse structures. You can import those automatically from GCC by clicking at the link at the bottom of the wizard page. Press Finish to make the project. Wizard screenshot intellisense settings
  9. The wizard will generate a Visual Studio project for a simple "Hello, World" application built with cygwin tools. To build it just select Build->Build Solution or press Ctrl+Shift+B.
  10. Once the project is built, set a breakpoint on the printf() line and start debugging by selecting Debug->Start debugging with GDB:
  11. Debugging your cygwin-based app with VisualGDB is not much different from debugging normal Windows applications: stepping, watch windows, call stack, memory view and many other features will work as usual. VisualGDB will seamlessly control the GDB debugger on behalf of Visual Studio. You can also enter GDB commands directly in the GDB Session window.To end debugging, press Shift+F5.
  12. You can always customize the GDB-specific properties of your project by right-clicking at it and selecting "VisualGDB Project Properties".
  13. From the properties window you can control GCC/GDB command lines and many advanced parameters.