Setting Breakpoints When Values Change or Become True
You can set data breakpoints that halt execution when an expression changes value or evaluates to true. The debugger automatically knows whether “changes” or “true” makes sense for the variable or expression you have entered — you don’t need to set this yourself.
You can set a breakpoint on any valid C or C++ expression. Breakpoint expressions can also use memory addresses and register mnemonics. The debugger interprets all constants as decimal numbers unless they begin with '0' (octal) or '0x' (hexadecimal).
This section covers the following topics:
Setting a Breakpoint When a Variable Changes Value
Setting a Breakpoint When an Expression Changes Value
Setting a Breakpoint When an Expression Is True
Setting a Breakpoint On a Variable Outside the Current Scope
Setting a Breakpoint When the Initial Element of an Array Changes Value
Setting a Breakpoint When the Initial Element of an Array Has a Specific Value
Setting a Breakpoint When a Particular Element of an Array Changes Value
Setting a Breakpoint When Any Element of an Array Changes Value
Setting a Breakpoint When Any of the First n Elements of an Array Change Value
Setting a Breakpoint When the Location Value of a Pointer Changes
Setting a Breakpoint When the Value at a Location Pointed to Changes
Setting a Breakpoint When an Array Pointed to by a Pointer Changes
Setting a Breakpoint When the Value at a Specified Memory Address Changes
Setting a Breakpoint When a Register Changes
Setting a Breakpoint When a Register Expression is True
Setting a Breakpoint When a Variable Changes Value
To set a breakpoint when a variable changes value
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type the name of the variable.
Click OK to set the breakpoint.
Setting a Breakpoint When an Expression Changes Value
To set a breakpoint when an expression changes value
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type an expression such as
x+y
.Click OK to set the breakpoint.
Setting a Breakpoint When an Expression Is True
To set a breakpoint when an expression is true
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type an expression, such as
x==3
, that evaluates to true or false.Click OK to set the breakpoint.
Setting a Breakpoint on a Variable Outside the Current Scope
To break on a variable outside the current scope
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type the variable name.
Select the drop-down arrow to the right of the text box.
From the menu that appears, click Advanced.
The Advanced Breakpoint dialog box appears.
In the Expression text box, type the function name and (if necessary) the filename of the variable.
Click OK to close the Advanced Breakpoint dialog box.
The information that you specified appears in the Expression text box in the Breakpoints dialog box.
In the Breakpoints dialog box, click OK to set the breakpoint.
Note You can enter context information directly into the Expression field, using the advanced breakpoints syntax. For details, see Using Advanced Breakpoint Syntax.
Setting a Breakpoint When the Initial Element of an Array Changes Value
To break when the initial element of an array changes value
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type the first element of the array (
myArray[0]
, for example).In the Number Of Elements text box on the Data tab, type
1
.Click OK to set the breakpoint on
myArray [0]
.
Setting a Breakpoint When the Initial Element of an Array Has a Specific Value
To break when the initial element of an array has a specific value
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type an expression containing the initial element of the array (
myArray[0]==1
, for example).In the Number Of Elements text box, type
1
.Click OK to set the breakpoint on
myArray [0]
.
Setting a Breakpoint When a Particular Element of an Array Changes Value
To break when a particular element of an array changes value
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type the element of the array (
myArray[12]
, for example).In the Number Of Elements text box, type
1
.Click OK to set the breakpoint on
myArray [12]
.
Setting a Breakpoint When Any Element of an Array Changes Value
To break when any element of an array changes value
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type the first element of the array (
myArray[0]
).In the Number Of Elements text box, type the number of elements in the array.
Click OK to set the breakpoint on
myArray
.
Setting a Breakpoint When Any of the First n Elements of an Array Change Value
To break when any of the first n elements of an array change value
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type the first element of the array (
myArray[0]
, for example).In the Number Of Elements text box, type n (for example,
10
).Click OK to set the breakpoint on
myArray[0]
throughmyArray[9]
.
Setting a Breakpoint When the Location Value of a Pointer Changes
To break when the location value of a pointer changes
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type the pointer variable name (
p
, for example).Click OK to set the breakpoint.
Setting a Breakpoint When the Value at a Location Pointed to Changes
To break when the value at a location pointed to changes
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type the dereferenced pointer variable name (
*p
orp->next
, for example).Click OK to set the breakpoint.
Setting a Breakpoint When an Array Pointed to by a Pointer Changes
To break when an array pointed to by a pointer changes
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type the dereferenced pointer variable name (
*p
, for example).In the Number Of Elements text box, type the length of the array in elements. For example, if the pointer is a pointer to double, and the array pointed to contains 100 values of type double, type
100
.Click OK to set the breakpoint.
Setting a Breakpoint When the Value at a Specified Memory Address Changes
To break when the value at a specified memory address changes
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type the memory address for the byte.
For a word or doubleword memory address, enclose the address in parentheses, and precede it with a cast operator. For example,
WO(21406036
) for the word at memory location 21406036. Use the cast operatorBY
for a byte (optional),WO
for a word, orDW
for a doubleword. (The debugger interprets all integer constants as decimal unless they begin with zero (0) for octal or zero and x (0x) for hexadecimal.)In the Number Of Elements text box, type the number of bytes, words, or doublewords to monitor. If you used the
BY
operator in the Expression field, specify the number of bytes. If you usedWO
, specify the number of words. If you usedDW
, specify the number of doublewords.Click OK to set the breakpoint.
Setting a Breakpoint When a Register Changes
To break when a register changes
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type a register mnemonic, such as
CS
.In the Number Of Elements text box, type the number of bytes to monitor.
Click OK to set the breakpoint.
Setting a Breakpoint When a Register Expression Is True
To break when a register expression is true
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type an expression that contains a boolean comparison operator, such as
CS==0
.In the Number Of Elements text box, type the number of bytes to monitor.
Click OK to set the breakpoint.
Note When you set a data breakpoint, the debugger places the variable or variables used into a special debug register, if possible. The number of debug registers is limited. (Intel 80386 and later CPUs provide four debug registers. Motorola 680X0 and PowerPC chips have no debug registers.) Furthermore, stacked-based variables (parameters) cannot be placed into debug registers. If a breakpoint variable cannot be placed into a debug register, the debugger must examine the variable’s memory location after every instruction to determine whether the contents have changed. These extra memory accesses reduce execution speed of the program with the debugger. In some cases, the program may appear to hang. Performance may be especially slow if you are debugging a remote application.