This quickstart guide shows how to build and debug a simple MinGW-based application using VisualGDB.
Before you begin, please download and install the following:
1. To create your first project, select File->New->Project in Visual Studio and then choose Visual C++ -> VisualGDB -> VisualGDB Project Wizard.
Please avoid spaces in directory names, as GDB does not support it.
2. Once VisualGDB wizard is started, select a target type. In this example we’ll create a simple MinGW application, so we select the first option:
3. At this step you can choose between creating a new project and importing existing code.
4. The toolchain selection stage allows selecting the GCC/GDB executables to use. For remote projects you will also need to select a remote machine that has the tools. Normally, VisualGDB should detect local MinGW and Cygwin installations. If this does not happen, please specify the paths manually.
By the way, when you press “next”, VisualGDB will attempt to start “gcc -v” and “gdb -v” to ensure that the specified executables are runnable and the path variables are not missing. If an error message appears here, please recheck your inputs. E.g., many MinGW-based tools need to have the MinGW bin directory in the %PATH% environment variable.
5. Next you can setup various GDB options. E.g. you can add your own startup commands, or force VisualGDB to create a log of all commands it sends to GDB.
6. At the next step you can specify the file mapping. This mapping will be used to convert GCC error messages, map location information from GDB and convert paths back when settings breakpoints. You can customize the file mapping here, in the project settings, or directly during debugging.
7. Finally you can set up the includes for IntelliSense.
Note that VisualGDB will also watch for “Entering directory” messages from GNU make and map relative paths reported by GCC correctly.
When you are done, press “finish”.
7. VisualGDB has created a sample source file, a generic Makefile and a file containing all GNU Make flags. You can customize the make files to add custom options, reference libraries, etc. VisualGDB will automatically add source files to the make file when you add them to your Visual Studio 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.
8. Put a breakpoint on the line that initializes the sz variable and start debugging using the “Debug->Start Debugging with GDB” command.
Iif the VIsualGDB commands do not appear, or stopped working after installing Visual Studio plugins, please run the following command line:
devenv /resetaddin VisualGDB.AddIn
Note that the VisualGDB.AddIn name is case-sensitive.
By the way, you can assign a shortcut (e.g. F6) to the “Start Debugging with GDB” command by selecting Tools->Options->Environment->Keyboard and selecting the “VisualGDB.AddIn.LaunchGDBProject” command.
9. When GDB starts and the breakpoint is hit, press F10 to do a single step and hover the mouse over the sz variable. Ensure that the Visual Studio shows its value. You can also try executing some raw GDB commands (e.g. “print sz”) in the GDB Session window.
If you want to try out some cool debugging techniques, check out this article for some ideas.
10. When you are done debugging, you can modify various project settings related to VisualGDB. Right-click on the project node in Solution Explorer and select “VisualGDB Project Properties”.
The VisualGDB Project Properties window will appear:
You can edit various project properties (e.g. make/GDB command lines), path mapping and GDB parameters. You can also create new VisualGDB-compatible project configurations from this window.