How do I set a watchpoint in Xcode 10?

1k Views Asked by At

Theoretically, if we interrupt the execution of the app, and we right click on a variable listed in the variables' section of the debug area, we get a contextual menu with the option "Watch variableName", and if we click on it, a watchpoint is set for that variable... BUT...I always get this nasty message: "error: no variable named '$R#' found in this frame", where # varies depending on the variable I try to watch.

Am I doing something wrong here?

1

There are 1 best solutions below

0
Hikarus On

My bad: I hadn't realized that in order to set a watchpoint for a variable, the execution must be stopped at the module WHERE THE VARIABLE IS DECLARED. Which makes no sense in the case of global variables, since their scope is the entire application. I stop execution at a point in another module where I'm actually using that variable, but since it's a module where it was not DECLARED, I get that weird error. So, I set a breakpoint at the very line where I declare the variable, and I'm able to set the watchpoint.

Thanks, @Rob, 'cos your question about the scope of the variable made me think about it :)