1

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Hikarus
  • 325
  • 4
  • 17
  • It works fine for me (in Xcode 10.1 in Swift). Is that an ivar? local var? What version of Xcode (really just 10 or 10.1)? Swift or Objective-C? Perhaps you can describe a little more about how to reproduce this behavior. – Rob Jan 09 '19 at 20:59
  • @Rob it's XCode 10.1 with Swift. And now that you mention it, it works for local variables only... is this supposed to be a normal behavior? shouldn't we be able to watch global variables as well?... – Hikarus Jan 09 '19 at 22:18
  • It works with both globals and ivars for me, fine. I run with breakpoint somewhere where I know the variable is initialized (e.g. in `viewDidLoad` or whatever), so I’m in frame for that variable, add the “watch”, continue execution, and it correctly identifies changes to that variable, whether ivar or global. Perhaps you can create a [MCVE](https://stackoverflow.com/help/mcve) and outline the precise steps that you’re taking, because it’s working fine for me. You need to help us reproduce the problem you’re describing. – Rob Jan 09 '19 at 22:25

1 Answers1

0

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 :)

Hikarus
  • 325
  • 4
  • 17