Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode: can't figure out Hit Count condition

This should be such an easy question to answer. I'm a bit of a newbie to Visual Studio Code and I'm struggling to work out how to get the "Hit Count" conditional breakpoint feature to work. I've got a simple for loop set up like this:

for (int i = 0; i < 10; i++)
{
  cout << i << endl;
}

I put a breakpoint on the cout line, right-clicked it and clicked "Edit Breakpoint..." and changed the drop-down box to "Hit Count". I want to simply have the breakpoint fire on the 5th iteration through the for loop, but I can't figure out how to write the expression. No matter what I write, the program breaks at the first pass through the loop. I've tried "5", "== 5" and "Hit Count == 5" but nothing works.

enter image description here

If anyone could tell me what I'm doing wrong, I'd be grateful! All the stuff I can find online is about Visual Studio and not VSCode.

like image 586
Andy Latham Avatar asked Jan 24 '26 23:01

Andy Latham


2 Answers

This link helps you.

https://github.com/microsoft/vscode/issues/13211

I think, If you want to use it when hit-count is 5, you can write '= 5'.

example

  • '> 10' break after 10 hits
  • '< 3' break on the first two hits
  • '= 10' same 10
  • '>= 10' Greater than or equal to 10.

For me,(using javascript) You can see the change(the output value 'i') in the left 'watch' section.
enter image description here

  • 1-hit-count, the output value 'i': 0
  • 2-hit-count, the output value 'i': 1
  • 3-hit-count, the output value 'i': 2
  • 4-hit-count, the output value 'i': 3
  • 5-hit-count, the output value 'i': 4
  • 6-hit-count, the output value 'i': 5
  • 7-hit-count, the output value 'i': 6
  • 8-hit-count, the output value 'i': 7
  • 9-hit-count, the output value 'i': 8
  • 10-hit-count, the output value 'i': 9

I set "hit-count '>= 5' ". so 4, 5, 6, 7, 8, 9(the output value 'i') are printed

I hope this helps

like image 60
romanus Avatar answered Jan 27 '26 18:01

romanus


The Hit Count feature is NOT supported by the GDB C++ debugger.

like image 38
Ahmed Ragab Avatar answered Jan 27 '26 18:01

Ahmed Ragab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!