Page 1 of 1

Breakpoint condition: variable content

Posted: Sat May 23, 2020 4:00 pm
by codemonster
Hello,
is it passible to set a breakpoint dependent on the value of a variable?

Thanks

Re: Breakpoint condition: variable content

Posted: Sat May 23, 2020 4:47 pm
by DavidGH
Hi,
is it possible to set a breakpoint dependent on the value of a variable?
Yes, of course; that's the sort of thing that Conditional Breakpoints do. See this (rather outdated) wiki page; the bottom picture shows the 'Create a Breakpoint or Watchpoint' dialog. In its Conditional Breaks field you can set any sensible expression e.g.
n>6
or
baz=="foobar"

Regards,

David

Re: Breakpoint condition: variable content

Posted: Sat May 23, 2020 6:40 pm
by codemonster
Hello,
yes, but it works strange:

Code: Select all

#include <iostream>
// Testprogram

int main()
{
    int x{ 1 };
    while (x++ < 8){
        std::cout << "x=" << x << std::endl;
        std::cout << "------" << std::endl;
    }
    return 0;
}
breakpoint in line 9 with condition: x=5

start/continue Debugger

Output (Terminal Settings = CMD):
x=2

then program stops

next command of me

Output next…... next:
-------
x=6
------
x=6
.......

Re: Breakpoint condition: variable content

Posted: Sat May 23, 2020 7:48 pm
by DavidGH
breakpoint in line 9 with condition: x=5
Perhaps the condition should be:
x==5

Re: Breakpoint condition: variable content

Posted: Sat May 23, 2020 8:40 pm
by codemonster
Thanks, that was the solution!