FIX: Conditional Breakpoint Doesn't Stop in Recursive Function

Last reviewed: September 18, 1997
Article ID: Q123160
1.50 1.51 | 1.00 2.00 2.10
WINDOWS   | WINDOWS NT
kbtool kbfixlist

The information in this article applies to:

  • The Integrated Debugger, included with:

        - Microsoft Visual C++ for Windows, versions 1.5 and 1.51
        - Microsoft Visual C++, 32-bit Edition, versions 1.0, 2.0, 2.1, and
    

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)" (without the quotation marks) 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 reference words: 1.00 1.50 2.00 2.10
KBCategory: kbtool kbfixlist
KBSubcategory: WBDebug
Keywords : WBDebug kbfixlist kbtool
Version : 1.50 1.51 | 1.00 2.00 2.10
Platform : NT WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.