This chapter examines the tools available for debugging Microsoft Foundation Class-based applications. You will learn how to prepare a project for debugging, build a project in debug mode, and enable various debugging options.
After completing this chapter, you will be able to:
® Prepare MFC projects for debugging.
® Use Developer Studio debugger and Visual C++ debugging tools.
® Add MFC debugging support to an application.
Debugging is the process of correcting or modifying your code so that your project can build cleanly, run smoothly, perform as expected, and be easy to maintain.
The Developer Studio debugger provides menus, windows, dialog boxes, and spreadsheet fields to help you track down errors. You can use drag-and-drop functionality to move debug information between components.
This section includes the following topics:
When you create a project in Developer Studio, you can build a debug version or a release version of a project. The debug version uses a different set of DLLs than the release version. Only release versions of a project can be distributed due to licensing restrictions on the DLLs used for debugging.
When you create a debug version of a project using the default settings, Developer Studio provides full symbolic debugging information in Microsoft Format. By default, no optimization features are set; generally, optimization makes debugging your program more difficult. By default, the release version of a project is optimized for maximum speed and performance; it includes no symbolic debugging information.
To build a debug version of your project using the default settings
1. On the Project menu, click Settings.
2. In the Project Settings dialog box, select Win32 Debug, and then click OK to select the default settings.
3. On the Build menu, click Set Active Configuration.
4. Build your program.
You can change the default debug options ; for example, you can instruct the compiler to output line numbers only, to generate a mapfile, or to redirect output.
Commands for debugging can be found on the Build menu, the Debug menu, the View menu, and the Edit menu. The following table describes the debugging menus.
Menu name Description
Debug Appears in the menu bar while the debugger is running (even if it is stopped at a breakpoint); the floating Debug toolbar also appears. From the Debug menu, you can control program execution and open the QuickWatch window. When the debugger is not running, the Debug menu is replaced by the Build menu.
View Contains commands that display the various debugger windows, such as the Variables window and the
Call Stack window.
Edit Provides access to the Breakpoints dialog box, from which you can insert, remove, enable, or disable breakpoints.
For more information about the debugger menus, see "Debugger Menu Items" in the Developer Studio online documentation.
Developer Studio provides a floating debugger toolbar and a miniature debugger toolbar to make most common debugging tasks easier. To access the debugger toolbars, right-click in any blank area on the Developer Studio menu bar. A pop-up menu will appear. To see an illustration that shows the Developer Studio environment with the pop-up menu displayed, click this icon.
Click Debug on the pop-up menu to display the floating debugger toolbar.
You can keep the Debug toolbar open while debugging your applications. The Debug toolbar also can be moved, docked, or closed to suit your debugging needs. If you forget what a particular symbol on the Debug toolbar means, pause the mouse pointer over the symbol and its function will appear.
Click Build MiniBar on the pop-up menu to display the miniature debugging toolbar. To see what functions are available, pause the mouse pointer over the symbols and descriptions will appear. The MiniBar is useful for setting breakpoints, stepping through applications, and viewing variables.
Several specialized windows display debugging information for your program. The following table lists the available debugging windows: Output, Watch, Variables, Registers, Memory, Call Stack, and Disassembly, and describes what they do.
Window name Description
Watch Displays names and values of variables and expressions.
Variables Displays information about variables used in the current and previous statements and function return values (on the Auto tab); variables local to the current function (on the Locals tab); and the object pointed to by the specified address (on the This tab).
Registers Displays the contents of the general-purpose and CPU status registers.
Memory Displays the current memory contents.
Call Stack Displays the stack of all function calls that have not returned.
Disassembly Displays the assembly-language code derived from disassembly of the compiled program.
When you are debugging, you can access the Output window by clicking Output on the View menu. You can access the other debugging windows by pointing to Debug Windows on the View menu and then clicking on the appropriate debugging window.
Debugger windows can be docked or floating. When a window is in floating mode, you can resize or minimize the window to increase the visibility of other windows.
You can copy information from any debugger window. You can print information only from the Output window.
To set formatting and other options for these windows, on the Tools menu, click Options, then click the Debug tab.
For more information about debugger windows, see "Working with Floating or Docking Windows" and "Debugger Windows" in the Developer Studio online documentation.
® Debugger Dialog Boxes
Dialog box Description
Breakpoints Displays a list of all breakpoints assigned to your project. Use the tabs in the Breakpoints dialog box to create new breakpoints of various types.Exceptions Displays system and user-defined exceptions for your project. Use the Exceptions dialog box to control how the debugger handles exceptions.
QuickWatch Displays a variable or expression. Use the QuickWatch dialog box to quickly view or modify a variable or expression, or to add it to the Watch window.
Threads Displays application threads available for debugging. Use the Threads dialog box to suspend and resume threads, and to set focus.
For more information about specific debugger dialog boxes, see "The Debugger Interface" in the Developer Studio online documentation.
No comments:
Post a Comment