0

I have two loops, one is nested. And this code just shifting data chunks in memory. When I set a breakpoint to catch when there are incorrect addresses, it almost stopes the loop and it starts running very slow(> 1 min). I tried to store addresses values in variables and then just compare them in breakpoint: ad1 != ad2 || ad3 != ad4. But it still slows down the code and for some reason the list size is changing to a huge value. When I'm turning off the breakpoint it goes fine.

Any ideas what's wrong?

Fun
  • 43
  • 3

1 Answers1

1

Conditional breakpoints are expensive in time-critical code. I suggest you move the check in code and outside the breakpoint, and set the breakpoint inside the if.

So :

if (ad1 != ad2){
    // Statement on which you break
}

The statement can be a printf so it doesn't get optimized away.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
  • What I actually do. But I'm still interesting why any condition breakpoint in exactly one place in the code has such behavior. In another loops with this job it works good. – Fun Aug 24 '23 at 19:26
  • @Fun Are both lopps called as frequently? If it's just one call per second, it won't be noticeable, if it's hundreds or thousands, it will. The breakpoint check isn't as cheap as a check in code, an interrupt is inserted in the executable and the debugger checks the values, unlike executing a simple cmp on the processor. – Luchian Grigore Aug 25 '23 at 11:20
  • I checked the iteration count of all these loops and find that it's actually a big value. So yea, in this case the condition breakpoint is affecting to the runtime. But can you tell me where I can read about how conditional breakpoint is calculating by debugger? I thought that the "price" of con. breakpoint depends on conditional expression length - the shorter the faster , but it's wrong as I found. – Fun Aug 25 '23 at 15:27