Setting Breakpoints Outside the Current Scope

If you want to set a breakpoint on a location or variable that is not within the current scope, there are two ways to do it:

  • Use the Advanced Breakpoint dialog box.

  • Specify the breakpoint directly on the Location or Data tab of the Breakpoints dialog box, using advanced breakpoint syntax.

Both methods achieve the same result, but the Advanced Breakpoint dialog box handles many details for you and does not require you to learn any special syntax.

Using the Advanced Breakpoint Dialog Box

To break on a location outside the current scope

  1. From the Edit menu, click Breakpoints.

  2. Click the Location tab on the Breakpoints dialog box.

  3. Select the drop-down arrow next to the Break At text box.

  4. From the menu that appears, click Advanced.

    The Advanced Breakpoint dialog box appears.

  5. In the Location text box, type the location (source line number, memory address, or function name) where you want to set the breakpoint.

  6. Under Context, type any necessary information in the Function, Source File, and Executable File text boxes. (It is not necessary to fill in all fields — only the ones you need to qualify the context.

    For example, to set a breakpoint at a line number in another source file, specify only the source file. To set a breakpoint in a dynamic-link library (DLL), you must specify the function, source file, and DLL. The DLL filename goes in the Executable File text box.)

  7. Click OK to close the Advanced Breakpoint dialog box.

    The information that you specified appears in the Break At text box in the Breakpoints dialog box.

  8. In the Breakpoints dialog box, click OK to set the breakpoint.

Using Advanced Breakpoint Syntax

To use advanced breakpoints syntax, you must qualify a breakpoint location or variable with a special context operator, as follows:

  • {[function],[source],[exe] } location

  • {[function],[source],[exe] } variable_name

  • {[function],[source],[exe] } expression

The context operator is a pair of braces ({}) containing two commas, and some combination of function name, source filename, and executable filename. If you omit either function or exe, the two commas cannot be omitted. The following syntax, for example, is illegal:

{File.c, File.exe} .143 — Bad

If you omit both source and exe, however, you can omit the commas. The following syntax is legal:

{Fun} .143

The location can be any line number, function, or memory address at which you can set a breakpoint. For example,

  • {[function],[source],[exe] }  .100 — A line number (this may not work with some languages)

  • {[function],[source],[exe] }  @100 — A line number (this works for all languages)

  • {[function],[source],[exe] }  Traverse — A function name

  • {[function],[source],[exe] }  CMyWindow::OnCall — A function name

  • {[function],[source],[exe] }  00406030 — A memory address (decimal)

  • {[function],[source],[exe] }  0x1002A — A memory address (hexadecimal)

  • {function,[source],[exe] } Label — A statement label. The context must include function since Label is visible in the function’s scope.

If the source or exe filename includes a comma, an embedded space, or a brace, you must use quotation marks around the filename so that the context parser can properly recognize the string. Single quotation marks are considered to be part of a Windows NT/Windows 95 filename, so you must use double quotation marks. For example,

{,a long, long, name.c, } .143

Another form of advanced breakpoints syntax uses the exclamation point instead of the context operator:

source!.location

This form of advanced breakpoint syntax does not include a function name or .EXE specifier. If you use this syntax to specify a filename that contains an exclamation point, you must surround the filename with double quotes:

“File.!c”!.115

You can also set data breakpoints. For more information, see Setting Breakpoints When Values Change or Become True.