Redaguoti

Bendrinti naudojant


Debugging Preparation: C++ Project Types

This section describes how to debug the basic project types created by the Visual C++ project templates.

Note that those project types that create DLLs as their output have been grouped into Debugging DLL Projects because of the common features they share.

In this topic

Recommended property settings

Win32 projects

Certain properties should be set the same way for all unmanaged debugging scenarios. The following tables display recommended property settings. Settings not listed here may vary among the different unmanaged project types. For more information, see Project Settings for a C++ Debug Configuration.

Configuration Properties | C/C++ | Optimization node

Property Name Setting
Optimization Set to Disabled (/0d). Optimized code is harder to debug, because the generated instructions do not correspond directly to your source code. If you find your program has a bug that appears only in optimized code, you can turn this setting on, but remember that code shown in the Disassembly window is generated from optimized source that might not match what you see in your source windows. Other features, such as stepping, might not behave as expected.

Configuration Properties | Linker | Debugging node

Property Name Setting
Generate debugging information You should always set this option to Yes (/DEBUG) to create debugging symbols and files needed for debugging. When the application goes into production, you can set it to off.

In this topic

Win32 projects

Win32 applications are traditional Windows programs written in C or C++. Debugging this type of application in Visual Studio is straightforward.

Win32 applications include MFC applications and ATL projects. They use Windows APIs and may use MFC or ATL, but they do not use the common language runtime (CLR). They can, however, call managed code that uses the CLR.

The following procedure explains how to debug a Win32 project from within Visual Studio. Another way to debug a Win32 application is to start the application outside of Visual Studio and attach to it. For more information, see Attach to Running Processes.

To debug a C or C++ Win32 application

  1. Open the project in Visual Studio.

  2. On the Debug menu, choose Start.

  3. Debug using the techniques discussed in First look at the debugger.

To manually set a Debug configuration

  1. On the View menu, click Property Pages.

  2. Click the Configuration Properties node to open it if it is not already

  3. Select General, and set the value of the Output row to Debug.

  4. Open the C/C++ node, and select General.

    In the Debug row you specify the type of debugging information to be generated by the compiler. Values you might choose include Program Database (/Zi) or Program Database for Edit & Continue (/ZI).

  5. Select Optimization, and in the Optimization row, select Disabled (/0d) from the drop-down list.

    Optimized code is harder to debug, because the generated instructions do not correspond directly to your source code. If you find your program has a bug that appears only in optimized code, you can turn this setting on, but remember that code shown in the Disassembly window is generated from optimized source that may not match what you see in your source windows. Features such as stepping are likely to show breakpoints and execution point incorrectly.

  6. Open the Linker node, and select Debugging. In the first Generate row, select Yes (/DEBUG) from the drop-down list. Always set this when you are debugging.

    For more information, see Project Settings for a C++ Debug Configuration.

    In this topic