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

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type the name of the variable.

  4. Click OK to set the breakpoint.

Setting a Breakpoint When an Expression Changes Value

To set a breakpoint when an expression changes value

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type an expression such as x+y.

  4. Click OK to set the breakpoint.

Setting a Breakpoint When an Expression Is True

To set a breakpoint when an expression is true

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type an expression, such as x==3, that evaluates to true or false.

  4. 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

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type the variable name.

  4. Select the drop-down arrow to the right of the text box.

  5. From the menu that appears, click Advanced.

    The Advanced Breakpoint dialog box appears.

  6. In the Expression text box, type the function name and (if necessary) the filename of the variable.

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

  8. 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

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type the first element of the array (myArray[0], for example).

  4. In the Number Of Elements text box on the Data tab, type 1.

  5. 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

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type an expression containing the initial element of the array (myArray[0]==1, for example).

  4. In the Number Of Elements text box, type 1.

  5. 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

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type the element of the array (myArray[12], for example).

  4. In the Number Of Elements text box, type 1.

  5. 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

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type the first element of the array (myArray[0]).

  4. In the Number Of Elements text box, type the number of elements in the array.

  5. 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

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type the first element of the array (myArray[0], for example).

  4. In the Number Of Elements text box, type n (for example, 10).

  5. Click OK to set the breakpoint on myArray[0] through myArray[9].

Setting a Breakpoint When the Location Value of a Pointer Changes

To break when the location value of a pointer changes

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type the pointer variable name (p, for example).

  4. 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

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type the dereferenced pointer variable name (*p or p->next, for example).

  4. 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

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type the dereferenced pointer variable name (*p, for example).

  4. 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.

  5. 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

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. 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 operator BY for a byte (optional), WO for a word, or DW 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.)

  4. 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 used WO, specify the number of words. If you used DW, specify the number of doublewords.

  5. Click OK to set the breakpoint.

Setting a Breakpoint When a Register Changes

To break when a register changes

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type a register mnemonic, such as CS.

  4. In the Number Of Elements text box, type the number of bytes to monitor.

  5. Click OK to set the breakpoint.

Setting a Breakpoint When a Register Expression Is True

To break when a register expression is true

  1. From the Edit menu, click Breakpoints.

  2. Click the Data tab of the Breakpoints dialog box.

  3. In the Expression text box, type an expression that contains a boolean comparison operator, such as CS==0.

  4. In the Number Of Elements text box, type the number of bytes to monitor.

  5. 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.