FIX: Conditional Breakpoint Doesn't Stop in Recursive Function

ID: Q123160


The information in this article applies to:
  • The Integrated Debugger, included with:
    • Microsoft Visual C++ for Windows, versions 1.5, 1.51
    • Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, 2.10


SYMPTOMS

Using "Break when Expression is True" in a recursive function in the Visual C++ integrated debugger may fail to stop program execution even if the expression becomes true.


RESOLUTION

Instead of using "Break when Expression is True," use "Break at Location if Expression is True" to work around the problem.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was not reproducible in Microsoft Visual C++, 32-bit Edition, version 4.0.


MORE INFORMATION

To demonstrate the problem, build the sample code below for debug mode and do the following:

  1. Choose Breakpoints... from the Debug menu.


  2. In the Breakpoints dialog, select "Break when Expression is True" for the Type field.


  3. In the Expression field, type {function1}(i==2) to specify the expression.


  4. Add the above breakpoint to the "Breakpoints:" list.


  5. Start the debugger. You will notice that the debugger terminates the debug session without breaking, even though i was equal to 2 at one point.


Sample Code


/* Compile options needed: /Zi /Od
*/ 

#include <stdio.h>

int function1( int i, int j )
{
  if ( i>0 )
  {
    return function1( i-1, j+1 );
  }
  else
  {
    return j;
  }
}

void main(void)
{
  int i;

  printf( "Before Recursive Call.\n" );
  i = function1( 10, 0 );
  printf( "Back from Recursive Call.\n" );
} 

Additional query words: 1.00 1.50 2.00 2.10

Keywords : kbDebug kbide
Version : winnt:
Platform : winnt
Issue type :


Last Reviewed: February 2, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.