Microsoft KB Archive/171065: Difference between revisions

From BetaArchive Wiki
m (Text replacement - ">" to ">")
m (Text replacement - """ to """)
 
Line 101: Line 101:
  int main()
  int main()
  {
  {
     cout << &quot;Start debugging&quot; << endl;
     cout << "Start debugging" << endl;


     for( int i = 0; i < 100; ++i )
     for( int i = 0; i < 100; ++i )
         cout << i << &quot;\n&quot;;        //SET A BREAKPOINT HERE
         cout << i << "\n";        //SET A BREAKPOINT HERE


   return 0;
   return 0;
Line 112: Line 112:
<br />
<br />


# From the Edit menu select &quot;Breakpoints...&quot;.
# From the Edit menu select "Breakpoints...".
# You will see in the dialog box for the Location tab that the breakpoint is set &quot;at{,test.cpp&quot;,}.line#&quot;. Highlight this breakpoint, and Condition is enabled. Click Condition.
# You will see in the dialog box for the Location tab that the breakpoint is set "at{,test.cpp",}.line#". Highlight this breakpoint, and Condition is enabled. Click Condition.
# A dialog box with an edit box entitled &quot;Enter the number of times to skip before stopping&quot; appears. Enter number 5 and click OK.
# A dialog box with an edit box entitled "Enter the number of times to skip before stopping" appears. Enter number 5 and click OK.
# Click OK again to close the dialog box.
# Click OK again to close the dialog box.
# From the Edit menu select &quot;Breakpoints...&quot; again. You will see that the text in the Breakpoints box now reads &quot;at{,test.cpp&quot;,}.line#,skip 5 time(s),(5 remaining)&quot;.
# From the Edit menu select "Breakpoints..." again. You will see that the text in the Breakpoints box now reads "at{,test.cpp",}.line#,skip 5 time(s),(5 remaining)".
# Click Cancel or OK to close the dialog box.
# Click Cancel or OK to close the dialog box.
# With the above setting, you want to skip the line of code with the breakpoint the specified number of times. Press the F5 key, and you will find that the breakpoint has been skipped 5 times and the value of i is now 7.
# With the above setting, you want to skip the line of code with the breakpoint the specified number of times. Press the F5 key, and you will find that the breakpoint has been skipped 5 times and the value of i is now 7.
# Again, from the Edit menu select &quot;Breakpoints...&quot;. This time you will notice that the text in the Breakpoints box reads &quot;at{,test.cpp&quot;,}.line#,skip 5 time(s),(0 remaining)&quot;.
# Again, from the Edit menu select "Breakpoints...". This time you will notice that the text in the Breakpoints box reads "at{,test.cpp",}.line#,skip 5 time(s),(0 remaining)".
# Click Condition button, and notice that the skip count is still 5.
# Click Condition button, and notice that the skip count is still 5.
# If you press the F5 key again, the breakpoint is not skipped 5 times. Instead it stops for every increment of i.
# If you press the F5 key again, the breakpoint is not skipped 5 times. Instead it stops for every increment of i.
Line 127: Line 127:
Change the skip count to a value other than the last set using Condition. For example set it to 0, click OK, and go back to main dialog box. Set Condition to 5, click OK, and click OK again to close the main dialog box. Press the F5 key, and the breakpoint is skipped 5 times. You must repeat this process every time you want to skip more than once.<br />
Change the skip count to a value other than the last set using Condition. For example set it to 0, click OK, and go back to main dialog box. Set Condition to 5, click OK, and click OK again to close the main dialog box. Press the F5 key, and the breakpoint is skipped 5 times. You must repeat this process every time you want to skip more than once.<br />
<br />
<br />
Alternatively, if your loop has a count variable like &quot;i&quot; in the sample code above, you can use conditional breakpoint to get the same effect. Set breakpoint to break when 'i % 5 == 0' is true.
Alternatively, if your loop has a count variable like "i" in the sample code above, you can use conditional breakpoint to get the same effect. Set breakpoint to break when 'i % 5 == 0' is true.


</div>
</div>

Latest revision as of 10:05, 21 July 2020

Article ID: 171065

Article Last Modified on 12/10/2003



APPLIES TO

  • The Integrated Debugger, when used with:
    • Microsoft Visual C++ 5.0 Enterprise Edition
    • Microsoft Visual C++ 6.0 Enterprise Edition
    • Microsoft Visual C++ 5.0 Professional Edition
    • Microsoft Visual C++ 6.0 Professional Edition
    • Microsoft Visual C++ 6.0 Standard Edition



This article was previously published under Q171065

SYMPTOMS

If you set a breakpoint with a skip count, the debugger behaves correctly and stops at the breakpoint for the first time after skipping the breakpoint the number of counts specified. However, after the first pass the breakpoint is hit every time without skipping the breakpoint for the specified counts.

CAUSE

The debugger resets the skip count to 0 after the first pass.

RESOLUTION

See the MORE INFORMATION section for a workaround.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

This problem was corrected in Microsoft Visual C++ .NET.


MORE INFORMATION

The skip count feature is very useful in a loop where you want to stop inside the loop after skipping a line of code for a certain number of times. The following sample describes a situation of this nature.

Steps to Reproduce Behavior

Build the following code with debug information.

// File name test.cpp

 #include <iostream.h>

 int main()
 {
     cout << "Start debugging" << endl;

     for( int i = 0; i < 100; ++i )
         cout << i << "\n";        //SET A BREAKPOINT HERE

   return 0;
 }
                

Set a breakpoint on the line shown and press the F5 key (Debug Go). The debugger will stop at this line of code. The Auto window will show the value of i to be 0. Press the F5 key. Again, the debugger stops at the breakpoint and the value of i is shown to be 1.

  1. From the Edit menu select "Breakpoints...".
  2. You will see in the dialog box for the Location tab that the breakpoint is set "at{,test.cpp",}.line#". Highlight this breakpoint, and Condition is enabled. Click Condition.
  3. A dialog box with an edit box entitled "Enter the number of times to skip before stopping" appears. Enter number 5 and click OK.
  4. Click OK again to close the dialog box.
  5. From the Edit menu select "Breakpoints..." again. You will see that the text in the Breakpoints box now reads "at{,test.cpp",}.line#,skip 5 time(s),(5 remaining)".
  6. Click Cancel or OK to close the dialog box.
  7. With the above setting, you want to skip the line of code with the breakpoint the specified number of times. Press the F5 key, and you will find that the breakpoint has been skipped 5 times and the value of i is now 7.
  8. Again, from the Edit menu select "Breakpoints...". This time you will notice that the text in the Breakpoints box reads "at{,test.cpp",}.line#,skip 5 time(s),(0 remaining)".
  9. Click Condition button, and notice that the skip count is still 5.
  10. If you press the F5 key again, the breakpoint is not skipped 5 times. Instead it stops for every increment of i.

Workaround

Change the skip count to a value other than the last set using Condition. For example set it to 0, click OK, and go back to main dialog box. Set Condition to 5, click OK, and click OK again to close the main dialog box. Press the F5 key, and the breakpoint is skipped 5 times. You must repeat this process every time you want to skip more than once.

Alternatively, if your loop has a count variable like "i" in the sample code above, you can use conditional breakpoint to get the same effect. Set breakpoint to break when 'i % 5 == 0' is true.

Keywords: kbbug kbfix kbnoupdate kbide kbdebug KB171065