GDB conditional breakpoint on arbitrary types such as C++ std::string equality

Is there any way I could set a conditional breakpoint on non-primitive types?

Yes, one way to do it is to convert non-primitive type to primitive one, in your case to char*, and use strcmp to compare strings.

condition 1 strcmp(myObject->myStringVar.c_str(),"foo") == 0

The answer to your question you asked is yes...in the general case it works for arbitrary classes and functions, and class member functions. You aren't stuck with testing primitive types. Class member overloads, like operator==, should work.

But I'd guess the problem with this case has to do with the operator== for std::string being a global templated operator overload:

http://www.cplusplus.com/reference/string/operators/

So the declarations are like:

template<class charT, class traits, class Allocator>
    bool operator==(const basic_string<charT,traits,Allocator>& rhs,
                const charT* lhs );

I wouldn't be surprised if gdb wouldn't know how to connect the dots on that for you.

Note that in addition to what @ks1322 said, you could stay in the C++ realm and more simply use std::string::compare():

condition 1 myObject->myStringVar.compare("foo") == 0

Tags:

Linux

C++

Gdb