Why sometimes 'self' isn't available while debugging with lldb?

只愿长相守 提交于 2019-11-30 17:33:48

I usually get this error when I have compiler optimization turned on. The compiler will generate code which does not necessarily follow your code logic flow.

Go to your project in the navigator -> Target -> Build settings -> Search for optimization level -> expand optimization level -> select the debug line -> change to none in both columns of your project and target.

Hope this helps.

I was having this problem and it went away when I edited my scheme and set the Run build to Debug. I had set it to AdHoc for testing Push Notifications and that apparently makes LLDB unhappy.

Because it's optimized away. Let's use an example:

void f(int self) {
  // Here, "self" is live:Its value is used in the call to NSLog()
  NSLog(@"I am %d",self);
  // Here, "self" is dead: Its value is never used.
  // I could do self=0 or self=self*self and nobody would know.
  // An optimizing compiler will typically optimize it away.
  // It might still be on the stack (in the parameters passed to NSLog())
  // but the compiler shouldn't assume this.
  NSLog(@"Another function call: %d", 1);
  // If "self" was on the stack, it will probably now have been overwritten.
}

Compilers do a lot of things to make your code faster/smaller; forgetting about variables which are no longer needed is a very common optimization.

inigo333

As already said in this other question:

In Build Settings, setting Precompile Prefix Header to NO fixed it for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!