Table of Contents
This chapter explains how to setup WinGDB for debugging and building programs for Windows using MinGW or Cygwin tool suite.
In this scenario the sources are stored and built on Windows using the gcc compiler.
One of possible options to start work with WinGDB is using a project template from the New Project dialog. Here you can choose from several project types: executable program, static library or shared library (shared libraries are not supported on some kinds of platforms).
This option creates the project and opens Project configuration wizard described below.
ou can also work with MinGW/Cygwin using WinGDB without any special project type. Just use any C++ project type that Visual Studio offers, e.g. Console application. This facilitates easy porting of existing Windows applications to MinGW/Cygwin platform.
WinGDB works with Visual Studio solution configurations. After creating the project, it is recommended you review configurations that Visual Studio creates. By default, these are Debug and Release configurations. If you want only to work on single platform, you may configure WinGDB for these configurations. If you plan multiplatform development, please read remarks on multiple configurations and platforms here.
The rest of this document covers the detailed configuration mode. You do not need to perform the steps described below while using the wizard, as it does them for you. It is however recommended to read the following sections and other documentation chapters, as they explain the Properties interface required to to utilise full capabilities of WinGDB. Some settings are also adjustable globally, using the Preferences dialog from main WinGDB menu.
To be able to debug with WinGDB, you must let it know the debugger location. To set that information, choose Preferences option from WinGDB menu. There is Default debugger location field in the preferences. You can enter full path to the debugger executable, or only the executable name. In the second case you have to configure your PATH variable on Windows host, so that the executable can be found. For MinGW or Cygwin this name is usually just "gdb".
Alternatively you can specify the debugger path in project or solution properties (Debugger path setting on Environment tab). This will override the global setting described above. Thus, you can use a different debugger in different projects or configurations. To return to default debugger, reset the Properties setting to default value.
If you use Cygwin, see Debugging Cygwin programs for additional information.
The most important property adjustable for a project or solution, is Target Type. All machine roles (Debug Host, Build Host and Debug Target) are fulfilled by the local machine, so you do not specify any logins.
WinGDB supports many possible scenarios of debugging with GDB. You have to select which one suits you. In this case, it will be "Windows native application (MinGW/Cygwin)".
WinGDB includes a simple makefile generator. This generator automatically creates a makefile from current project. Generated makefiles can be used with standard GNU make. Other build systems are in plans. The generator is optional, you can write your makefile by hand if you wish, or use a build system which is currently not supported.
You can find more information about the makefile generator in this section.
WinGDB has a simple mechanism to control compilation using make or any other build system. It works both in remote and local mode. It can start any build command, however if you want to be able to locate errors and warning in the source code, the build command output must be compatible with standard make and gcc message format. For best results, use standard GNU make.
You have to set some additional properties before using it. Right click on your project in Solution Explorer and open the Properties dialog. You do not have to enter any login information, since the build will be performed on local machine. Go to the Project build tab. Here you can set the following properties:
If you click on solution instead of project, there will also be shown another tab, Remote solution build. On that tab there is a similar set of options, this time concerning the whole solution. There is also one new option, Solution build mode. You can choose whether the soluton build will execute a build command for each project (with respect to their dependencies), or run build commands configured by the remaining options. Use the first possibility when you do not have a separate makefile for the whole solution, and the second one when you do have.
Apart from Remote solution build, there is also regular Remote build tab. On that tab you can set default settings for the projects, which can be then selectively overridden on any project settings page.
To start the build, choose one of options from the Build submenu from WinGDB menu on any project or solution in Solution Explorer. You will see results in the console. When you click on an error or warning, the code editor will jump to appropriate place in the code.
You can also use Rebuild and Clean and Deploy options to perform these actions.
To launch a program in debug mode, WinGDB needs to know the full path of the program. You specify it in the Executable path field on Debug tab.
You can also set some optional parameters, like program Arguments, additional Environment variables and Working directory. If you set Stop in main() option, the program will stop at the beginning of main() function. This option is added for convenience, as you can achieve the same effect by setting a function breakpoint in Visual Studio before starting the program. Also note that not all Windows programs have main() function, only those compiled for the Console subsystem. If your program starts with WinMain, just put a breakpoint at the beginning of it.
In order to attach to a process, choose Attach to process option from WinGDB menu. Select Windows native application mode in Target type field and press Refresh button. You will see a list of running processes. You can select a process and double-click it or press Attach to start debugging. Alternatively you can set some additional options by pressing Advanced settings button.
Table of Contents