Set a breakpoint that stops the code whenever a variable matches a given value, in XCode

Viewed 26

In the following minimal code

#include <iostream>

class MyClass{
    
public:
    
    bool x;
    
    void MyFunction();  
    
};

void MyClass::MyFunction(void){
    
    std::cout << "You just called MyFunction\n";
    
}

int main(int argc, const char * argv[]) {

    MyClass my_class;
    my_class.MyFunction();

    return 0;
    
}

I would like, in XCode, to stop the code with a breakpoint or watchpoint whenever the variable x of MyClass equals true. I have tried with watchpoints and symbolic breakpoints, but nothing works.

Do you know how to do this? Thanks!

1 Answers

Use a conditional breakpoint.

Set a breakpoint on a line of code in Xcode's editor. Select the breakpoint, right-click, and choose Edit Breakpoint.

A popover opens. Enter the condition in the Condition text field.

Related