共用方式為


Debugging Preparation: Visual 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

  • To debug a C or C++ Win32 application

  • To manually set a Debug configuration

Windows Forms applications (.NET)

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 with the Visual Studio Debugger.

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 Debugger Roadmap.

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, seeProject Settings for a C++ Debug Configuration.

In this topic

Windows Forms applications (.NET)

The Windows Forms Application (.NET) template creates a Visual C++ Windows Forms application. For more information, see How to: Create a New Windows Forms Application Project.

Debugging this type of application in Visual Studio is similar to that in managed Windows Forms applications.

When you create a Windows Forms project with the project template, Visual Studio automatically creates required settings for the Debug and Release configurations. If necessary, you can change these settings in the <project name> Property Pages dialog box. For more information, see Debug and Release Configurations.

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

Another way to debug a Windows Forms application is to start the application outside of Visual Studio and attach to it. For more information, see Attaching to a Running Program or Multiple Programs.

In this topic

See Also

Tasks

Debug and Release Configurations

How to: Create a New Windows Forms Application Project

Reference

Project Settings for a C++ Debug Configuration

Other Resources

Debugger Roadmap

Attaching to a Running Program or Multiple Programs