I'm very confused about conditional breakpoints in gdb.
Recently, I wanted to put a breakpoint which breaks when a specific variable is equal to "foo" in a C++ program.
To do that I typed this in the gdb CLI :
break LINE_NUMBER if strcmp(myVar, "foo") == 0
but it took me a very long time and a lot of tries to find how to code it.
I've first started with :
break LINE_NUMBER if myVar == "foo"
break LINE_NUMBER if myVar.c_str() == "foo"
...
before I finally found out conditional breakpoints MAY have to be programmed in C.
Anyone knows where the rules to code conditional breakpoints are written ?
I've read the documentation but didn't find the info I needed...
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Conditions.html#Conditions
Documentation explicitly states that a condition is a Boolean expression in your programming language:
Your program is written in C++ so in theory any valid C++ Boolean expression should work. But in practice GDB has a limited support of C++ expressions, only some subset of them works,
strcmp(myVar, "foo") == 0is one of the examples which works. You can find some areas of improvement on Expression Evaluation on GDB Wiki.