Share via


Variable and Expression Watching

Use the Watch window to specify variables and expressions that you want to watch while debugging your program. You can also modify the value of a variable in the Watch window.

The Watch window contains four tabs: Watch1, Watch2, Watch3, and Watch4. Each tab displays a user-specified list of variables and expressions in a spreadsheet field. You can group variables that you want to watch together onto the same tab. For example, you could put variables related to a specific window on one tab and variables related to a dialog box on another tab. You could watch the first tab when debugging the window and the second tab when debugging the dialog box.

If you add an array, an object, or a structure variable to the Watch window, plus (+) or minus (–) boxes appear in the Name column. You can use these boxes to expand or collapse your view of the variable.

If the value of a variable appears in red, it indicates that the value has recently changed. Only the last value to change appears in red.

Note   Red is the default color. To change the color, choose Options from the Tools menu, and then choose the Format tab. Select one of the highlight items in the Colors box on the Format tab, for example, Value Highlight, choose a new color in the Foreground box, and then choose OK.

If the variable is an object, a reference, or a C++ pointer to an object, the Watch window automatically expands the variable to show the most important data at the top level. For example, suppose that you had the following C++ object.

CString String  =   {...}
char *   m_pchData =0x7ffdf000 "abc"
   int          m_nDataLength=4
   int          m_nAllocLength=1244628

The Watch window displays the following:

String  =   {"abc"}

If the variable is a reference or a C++ pointer to an object, the Watch window automatically downcasts the reference or pointer. The Watch window adds an extra member to the expanded object. This extra member, which looks like another base class, indicates the derived subclass. For example, if a variable that is declared as a C++ pointer to CObject really points to a CComboBox, the Watch window recognizes this and adds an extra member so that you can access the CComboBox members.

The Watch window displays values in their default format. You can use formatting characters to change the display format. The following example shows the command used to specify a hexadecimal value x as a Unicode character.

x,su 

In addition to the global variables of the current process, you can also review global variables of any module that is loaded, if you qualify the name with the context operator. For example, no matter what the current process is, you can examine the ProcArray structure in the kernel by typing a command in a Watch window. The following code example shows an example of this command.

{,,nk.exe}ProcArray 

You can review a module by casting a thread address. If you want to look at the thread structure for the Shell.exe process from the Processes command output, you can type a command in the Watch window. The following code example shows this, assuming the process address is 0:0x08cbe0a5.

(PTHREAD)0:0x08cbe0a5c 

The Watch window does not display variable type information. You can view information for a variable type by using the window's property page.

See Also

Debug Information Viewing | Viewing the Value of a Variable or Expression or the Contents of a Register in the Watch Window | Viewing the Value of a Variable or Expression or the Contents of a Register by Using QuickWatch | Character Formatting of Watch Variables

 Last updated on Friday, October 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.