PRB: Conditional Breakpoints Cannot Always Be Set (78853)



The information in this article applies to:

  • The Integrated Debugger, when used with:
    • Microsoft Visual C++ for Windows, 16-bit edition 1.0
    • Microsoft Visual C++ for Windows, 16-bit edition 1.5
    • Microsoft Visual C++ for Windows, 16-bit edition 1.51
    • Microsoft Visual C++ for Windows, 16-bit edition 1.52
    • Microsoft Visual C++, 32-bit Editions 1.0
    • Microsoft Visual C++, 32-bit Editions 2.0
    • Microsoft Visual C++, 32-bit Editions 2.1
    • Microsoft Visual C++, 32-bit Editions 4.0
    • Microsoft Visual C++, 32-bit Editions 5.0

This article was previously published under Q78853

SYMPTOMS

In the Visual Workbench debugger, an attempt to set conditional breakpoints may fail. A message box may appear containing a message such as
The breakpoint <breakpoint_name> cannot be set.
Or, as with the Developer Studio debugger included with Visual C++ 4.0 and later, the conditional breakpoint may appear to be set, but when the debug session is initiated, a message box may appear containing the following text:
One or more of the breakpoints cannot be set and have been
disabled. Execution will stop at the beginning of the program.

CAUSE

This problem occurs only when you attempt to set the breakpoint while the specified variable is out of scope.

RESOLUTION

There are two methods to address this situation:

  • Trace into the program until the variable is in scope, then set the breakpoint.
  • Specify the context of the variable when you set the breakpoint. For example, specify a breakpoint on "{main}a" instead of on "a".

MORE INFORMATION

Perform the following six steps to demonstrate this error with Visual C++ versions 2.x and earlier:

  1. Create a new application to contain the code example below.
  2. From the Project menu, choose Options. In the Program Type list box, choose QuickWin EXE and choose OK.
  3. Choose Build from the Project menu to build the sample program.
  4. Choose Breakpoints from the Debug menu; a dialog box appears.
  5. Set the Break field to "If Expr is True" and type "a" in the Expression edit control. Because the default length is 1 as is the size of "a," choose the Add button, then choose OK.
  6. Press F5 to run the program.
Perform the following six steps to demonstrate this error with the Developer Studio:

  1. Create a new console application project.
  2. Save the code example below as t.c and add it to the project.
  3. Choose Build t.exe from the Build menu.
  4. Choose Breakpoints... from the Edit menu. The Breakpoints dialog box appears.
  5. In the Location Tab, type "main" in the Break at field. Press the Condition button to display the Breakpoint Condition dialog box. Type "a" in the Break when expression changes field. Press OK to close the Breakpoint Condition dialog box. Press OK to close the Breakpoints dialog box.
  6. Press F5 to run the program.
At this point, a message box appears with the error message listed in the SYMPTOMS section above and the breakpoint is not set. When you choose OK in the error message box, programs debugged with Visual C++ versions 2.x and earlier run to completion because no breakpoints are set; programs debugged with Developer Studio halt at the beginning of the program (as if a breakpoint were set) and may be stepped through if desired.

If you are setting a breakpoint from within a C++ member function, you need to specify '{ClassName::Member}' in order to set the breakpoint properly.

Sample Code

   /*
    * Compile options needed: none
    */ 

   void main(void)
   {
      char a;

      a = 'a';
   }
				
NOTE: The breakpoint evaluator doesn't take into account the preprocessor's #define statements.

Modification Type:MajorLast Reviewed:12/12/2003
Keywords:kbBug kbDebug kbide kbprb KB78853